[Libreoffice-commits] .: Branch 'feature/gsoc2011_wizards' - wizards/com

Xisco Fauli xfauli at kemper.freedesktop.org
Wed Jun 29 09:48:22 PDT 2011


 wizards/com/sun/star/wizards/common/ConfigGroup.py        |    7 
 wizards/com/sun/star/wizards/common/Configuration.py      |    1 
 wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py   |    1 
 wizards/com/sun/star/wizards/ui/event/CommonListener.py   |    1 
 wizards/com/sun/star/wizards/ui/event/DataAware.py        |  172 --------------
 wizards/com/sun/star/wizards/ui/event/DataAwareField.py   |   35 ++
 wizards/com/sun/star/wizards/ui/event/RadioDataAware.java |    1 
 wizards/com/sun/star/wizards/ui/event/RadioDataAware.py   |    9 
 wizards/com/sun/star/wizards/ui/event/UnoDataAware.py     |   17 -
 9 files changed, 65 insertions(+), 179 deletions(-)

New commits:
commit 07fa97d8a10db2e8789d9b725359e3bd8be10db5
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Wed Jun 29 18:47:40 2011 +0200

    Save Configuration

diff --git a/wizards/com/sun/star/wizards/common/ConfigGroup.py b/wizards/com/sun/star/wizards/common/ConfigGroup.py
index 89e6c83..9019ffe 100644
--- a/wizards/com/sun/star/wizards/common/ConfigGroup.py
+++ b/wizards/com/sun/star/wizards/common/ConfigGroup.py
@@ -20,9 +20,10 @@ class ConfigGroup(ConfigNode):
             child.writeConfiguration(configView.getByName(propertyName),
                 prefix)
         else:
-            print getattr(self,field)
-            configView.setHierarchicalPropertyValue(propertyName,getattr(self,field))
-
+            try:
+                setattr(configView,propertyName,getattr(self,field))
+            except Exception:
+                pass
 
     def readConfiguration(self, configurationView, param):
         for name,data in inspect.getmembers(self):
diff --git a/wizards/com/sun/star/wizards/common/Configuration.py b/wizards/com/sun/star/wizards/common/Configuration.py
index d11f1c5..20f4bd3 100644
--- a/wizards/com/sun/star/wizards/common/Configuration.py
+++ b/wizards/com/sun/star/wizards/common/Configuration.py
@@ -132,7 +132,6 @@ class Configuration(object):
             return configView.getByName(name)
         else:
             # the new element is the result !
-            print type(configView)
             newNode = configView.createInstance()
             # insert it - this also names the element
             configView.insertByName(name, newNode)
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index 6af7026..4b48e57 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -157,7 +157,6 @@ class FaxWizardDialogImpl(FaxWizardDialog):
                         endWizard = False
                         return False
 
-
             self.myFaxDoc.setWizardTemplateDocInfo( \
                 self.resources.resFaxWizardDialog_title,
                 self.resources.resTemplateDescription)
diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.py b/wizards/com/sun/star/wizards/ui/event/CommonListener.py
index 6ff0366..3bd4862 100644
--- a/wizards/com/sun/star/wizards/ui/event/CommonListener.py
+++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.py
@@ -34,7 +34,6 @@
 
 # OOo's libraries
 import unohelper
-import inspect
 
 from com.sun.star.awt import XActionListener
 class ActionListenerProcAdapter( unohelper.Base, XActionListener ):
diff --git a/wizards/com/sun/star/wizards/ui/event/DataAware.py b/wizards/com/sun/star/wizards/ui/event/DataAware.py
index f21b86b..b0360eb 100644
--- a/wizards/com/sun/star/wizards/ui/event/DataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/DataAware.py
@@ -1,6 +1,7 @@
 from common.PropertyNames import *
 from abc import ABCMeta, abstractmethod
 import traceback
+from ui.event.CommonListener import *
 
 '''
 @author rpiterman
@@ -32,27 +33,6 @@ class DataAware(object):
         self._value = value_
 
     '''
-    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.
-    '''
-
-    def setToData(self, newValue):
-        self._value.set(newValue, self._dataObject)
-
-    '''
-    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.
-    '''
-
-    def getFromData(self):
-        return self._value.get(self._dataObject)
-
-    '''
     sets the given value to the UI control
     @param newValue the value to set to the ui control.
     '''
@@ -75,7 +55,7 @@ class DataAware(object):
     '''
 
     def updateUI(self):
-        data = self.getFromData()
+        data = self._value.get(self._dataObject)
         ui = self.getFromUI()
         if data is not ui:
             try:
