From c1dc50aeaae0787ed229539e24de5ae8344f12a4 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Thu, 16 Apr 2020 22:25:07 +0200 Subject: [PATCH] Hide annotations --- .../libreoffice/metadata/Document.java | 49 ++++++++++++++++++- .../libreoffice/metadata/views/EditorGUI.java | 9 ++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/source/pro/litvinovg/libreoffice/metadata/Document.java b/source/pro/litvinovg/libreoffice/metadata/Document.java index d18dd0f..5b65602 100644 --- a/source/pro/litvinovg/libreoffice/metadata/Document.java +++ b/source/pro/litvinovg/libreoffice/metadata/Document.java @@ -10,14 +10,22 @@ import com.sun.star.beans.IllegalTypeException; import com.sun.star.beans.NotRemoveableException; import com.sun.star.beans.Property; import com.sun.star.beans.PropertyExistException; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.PropertyVetoException; import com.sun.star.beans.UnknownPropertyException; import com.sun.star.beans.XPropertyContainer; import com.sun.star.beans.XPropertySet; import com.sun.star.beans.XPropertySetInfo; import com.sun.star.document.XDocumentProperties; import com.sun.star.document.XDocumentPropertiesSupplier; +import com.sun.star.frame.XController; import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchHelper; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XFrame; import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.WrappedTargetException; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiServiceFactory; @@ -25,6 +33,7 @@ import com.sun.star.text.XText; import com.sun.star.text.XTextDocument; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; +import com.sun.star.view.XViewSettingsSupplier; import pro.litvinovg.libreoffice.DocumentParser; import pro.litvinovg.libreoffice.MetadataCleaner; @@ -49,6 +58,9 @@ public class Document { private XDocumentPropertiesSupplier documentPropertiesSupplier; private XText text = null; private ArrayList outline = new ArrayList(); + private XFrame frame; + private XDispatchProvider dispatchProvider; + XTextDocument textDocument; public Document(XComponentContext componentContext) { context = componentContext; @@ -60,6 +72,8 @@ public class Document { getDocumentText(); multiServiceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, currentDocument); readMetadataInDocument(); + frame = xDesktop.getCurrentFrame(); + dispatchProvider = UnoRuntime.queryInterface( com.sun.star.frame.XDispatchProvider.class, frame ); } catch (Exception e) { System.out.println("xDesktop inaccessible. Can not proceed."); e.printStackTrace(); @@ -68,7 +82,7 @@ public class Document { } private void getDocumentText() { - XTextDocument textDocument = UnoRuntime.queryInterface(XTextDocument.class,currentDocument); + textDocument = UnoRuntime.queryInterface(XTextDocument.class,currentDocument); text = textDocument.getText(); } @@ -277,4 +291,37 @@ public class Document { return outline; } + public void hideAnnotations() { + XController controller = textDocument.getCurrentController(); + XViewSettingsSupplier viewSettings = UnoRuntime.queryInterface( XViewSettingsSupplier.class, controller); + XPropertySet properties = viewSettings.getViewSettings(); + try { + properties.setPropertyValue("ShowAnnotations", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (UnknownPropertyException e) { + e.printStackTrace(); + } catch (PropertyVetoException e) { + e.printStackTrace(); + } catch (WrappedTargetException e) { + e.printStackTrace(); + } + + /* + * try { Object dispatchHelperObj = + * multiComponentFactory.createInstanceWithContext( + * "com.sun.star.frame.DispatchHelper", context); XDispatchHelper dispatchHelper + * = UnoRuntime.queryInterface( XDispatchHelper.class, dispatchHelperObj); + * PropertyValue empty = new PropertyValue(); PropertyValue[] array = new + * PropertyValue[] {empty}; XDispatchProvider dispatchProvider = + * UnoRuntime.queryInterface( XDispatchProvider.class, frame); + * dispatchHelper.executeDispatch(dispatchProvider, ".uno:ShowAnnotations", "", + * 0, array); + * + * + * } catch (com.sun.star.uno.Exception e) { e.printStackTrace(); } + */ + + } + } diff --git a/source/pro/litvinovg/libreoffice/metadata/views/EditorGUI.java b/source/pro/litvinovg/libreoffice/metadata/views/EditorGUI.java index fed4c03..b1453f4 100644 --- a/source/pro/litvinovg/libreoffice/metadata/views/EditorGUI.java +++ b/source/pro/litvinovg/libreoffice/metadata/views/EditorGUI.java @@ -176,9 +176,9 @@ public class EditorGUI extends JFrame { panelStandardMetadata = new JPanel(); tabbedPane.addTab("Метаданные либры", null, panelStandardMetadata, null); tabbedPane.setEnabledAt(0, true); - if (true) { - addMetadataTab(new OutlineElement(null, "Тестовое название")); - } + /* + * if (true) { addMetadataTab(new OutlineElement(null, "Тестовое название")); } + */ for (OutlineElement element : outline) { addMetadataTab(element); } @@ -418,7 +418,10 @@ public class EditorGUI extends JFrame { document.setCustomDocumentProperties(docCustomProps); updateOutlineMetadata(); document.writeOutlineMetadata(); + document.hideAnnotations(); } + + private void updateOutlineMetadata() { for (MetadataTableModel table : tableModels) { table.writeToOutline();