summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/ui/event
diff options
context:
space:
mode:
Diffstat (limited to 'wizards/com/sun/star/wizards/ui/event')
-rw-r--r--wizards/com/sun/star/wizards/ui/event/AbstractListener.java133
-rw-r--r--wizards/com/sun/star/wizards/ui/event/CommonListener.java167
-rw-r--r--wizards/com/sun/star/wizards/ui/event/DataAware.java365
-rw-r--r--wizards/com/sun/star/wizards/ui/event/DataAwareFields.java507
-rw-r--r--wizards/com/sun/star/wizards/ui/event/EventNames.java52
-rw-r--r--wizards/com/sun/star/wizards/ui/event/ListModelBinder.java209
-rw-r--r--wizards/com/sun/star/wizards/ui/event/MethodInvocation.java108
-rw-r--r--wizards/com/sun/star/wizards/ui/event/RadioDataAware.java101
-rw-r--r--wizards/com/sun/star/wizards/ui/event/SimpleDataAware.java84
-rw-r--r--wizards/com/sun/star/wizards/ui/event/Task.java204
-rw-r--r--wizards/com/sun/star/wizards/ui/event/TaskEvent.java65
-rw-r--r--wizards/com/sun/star/wizards/ui/event/TaskListener.java51
-rw-r--r--wizards/com/sun/star/wizards/ui/event/UnoDataAware.java265
13 files changed, 2311 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/ui/event/AbstractListener.java b/wizards/com/sun/star/wizards/ui/event/AbstractListener.java
new file mode 100644
index 000000000000..ebbcba96f58c
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/AbstractListener.java
@@ -0,0 +1,133 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import com.sun.star.awt.XControl;
+import com.sun.star.lang.EventObject;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.wizards.common.Helper;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Hashtable;
+
+/**
+ * This class is a base class for listener classes.
+ * It uses a hashtable to map between a ComponentName, EventName and a MethodInvokation Object.
+ * To use this class do the following:<br/>
+ * <list>
+ * <li>Write a subclass which implements the needed Listener(s).</li>
+ * in the even methods, use invoke(...).
+ * <li>When instanciating the component, register the subclass as the event listener.</li>
+ * <li>Write the methods which should be performed when the event occures.</li>
+ * <li>call the "add" method, to define a component-event-action mapping.</li>
+ * </list>
+ * @author rpiterman
+ */
+public class AbstractListener
+{
+
+ private Hashtable mHashtable = new Hashtable();
+
+ /** Creates a new instance of AbstractListener */
+ public AbstractListener()
+ {
+ }
+
+ public void add(String componentName, String eventName, String methodName, Object target)
+ {
+ try
+ {
+ add(componentName, eventName, new MethodInvocation(methodName, target));
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void add(String componentName, String eventName, MethodInvocation mi)
+ {
+ mHashtable.put(componentName + eventName, mi);
+ }
+
+ public MethodInvocation get(String componentName, String eventName)
+ {
+ return (MethodInvocation) mHashtable.get(componentName + eventName);
+ }
+
+ public Object invoke(String componentName, String eventName, Object param)
+ {
+ try
+ {
+ MethodInvocation mi = get(componentName, eventName);
+ if (mi != null)
+ {
+ return mi.invoke(param);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ catch (InvocationTargetException ite)
+ {
+
+ System.out.println("=======================================================");
+ System.out.println("=== Note: An Exception was thrown which should have ===");
+ System.out.println("=== caused a crash. I caught it. Please report this ===");
+ System.out.println("=== to openoffice.org ===");
+ System.out.println("=======================================================");
+
+ ite.printStackTrace();
+
+ }
+ catch (IllegalAccessException iae)
+ {
+ iae.printStackTrace();
+ }
+ catch (Exception ex)
+ {
+ System.out.println("=======================================================");
+ System.out.println("=== Note: An Exception was thrown which should have ===");
+ System.out.println("=== caused a crash. I Catched it. Please report this ==");
+ System.out.println("=== to openoffice.org ==");
+ System.out.println("=======================================================");
+ ex.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /**
+ * Rerurns the property "name" of the Object which is the source of the event.
+ */
+ public static String getEventSourceName(EventObject eventObject)
+ {
+ XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, eventObject.Source);
+ return (String) Helper.getUnoPropertyValue(xControl.getModel(), "Name", String.class);
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.java b/wizards/com/sun/star/wizards/ui/event/CommonListener.java
new file mode 100644
index 000000000000..18f33af2cef8
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.java
@@ -0,0 +1,167 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import com.sun.star.awt.*;
+import com.sun.star.lang.EventObject;
+
+/**
+ *
+ * @author rpiterman
+ */
+public class CommonListener extends AbstractListener implements XActionListener, XItemListener, XTextListener, EventNames, XWindowListener, XMouseListener, XFocusListener, XKeyListener
+{
+
+ /** Creates a new instance of CommonListener */
+ public CommonListener()
+ {
+ }
+
+ /**
+ * Implementation of com.sun.star.awt.XActionListener
+ */
+ public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent)
+ {
+ invoke(getEventSourceName(actionEvent), EVENT_ACTION_PERFORMED, actionEvent);
+ }
+
+ public void disposing(com.sun.star.lang.EventObject eventObject)
+ {
+ }
+
+ /**
+ * Implementation of com.sun.star.awt.XItemListener
+ */
+ public void itemStateChanged(ItemEvent itemEvent)
+ {
+ invoke(getEventSourceName(itemEvent), EVENT_ITEM_CHANGED, itemEvent);
+ }
+
+ /**
+ * Implementation of com.sun.star.awt.XTextListener
+ */
+ public void textChanged(TextEvent textEvent)
+ {
+ invoke(getEventSourceName(textEvent), EVENT_TEXT_CHANGED, textEvent);
+ }
+
+ /**
+ * @see com.sun.star.awt.XWindowListener#windowResized(com.sun.star.awt.WindowEvent)
+ */
+ public void windowResized(WindowEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_WINDOW_RESIZED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XWindowListener#windowMoved(com.sun.star.awt.WindowEvent)
+ */
+ public void windowMoved(WindowEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_WINDOW_MOVED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XWindowListener#windowShown(com.sun.star.lang.EventObject)
+ */
+ public void windowShown(EventObject event)
+ {
+ invoke(getEventSourceName(event), EVENT_WINDOW_SHOWN, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XWindowListener#windowHidden(com.sun.star.lang.EventObject)
+ */
+ public void windowHidden(EventObject event)
+ {
+ invoke(getEventSourceName(event), EVENT_WINDOW_HIDDEN, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XMouseListener#mousePressed(com.sun.star.awt.MouseEvent)
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_MOUSE_PRESSED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XMouseListener#mouseReleased(com.sun.star.awt.MouseEvent)
+ */
+ public void mouseReleased(MouseEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_KEY_RELEASED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XMouseListener#mouseEntered(com.sun.star.awt.MouseEvent)
+ */
+ public void mouseEntered(MouseEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_MOUSE_ENTERED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XMouseListener#mouseExited(com.sun.star.awt.MouseEvent)
+ */
+ public void mouseExited(MouseEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_MOUSE_EXITED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XFocusListener#focusGained(com.sun.star.awt.FocusEvent)
+ */
+ public void focusGained(FocusEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_FOCUS_GAINED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XFocusListener#focusLost(com.sun.star.awt.FocusEvent)
+ */
+ public void focusLost(FocusEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_FOCUS_LOST, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XKeyListener#keyPressed(com.sun.star.awt.KeyEvent)
+ */
+ public void keyPressed(KeyEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_KEY_PRESSED, event);
+ }
+
+ /**
+ * @see com.sun.star.awt.XKeyListener#keyReleased(com.sun.star.awt.KeyEvent)
+ */
+ public void keyReleased(KeyEvent event)
+ {
+ invoke(getEventSourceName(event), EVENT_KEY_RELEASED, event);
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/DataAware.java b/wizards/com/sun/star/wizards/ui/event/DataAware.java
new file mode 100644
index 000000000000..b81b8e71bcdb
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/DataAware.java
@@ -0,0 +1,365 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author rpiterman
+ * DataAware objects are used to live-synchronize UI and DataModel/DataObject.
+ * It is used as listener on UI events, to keep the DataObject up to date.
+ * This class, as a base abstract class, sets a frame of functionality,
+ * delegating the data Object get/set methods to a Value object,
+ * and leaving the UI get/set methods abstract.
+ * Note that event listenning is *not* a part of this model.
+ * the updateData() or updateUI() methods should be porogramatically called.
+ * in child classes, the updateData() will be binded to UI event calls.
+ * <br><br>
+ * This class holds references to a Data Object and a Value object.
+ * The Value object "knows" how to get and set a value from the
+ * Data Object.
+ */
+public abstract class DataAware {
+
+ /**
+ * this is the data object.
+ */
+ protected Object dataObject;
+ //protected Method setMethod;
+ //protected Method getMethod;
+ /**
+ * A Value Object knows how to get/set a value
+ * from/to the data object.
+ */
+ protected Value value;
+
+ /**
+ * creates a DataAware object for the given data object and Value object.
+ * @param dataObject_
+ * @param value_
+ */
+ protected DataAware(Object dataObject_, Value value_) {
+ dataObject = dataObject_;
+ value = value_;
+ //getMethod = createGetMethod(dataPropName, dataObject);
+ //setMethod = createSetMethod(dataPropName, dataObject, getMethod.getReturnType());
+ }
+
+ /**
+ * returns the data object.
+ * @return
+ */
+ public Object getDataObject() {
+ return dataObject;
+ }
+
+ /**
+ * sets a new data object. Optionally
+ * update the UI.
+ * @param obj the new data object.
+ * @param updateUI if true updateUI() will be called.
+ */
+ public void setDataObject(Object obj, boolean updateUI) {
+
+ if (obj != null && !value.isAssignable(obj.getClass()))
+ throw new ClassCastException("can not cast new DataObject to original Class");
+
+ dataObject = obj;
+
+ if (updateUI)
+ updateUI();
+
+ }
+
+ /**
+ * Sets the given value to the data object.
+ * this method delegates the job to the
+ * Value object, but can be overwritten if
+ * another kind of Data is needed.
+ * @param newValue the new value to set to the DataObject.
+ */
+ protected void setToData(Object newValue) {
+ value.set(newValue,getDataObject());
+ }
+
+ /**
+ * gets the current value from the data obejct.
+ * this method delegates the job to
+ * the value object.
+ * @return the current value of the data object.
+ */
+ protected Object getFromData() {
+ return value.get(getDataObject());
+ }
+
+ /**
+ * sets the given value to the UI control
+ * @param newValue the value to set to the ui control.
+ */
+ protected abstract void setToUI(Object newValue);
+
+ /**
+ * gets the current value from the UI control.
+ * @return the current value from the UI control.
+ */
+ protected abstract Object getFromUI();
+
+ /**
+ * updates the UI control according to the
+ * current state of the data object.
+ */
+ public void updateUI() {
+ Object data = getFromData();
+ Object ui = getFromUI();
+ if (!equals(data, ui))
+ try {
+ setToUI(data);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ //TODO tell user...
+ }
+ enableControls(data);
+ }
+
+ /**
+ * enables
+ * @param currentValue
+ */
+ protected void enableControls(Object currentValue) {
+ }
+
+ /**
+ * updates the DataObject according to
+ * the current state of the UI control.
+ */
+ public void updateData() {
+ Object data = getFromData();
+ Object ui = getFromUI();
+ if (!equals(data, ui))
+ setToData(ui);
+ enableControls(ui);
+ }
+
+ public interface Listener {
+ public void eventPerformed(Object event);
+ }
+
+ /**
+ * compares the two given objects.
+ * This method is null safe and returns true also if both are null...
+ * If both are arrays, treats them as array of short and compares them.
+ * @param a first object to compare
+ * @param b second object to compare.
+ * @return true if both are null or both are equal.
+ */
+ protected boolean equals(Object a, Object b) {
+ if (a == null && b == null)
+ return true;
+ if (a == null || b == null)
+ return false;
+ if (a.getClass().isArray()) {
+ if (b.getClass().isArray())
+ return Arrays.equals((short[]) a, (short[]) b);
+ else
+ return false;
+ }
+ return a.equals(b);
+ }
+
+ /**
+ * given a collection containing DataAware objects,
+ * calls updateUI() on each memebr of the collection.
+ * @param dataAwares a collection containing DataAware objects.
+ */
+ public static void updateUI(Collection dataAwares) {
+ for (Iterator i = dataAwares.iterator(); i.hasNext();)
+ ((DataAware) i.next()).updateUI();
+ }
+
+ public static void updateData(Collection dataAwares) {
+ for (Iterator i = dataAwares.iterator(); i.hasNext();)
+ ((DataAware) i.next()).updateData();
+ }
+
+ /**
+ * /**
+ * Given a collection containing DataAware objects,
+ * sets the given DataObject to each DataAware object
+ * in the given collection
+ * @param dataAwares a collection of DataAware objects.
+ * @param dataObject new data object to set to the DataAware objects in the given collection.
+ * @param updateUI if true, calls updateUI() on each DataAware object.
+ */public static void setDataObject(Collection dataAwares, Object dataObject, boolean updateUI) {
+ for (Iterator i = dataAwares.iterator(); i.hasNext();)
+ ((DataAware) i.next()).setDataObject(dataObject, updateUI);
+ }
+
+ /**
+ * Value objects read and write a value from and
+ * to an object. Typically using reflection and JavaBeans properties
+ * or directly using memeber reflection API.
+ * DataAware delegates the handling of the DataObject
+ * to a Value object.
+ * 2 implementations currently exist: PropertyValue,
+ * using JavaBeans properties reflection, and DataAwareFields classes
+ * which implement different memeber types.
+ */
+ public interface Value {
+ /**
+ * gets a value from the given object.
+ * @param target the object to get the value from.
+ * @return the value from the given object.
+ */
+ public Object get(Object target);
+ /**
+ * sets a value to the given object.
+ * @param value the value to set to the object.
+ * @param target the object to set the value to.
+ */
+ public void set(Object value, Object target);
+ /**
+ * checks if this Value object can handle
+ * the given object type as a target.
+ * @param type the type of a target to check
+ * @return true if the given class is acceptible for
+ * the Value object. False if not.
+ */
+ public boolean isAssignable(Class type);
+ }
+
+ /**
+ * implementation of Value, handling JavaBeans properties through
+ * reflection.
+ * This Object gets and sets a value a specific
+ * (JavaBean-style) property on a given object.
+ * @author rp143992
+ */
+ public static class PropertyValue implements Value {
+ /**
+ * the get method of the JavaBean-style property
+ */
+ private Method getMethod;
+ /**
+ * the set method of the JavaBean-style property
+ */
+ private Method setMethod;
+
+ /**
+ * creates a PropertyValue for the property with
+ * the given name, of the given JavaBean object.
+ * @param propertyName the property to access. Must be a Cup letter (e.g. "Name" for getName() and setName("..."). )
+ * @param propertyOwner the object which "own" or "contains" the property.
+ */
+ public PropertyValue(String propertyName, Object propertyOwner) {
+ getMethod = createGetMethod(propertyName, propertyOwner);
+ setMethod = createSetMethod(propertyName, propertyOwner, getMethod.getReturnType());
+ }
+
+ /**
+ * called from the constructor, and creates a get method reflection object
+ * for the given property and object.
+ * @param propName the property name0
+ * @param obj the object which contains the property.
+ * @return the get method reflection object.
+ */
+ private static Class[] EMPTY_ARRAY = new Class[0];
+
+ protected Method createGetMethod(String propName, Object obj)
+ {
+ Method m = null;
+ try
+ { //try to get a "get" method.
+
+ m = obj.getClass().getMethod("get" + propName, EMPTY_ARRAY);
+ }
+ catch (NoSuchMethodException ex1)
+ {
+ throw new IllegalArgumentException("get" + propName + "() method does not exist on " + obj.getClass().getName());
+ }
+ return m;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#get(java.lang.Object)
+ */
+ public Object get(Object target) {
+ try {
+ return getMethod.invoke(target, EMPTY_ARRAY);
+ } catch (IllegalAccessException ex1) {
+ ex1.printStackTrace();
+ } catch (InvocationTargetException ex2) {
+ ex2.printStackTrace();
+ } catch (NullPointerException npe) {
+ if (getMethod.getReturnType().equals(String.class))
+ return "";
+ if (getMethod.getReturnType().equals(Short.class))
+ return new Short((short) 0);
+ if (getMethod.getReturnType().equals(Integer.class))
+ return new Integer(0);
+ if (getMethod.getReturnType().equals(short[].class))
+ return new short[0];
+ }
+ return null;
+
+ }
+
+ protected Method createSetMethod(String propName, Object obj, Class paramClass) {
+ Method m = null;
+ try {
+ m = obj.getClass().getMethod("set" + propName, new Class[] { paramClass });
+ } catch (NoSuchMethodException ex1) {
+ throw new IllegalArgumentException("set" + propName + "(" + getMethod.getReturnType().getName() + ") method does not exist on " + obj.getClass().getName());
+ }
+ return m;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#set(java.lang.Object, java.lang.Object)
+ */
+ public void set(Object value, Object target) {
+ try {
+ setMethod.invoke(target, new Object[] {value});
+ } catch (IllegalAccessException ex1) {
+ ex1.printStackTrace();
+ } catch (InvocationTargetException ex2) {
+ ex2.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#isAssignable(java.lang.Class)
+ */
+ public boolean isAssignable(Class type) {
+ return getMethod.getDeclaringClass().isAssignableFrom(type) &&
+ setMethod.getDeclaringClass().isAssignableFrom(type);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/DataAwareFields.java b/wizards/com/sun/star/wizards/ui/event/DataAwareFields.java
new file mode 100644
index 000000000000..74881d7b1f23
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/DataAwareFields.java
@@ -0,0 +1,507 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import java.lang.reflect.Field;
+
+import com.sun.star.uno.Any;
+
+/**
+ * This class is a factory for Value objects for different types of
+ * memebers.
+ * Other than some Value implementations classes this class contains static
+ * type conversion methods and factory methods.
+ *
+ * @see com.sun.star.wizards.ui.event.DataAware.Value
+ */
+public class DataAwareFields
+{
+
+ private static final String TRUE = "true";
+ private static final String FALSE = "false";
+
+ /**
+ * returns a Value Object which sets and gets values
+ * and converting them to other types, according to the "value" argument.
+ *
+ * @param owner
+ * @param fieldname
+ * @param value
+ * @return
+ * @throws NoSuchFieldException
+ */
+ public static DataAware.Value getFieldValueFor(Object owner, String fieldname, Object value)
+ {
+ try
+ {
+ Field f = owner.getClass().getField(fieldname);
+
+ Class c = f.getType();
+ Class c2 = value.getClass();
+ if (c.equals(Boolean.TYPE))
+ {
+ return new BooleanFieldValue(f, c2);
+ }
+ else if (c.equals(Integer.TYPE))
+ {
+ return new IntFieldValue(f, c2);
+ }
+ else if (c.equals(Double.TYPE))
+ {
+ return new DoubleFieldValue(f, c2);
+ }
+ else if (c.equals(String.class) && c2.equals(Integer.class))
+ {
+ return new ConvertedStringValue(f, c2);
+ }
+ else
+ {
+ return new SimpleFieldValue(f);
+ }
+ }
+ catch (NoSuchFieldException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * an abstract implementation of DataAware.Value to access
+ * object memebers (fields) usign reflection.
+ */
+ private static abstract class FieldValue implements DataAware.Value
+ {
+
+ Field field;
+
+ public FieldValue(Field field_)
+ {
+ field = field_;
+ }
+
+ public boolean isAssignable(Class type)
+ {
+ return field.getDeclaringClass().isAssignableFrom(type);
+ }
+ }
+
+ private static class BooleanFieldValue extends FieldValue
+ {
+
+ private Class convertTo;
+
+ public BooleanFieldValue(Field f, Class convertTo_)
+ {
+ super(f);
+ convertTo = convertTo_;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#get(java.lang.Object)
+ */
+ public Object get(Object target)
+ {
+ try
+ {
+ boolean b = field.getBoolean(target);
+ if (convertTo.equals(Boolean.class))
+ {
+ return b ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (Number.class.isAssignableFrom(convertTo))
+ {
+ return toNumber(b ? 1 : 0, convertTo);
+ }
+ else if (convertTo.equals(String.class))
+ {
+ return String.valueOf(b);
+ }
+ else if (convertTo.isArray())
+ {
+ return toShortArray(toInt(b));
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert boolean value to given type (" + convertTo.getName() + ").");
+ }
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public void set(Object value, Object target)
+ {
+ try
+ {
+ field.setBoolean(target, toBoolean(value));
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static class IntFieldValue extends FieldValue
+ {
+
+ private Class convertTo;
+
+ public IntFieldValue(Field f, Class convertTo_)
+ {
+ super(f);
+ convertTo = convertTo_;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#get(java.lang.Object)
+ */
+ public Object get(Object target)
+ {
+ try
+ {
+ int i = field.getInt(target);
+ if (convertTo.equals(Boolean.class))
+ {
+ return i != 0 ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (Number.class.isAssignableFrom(convertTo))
+ {
+ return toNumber(i, convertTo);
+ }
+ else if (convertTo.equals(String.class))
+ {
+ return String.valueOf(i);
+ }
+ else if (convertTo.isArray())
+ {
+ return toShortArray(i);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert int value to given type (" + convertTo.getName() + ").");
+ }
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public void set(Object value, Object target)
+ {
+ try
+ {
+ field.setInt(target, (int) toDouble(value));
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static class DoubleFieldValue extends FieldValue
+ {
+
+ private Class convertTo;
+
+ public DoubleFieldValue(Field f, Class convertTo_)
+ {
+ super(f);
+ convertTo = convertTo_;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#get(java.lang.Object)
+ */
+ public Object get(Object target)
+ {
+ try
+ {
+ double d = field.getDouble(target);
+ if (convertTo.equals(Boolean.class))
+ {
+ return d != 0 ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (Number.class.isAssignableFrom(convertTo))
+ {
+ return toNumber(d, convertTo);
+ }
+ else if (convertTo.equals(String.class))
+ {
+ return String.valueOf(d);
+ }
+ else if (convertTo.isArray())
+ {
+ return toShortArray(d);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert int value to given type (" + convertTo.getName() + ").");
+ }
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public void set(Object value, Object target)
+ {
+ try
+ {
+ field.setDouble(target, toDouble(value));
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static class ConvertedStringValue extends FieldValue
+ {
+
+ private Class convertTo;
+
+ public ConvertedStringValue(Field f, Class convertTo_)
+ {
+ super(f);
+ convertTo = convertTo_;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#get(java.lang.Object)
+ */
+ public Object get(Object target)
+ {
+ try
+ {
+ String s = (String) field.get(target);
+
+ if (convertTo.equals(Boolean.class))
+ {
+ return (s != null && !s.equals("") && s.equals("true")) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (convertTo.equals(Integer.class))
+ {
+ if (s == null || s.equals(""))
+ {
+ return Any.VOID;
+ }
+ else
+ {
+ return new Integer(s);
+ }
+ }
+ else if (convertTo.equals(Double.class))
+ {
+ if (s == null || s.equals(""))
+ {
+ return Any.VOID;
+ }
+ else
+ {
+ return new Double(s);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert int value to given type (" + convertTo.getName() + ").");
+ }
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public void set(Object value, Object target)
+ {
+ try
+ {
+ field.set(target, value == null || (value.equals(Any.VOID)) ? "" : value.toString());
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static class SimpleFieldValue extends FieldValue
+ {
+
+ public SimpleFieldValue(Field f)
+ {
+ super(f);
+ }
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.event.DataAware.Value#get(java.lang.Object)
+ */
+
+ public Object get(Object target)
+ {
+ try
+ {
+ if (target == null)
+ {
+ if (field.getType().equals(String.class))
+ {
+ return "";
+ }
+ if (field.getType().equals(Short.class))
+ {
+ return new Short((short) 0);
+ }
+ if (field.getType().equals(Integer.class))
+ {
+ return new Integer(0);
+ }
+ if (field.getType().equals(short[].class))
+ {
+ return new short[0];
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return field.get(target);
+ }
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public void set(Object value, Object target)
+ {
+ try
+ {
+ field.set(target, value);
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static double toDouble(Object value)
+ {
+ if (value instanceof Boolean)
+ {
+ return ((Boolean) value).booleanValue() ? 1 : 0;
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).doubleValue();
+ }
+ else if (value instanceof String)
+ {
+ return Double.valueOf((String) value).doubleValue();
+ }
+ else if (value instanceof short[])
+ {
+ return ((short[]) value).length == 0 ? 0 : ((short[]) value)[0];
+ }
+ else
+ {
+ throw new IllegalArgumentException("Can't convert value to double." + value.getClass().getName());
+ }
+ }
+
+ private static boolean toBoolean(Object value)
+ {
+ if (value instanceof Boolean)
+ {
+ return ((Boolean) value).booleanValue();
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).intValue() != 0;
+ }
+ else if (value instanceof String)
+ {
+ return ((String) value).equals(TRUE);
+ }
+ else if (value instanceof short[])
+ {
+ return ((short[]) value).length != 0 && ((short[]) value)[0] != 0;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Can't convert value to boolean." + value.getClass().getName());
+ }
+ }
+
+ private static int toInt(boolean b)
+ {
+ return b ? 1 : 0;
+ }
+
+ private static short[] toShortArray(double i)
+ {
+ return new short[]
+ {
+ (short) i
+ };
+ }
+
+ private static Number toNumber(double i, Class c)
+ {
+ if (c.equals(Integer.class))
+ {
+ return new Integer((int) i);
+ }
+ else if (c.equals(Short.class))
+ {
+ return new Short((short) i);
+ }
+ else if (c.equals(Double.class))
+ {
+ return new Double(i);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert to the given Number type.");
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/EventNames.java b/wizards/com/sun/star/wizards/ui/event/EventNames.java
new file mode 100644
index 000000000000..50aa32dc57aa
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/EventNames.java
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+/**
+ *
+ * @author rpiterman
+ */
+public interface EventNames
+{
+
+ //common listener events
+ public static final String EVENT_ACTION_PERFORMED = "APR";
+ public static final String EVENT_ITEM_CHANGED = "ICH";
+ public static final String EVENT_TEXT_CHANGED = "TCH"; //window events (XWindow)
+ public static final String EVENT_WINDOW_RESIZED = "WRE";
+ public static final String EVENT_WINDOW_MOVED = "WMO";
+ public static final String EVENT_WINDOW_SHOWN = "WSH";
+ public static final String EVENT_WINDOW_HIDDEN = "WHI"; //focus events (XWindow)
+ public static final String EVENT_FOCUS_GAINED = "FGA";
+ public static final String EVENT_FOCUS_LOST = "FLO"; //keyboard events
+ public static final String EVENT_KEY_PRESSED = "KPR";
+ public static final String EVENT_KEY_RELEASED = "KRE"; //mouse events
+ public static final String EVENT_MOUSE_PRESSED = "MPR";
+ public static final String EVENT_MOUSE_RELEASED = "MRE";
+ public static final String EVENT_MOUSE_ENTERED = "MEN";
+ public static final String EVENT_MOUSE_EXITED = "MEX"; //other events
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/ListModelBinder.java b/wizards/com/sun/star/wizards/ui/event/ListModelBinder.java
new file mode 100644
index 000000000000..b2dc75f22f48
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/ListModelBinder.java
@@ -0,0 +1,209 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import javax.swing.ListModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+import com.sun.star.awt.XComboBox;
+import com.sun.star.awt.XListBox;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.wizards.common.Helper;
+
+/**
+ * @author rpiterman
+
+ * */
+public class ListModelBinder implements ListDataListener
+{
+
+ private XListBox unoList;
+ private Object unoListModel;
+ private ListModel listModel;
+ private Renderer renderer = new Renderer()
+ {
+
+ public String render(Object item)
+ {
+ if (item == null)
+ {
+ return "";
+ }
+ else
+ {
+ return item.toString();
+ }
+ }
+ };
+
+ public ListModelBinder(Object unoListBox, ListModel listModel_)
+ {
+ unoList = (XListBox) UnoRuntime.queryInterface(XListBox.class, unoListBox);
+ unoListModel = UnoDataAware.getModel(unoListBox);
+ setListModel(listModel_);
+ }
+
+ public void setListModel(ListModel newListModel)
+ {
+ if (listModel != null)
+ {
+ listModel.removeListDataListener(this);
+ }
+ listModel = newListModel;
+ listModel.addListDataListener(this);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.event.ListDataListener#contentsChanged(javax.swing.event.ListDataEvent)
+ */
+ public void contentsChanged(ListDataEvent lde)
+ {
+ short[] selected = getSelectedItems();
+ for (short i = (short) lde.getIndex0(); i <= lde.getIndex1(); i++)
+ {
+ update(i);
+ }
+ setSelectedItems(selected);
+ }
+
+ protected void update(short i)
+ {
+ remove(i, i);
+ insert(i);
+ }
+
+ protected void remove(short i1, short i2)
+ {
+ unoList.removeItems((short) i1, (short) (i2 - i1 + 1));
+ }
+
+ protected void insert(short i)
+ {
+ unoList.addItem(getItemString(i), i);
+ }
+
+ protected String getItemString(short i)
+ {
+ return getItemString(listModel.getElementAt((int) i));
+ }
+
+ protected String getItemString(Object item)
+ {
+ return renderer.render(item);
+ }
+
+ protected short[] getSelectedItems()
+ {
+ return (short[]) Helper.getUnoPropertyValue(unoListModel, "SelectedItems");
+ }
+
+ protected void setSelectedItems(short[] selected)
+ {
+ Helper.setUnoPropertyValue(unoListModel, "SelectedItems", selected);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.event.ListDataListener#intervalAdded(javax.swing.event.ListDataEvent)
+ */
+ public void intervalAdded(ListDataEvent lde)
+ {
+ //Short[] selected = getSelectedItems();
+ for (short i = (short) lde.getIndex0(); i <= lde.getIndex1(); i++)
+ {
+ insert(i);
+
+ /*int insertedItems = lde.getIndex1() - lde.getIndex0() + 1;
+
+ for (int i = 0; i<selected.length; i++)
+ if (selected[i].intValue() >= lde.getIndex0())
+ selected[i] = new Short((short)(selected[i].shortValue() + insertedItems));
+ setSelectedItems(selected);*/
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.event.ListDataListener#intervalRemoved(javax.swing.event.ListDataEvent)
+ */
+ public void intervalRemoved(ListDataEvent lde)
+ {
+ //Short[] selected = getSelectedItems();
+
+ remove((short) lde.getIndex0(), (short) lde.getIndex1());
+
+ /*int removed = 0;
+ for (int i = 0; i<selected.length; i++) {
+ short s = selected[i].shortValue();
+ if (s>=lde.getIndex0() && s<==lde.getIndex1()) {
+ selected[i] = null;
+ removed++;
+ }
+ }
+
+ Short[] newSelected = (removed > 0 ? new Short[selected.length - removed] : selected;
+ if (removed>0)
+
+ if (selected[i].intValue() >= lde.getIndex0())
+ */
+ }
+
+ public static interface Renderer
+ {
+
+ public String render(Object item);
+ }
+
+ public static void fillList(Object list, Object[] items, Renderer renderer)
+ {
+ XListBox xlist = (XListBox) UnoRuntime.queryInterface(XListBox.class, list);
+ Helper.setUnoPropertyValue(UnoDataAware.getModel(list), "StringItemList", new String[]
+ {
+ });
+ for (short i = 0; i < items.length; i++)
+ {
+ if (items[i] != null)
+ {
+ xlist.addItem((renderer != null ? renderer.render(items[i]) : items[i].toString()), i);
+ }
+ }
+ }
+
+ public static void fillComboBox(Object list, Object[] items, Renderer renderer)
+ {
+ XComboBox xComboBox = (XComboBox) UnoRuntime.queryInterface(XComboBox.class, list);
+ Helper.setUnoPropertyValue(UnoDataAware.getModel(list), "StringItemList", new String[]
+ {
+ });
+ for (short i = 0; i < items.length; i++)
+ {
+ if (items[i] != null)
+ {
+ xComboBox.addItem((renderer != null ? renderer.render(items[i]) : items[i].toString()), i);
+ }
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java b/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java
new file mode 100644
index 000000000000..c45a496c7849
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java
@@ -0,0 +1,108 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Encapsulate a Method invocation.
+ * In the constructor one defines a method, a target object and an optional
+ * Parameter.
+ * Then one calls "invoke", with or without a parameter. <br/>
+ * Limitations: I do not check anything myself. If the param is not ok, from the
+ * wrong type, or the mothod doesnot exist on the given object.
+ * You can trick this class howmuch you want: it will all throw exceptions
+ * on the java level. i throw no error warnings or my own excceptions...
+ * @author rpiterman
+ */
+public class MethodInvocation
+{
+
+ static final Class[] EMPTY_ARRAY =
+ {
+ };
+ //the method to invoke.
+ Method mMethod;
+ //the object to invoke the method on.
+ Object mObject;
+ //with one Parameter / without
+ boolean mWithParam;
+
+ /** Creates a new instance of MethodInvokation */
+ public MethodInvocation(String methodName, Object obj) throws NoSuchMethodException
+ {
+ this(methodName, obj, null);
+ }
+
+ public MethodInvocation(Method method, Object obj)
+ {
+ this(method, obj, null);
+ }
+
+ public MethodInvocation(String methodName, Object obj, Class paramClass) throws NoSuchMethodException
+ {
+ this(paramClass == null ? obj.getClass().getMethod(methodName, null) : obj.getClass().getMethod(methodName, new Class[]
+ {
+ paramClass
+ }), obj, paramClass);
+ }
+
+ public MethodInvocation(Method method, Object obj, Class paramClass)
+ {
+ mMethod = method;
+ mObject = obj;
+ mWithParam = !(paramClass == null);
+ }
+
+ /**
+ * Returns the result of calling the method on the object, or null, if no result.
+ */
+ public Object invoke(Object param) throws IllegalAccessException, InvocationTargetException
+ {
+ if (mWithParam)
+ {
+ return mMethod.invoke(mObject, new Object[]
+ {
+ (Object) param
+ });
+ }
+ else
+ {
+ return mMethod.invoke(mObject, EMPTY_ARRAY);
+ }
+ }
+
+ /**
+ * This method is a convenience method.
+ * It is the same as calling invoke(null);
+ */
+ public Object invoke() throws IllegalAccessException, InvocationTargetException
+ {
+ return invoke(null);
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java
new file mode 100644
index 000000000000..7dddea572503
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java
@@ -0,0 +1,101 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import com.sun.star.awt.XItemListener;
+import com.sun.star.awt.XRadioButton;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ * @author rpiterman
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class RadioDataAware extends DataAware
+{
+
+ protected XRadioButton[] radioButtons;
+
+ public RadioDataAware(Object data, Value value, Object[] radioButs)
+ {
+ super(data, value);
+ radioButtons = new XRadioButton[radioButs.length];
+ for (int i = 0; i < radioButs.length; i++)
+ {
+ radioButtons[i] = (XRadioButton) UnoRuntime.queryInterface(XRadioButton.class, radioButs[i]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.DataAware#setToUI(java.lang.Object)
+ */
+ protected void setToUI(Object value)
+ {
+ int selected = ((Number) value).intValue();
+ if (selected == -1)
+ {
+ for (int i = 0; i < radioButtons.length; i++)
+ {
+ radioButtons[i].setState(false);
+ }
+ }
+ else
+ {
+ radioButtons[selected].setState(true);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.star.wizards.ui.DataAware#getFromUI()
+ */
+ protected Object getFromUI()
+ {
+ for (int i = 0; i < radioButtons.length; i++)
+ {
+ if (radioButtons[i].getState())
+ {
+ return new Integer(i);
+ }
+ }
+ return new Integer(-1);
+ }
+
+ public static DataAware attachRadioButtons(Object data, String dataProp, Object[] buttons, final Listener listener, boolean field)
+ {
+ final RadioDataAware da = new RadioDataAware(data,
+ field
+ ? DataAwareFields.getFieldValueFor(data, dataProp, new Integer(0))
+ : new DataAware.PropertyValue(dataProp, data), buttons);
+ XItemListener xil = UnoDataAware.itemListener(da, listener);
+ for (int i = 0; i < da.radioButtons.length; i++)
+ {
+ da.radioButtons[i].addItemListener(xil);
+ }
+ return da;
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/SimpleDataAware.java b/wizards/com/sun/star/wizards/ui/event/SimpleDataAware.java
new file mode 100644
index 000000000000..8a9c2200d76d
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/SimpleDataAware.java
@@ -0,0 +1,84 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+public class SimpleDataAware extends DataAware
+{
+
+ protected Object control;
+ protected Object[] disableObjects = new Object[0];
+ protected Value controlValue;
+
+ public SimpleDataAware(Object dataObject, Value value, Object control_, Value controlValue_)
+ {
+ super(dataObject, value);
+ control = control_;
+ controlValue = controlValue_;
+ }
+
+ /*
+ protected void enableControls(Object value) {
+ Boolean b = getBoolean(value);
+ for (int i = 0; i<disableObjects.length; i++)
+ UIHelper.setEnabled(disableObjects[i],b);
+ }
+ */
+ protected void setToUI(Object value)
+ {
+ controlValue.set(value, control);
+ }
+
+ /**
+ * Try to get from an arbitrary object a boolean value.
+ * Null returns Boolean.FALSE;
+ * A Boolean object returns itself.
+ * An Array returns true if it not empty.
+ * An Empty String returns Boolean.FALSE.
+ * everything else returns a Boolean.TRUE.
+ * @param value
+ * @return
+ */
+ /*protected Boolean getBoolean(Object value) {
+ if (value==null)
+ return Boolean.FALSE;
+ if (value instanceof Boolean)
+ return (Boolean)value;
+ else if (value.getClass().isArray())
+ return ((short[])value).length != 0 ? Boolean.TRUE : Boolean.FALSE;
+ else if (value.equals("")) return Boolean.FALSE;
+ else return Boolean.TRUE;
+ }
+
+ public void disableControls(Object[] controls) {
+ disableObjects = controls;
+ }
+ */
+ protected Object getFromUI()
+ {
+ return controlValue.get(control);
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/Task.java b/wizards/com/sun/star/wizards/ui/event/Task.java
new file mode 100644
index 000000000000..16feacd5e1fa
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/Task.java
@@ -0,0 +1,204 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * @author rpiterman
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class Task
+{
+
+ private int successfull = 0;
+ private int failed = 0;
+ private int max = 0;
+ private String taskName;
+ private List listeners = new Vector();
+ private String subtaskName;
+
+ public Task(String taskName_, String subtaskName_, int max_)
+ {
+ taskName = taskName_;
+ subtaskName = subtaskName_;
+ max = max_;
+ }
+
+ public void start()
+ {
+ fireTaskStarted();
+ }
+
+ public void fail()
+ {
+ fireTaskFailed();
+ }
+
+ public int getMax()
+ {
+ return max;
+ }
+
+ public void setMax(int max_)
+ {
+ max = max_;
+ fireTaskStatusChanged();
+ }
+
+ public void advance(boolean success_)
+ {
+ if (success_)
+ {
+ successfull++;
+ }
+ else
+ {
+ failed++;
+ }
+ fireTaskStatusChanged();
+ if (failed + successfull == max)
+ {
+ fireTaskFinished();
+ }
+ }
+
+ public void advance(boolean success_, String nextSubtaskName)
+ {
+ advance(success_);
+ setSubtaskName(nextSubtaskName);
+ }
+
+ public int getStatus()
+ {
+ return successfull + failed;
+ }
+
+ public void addTaskListener(TaskListener tl)
+ {
+ listeners.add(tl);
+ }
+
+ public void removeTaskListener(TaskListener tl)
+ {
+ listeners.remove(tl);
+ }
+
+ protected void fireTaskStatusChanged()
+ {
+ TaskEvent te = new TaskEvent(this, TaskEvent.TASK_STATUS_CHANGED);
+
+ for (int i = 0; i < listeners.size(); i++)
+ {
+ ((TaskListener) listeners.get(i)).taskStatusChanged(te);
+ }
+ }
+
+ protected void fireTaskStarted()
+ {
+ TaskEvent te = new TaskEvent(this, TaskEvent.TASK_STARTED);
+
+ for (int i = 0; i < listeners.size(); i++)
+ {
+ ((TaskListener) listeners.get(i)).taskStarted(te);
+ }
+ }
+
+ protected void fireTaskFailed()
+ {
+ TaskEvent te = new TaskEvent(this, TaskEvent.TASK_FAILED);
+
+ for (int i = 0; i < listeners.size(); i++)
+ {
+ ((TaskListener) listeners.get(i)).taskFinished(te);
+ }
+ }
+
+ protected void fireTaskFinished()
+ {
+ TaskEvent te = new TaskEvent(this, TaskEvent.TASK_FINISHED);
+
+ for (int i = 0; i < listeners.size(); i++)
+ {
+ ((TaskListener) listeners.get(i)).taskFinished(te);
+ }
+ }
+
+ protected void fireSubtaskNameChanged()
+ {
+ TaskEvent te = new TaskEvent(this, TaskEvent.SUBTASK_NAME_CHANGED);
+
+ for (int i = 0; i < listeners.size(); i++)
+ {
+ ((TaskListener) listeners.get(i)).subtaskNameChanged(te);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public String getSubtaskName()
+ {
+ return subtaskName;
+ }
+
+ /**
+ * @return
+ */
+ public String getTaskName()
+ {
+ return taskName;
+ }
+
+ /**
+ * @param string
+ */
+ public void setSubtaskName(String string)
+ {
+ subtaskName = string;
+ fireSubtaskNameChanged();
+ }
+
+ /**
+ * @return
+ */
+ public int getFailed()
+ {
+ return failed;
+ }
+
+ /**
+ * @return
+ */
+ public int getSuccessfull()
+ {
+ return successfull;
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/TaskEvent.java b/wizards/com/sun/star/wizards/ui/event/TaskEvent.java
new file mode 100644
index 000000000000..1c54cfea2fa6
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/TaskEvent.java
@@ -0,0 +1,65 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import java.util.EventObject;
+
+/**
+ * @author rpiterman
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TaskEvent extends EventObject
+{
+
+ public static final int TASK_STARTED = 1;
+ public static final int TASK_FINISHED = 2;
+ public static final int TASK_STATUS_CHANGED = 3;
+ public static final int SUBTASK_NAME_CHANGED = 4;
+ public static final int TASK_FAILED = 5;
+ private int type;
+
+ /**
+ * general constructor-
+ * @param source
+ * @param type_
+ * @param max_
+ * @param success_
+ * @param failed_
+ */
+ public TaskEvent(Task source, int type_)
+ {
+ super(source);
+ type = type_;
+ }
+
+ public Task getTask()
+ {
+ return (Task) getSource();
+ }
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/TaskListener.java b/wizards/com/sun/star/wizards/ui/event/TaskListener.java
new file mode 100644
index 000000000000..114747c30776
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/TaskListener.java
@@ -0,0 +1,51 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import java.util.EventListener;
+
+/**
+ * @author rpiterman
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public interface TaskListener extends EventListener
+{
+
+ public void taskStarted(TaskEvent te);
+
+ public void taskFinished(TaskEvent te);
+
+ /**
+ * is called when the status of the task has advanced.
+ * @param te
+ */
+ public void taskStatusChanged(TaskEvent te);
+
+ public void subtaskNameChanged(TaskEvent te);
+}
diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.java b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.java
new file mode 100644
index 000000000000..632609d85f05
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.java
@@ -0,0 +1,265 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.ui.event;
+
+import com.sun.star.awt.*;
+import com.sun.star.lang.EventObject;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.wizards.common.Helper;
+
+/**
+ * @author rpiterman
+ *
+ * This class suppoprts imple cases where a UI control can
+ * be directly synchronized with a data property.
+ * Such controls are: the different text controls
+ * (synchronizing the "Text" , "Value", "Date", "Time" property),
+ * Checkbox controls, Dropdown listbox controls (synchronizing the
+ * SelectedItems[] property.
+ * For those controls, static convenience methods are offered, to simplify use.
+ */
+public class UnoDataAware extends DataAware
+{
+
+ protected Object unoControl;
+ protected Object unoModel;
+ protected String unoPropName;
+ protected Object[] disableObjects = new Object[0];
+ protected boolean inverse = false;
+
+ protected UnoDataAware(Object dataObject, Value value, Object unoObject_, String unoPropName_)
+ {
+ super(dataObject, value);
+ unoControl = unoObject_;
+ unoModel = getModel(unoControl);
+ unoPropName = unoPropName_;
+ }
+
+ public void setInverse(boolean i)
+ {
+ inverse = i;
+ }
+
+ protected void enableControls(Object value)
+ {
+ Boolean b = getBoolean(value);
+ if (inverse)
+ {
+ b = b.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
+ }
+ for (int i = 0; i < disableObjects.length; i++)
+ {
+ setEnabled(disableObjects[i], b);
+ }
+ }
+
+ protected void setToUI(Object value)
+ {
+ //System.out.println("Settings uno property : "+ Helper.getUnoPropertyValue(this.unoModel,"Name") + "<-" +stringof(value));
+ Helper.setUnoPropertyValue(unoModel, unoPropName, value);
+ }
+
+ private String stringof(Object value)
+ {
+ if (value.getClass().isArray())
+ {
+ StringBuffer sb = new StringBuffer("[");
+ for (int i = 0; i < ((short[]) value).length; i++)
+ {
+ sb.append(((short[]) value)[i]).append(" , ");
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+ else
+ {
+ return value.toString();
+ }
+ }
+
+ /**
+ * Try to get from an arbitrary object a boolean value.
+ * Null returns Boolean.FALSE;
+ * A Boolean object returns itself.
+ * An Array returns true if it not empty.
+ * An Empty String returns Boolean.FALSE.
+ * everything else returns a Boolean.TRUE.
+ * @param value
+ * @return
+ */
+ protected Boolean getBoolean(Object value)
+ {
+ if (value == null)
+ {
+ return Boolean.FALSE;
+ }
+ if (value instanceof Boolean)
+ {
+ return (Boolean) value;
+ }
+ else if (value.getClass().isArray())
+ {
+ return ((short[]) value).length != 0 ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (value.equals(""))
+ {
+ return Boolean.FALSE;
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).intValue() == 0 ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else
+ {
+ return Boolean.TRUE;
+ }
+ }
+
+ public void disableControls(Object[] controls)
+ {
+ disableObjects = controls;
+ }
+
+ protected Object getFromUI()
+ {
+ return Helper.getUnoPropertyValue(unoModel, unoPropName);
+ }
+
+ private static UnoDataAware attachTextControl(Object data, String prop, Object unoText, final Listener listener, String unoProperty, boolean field, Object value)
+ {
+ XTextComponent text = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, unoText);
+ final UnoDataAware uda = new UnoDataAware(data,
+ field
+ ? DataAwareFields.getFieldValueFor(data, prop, value)
+ : new DataAware.PropertyValue(prop, data),
+ text, unoProperty);
+ text.addTextListener(new XTextListener()
+ {
+
+ public void textChanged(TextEvent te)
+ {
+ uda.updateData();
+ if (listener != null)
+ {
+ listener.eventPerformed(te);
+ }
+ }
+
+ public void disposing(EventObject eo)
+ {
+ }
+ });
+ return uda;
+ }
+
+ public static UnoDataAware attachEditControl(Object data, String prop, Object unoControl, Listener listener, boolean field)
+ {
+ return attachTextControl(data, prop, unoControl, listener, "Text", field, "");
+ }
+
+ public static UnoDataAware attachDateControl(Object data, String prop, Object unoControl, Listener listener, boolean field)
+ {
+ return attachTextControl(data, prop, unoControl, listener, "Date", field, new Integer(0));
+ }
+
+ public static UnoDataAware attachTimeControl(Object data, String prop, Object unoControl, Listener listener, boolean field)
+ {
+ return attachTextControl(data, prop, unoControl, listener, "Time", field, new Integer(0));
+ }
+
+ public static UnoDataAware attachNumericControl(Object data, String prop, Object unoControl, Listener listener, boolean field)
+ {
+ return attachTextControl(data, prop, unoControl, listener, "Value", field, new Double(0));
+ }
+
+ public static UnoDataAware attachCheckBox(Object data, String prop, Object checkBox, final Listener listener, boolean field)
+ {
+ XCheckBox xcheckBox = ((XCheckBox) UnoRuntime.queryInterface(XCheckBox.class, checkBox));
+ final UnoDataAware uda = new UnoDataAware(data,
+ field
+ ? DataAwareFields.getFieldValueFor(data, prop, new Short((short) 0))
+ : new DataAware.PropertyValue(prop, data),
+ checkBox, "State");
+ xcheckBox.addItemListener(itemListener(uda, listener));
+ return uda;
+ }
+
+ static XItemListener itemListener(final DataAware da, final Listener listener)
+ {
+ return new XItemListener()
+ {
+
+ public void itemStateChanged(ItemEvent ie)
+ {
+ da.updateData();
+ if (listener != null)
+ {
+ listener.eventPerformed(ie);
+ }
+ }
+
+ public void disposing(EventObject eo)
+ {
+ }
+ };
+ }
+
+ public static UnoDataAware attachLabel(Object data, String prop, Object label, final Listener listener, boolean field)
+ {
+ return new UnoDataAware(data,
+ field ? DataAwareFields.getFieldValueFor(data, prop, "")
+ : new DataAware.PropertyValue(prop, data),
+ label, "Label");
+ }
+
+ public static UnoDataAware attachListBox(Object data, String prop, Object listBox, final Listener listener, boolean field)
+ {
+ XListBox xListBox = (XListBox) UnoRuntime.queryInterface(XListBox.class, listBox);
+ final UnoDataAware uda = new UnoDataAware(data,
+ field
+ ? DataAwareFields.getFieldValueFor(data, prop, new short[0])
+ : new DataAware.PropertyValue(prop, data),
+ listBox, "SelectedItems");
+ xListBox.addItemListener(itemListener(uda, listener));
+ return uda;
+ }
+
+ public static Object getModel(Object control)
+ {
+ return ((XControl) UnoRuntime.queryInterface(XControl.class, control)).getModel();
+ }
+
+ public static void setEnabled(Object control, boolean enabled)
+ {
+ setEnabled(control, enabled ? Boolean.TRUE : Boolean.FALSE);
+ }
+
+ public static void setEnabled(Object control, Boolean enabled)
+ {
+ Helper.setUnoPropertyValue(getModel(control), "Enabled", enabled);
+ }
+}