@@ -90,15 +70,13 @@ class DataAware(object):
     '''
 
     def updateData(self):
-        data = self.getFromData()
-        ui = self.getFromUI()
-        if not equals(data, ui):
-            setToData(ui)
-
-    class Listener(object):
-        @abstractmethod
-        def eventPerformed (self, event):
-            pass
+        try:
+            data = self._value.get(self._dataObject)
+            ui = self.getFromUI()
+            if data is not ui:
+                self._value.Set(ui, self._dataObject)
+        except Exception:
+            traceback.print_exc()
 
     '''
     compares the two given objects.
@@ -168,135 +146,3 @@ class DataAware(object):
     def setDataObjects(self, dataAwares, dataObject, updateUI):
         for i in dataAwares:
             i.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.
-    '''
-    class Value (object):
-
-        '''gets a value from the given object.
-        @param target the object to get the value from.
-        @return the value from the given object.
-        '''
-        @abstractmethod
-        def Get (self, target):
-            pass
-
-        '''
-        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.
-        '''
-        @abstractmethod
-        def Set (self, value, target):
-            pass
-
-        '''
-        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.
-        '''
-        @abstractmethod
-        def isAssifrom(self, Type):
-            pass
-
-    '''
-    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
-    '''
-    class PropertyValue(Value):
-
-        __EMPTY_ARRAY = range(0)
-
-        '''
-        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. PropertyNames.PROPERTY_NAME for getName() and setName("..."). )
-        @param propertyOwner the object which "own" or "contains" the property
-        '''
-
-        def __init__(self, propertyName, propertyOwner):
-            self.getMethod = createGetMethod(propertyName, propertyOwner)
-            self.setMethod = createSetMethod(
-                propertyName, propertyOwner, self.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.
-        '''
-
-        def createGetMethod(self, propName, obj):
-            m = None
-            try:
-                #try to get a "get" method.
-                m = obj.getClass().getMethod(
-                    "get" + propName, self.__class__.__EMPTY_ARRAY)
-            except NoSuchMethodException, ex1:
-                raise IllegalArgumentException (
-                    "get" + propName + "() method does not exist on " + \
-                    obj.Class.Name)
-
-            return m
-
-        def Get(self, target):
-            try:
-                return self.getMethod.invoke(
-                    target, self.__class__.__EMPTY_ARRAY)
-            except IllegalAccessException, ex1:
-                ex1.printStackTrace()
-            except InvocationTargetException, ex2:
-                ex2.printStackTrace()
-            except NullPointerException, npe:
-                if isinstance(self.getMethod.getReturnType(),str):
-                    return ""
-
-                if isinstance(self.getMethod.getReturnType(),int ):
-                    return 0
-
-                if isinstance(self.getMethod.getReturnType(),tuple):
-                    return 0
-
-                if isinstance(self.getMethod.getReturnType(),list ):
-                    return []
-
-            return None
-
-        def createSetMethod(self, propName, obj, paramClass):
-            m = None
-            try:
-                m = obj.getClass().getMethod("set" + propName, [paramClass])
-            except NoSuchMethodException, ex1:
-                raise IllegalArgumentException ("set" + propName + "(" + \
-                    self.getMethod.getReturnType().getName() + \
-                    ") method does not exist on " + obj.Class.Name);
-
-            return m
-
-        def Set(self, value, target):
-            try:
-                self.setMethod.invoke(target, [value])
-            except IllegalAccessException, ex1:
-                ex1.printStackTrace()
-            except InvocationTargetException, ex2:
-                ex2.printStackTrace()
-
-        def isAssignable(self, type):
-            return self.getMethod.getDeclaringClass().isAssignableFrom(type) \
-                and self.setMethod.getDeclaringClass().isAssignableFrom(type)
-
diff --git a/wizards/com/sun/star/wizards/ui/event/DataAwareField.py b/wizards/com/sun/star/wizards/ui/event/DataAwareField.py
new file mode 100644
index 0000000..8f8b64f
--- /dev/null
+++ b/wizards/com/sun/star/wizards/ui/event/DataAwareField.py
@@ -0,0 +1,35 @@
+import traceback
+from DataAware import *
+import uno
+
+class DataAwareField(object):
+
+    def __init__(self, field, convertTo):
+        self.convertTo = convertTo
+        self.field = field
+
+    def get(self, target):
+        try:
+            i = getattr(target, self.field)
+            if isinstance(self.convertTo, bool):
+                if i:
+                    return True
+                else:
+                    return False
+            elif isinstance(self.convertTo,int):
+                return int(i)
+            elif isinstance(self.convertTo,str):
+                return str(i)
+            elif self.convertTo.type == uno.Any("short",0).type:
+                return uno.Any("[]short",(i,))
+            else:
+                raise AttributeError(
+                    "Cannot convert int value to given type (" + \
+                    str(type(self.convertTo)) + ").")
+
+        except AttributeError, ex:
+            traceback.print_exc()
+            return None
+
+    def Set(self, value, target):
+            setattr(target, self.field, value)
diff --git a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java
index ceaeaa0..3954b2e 100644
--- a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java
+++ b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.java
@@ -92,7 +92,6 @@ public class RadioDataAware extends DataAware
                 ? DataAwareFields.getFieldValueFor(data, dataProp, new Integer(0))
                 : new DataAware.PropertyValue(dataProp, data), buttons);
         XItemListener xil = UnoDataAware.itemListener(da, listener);
