diff options
author | Xisco Fauli <anistenis@gmail.com> | 2011-06-29 18:47:40 +0200 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2011-06-29 18:47:40 +0200 |
commit | 7dff2956f84668a425ca7770946c21911d60178a (patch) | |
tree | 93df9f59c6aca90581a0d1ce49e49c52e4d5ccb3 /wizards/com | |
parent | 315aa5d4a25369689cd0f7ade5b7064eb832a80a (diff) |
Save Configuration
Diffstat (limited to 'wizards/com')
9 files changed, 65 insertions, 179 deletions
diff --git a/wizards/com/sun/star/wizards/common/ConfigGroup.py b/wizards/com/sun/star/wizards/common/ConfigGroup.py index 89e6c834c6cd..9019ffe63575 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 d11f1c5ced69..20f4bd374f55 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 6af70260637a..4b48e57e63b7 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 6ff03667d669..3bd4862402ec 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 f21b86b76f82..b0360ebe74b6 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 000000000000..8f8b64fed08c --- /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 78e8f3ed9707..7dddea572503 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 0eb4678f6c9f..12f6e94f7a10 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 c2ed02723236..c12a81c33f35 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): |