This commit is contained in:
Georgy Litvinov 2020-07-30 17:31:14 +02:00
parent 2c93aad7a4
commit c1beb95d51
4 changed files with 118 additions and 16 deletions

View file

@ -4,6 +4,7 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import pro.litvinovg.w2phtml.gui.ConfigurationWindow;
import pro.litvinovg.w2phtml.gui.Document;
import com.sun.star.lib.uno.helper.Factory;

View file

@ -32,7 +32,6 @@ public class ConfigurationReader {
private void readOptions(HashMap<String, Component> configuration) {
Set<String> options = configuration.keySet();
for (String optionName : options) {
//Debug.printLog(string, context);
String optionValue = null;
Component component = configuration.get(optionName);
if (component.getClass().equals(JTextField.class)) {
@ -45,20 +44,7 @@ public class ConfigurationReader {
Debug.printLog(optionName + " : " + optionValue, context);
}
/*for (Component component : components) {
if (component.getClass().equals(JTextField.class)) {
textFields.add(component);
} else if (component.getClass().equals(JCheckBox.class)) {
checkBoxes.add(component);
} else if (component.getClass().equals(JLabel.class)) {
labels.add(component);
}
}
for (Iterator iterator = checkBoxes.iterator(); iterator.hasNext();) {
JCheckBox checkBox = (JCheckBox) iterator.next();
checkBox.get
}*/
}

View file

@ -566,7 +566,7 @@ public class ConfigurationWindow extends JFrame {
}
public static void runGUI(XComponentContext context) {
Document doc = new Document(context);
if (singleFrame != null) {
singleFrame.dispose();
}

View file

@ -0,0 +1,115 @@
package pro.litvinovg.w2phtml.gui;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
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.frame.XModel;
import com.sun.star.frame.XStorable;
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;
import com.sun.star.lang.XServiceInfo;
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.util.XModifiable;
import com.sun.star.view.XViewSettingsSupplier;
import pro.litvinovg.xml.Debug;
public class Document {
private XComponentContext context;
private XDesktop xDesktop;
private XMultiComponentFactory multiComponentFactory;
private XMultiServiceFactory multiServiceFactory;
private XComponent currentDocument;
private XDocumentProperties documentProperties;
private XDocumentPropertiesSupplier documentPropertiesSupplier;
private XText text = null;
private XFrame frame;
private XDispatchProvider dispatchProvider;
XTextDocument textDocument;
public Document(XComponentContext componentContext) {
if (componentContext != null) {
context = componentContext;
multiComponentFactory = context.getServiceManager();
try {
Object oDesktop = multiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", context);
xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop);
currentDocument = xDesktop.getCurrentComponent();
//Get document readOnly status. If so, abort.
//Get document path. If doc not saved - abort.
if (currentDocument == null) {
return;
}
//Get document type. Work only with ODT.
XModel model = UnoRuntime.queryInterface(XModel.class, currentDocument);
if (!isSupported(currentDocument,"com.sun.star.text.TextDocument")) {
return;
}
XTextDocument textDoc = UnoRuntime.queryInterface(XTextDocument.class, currentDocument);
if (textDoc == null) {
Debug.printLog("Error. TextDoc is null.", componentContext);
return;
}
XStorable storable = UnoRuntime.queryInterface(XStorable.class, textDoc);
if (storable == null || storable.isReadonly()) {
Debug.printLog("Document is read only", componentContext);
} else {
Debug.printLog("Document is in rw mode", componentContext);
}
XModifiable modifieable = UnoRuntime.queryInterface(XModifiable.class, textDoc);
if (modifieable == null || modifieable.isModified()) {
Debug.printLog("Document is modified", componentContext);
} else {
Debug.printLog("Document isn't modified", componentContext);
}
String url = model.getURL();
Debug.printLog("Document url " + url, componentContext);
} catch (Exception e) {
System.out.println("xDesktop inaccessible. Can not proceed.");
e.printStackTrace();
System.exit(1);
}
}
}
private boolean isSupported(Object object, String service) {
XServiceInfo info = UnoRuntime.queryInterface(XServiceInfo.class, object);
if (info == null) {
return false;
}
return info.supportsService(service);
}
}