scripting: line break (code formatting)
Change-Id: Ib1a8d7e4bdaad2f4eae822d9af280fd5b6f9dd7b Reviewed-on: https://gerrit.libreoffice.org/11794 Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
This commit is contained in:
committed by
David Tardon
parent
b1d48f0d9a
commit
e41597eade
@@ -39,6 +39,7 @@ import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class DialogFactory {
|
||||
|
||||
private static DialogFactory factory;
|
||||
private XComponentContext xComponentContext;
|
||||
|
||||
@@ -58,8 +59,7 @@ public class DialogFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public static DialogFactory getDialogFactory()
|
||||
throws java.lang.Exception {
|
||||
public static DialogFactory getDialogFactory() throws java.lang.Exception {
|
||||
if (factory == null) {
|
||||
throw new java.lang.Exception("DialogFactory not initialized");
|
||||
}
|
||||
@@ -67,8 +67,6 @@ public class DialogFactory {
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String showInputDialog(String title, String prompt) {
|
||||
final XDialog xDialog;
|
||||
|
||||
@@ -79,19 +77,22 @@ public class DialogFactory {
|
||||
}
|
||||
|
||||
// add an action listener to the button controls
|
||||
XControlContainer controls = UnoRuntime.queryInterface(XControlContainer.class,
|
||||
xDialog);
|
||||
XControlContainer controls =
|
||||
UnoRuntime.queryInterface(XControlContainer.class, xDialog);
|
||||
|
||||
XButton okButton =
|
||||
UnoRuntime.queryInterface(XButton.class, controls.getControl("Ok"));
|
||||
|
||||
XButton okButton = UnoRuntime.queryInterface(
|
||||
XButton.class, controls.getControl("Ok"));
|
||||
okButton.setActionCommand("Ok");
|
||||
|
||||
XButton cancelButton = UnoRuntime.queryInterface(
|
||||
XButton.class, controls.getControl("Cancel"));
|
||||
XButton cancelButton =
|
||||
UnoRuntime.queryInterface(XButton.class, controls.getControl("Cancel"));
|
||||
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
|
||||
final XTextComponent textField = UnoRuntime.queryInterface(
|
||||
XTextComponent.class, controls.getControl("NameField"));
|
||||
final XTextComponent textField =
|
||||
UnoRuntime.queryInterface(XTextComponent.class,
|
||||
controls.getControl("NameField"));
|
||||
|
||||
final ResultHolder resultHolder = new ResultHolder();
|
||||
|
||||
@@ -120,8 +121,9 @@ public class DialogFactory {
|
||||
return (String)resultHolder.getResult();
|
||||
}
|
||||
|
||||
private void setDimensions(Object o, int x, int y, int width, int height)
|
||||
throws com.sun.star.uno.Exception {
|
||||
private void setDimensions(Object o, int x, int y, int width, int height) throws
|
||||
com.sun.star.uno.Exception {
|
||||
|
||||
XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, o);
|
||||
|
||||
props.setPropertyValue("PositionX", Integer.valueOf(x));
|
||||
@@ -130,8 +132,9 @@ public class DialogFactory {
|
||||
props.setPropertyValue("Width", Integer.valueOf(width));
|
||||
}
|
||||
|
||||
private XDialog createInputDialog(String title, String prompt)
|
||||
throws com.sun.star.uno.Exception {
|
||||
private XDialog createInputDialog(String title, String prompt) throws
|
||||
com.sun.star.uno.Exception {
|
||||
|
||||
if (title == null || title.length() == 0) {
|
||||
title = "Scripting Framework";
|
||||
}
|
||||
@@ -146,18 +149,19 @@ public class DialogFactory {
|
||||
|
||||
// create the dialog model and set the properties
|
||||
Object dialogModel = xMultiComponentFactory.createInstanceWithContext(
|
||||
"com.sun.star.awt.UnoControlDialogModel", xComponentContext);
|
||||
"com.sun.star.awt.UnoControlDialogModel",
|
||||
xComponentContext);
|
||||
|
||||
setDimensions(dialogModel, 100, 100, 157, 58);
|
||||
|
||||
XPropertySet props = UnoRuntime.queryInterface(
|
||||
XPropertySet.class, dialogModel);
|
||||
XPropertySet props =
|
||||
UnoRuntime.queryInterface(XPropertySet.class, dialogModel);
|
||||
|
||||
props.setPropertyValue("Title", title);
|
||||
|
||||
// get the service manager from the dialog model
|
||||
XMultiServiceFactory xMultiServiceFactory =
|
||||
UnoRuntime.queryInterface(
|
||||
XMultiServiceFactory.class, dialogModel);
|
||||
UnoRuntime.queryInterface(XMultiServiceFactory.class, dialogModel);
|
||||
|
||||
// create the label model and set the properties
|
||||
Object label = xMultiServiceFactory.createInstance(
|
||||
@@ -165,8 +169,9 @@ public class DialogFactory {
|
||||
|
||||
setDimensions(label, 15, 5, 134, 12);
|
||||
|
||||
XPropertySet labelProps = UnoRuntime.queryInterface(
|
||||
XPropertySet.class, label);
|
||||
XPropertySet labelProps =
|
||||
UnoRuntime.queryInterface(XPropertySet.class, label);
|
||||
|
||||
labelProps.setPropertyValue("Name", "PromptLabel");
|
||||
labelProps.setPropertyValue("Label", prompt);
|
||||
|
||||
@@ -176,8 +181,9 @@ public class DialogFactory {
|
||||
|
||||
setDimensions(edit, 15, 18, 134, 12);
|
||||
|
||||
XPropertySet editProps = UnoRuntime.queryInterface(
|
||||
XPropertySet.class, edit);
|
||||
XPropertySet editProps =
|
||||
UnoRuntime.queryInterface(XPropertySet.class, edit);
|
||||
|
||||
editProps.setPropertyValue("Name", "NameField");
|
||||
|
||||
// create the OK button
|
||||
@@ -186,8 +192,9 @@ public class DialogFactory {
|
||||
|
||||
setDimensions(okButtonModel, 40, 39, 38, 15);
|
||||
|
||||
XPropertySet buttonProps = UnoRuntime.queryInterface(
|
||||
XPropertySet.class, okButtonModel);
|
||||
XPropertySet buttonProps =
|
||||
UnoRuntime.queryInterface(XPropertySet.class, okButtonModel);
|
||||
|
||||
buttonProps.setPropertyValue("Name", "Ok");
|
||||
buttonProps.setPropertyValue("Label", "Ok");
|
||||
|
||||
@@ -197,14 +204,15 @@ public class DialogFactory {
|
||||
|
||||
setDimensions(cancelButtonModel, 83, 39, 38, 15);
|
||||
|
||||
buttonProps = UnoRuntime.queryInterface(
|
||||
XPropertySet.class, cancelButtonModel);
|
||||
buttonProps =
|
||||
UnoRuntime.queryInterface(XPropertySet.class, cancelButtonModel);
|
||||
|
||||
buttonProps.setPropertyValue("Name", "Cancel");
|
||||
buttonProps.setPropertyValue("Label", "Cancel");
|
||||
|
||||
// insert the control models into the dialog model
|
||||
XNameContainer xNameCont = UnoRuntime.queryInterface(XNameContainer.class,
|
||||
dialogModel);
|
||||
XNameContainer xNameCont =
|
||||
UnoRuntime.queryInterface(XNameContainer.class, dialogModel);
|
||||
|
||||
xNameCont.insertByName("PromptLabel", label);
|
||||
xNameCont.insertByName("NameField", edit);
|
||||
@@ -213,21 +221,23 @@ public class DialogFactory {
|
||||
|
||||
// create the dialog control and set the model
|
||||
Object dialog = xMultiComponentFactory.createInstanceWithContext(
|
||||
"com.sun.star.awt.UnoControlDialog", xComponentContext);
|
||||
XControl xControl = UnoRuntime.queryInterface(
|
||||
XControl.class, dialog);
|
||||
"com.sun.star.awt.UnoControlDialog",
|
||||
xComponentContext);
|
||||
|
||||
XControl xControl = UnoRuntime.queryInterface(XControl.class, dialog);
|
||||
|
||||
XControlModel xControlModel =
|
||||
UnoRuntime.queryInterface(XControlModel.class, dialogModel);
|
||||
|
||||
XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class,
|
||||
dialogModel);
|
||||
xControl.setModel(xControlModel);
|
||||
|
||||
// create a peer
|
||||
Object toolkit = xMultiComponentFactory.createInstanceWithContext(
|
||||
"com.sun.star.awt.ExtToolkit", xComponentContext);
|
||||
XToolkit xToolkit = UnoRuntime.queryInterface(
|
||||
XToolkit.class, toolkit);
|
||||
XWindow xWindow = UnoRuntime.queryInterface(
|
||||
XWindow.class, xControl);
|
||||
"com.sun.star.awt.ExtToolkit",
|
||||
xComponentContext);
|
||||
|
||||
XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit);
|
||||
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xControl);
|
||||
xWindow.setVisible(false);
|
||||
xControl.createPeer(xToolkit, null);
|
||||
|
||||
@@ -235,6 +245,7 @@ public class DialogFactory {
|
||||
}
|
||||
|
||||
private static class ResultHolder {
|
||||
|
||||
private Object result = null;
|
||||
|
||||
public Object getResult() {
|
||||
@@ -245,4 +256,4 @@ public class DialogFactory {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,19 +48,17 @@ import java.util.HashMap;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class ParcelBrowseNode extends PropertySet
|
||||
implements XBrowseNode, XInvocation {
|
||||
public class ParcelBrowseNode extends PropertySet implements
|
||||
XBrowseNode, XInvocation {
|
||||
|
||||
private ScriptProvider provider;
|
||||
private Collection<XBrowseNode> browsenodes;
|
||||
private ParcelContainer container;
|
||||
private Parcel parcel;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public ParcelBrowseNode(ScriptProvider provider, ParcelContainer container,
|
||||
String parcelName) {
|
||||
|
||||
this.provider = provider;
|
||||
this.container = container;
|
||||
|
||||
@@ -68,30 +66,28 @@ public class ParcelBrowseNode extends PropertySet
|
||||
try {
|
||||
this.parcel = (Parcel)this.container.getByName(parcelName);
|
||||
} catch (Exception e) {
|
||||
|
||||
LogUtils.DEBUG("** Exception: " + e);
|
||||
LogUtils.DEBUG(" ** Failed to get parcel named " +
|
||||
parcelName + " from container");
|
||||
LogUtils.DEBUG(" ** Failed to get parcel named " + parcelName +
|
||||
" from container");
|
||||
}
|
||||
|
||||
registerProperty("Deletable", new Type(boolean.class),
|
||||
(short)0, "deletable");
|
||||
registerProperty("Editable", new Type(boolean.class),
|
||||
(short)0, "editable");
|
||||
registerProperty("Creatable", new Type(boolean.class),
|
||||
(short)0, "creatable");
|
||||
registerProperty("Renamable", new Type(boolean.class),
|
||||
(short)0, "renamable");
|
||||
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
|
||||
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
|
||||
registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable");
|
||||
registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable");
|
||||
|
||||
String parcelDirUrl = parcel.getPathToParcel();
|
||||
XComponentContext xCtx = provider.getScriptingContext().getComponentContext();
|
||||
XMultiComponentFactory xFac = xCtx.getServiceManager();
|
||||
|
||||
try {
|
||||
XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class,
|
||||
xFac.createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess",
|
||||
xCtx));
|
||||
|
||||
XSimpleFileAccess xSFA =
|
||||
UnoRuntime.queryInterface(XSimpleFileAccess.class,
|
||||
xFac.createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess",
|
||||
xCtx));
|
||||
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
// TODO propagate potential errors
|
||||
LogUtils.DEBUG("Caught exception creating ParcelBrowseNode " + e);
|
||||
@@ -150,11 +146,13 @@ public class ParcelBrowseNode extends PropertySet
|
||||
}
|
||||
|
||||
public Object invoke(String aFunctionName, Object[] aParams,
|
||||
short[][] aOutParamIndex, Object[][] aOutParam)
|
||||
throws com.sun.star.lang.IllegalArgumentException,
|
||||
short[][] aOutParamIndex, Object[][] aOutParam) throws
|
||||
com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.script.CannotConvertException,
|
||||
com.sun.star.reflection.InvocationTargetException {
|
||||
|
||||
LogUtils.DEBUG("ParcelBrowseNode invoke for " + aFunctionName);
|
||||
|
||||
// Initialise the out parameters - not used but prevents error in
|
||||
// UNO bridge
|
||||
aOutParamIndex[0] = new short[0];
|
||||
@@ -166,21 +164,22 @@ public class ParcelBrowseNode extends PropertySet
|
||||
try {
|
||||
String newName;
|
||||
|
||||
if (aParams == null || aParams.length < 1 ||
|
||||
!AnyConverter.isString(aParams[0])) {
|
||||
if (aParams == null || aParams.length < 1
|
||||
|| !AnyConverter.isString(aParams[0])) {
|
||||
|
||||
String prompt = "Enter name for new Script";
|
||||
String title = "Create Script";
|
||||
|
||||
// try to get a DialogFactory instance, if it fails
|
||||
// just use a Swing JOptionPane to prompt for the name
|
||||
try {
|
||||
DialogFactory dialogFactory =
|
||||
DialogFactory.getDialogFactory();
|
||||
|
||||
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
|
||||
newName = dialogFactory.showInputDialog(title, prompt);
|
||||
} catch (Exception e) {
|
||||
|
||||
newName = JOptionPane.showInputDialog(null, prompt, title,
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
}
|
||||
} else {
|
||||
newName = AnyConverter.toString(aParams[0]);
|
||||
@@ -190,7 +189,10 @@ public class ParcelBrowseNode extends PropertySet
|
||||
result = new Any(new Type(Boolean.class), Boolean.FALSE);
|
||||
} else {
|
||||
String source = provider.getScriptEditor().getTemplate();
|
||||
String languageName = newName + "." + provider.getScriptEditor().getExtension();
|
||||
|
||||
String languageName =
|
||||
newName + "." + provider.getScriptEditor().getExtension();
|
||||
|
||||
String language = container.getLanguage();
|
||||
|
||||
ScriptEntry entry = new ScriptEntry(language, languageName, "",
|
||||
@@ -200,7 +202,8 @@ public class ParcelBrowseNode extends PropertySet
|
||||
ScriptMetaData data = new ScriptMetaData(parcel, entry, source);
|
||||
parcel.insertByName(languageName, data);
|
||||
|
||||
ScriptBrowseNode sbn = new ScriptBrowseNode(provider, parcel, languageName);
|
||||
ScriptBrowseNode sbn =
|
||||
new ScriptBrowseNode(provider, parcel, languageName);
|
||||
|
||||
if (browsenodes == null) {
|
||||
LogUtils.DEBUG("browsenodes null!!");
|
||||
@@ -208,14 +211,12 @@ public class ParcelBrowseNode extends PropertySet
|
||||
}
|
||||
|
||||
browsenodes.add(sbn);
|
||||
|
||||
result = new Any(new Type(XBrowseNode.class), sbn);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("ParcelBrowseNode[create] failed with: " + e);
|
||||
LogUtils.DEBUG(LogUtils.getTrace(e));
|
||||
result = new Any(new Type(Boolean.class), Boolean.FALSE);
|
||||
|
||||
}
|
||||
} else if (aFunctionName.equals("Deletable")) {
|
||||
try {
|
||||
@@ -228,6 +229,7 @@ public class ParcelBrowseNode extends PropertySet
|
||||
result = new Any(new Type(Boolean.class), Boolean.FALSE);
|
||||
}
|
||||
} else if (aFunctionName.equals("Renamable")) {
|
||||
|
||||
String newName = null;
|
||||
|
||||
try {
|
||||
@@ -240,13 +242,13 @@ public class ParcelBrowseNode extends PropertySet
|
||||
// try to get a DialogFactory instance, if it fails
|
||||
// just use a Swing JOptionPane to prompt for the name
|
||||
try {
|
||||
DialogFactory dialogFactory =
|
||||
DialogFactory.getDialogFactory();
|
||||
|
||||
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
|
||||
newName = dialogFactory.showInputDialog(title, prompt);
|
||||
} catch (Exception e) {
|
||||
|
||||
newName = JOptionPane.showInputDialog(null, prompt, title,
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
}
|
||||
} else {
|
||||
newName = AnyConverter.toString(aParams[0]);
|
||||
@@ -259,8 +261,8 @@ public class ParcelBrowseNode extends PropertySet
|
||||
getChildNodes();
|
||||
}
|
||||
|
||||
ScriptBrowseNode[] childNodes = browsenodes.toArray(new
|
||||
ScriptBrowseNode[browsenodes.size()]);
|
||||
ScriptBrowseNode[] childNodes =
|
||||
browsenodes.toArray(new ScriptBrowseNode[browsenodes.size()]);
|
||||
|
||||
for (int index = 0; index < childNodes.length; index++) {
|
||||
childNodes[ index ].updateURI(p);
|
||||
@@ -280,14 +282,14 @@ public class ParcelBrowseNode extends PropertySet
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setValue(String aPropertyName, Object aValue)
|
||||
throws com.sun.star.beans.UnknownPropertyException,
|
||||
public void setValue(String aPropertyName, Object aValue) throws
|
||||
com.sun.star.beans.UnknownPropertyException,
|
||||
com.sun.star.script.CannotConvertException,
|
||||
com.sun.star.reflection.InvocationTargetException {
|
||||
}
|
||||
|
||||
public Object getValue(String aPropertyName)
|
||||
throws com.sun.star.beans.UnknownPropertyException {
|
||||
public Object getValue(String aPropertyName) throws
|
||||
com.sun.star.beans.UnknownPropertyException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -298,4 +300,4 @@ public class ParcelBrowseNode extends PropertySet
|
||||
public boolean hasProperty(String aName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,12 +24,13 @@ import com.sun.star.script.framework.provider.ScriptProvider;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
|
||||
public class PkgProviderBrowseNode extends ProviderBrowseNode {
|
||||
|
||||
public PkgProviderBrowseNode(ScriptProvider provider, ParcelContainer container,
|
||||
XComponentContext xCtx) {
|
||||
|
||||
super(provider, container, xCtx);
|
||||
|
||||
LogUtils.DEBUG("*** PkgProviderBrowseNode ctor container name = " +
|
||||
container.getName());
|
||||
LogUtils.DEBUG("*** PkgProviderBrowseNode ctor container path = " +
|
||||
@@ -38,8 +39,7 @@ public class PkgProviderBrowseNode extends ProviderBrowseNode {
|
||||
container.getElementNames().length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@Override public String getName() {
|
||||
return (container != null) ? container.getName() : "Unknown";
|
||||
}
|
||||
|
||||
|
@@ -44,37 +44,32 @@ import java.util.Collection;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class ProviderBrowseNode extends PropertySet
|
||||
implements XBrowseNode, XInvocation {
|
||||
public class ProviderBrowseNode extends PropertySet implements
|
||||
XBrowseNode, XInvocation {
|
||||
|
||||
private ScriptProvider provider;
|
||||
private Collection<XBrowseNode> browsenodes;
|
||||
private String name;
|
||||
protected ParcelContainer container;
|
||||
|
||||
private XComponentContext m_xCtx;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public ProviderBrowseNode(ScriptProvider provider, ParcelContainer container,
|
||||
XComponentContext xCtx) {
|
||||
|
||||
LogUtils.DEBUG("*** ProviderBrowseNode ctor");
|
||||
this.container = container;
|
||||
this.name = this.container.getLanguage();
|
||||
this.provider = provider;
|
||||
this.m_xCtx = xCtx;
|
||||
|
||||
registerProperty("Deletable", new Type(boolean.class),
|
||||
(short)0, "deletable");
|
||||
registerProperty("Creatable", new Type(boolean.class),
|
||||
(short)0, "creatable");
|
||||
registerProperty("Editable", new Type(boolean.class),
|
||||
(short)0, "editable");
|
||||
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
|
||||
registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable");
|
||||
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
|
||||
XSimpleFileAccess xSFA = null;
|
||||
XMultiComponentFactory xFac = m_xCtx.getServiceManager();
|
||||
|
||||
try {
|
||||
|
||||
xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class,
|
||||
xFac.createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess",
|
||||
@@ -84,7 +79,6 @@ public class ProviderBrowseNode extends PropertySet
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
LogUtils.DEBUG("Caught exception in creation of ProviderBrowseNode ");
|
||||
LogUtils.DEBUG(LogUtils.getTrace(e));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +90,11 @@ public class ProviderBrowseNode extends PropertySet
|
||||
LogUtils.DEBUG("***** ProviderBrowseNode.getChildNodes()");
|
||||
|
||||
if (hasChildNodes()) {
|
||||
|
||||
// needs initialisation?
|
||||
LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " +
|
||||
container);
|
||||
|
||||
String[] parcels = container.getElementNames();
|
||||
browsenodes = new ArrayList<XBrowseNode>(parcels.length);
|
||||
|
||||
@@ -113,13 +109,16 @@ public class ProviderBrowseNode extends PropertySet
|
||||
}
|
||||
|
||||
ParcelContainer[] packageContainers = container.getChildContainers();
|
||||
|
||||
LogUtils.DEBUG("**** For container named " + container.getName() +
|
||||
" with root path " + container.getParcelContainerDir() + " has " +
|
||||
packageContainers.length + " child containers ");
|
||||
" with root path " + container.getParcelContainerDir() +
|
||||
" has " + packageContainers.length + " child containers ");
|
||||
|
||||
for (ParcelContainer packageContainer : packageContainers) {
|
||||
XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer,
|
||||
m_xCtx);
|
||||
|
||||
XBrowseNode node =
|
||||
new PkgProviderBrowseNode(provider, packageContainer, m_xCtx);
|
||||
|
||||
browsenodes.add(node);
|
||||
}
|
||||
} else {
|
||||
@@ -134,15 +133,13 @@ public class ProviderBrowseNode extends PropertySet
|
||||
boolean result = true;
|
||||
|
||||
if (container == null ||
|
||||
(!container.hasElements() &&
|
||||
container.getChildContainers().length == 0)) {
|
||||
(!container.hasElements() && container.getChildContainers().length == 0)) {
|
||||
|
||||
result = false;
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " +
|
||||
"name=" + name +
|
||||
", path=" + container.getParcelContainerDir() +
|
||||
", result=" + result);
|
||||
LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " + "name=" + name +
|
||||
", path=" + container.getParcelContainerDir() + ", result=" + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -162,10 +159,11 @@ public class ProviderBrowseNode extends PropertySet
|
||||
}
|
||||
|
||||
public Object invoke(String aFunctionName, Object[] aParams,
|
||||
short[][] aOutParamIndex, Object[][] aOutParam)
|
||||
throws com.sun.star.lang.IllegalArgumentException,
|
||||
short[][] aOutParamIndex, Object[][] aOutParam) throws
|
||||
com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.script.CannotConvertException,
|
||||
com.sun.star.reflection.InvocationTargetException {
|
||||
|
||||
// Initialise the out parameters - not used but prevents error in
|
||||
// UNO bridge
|
||||
aOutParamIndex[0] = new short[0];
|
||||
@@ -179,19 +177,20 @@ public class ProviderBrowseNode extends PropertySet
|
||||
|
||||
if (aParams == null || aParams.length < 1 ||
|
||||
!AnyConverter.isString(aParams[0])) {
|
||||
|
||||
String prompt = "Enter name for new Parcel";
|
||||
String title = "Create Parcel";
|
||||
|
||||
// try to get a DialogFactory instance, if it fails
|
||||
// just use a Swing JOptionPane to prompt for the name
|
||||
try {
|
||||
DialogFactory dialogFactory =
|
||||
DialogFactory.getDialogFactory();
|
||||
|
||||
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
|
||||
name = dialogFactory.showInputDialog(title, prompt);
|
||||
} catch (Exception e) {
|
||||
|
||||
name = JOptionPane.showInputDialog(null, prompt, title,
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
}
|
||||
} else {
|
||||
name = AnyConverter.toString(aParams[0]);
|
||||
@@ -215,8 +214,6 @@ public class ProviderBrowseNode extends PropertySet
|
||||
}
|
||||
|
||||
browsenodes.add(parcel);
|
||||
|
||||
|
||||
result = new Any(new Type(XBrowseNode.class), parcel);
|
||||
}
|
||||
}
|
||||
@@ -233,14 +230,15 @@ public class ProviderBrowseNode extends PropertySet
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setValue(String aPropertyName, Object aValue)
|
||||
throws com.sun.star.beans.UnknownPropertyException,
|
||||
public void setValue(String aPropertyName, Object aValue) throws
|
||||
com.sun.star.beans.UnknownPropertyException,
|
||||
com.sun.star.script.CannotConvertException,
|
||||
com.sun.star.reflection.InvocationTargetException {
|
||||
}
|
||||
|
||||
public Object getValue(String aPropertyName)
|
||||
throws com.sun.star.beans.UnknownPropertyException {
|
||||
public Object getValue(String aPropertyName) throws
|
||||
com.sun.star.beans.UnknownPropertyException {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -251,4 +249,4 @@ public class ProviderBrowseNode extends PropertySet
|
||||
public boolean hasProperty(String aName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,20 +50,20 @@ import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ScriptBrowseNode extends PropertySet
|
||||
implements XBrowseNode, XInvocation {
|
||||
public class ScriptBrowseNode extends PropertySet implements
|
||||
XBrowseNode, XInvocation {
|
||||
|
||||
private ScriptProvider provider;
|
||||
|
||||
private Parcel parent;
|
||||
private String name;
|
||||
|
||||
|
||||
private boolean editable = false;
|
||||
private boolean deletable = false;
|
||||
private boolean renamable = false;
|
||||
|
||||
public ScriptBrowseNode(ScriptProvider provider, Parcel parent,
|
||||
String name) {
|
||||
public ScriptBrowseNode(ScriptProvider provider, Parcel parent, String name) {
|
||||
|
||||
this.provider = provider;
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
@@ -72,10 +72,12 @@ public class ScriptBrowseNode extends PropertySet
|
||||
|
||||
try {
|
||||
ScriptMetaData data = (ScriptMetaData)parent.getByName(name);
|
||||
XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class,
|
||||
xFac.createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess",
|
||||
xCtx));
|
||||
|
||||
XSimpleFileAccess xSFA = UnoRuntime.queryInterface(
|
||||
XSimpleFileAccess.class,
|
||||
xFac.createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess",
|
||||
xCtx));
|
||||
|
||||
if (provider.hasScriptEditor()) {
|
||||
this.editable = true;
|
||||
@@ -83,8 +85,10 @@ public class ScriptBrowseNode extends PropertySet
|
||||
try {
|
||||
if (!parent.isUnoPkg()
|
||||
&& !xSFA.isReadOnly(parent.getPathToParcel())) {
|
||||
|
||||
this.deletable = true;
|
||||
this.renamable = true;
|
||||
|
||||
}
|
||||
}
|
||||
// TODO propagate errors
|
||||
@@ -98,23 +102,20 @@ public class ScriptBrowseNode extends PropertySet
|
||||
}
|
||||
// TODO fix exception types to be caught here, should we rethrow?
|
||||
catch (Exception e) {
|
||||
LogUtils.DEBUG("** caught exception getting script data for " + name + " ->" +
|
||||
e.toString());
|
||||
|
||||
LogUtils.DEBUG("** caught exception getting script data for " + name +
|
||||
" ->" + e.toString());
|
||||
|
||||
}
|
||||
|
||||
registerProperty("Deletable", new Type(boolean.class),
|
||||
(short)0, "deletable");
|
||||
registerProperty("Editable", new Type(boolean.class),
|
||||
(short)0, "editable");
|
||||
registerProperty("Renamable", new Type(boolean.class),
|
||||
(short)0, "renamable");
|
||||
registerProperty("URI", new Type(String.class),
|
||||
(short)0, "uri");
|
||||
registerProperty("Description", new Type(String.class),
|
||||
(short)0, "description");
|
||||
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
|
||||
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
|
||||
registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable");
|
||||
registerProperty("URI", new Type(String.class), (short)0, "uri");
|
||||
registerProperty("Description", new Type(String.class), (short)0,
|
||||
"description");
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -143,11 +144,10 @@ public class ScriptBrowseNode extends PropertySet
|
||||
try {
|
||||
data = (ScriptMetaData)parent.getByName(name);
|
||||
}
|
||||
|
||||
// TODO fix exception types to be caught here, should we rethrow?
|
||||
catch (Exception e) {
|
||||
LogUtils.DEBUG("** caught exception getting script data for " + name + " ->" +
|
||||
e.toString());
|
||||
LogUtils.DEBUG("** caught exception getting script data for " + name +
|
||||
" ->" + e.toString());
|
||||
}
|
||||
}
|
||||
// implementation of XInvocation interface
|
||||
@@ -156,10 +156,11 @@ public class ScriptBrowseNode extends PropertySet
|
||||
}
|
||||
|
||||
public Object invoke(String aFunctionName, Object[] aParams,
|
||||
short[][] aOutParamIndex, Object[][] aOutParam)
|
||||
throws com.sun.star.lang.IllegalArgumentException,
|
||||
short[][] aOutParamIndex, Object[][] aOutParam) throws
|
||||
com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.script.CannotConvertException,
|
||||
com.sun.star.reflection.InvocationTargetException {
|
||||
|
||||
// Initialise the out parameters - not used but prevents error in
|
||||
// UNO bridge
|
||||
aOutParamIndex[0] = new short[0];
|
||||
@@ -169,31 +170,37 @@ public class ScriptBrowseNode extends PropertySet
|
||||
|
||||
if (aFunctionName.equals("Editable")) {
|
||||
if (!editable) {
|
||||
NoSupportException nse = new NoSupportException(
|
||||
aFunctionName + " is not editable ");
|
||||
|
||||
NoSupportException nse =
|
||||
new NoSupportException(aFunctionName + " is not editable ");
|
||||
|
||||
throw new InvocationTargetException(
|
||||
"Scripting framework error editing script", null, nse);
|
||||
|
||||
}
|
||||
|
||||
XScriptContext ctxt = provider.getScriptingContext();
|
||||
XScriptContext ctxt = provider.getScriptingContext();
|
||||
ScriptMetaData data = null;
|
||||
|
||||
try {
|
||||
data = (ScriptMetaData)parent.getByName(name);
|
||||
} catch (NoSuchElementException nse) {
|
||||
|
||||
throw new com.sun.star.lang.IllegalArgumentException(
|
||||
name + " does not exist or can't be found ");
|
||||
|
||||
} catch (com.sun.star.lang.WrappedTargetException wte) {
|
||||
|
||||
// rethrow
|
||||
throw new InvocationTargetException(
|
||||
"Scripting framework editing script ",
|
||||
null, wte.TargetException);
|
||||
"Scripting framework editing script ", null, wte.TargetException);
|
||||
|
||||
}
|
||||
|
||||
provider.getScriptEditor().edit(ctxt, data);
|
||||
} else if (aFunctionName.equals("Deletable")) {
|
||||
if (!deletable) {
|
||||
|
||||
NoSupportException nse = new NoSupportException(
|
||||
aFunctionName + " is not supported for this node");
|
||||
|
||||
@@ -205,19 +212,23 @@ public class ScriptBrowseNode extends PropertySet
|
||||
parent.removeByName(name);
|
||||
result = new Any(new Type(Boolean.class), Boolean.TRUE);
|
||||
} catch (NoSuchElementException nse) {
|
||||
|
||||
throw new com.sun.star.lang.IllegalArgumentException(
|
||||
name + " does not exist or can't be found ");
|
||||
|
||||
} catch (WrappedTargetException wte) {
|
||||
|
||||
// rethrow
|
||||
throw new InvocationTargetException(
|
||||
"Scripting framework deleting script ",
|
||||
null, wte.TargetException);
|
||||
"Scripting framework deleting script ", null, wte.TargetException);
|
||||
|
||||
}
|
||||
|
||||
} else if (aFunctionName.equals("Renamable")) {
|
||||
result = new Any(new Type(XBrowseNode.class), new XBrowseNode[0]);
|
||||
|
||||
if (!renamable) {
|
||||
|
||||
NoSupportException nse = new NoSupportException(
|
||||
aFunctionName + " is not supported for this node");
|
||||
|
||||
@@ -232,15 +243,17 @@ public class ScriptBrowseNode extends PropertySet
|
||||
String oldSource = oldData.getSource();
|
||||
|
||||
LogUtils.DEBUG("Create renamed script");
|
||||
|
||||
String languageName =
|
||||
newName + "." + provider.getScriptEditor().getExtension();
|
||||
|
||||
String language = provider.getName();
|
||||
|
||||
ScriptEntry entry = new ScriptEntry(
|
||||
language, languageName, "", new HashMap<String, String>());
|
||||
ScriptEntry entry = new ScriptEntry(language, languageName, "",
|
||||
new HashMap<String, String>());
|
||||
|
||||
ScriptMetaData data = new ScriptMetaData(
|
||||
parent, entry, oldSource);
|
||||
ScriptMetaData data =
|
||||
new ScriptMetaData(parent, entry, oldSource);
|
||||
|
||||
parent.insertByName(languageName, data);
|
||||
|
||||
@@ -250,35 +263,42 @@ public class ScriptBrowseNode extends PropertySet
|
||||
name = languageName;
|
||||
result = new Any(new Type(XBrowseNode.class), this);
|
||||
} catch (NoSuchElementException nse) {
|
||||
|
||||
throw new com.sun.star.lang.IllegalArgumentException(
|
||||
name + " does not exist or can't be found ");
|
||||
|
||||
} catch (ElementExistException eee) {
|
||||
|
||||
// rethrow
|
||||
throw new InvocationTargetException(
|
||||
"Scripting framework error renaming script ",
|
||||
null, eee);
|
||||
"Scripting framework error renaming script ", null, eee);
|
||||
|
||||
} catch (WrappedTargetException wte) {
|
||||
|
||||
// rethrow
|
||||
throw new InvocationTargetException(
|
||||
"Scripting framework rename script ",
|
||||
null, wte.TargetException);
|
||||
"Scripting framework rename script ", null, wte.TargetException);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
throw new com.sun.star.lang.IllegalArgumentException(
|
||||
"Function " + aFunctionName + " not supported.");
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setValue(String aPropertyName, Object aValue)
|
||||
throws com.sun.star.beans.UnknownPropertyException,
|
||||
public void setValue(String aPropertyName, Object aValue) throws
|
||||
com.sun.star.beans.UnknownPropertyException,
|
||||
com.sun.star.script.CannotConvertException,
|
||||
com.sun.star.reflection.InvocationTargetException {
|
||||
}
|
||||
|
||||
public Object getValue(String aPropertyName)
|
||||
throws com.sun.star.beans.UnknownPropertyException {
|
||||
public Object getValue(String aPropertyName) throws
|
||||
com.sun.star.beans.UnknownPropertyException {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -289,4 +309,4 @@ public class ScriptBrowseNode extends PropertySet
|
||||
public boolean hasProperty(String aName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user