-        System.out.println(listener);
         for (int i = 0; i < da.radioButtons.length; i++)
         {
             da.radioButtons[i].addItemListener(xil);
diff --git a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
index 0eb4678..12f6e94 100644
--- a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
@@ -1,5 +1,5 @@
 from DataAware import *
-from DataAwareFields import *
+from DataAwareField import DataAwareField
 from UnoDataAware import *
 import time
 '''
@@ -34,9 +34,12 @@ class RadioDataAware(DataAware):
     @classmethod
     def attachRadioButtons(self, data, dataProp, buttons, field):
         if field:
-            aux = DataAwareFields.getFieldValueFor(data, dataProp, 0)
+            aux = DataAwareField(dataProp, 0)
         else:
-            aux = DataAware.PropertyValue (dataProp, data)
+            aux = DataAware.PropertyValue(dataProp, data)
 
         da = RadioDataAware(data, aux , buttons)
+        method = getattr(da,"updateData")
+        for i in da.radioButtons:
+            i.addItemListener(ItemListenerProcAdapter(method))
         return da
diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
index c2ed027..c12a81c 100644
--- a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
@@ -1,5 +1,5 @@
 from DataAware import *
-from DataAwareFields import *
+from DataAwareField import DataAwareField
 from common.Helper import *
 
 '''
@@ -84,10 +84,12 @@ class UnoDataAware(DataAware):
     def __attachTextControl(
         self, data, prop, unoText, unoProperty, field, value):
         if field:
-            aux = DataAwareFields.getFieldValueFor(data, prop, value)
+            aux = DataAwareField(prop, value)
         else:
             aux = DataAware.PropertyValue (prop, data)
         uda = UnoDataAware(data, aux, unoText, unoProperty)
+        method = getattr(uda,"updateData")
+        unoText.addTextListener(TextListenerProcAdapter(method))
         return uda
 
     @classmethod
@@ -112,15 +114,17 @@ class UnoDataAware(DataAware):
     @classmethod
     def attachCheckBox(self, data, prop, checkBox, field):
         if field:
-            aux = DataAwareFields.getFieldValueFor(data, prop, 0)
+            aux = DataAwareField(prop, 0)
         else:
             aux = DataAware.PropertyValue (prop, data)
         uda = UnoDataAware(data, aux , checkBox, PropertyNames.PROPERTY_STATE)
+        method = getattr(uda,"updateData")
+        checkBox.addItemListener(ItemListenerProcAdapter(method))
         return uda
 
     def attachLabel(self, data, prop, label, field):
         if field:
-            aux = DataAwareFields.getFieldValueFor(data, prop, "")
+            aux = DataAwareField(prop, "")
         else:
             aux = DataAware.PropertyValue (prop, data)
         return UnoDataAware(data, aux, label, PropertyNames.PROPERTY_LABEL)
@@ -128,11 +132,12 @@ class UnoDataAware(DataAware):
     @classmethod
     def attachListBox(self, data, prop, listBox, field):
         if field:
-            aux = DataAwareFields.getFieldValueFor(
-                data, prop, uno.Any("short",0))
+            aux = DataAwareField(prop, uno.Any("short",0))
         else:
             aux = DataAware.PropertyValue (prop, data)
         uda = UnoDataAware(data, aux, listBox, "SelectedItems")
+        method = getattr(uda,"updateData")
+        listBox.addItemListener(ItemListenerProcAdapter(method))
         return uda
 
     def setEnabled(self, control, enabled):


More information about the Libreoffice-commits mailing list