diff options
author | Javier Fernandez <jfernandez@igalia.com> | 2013-03-08 12:56:16 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-03-27 12:03:29 +0000 |
commit | 6db890bfbb4cc86d0963599b70033b4eb32ff154 (patch) | |
tree | 734afc5652ef676ba2509cbb66aeebfc1c5a9667 /wizards/com/sun | |
parent | 8c9b05685ff32b309e3447f2030c86e6a1ab9293 (diff) |
Ugly Hack: using our own WebConfigSet while the Topic stuff is not integrated.
Change-Id: I0df92af6b01e5eab99212bb1587f7165c70fd59b
Diffstat (limited to 'wizards/com/sun')
5 files changed, 226 insertions, 17 deletions
diff --git a/wizards/com/sun/star/wizards/web/WebConfigSet.py b/wizards/com/sun/star/wizards/web/WebConfigSet.py new file mode 100644 index 000000000000..88b49f227666 --- /dev/null +++ b/wizards/com/sun/star/wizards/web/WebConfigSet.py @@ -0,0 +1,209 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback +from ..common.ConfigGroup import ConfigGroup +from ..common.Configuration import Configuration +from ..common.XMLProvider import XMLProvider + +class WebConfigSet(ConfigGroup): + ''' + After reading the configuration set items, + the ConfigSet checks this field. + If it is true, it will remove any nulls from + the vector. + subclasses can change this field in the constructor + to avoid this "deletion" of nulls. + ''' + + def __init__(self, childType): + print ("DEBUG !!! childType: ", childType) + self.childClass = childType + self.childrenMap = {} + self.childrenList = [] + self.noNulls = False + + def add(self, name, o): + print ("DEBUG !!! WebConfigSet.add -- name: ", name) + if (o is None): + print ("DEBUG !!! WebConfigSet.add -- Received None object as argument.") + oldO = None + if (name in self.childrenMap): + oldO = self.childrenMap[name] + self.childrenMap[name] = o + try: + i = int(name) + print ("DEBUG !!! WebConfigSet.add -- name IS an integer.") + self.childrenList.insert(i, o) + except Exception: + print ("DEBUG !!! WebConfigSet.add -- name IS NOT an integer.") + try: + i = o.cp_Index + print ("DEBUG !!! WebConfigSet.add -- index: ", i) + oldSize = self.getSize() + print ("DEBUG !!! WebConfigSet.add -- oldSize: ", oldSize) + if oldSize < i: + newSize = i - oldSize + self.childrenList += [None] * newSize + self.noNulls |= True + else: + self.noNulls |= False + print ("DEBUG !!! WebConfigSet.add -- inserting object o: ", o) + self.childrenList.insert(i, o) + if oldSize > i: + oldSize = i + except Exception: + if (oldO is not None): + print ("DEBUG !!! WebConfigSet.add -- No cp_Index attribute, but element already present, so replace it.") + i = self.childrenList.index(oldO) + self.childrenList[i] = o + else: + print ("DEBUG !!! WebConfigSet.add -- No cp_Index attribute, so just append it.") + self.childrenList.append(o) + + + def writeConfiguration(self, configView, param): + print ("DEBUG !!! writeConfiguration --") + names = self.childrenMap.keys() + #first I remove all the children from the configuration. + children = configView.ElementNames + print ("DEBUG !!! writeConfiguration -- children length: ", len(children)) + if children: + print ("DEBUG !!! writeConfiguration -- removing childrens.") + for i in children: + try: + Configuration.removeNode(configView, i) + except Exception: + traceback.print_exc() + + # and add them new. + for i in names: + try: + child = self.getElement(i) + childView = Configuration.addConfigNode(configView, i) + child.writeConfiguration(childView, param) + except Exception: + traceback.print_exc() + + def readConfiguration(self, configurationView, param): + names = configurationView.ElementNames + if names: + for i in names: + print ("DEBUG !!! readConfiguration -- name: ", i) + try: + child = self.childClass() + child.root = self.root + child.readConfiguration( + configurationView.getByName(i), param) + self.add(i, child) + except Exception: + traceback.print_exc() + #remove any nulls from the list + if self.noNulls: + i = 0 + while i < len(self.childrenList): + if self.childrenList[i] is None: + del self.childrenList[i] + i -= 1 + i += 1 + + def remove(self, obj): + key = getKey(obj) + self.childrenMap.remove(key) + i = self.childrenList.indexOf(obj) + self.childrenList.remove(obj) + #fireListDataListenerIntervalRemoved(i, i) + + def remove(self, i): + o = getElementAt(i) + remove(o) + + def clear(self): + self.childrenMap.clear() + del self.childrenList[:] + + def createDOM(self, parent): + items = self.childrenList + i = 0 + while i < len(items): + item = items[i] + if isinstance(item, XMLProvider): + item.createDOM(parent) + + i += 1 + return parent + + def getKey(self, _object): + for k,v in self.childrenMap.items(): + if v is _object: + return k + return None + + def getElementAt(self, i): + return self.childrenList[i] + + def getElement(self, o): + return self.childrenMap[o] + + def getSize(self): + return len(self.childrenList) + + def getIndexOf(self, item): + return self.childrenList.index(item) + + ''' + Set members might include a property + which orders them. + This method reindexes the given member to be + the index number 0 + Do not forget to call commit() after calling this method. + @param confView + @param memebrName + ''' + + def reindexSet(self, confView, memberName, indexPropertyName): + ''' + First I read all memebrs of the set, + except the one that should be number 0 + to a vector, ordered by there index property + ''' + names = Configuration.getChildrenNames(confView) + v = [] + member = None + index = 0 + i = 0 + while i < len(names): + if not names[i] == memberName: + member = Configuration.getNode(names[i], confView) + index = Configuration.getInt(indexPropertyName, member) + while index >= v.size(): + v.append(None) + v[index] = member + ''' + Now I reindex them + ''' + i += 1 + index = 1 + i = 0 + while i < len(v): + member = v[i] + if member != None: + Configuration.set((index + 1), indexPropertyName, member) + i += 1 + + def sort(self, comparator): + self.childrenList.sort(comparator) diff --git a/wizards/com/sun/star/wizards/web/data/CGContent.py b/wizards/com/sun/star/wizards/web/data/CGContent.py index c85d7dfb301a..49e3aba0400c 100644 --- a/wizards/com/sun/star/wizards/web/data/CGContent.py +++ b/wizards/com/sun/star/wizards/web/data/CGContent.py @@ -16,7 +16,7 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # from ...common.ConfigGroup import ConfigGroup -from ...common.ConfigSet import ConfigSet +from ..WebConfigSet import WebConfigSet from ...common.XMLHelper import XMLHelper from .CGDocument import CGDocument @@ -27,8 +27,8 @@ class CGContent(ConfigGroup): cp_Name = str() cp_Description = str() #COMMENTED - #cp_Contents = ConfigSet(CGContent) - cp_Documents = ConfigSet(CGDocument()) + #cp_Contents = WebConfigSet(CGContent) + cp_Documents = WebConfigSet(CGDocument()) def createDOM(self, parent): myElement = XMLHelper.addElement( diff --git a/wizards/com/sun/star/wizards/web/data/CGExporter.py b/wizards/com/sun/star/wizards/web/data/CGExporter.py index 74288c755182..0368d0eeab97 100644 --- a/wizards/com/sun/star/wizards/web/data/CGExporter.py +++ b/wizards/com/sun/star/wizards/web/data/CGExporter.py @@ -15,7 +15,7 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -from ...common.ConfigSet import ConfigSet +from ..WebConfigSet import WebConfigSet from ...common.ConfigGroup import ConfigGroup from .CGArgument import CGArgument @@ -33,7 +33,7 @@ class CGExporter(ConfigGroup): cp_Binary = bool() cp_PageType = int() targetTypeName = "" - cp_Arguments = ConfigSet(CGArgument()) + cp_Arguments = WebConfigSet(CGArgument) def supports(self, mime): return CGExporter.cp_SupportedMimeTypes == "" or \ diff --git a/wizards/com/sun/star/wizards/web/data/CGSession.py b/wizards/com/sun/star/wizards/web/data/CGSession.py index 211cea996b3d..a2c32d1d06ac 100644 --- a/wizards/com/sun/star/wizards/web/data/CGSession.py +++ b/wizards/com/sun/star/wizards/web/data/CGSession.py @@ -18,7 +18,7 @@ import uno from ...common.ConfigGroup import ConfigGroup -from ...common.ConfigSet import ConfigSet +from ..WebConfigSet import WebConfigSet from ...common.XMLHelper import XMLHelper from .CGContent import CGContent from .CGDesign import CGDesign @@ -36,7 +36,7 @@ class CGSession(ConfigGroup): cp_Content = CGContent() cp_Design = CGDesign() cp_GeneralInfo = CGGeneralInfo() - cp_Publishing = ConfigSet(CGPublish()) + cp_Publishing = WebConfigSet(CGPublish) valid = False def createDOM(self, parent): @@ -62,7 +62,7 @@ class CGSession(ConfigGroup): return self.root.cp_Layouts.getElement(self.cp_Design.cp_Layout) def getStyle(self): - return self.root.cp_Styles.getElementAt(self.cp_Design.cp_Style) + return self.root.cp_Styles.getElement(self.cp_Design.cp_Style) def createDOM1(self): doc = Document() diff --git a/wizards/com/sun/star/wizards/web/data/CGSettings.py b/wizards/com/sun/star/wizards/web/data/CGSettings.py index ecada3f14b82..5a8a85f6f4fe 100644 --- a/wizards/com/sun/star/wizards/web/data/CGSettings.py +++ b/wizards/com/sun/star/wizards/web/data/CGSettings.py @@ -21,9 +21,9 @@ from datetime import date as dateTimeObject from ...common.FileAccess import FileAccess from ...common.ConfigGroup import ConfigGroup -from ...common.ConfigSet import ConfigSet from ...common.NumberFormatter import NumberFormatter from ...common.Properties import Properties +from ..WebConfigSet import WebConfigSet from .CGExporter import CGExporter from .CGLayout import CGLayout from .CGStyle import CGStyle @@ -45,14 +45,14 @@ class CGSettings(ConfigGroup): RESOURCE_SIZE_TEMPLATE = 4 cp_WorkDir = str() - cp_Exporters = ConfigSet(CGExporter()) - cp_Layouts = ConfigSet(CGLayout()) - cp_Styles = ConfigSet(CGStyle()) - cp_IconSets = ConfigSet(CGIconSet()) - cp_BackgroundImages = ConfigSet(CGImage()) - cp_SavedSessions = ConfigSet(CGSessionName()) - cp_Filters = ConfigSet(CGFilter()) - savedSessions = ConfigSet(CGSessionName()) + cp_Exporters = WebConfigSet(CGExporter) + cp_Layouts = WebConfigSet(CGLayout) + cp_Styles = WebConfigSet(CGStyle) + cp_IconSets = WebConfigSet(CGIconSet) + cp_BackgroundImages = WebConfigSet(CGImage) + cp_SavedSessions = WebConfigSet(CGSessionName) + cp_Filters = WebConfigSet(CGFilter) + savedSessions = WebConfigSet(CGSessionName) cp_DefaultSession = CGSession() cp_LastSavedSession = str() fileAccess = None |