PageRenderTime 103ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 31ms app.codeStats 21ms

/src/mpv5/utils/ooo/OOOPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 143 lines | 76 code | 21 blank | 46 comment | 9 complexity | 1795270673fe0c8747f93f0ac2a65b50 MD5 | raw file
  1package mpv5.utils.ooo;
  2
  3
  4import javax.swing.JPanel;
  5import java.awt.BorderLayout;
  6import ag.ion.bion.officelayer.desktop.GlobalCommands;
  7import ag.ion.bion.officelayer.desktop.IFrame;
  8import ag.ion.bion.officelayer.document.DocumentDescriptor;
  9import ag.ion.bion.officelayer.document.IDocument;
 10import ag.ion.bion.officelayer.form.IFormComponent;
 11
 12import ag.ion.bion.officelayer.text.ITextDocument;
 13import com.sun.star.awt.XTextComponent;
 14import com.sun.star.beans.XPropertySet;
 15import com.sun.star.form.XFormComponent;
 16import com.sun.star.uno.UnoRuntime;
 17import enoa.connection.NoaConnection;
 18import java.io.File;
 19import java.util.Hashtable;
 20
 21
 22import mpv5.globals.Messages;
 23import mpv5.logging.Log;
 24import mpv5.ui.frames.MPView;
 25
 26public class OOOPanel extends JPanel {
 27
 28    public OOOPanel() {
 29        super(new BorderLayout());
 30    }
 31
 32    /**
 33     * Loads the given template into this panel.
 34     *
 35     * @param odtFile
 36     * @deprecated Do not use this, needs a local OO installation and has never worked well.
 37     */
 38    @Deprecated
 39    public void constructOOOPanel(final File odtFile) {
 40            mpv5.YabsViewProxy.instance().setWaiting(true);
 41
 42            ITextDocument textDocument;
 43            setVisible(true);
 44
 45            try {
 46                IFrame officeFrame = NoaConnection.getConnection().getDesktopService().constructNewOfficeFrame(this);
 47                officeFrame.setFocus();
 48                if (odtFile != null) {
 49                    IDocument document = NoaConnection.getConnection().getDocumentService().loadDocument(officeFrame, odtFile.getPath());
 50                    textDocument = (ITextDocument) document;
 51                } else {
 52                    NoaConnection.getConnection().getDocumentService().constructNewDocument(officeFrame, IDocument.WRITER, DocumentDescriptor.DEFAULT);
 53                }
 54
 55                configureFrame(officeFrame);
 56            } catch (Exception ex) {
 57                Log.Debug(ex);
 58            } finally {
 59                getParent().validate();
 60                mpv5.YabsViewProxy.instance().setWaiting(false);
 61            }
 62            mpv5.YabsViewProxy.instance().addMessage(Messages.OO_DONE_LOADING);
 63        
 64    }
 65
 66    /**
 67     * Configures the given IFrame to print the closed document's path to System.out on close<br/>
 68     * and removes the Close and Quit capabilites of the frame
 69     * @param officeFrame
 70     */
 71    public void configureFrame(IFrame officeFrame) {
 72//
 73//        officeFrame.addDispatchDelegate(GlobalCommands.SAVE, new IDispatchDelegate() {
 74//
 75//            @Override
 76//            public void dispatch(Object[] arg0) {
 77//                try {
 78//                    QueryHandler.instanceOf().clone(Context.getFiles()).insertFile(new File(NoaConnection.getConnection().getDocumentService().getCurrentDocuments()[0].getPersistenceService().getLocation().getPath()),
 79//                            mpv5.db.objects.User.getCurrentUser(), new SaveString("Template", true));
 80//                } catch (DocumentException ex) {
 81//                    Log.Debug(ex);
 82//                }
 83//            }
 84//        });
 85//
 86//        officeFrame.addDispatchDelegate(GlobalCommands.OPEN_DOCUMENT, new IDispatchDelegate() {
 87//
 88//            @Override
 89//            public void dispatch(Object[] arg0) {
 90////                try {
 91////
 92//////                    officeApplication.getDocumentService().loadDocument(officeFrame, officeFrame.);
 93////                } catch (OfficeApplicationException ex) {
 94////                    Log.Debug(ex);
 95////                }
 96//            }
 97//        });
 98
 99        officeFrame.updateDispatches();
100        officeFrame.disableDispatch(GlobalCommands.CLOSE_DOCUMENT);
101        officeFrame.disableDispatch(GlobalCommands.QUIT_APPLICATION);
102
103    }
104
105    /**
106     * Fill the form fields of the template with values
107     * @param textDocument
108     * @param template
109     * @param data
110     * @throws java.lang.Exception
111     */
112    public void fillFields(ITextDocument textDocument, File template, Hashtable<String, String> data) throws Exception {
113
114        IFormComponent[] formComponents = textDocument.getFormService().getFormComponents();
115        // iterate over hashtable and insert values into field masters
116        java.util.Enumeration keys = data.keys();
117        String key = null;
118        while (keys.hasMoreElements()) {
119
120            try {
121                // get column name
122                key = (String) keys.nextElement();
123
124                for (int i = 0; i < formComponents.length; i++) {
125
126                    XFormComponent xFormComponent = formComponents[i].getXFormComponent();
127                    XTextComponent xTextComponent = formComponents[i].getXTextComponent();
128                    XPropertySet propertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
129                            xFormComponent);
130
131                    if (propertySet != null && propertySet.getPropertySetInfo().hasPropertyByName("Name")) {
132                        String name = propertySet.getPropertyValue("Name").toString();
133                        if (name.equalsIgnoreCase(key)) {
134                            xTextComponent.setText(data.get(key));
135                        }
136                    }
137                }
138            } catch (Exception noSuchElementException) {
139                Log.Print(noSuchElementException.getMessage());
140            }
141        }
142    }
143}