PageRenderTime 22ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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