Rearrange some dialog code
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@238 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
fcd9c12304
commit
b0b61acb19
3 changed files with 22 additions and 271 deletions
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.5 (2015-04-09)
|
||||
* Version 1.6 (2015-04-09)
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2014-10-27)
|
||||
* Version 1.6 (2015-04-15)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -39,8 +39,8 @@ import com.sun.star.util.Date;
|
|||
*/
|
||||
public class DialogAccess {
|
||||
|
||||
/** The XDialog containing the controls. The subclass must override this */
|
||||
private Object xDialog = null;
|
||||
/** The XDialog containing the controls. */
|
||||
private XDialog xDialog = null;
|
||||
|
||||
// State of a checkbox
|
||||
|
||||
|
@ -51,6 +51,14 @@ public class DialogAccess {
|
|||
public DialogAccess(XDialog xDialog) {
|
||||
this.xDialog = xDialog;
|
||||
}
|
||||
|
||||
protected void setDialog(XDialog xDialog) {
|
||||
this.xDialog = xDialog;
|
||||
}
|
||||
|
||||
protected XDialog getDialog() {
|
||||
return this.xDialog;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Helpers to access controls in the dialog (to be used by the subclass)
|
||||
|
|
|
@ -16,27 +16,19 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-12-16)
|
||||
* Version 1.6 (2015-04-15)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.awt.XControl;
|
||||
import com.sun.star.awt.XControlContainer;
|
||||
import com.sun.star.awt.XControlModel;
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XDialogEventHandler;
|
||||
import com.sun.star.awt.XDialogProvider2;
|
||||
//import com.sun.star.beans.PropertyVetoException;
|
||||
//import com.sun.star.beans.UnknownPropertyException;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
//import com.sun.star.lang.IllegalArgumentException;
|
||||
//import com.sun.star.lang.WrappedTargetException;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.lang.XServiceName;
|
||||
|
@ -50,9 +42,8 @@ import com.sun.star.uno.XComponentContext;
|
|||
|
||||
/** This class provides an abstract uno component which implements a dialog
|
||||
* from an xml description (using the DialogProvider2 service)
|
||||
* TODO: Use DialogAccess.java
|
||||
*/
|
||||
public abstract class DialogBase implements
|
||||
public abstract class DialogBase extends DialogAccess implements
|
||||
XTypeProvider, XServiceInfo, XServiceName, // Uno component
|
||||
XExecutableDialog, // Execute the dialog
|
||||
XDialogEventHandler { // Event handling for dialog
|
||||
|
@ -92,23 +83,13 @@ public abstract class DialogBase implements
|
|||
*/
|
||||
protected abstract void endDialog();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Some constants
|
||||
|
||||
// State of a checkbox
|
||||
protected static final short CHECKBOX_NOT_CHECKED = 0;
|
||||
protected static final short CHECKBOX_CHECKED = 1;
|
||||
protected static final short CHECKBOX_DONT_KNOW = 2;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Some private global variables
|
||||
|
||||
// The component context (from constructor)
|
||||
protected XComponentContext xContext;
|
||||
|
||||
// The dialog (created by XExecutableDialog implementation)
|
||||
private XDialog xDialog;
|
||||
// The dialog title (created by XExecutableDialog implementation)
|
||||
private String sTitle;
|
||||
|
||||
|
||||
|
@ -117,8 +98,8 @@ public abstract class DialogBase implements
|
|||
|
||||
/** Create a new OptionsDialogBase */
|
||||
public DialogBase(XComponentContext xContext) {
|
||||
super(null);
|
||||
this.xContext = xContext;
|
||||
xDialog = null;
|
||||
sTitle = null;
|
||||
}
|
||||
|
||||
|
@ -184,20 +165,20 @@ public abstract class DialogBase implements
|
|||
UnoRuntime.queryInterface(XDialogProvider2.class, provider);
|
||||
String sDialogUrl = "vnd.sun.star.script:"+getDialogLibraryName()+"."
|
||||
+getDialogName()+"?location=application";
|
||||
xDialog = xDialogProvider.createDialogWithHandler(sDialogUrl, this);
|
||||
if (sTitle!=null) { xDialog.setTitle(sTitle); }
|
||||
setDialog(xDialogProvider.createDialogWithHandler(sDialogUrl, this));
|
||||
if (sTitle!=null) { getDialog().setTitle(sTitle); }
|
||||
|
||||
// Do initialization using method from subclass
|
||||
initialize();
|
||||
|
||||
// Execute the dialog
|
||||
short nResult = xDialog.execute();
|
||||
short nResult = getDialog().execute();
|
||||
|
||||
if (nResult == ExecutableDialogResults.OK) {
|
||||
// Finalize after execution of dialog using method from subclass
|
||||
endDialog();
|
||||
}
|
||||
xDialog.endExecute();
|
||||
getDialog().endExecute();
|
||||
return nResult;
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -217,244 +198,6 @@ public abstract class DialogBase implements
|
|||
// We do not support any method names, subclass should take care of this
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Helpers to access controls in the dialog (to be used by the subclass)
|
||||
// Note: The helpers fail silently if an exception occurs. Could query the
|
||||
// the ClassId property for the control type and check that the property
|
||||
// exists to ensure a correct behaviour in all cases, but as long as the
|
||||
// helpers are used correctly, this doesn't really matter.
|
||||
|
||||
// Get the properties of a named control in the dialog
|
||||
private XPropertySet getControlProperties(String sControlName) {
|
||||
XControlContainer xContainer = (XControlContainer)
|
||||
UnoRuntime.queryInterface(XControlContainer.class, xDialog);
|
||||
XControl xControl = xContainer.getControl(sControlName);
|
||||
XControlModel xModel = xControl.getModel();
|
||||
XPropertySet xPropertySet = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class, xModel);
|
||||
return xPropertySet;
|
||||
}
|
||||
|
||||
|
||||
protected void setControlEnabled(String sControlName, boolean bEnabled) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Enabled", new Boolean(bEnabled));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist
|
||||
}
|
||||
}
|
||||
|
||||
protected short getCheckBoxState(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Short) xPropertySet.getPropertyValue("State")).shortValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a checkbox
|
||||
return CHECKBOX_DONT_KNOW;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean getCheckBoxStateAsBoolean(String sControlName) {
|
||||
return getCheckBoxState(sControlName)==CHECKBOX_CHECKED;
|
||||
}
|
||||
|
||||
protected void setCheckBoxState(String sControlName, short nState) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("State",new Short(nState));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// will fail if the control does not exist or is not a checkbox or
|
||||
// nState has an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
protected void setCheckBoxStateAsBoolean(String sControlName, boolean bChecked) {
|
||||
setCheckBoxState(sControlName,bChecked ? CHECKBOX_CHECKED : CHECKBOX_NOT_CHECKED);
|
||||
}
|
||||
|
||||
protected String[] getListBoxStringItemList(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String[]) xPropertySet.getPropertyValue("StringItemList");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected void setListBoxStringItemList(String sControlName, String[] items) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("StringItemList",items);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
}
|
||||
}
|
||||
|
||||
protected short getListBoxSelectedItem(String sControlName) {
|
||||
// Returns the first selected element in case of a multiselection
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
short[] selection = (short[]) xPropertySet.getPropertyValue("SelectedItems");
|
||||
return selection[0];
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setListBoxSelectedItem(String sControlName, short nIndex) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
short[] selection = new short[1];
|
||||
selection[0] = nIndex;
|
||||
xPropertySet.setPropertyValue("SelectedItems",selection);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box or
|
||||
// nIndex is an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
protected short getListBoxLineCount(String sControlName) {
|
||||
// Returns the first selected element in case of a multiselection
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Short) xPropertySet.getPropertyValue("LineCount")).shortValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setListBoxLineCount(String sControlName, short nLineCount) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("LineCount",new Short(nLineCount));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box or
|
||||
// nLineCount is an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
protected String getComboBoxText(String sControlName) {
|
||||
// Returns the text of a combobox
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Text");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a combo
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected void setComboBoxText(String sControlName, String sText) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Text", sText);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a combo box or
|
||||
// nText is an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
protected String getTextFieldText(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Text");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a text field
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected void setTextFieldText(String sControlName, String sText) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Text",sText);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a text field
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabelText(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Label");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a label
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setLabelText(String sControlName, String sLabel) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Label",sLabel);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a label
|
||||
}
|
||||
}
|
||||
|
||||
protected String getFormattedFieldText(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Text");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a formatted field
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected void setFormattedFieldText(String sControlName, String sText) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Text",sText);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a formatted field
|
||||
}
|
||||
}
|
||||
|
||||
protected int getNumericFieldValue(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Double) xPropertySet.getPropertyValue("Value")).intValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a numeric field
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setNumericFieldValue(String sControlName, int nValue) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Value",new Double(nValue));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a numeric field
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue