def getContainer(self, recurse): if self._container is None or self._containerRecursive != recurse: self._container = HierarchicalContainer() self._container.addContainerProperty(self.PROPERTY_NAME, str, '') self._container.addContainerProperty(self.PROPERTY_DESCRIPTION, str, '') # fill self.addFeatures(self, self._container, recurse) return self._container
def removeItemRecursively(self, itemId): """Removes the Item identified by given itemId and all its children. @see: L{removeItem} @param itemId: the identifier of the Item to be removed @return: true if the operation succeeded """ dummy = HierarchicalContainer() return HierarchicalContainer.removeItemRecursively(dummy, self, itemId)
def testParentWhenRemovingFilterFromContainer(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(True) container.addContainerFilter(self.FULLY_QUALIFIED_NAME, 'ab', False, False) p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertEquals('com.vaadin.ui', p1) p1 = container.getParent( 'com.vaadin.terminal.gwt.client.ui.VPopupCalendar') self.assertIsNone(p1) container.removeAllContainerFilters() p1 = container.getParent( 'com.vaadin.terminal.gwt.client.ui.VPopupCalendar') self.assertEquals('com.vaadin.terminal.gwt.client.ui', p1)
def testHierarchicalContainer(self): hc = HierarchicalContainer() self.populateContainer(hc) hc.sort(['name'], [True]) self.verifyOrder(hc, ['Audi', 'C++', 'Call of Duty', 'Cars', 'English', 'Fallout', 'Finnish', 'Ford', 'Games', 'Java', 'Might and Magic', 'Natural languages', 'PHP', 'Programming languages', 'Python', 'Red Alert', 'Swedish', 'Toyota', 'Volvo']) self.assertArrays(list(hc.rootItemIds()), [self._nameToId['Cars'], self._nameToId['Games'], self._nameToId['Natural languages'], self._nameToId['Programming languages']]) self.assertArrays(list(hc.getChildren(self._nameToId['Games'])), [self._nameToId['Call of Duty'], self._nameToId['Fallout'], self._nameToId['Might and Magic'], self._nameToId['Red Alert']])
def __init__(self, caption=None, dataSource=None): """Creates a TreeTable instance with optional captions and data source. @param caption: the caption for the component @param dataSource: the dataSource that is used to list items in the component """ if dataSource is None: dataSource = HierarchicalContainer() super(TreeTable, self).__init__(caption, dataSource) self._cStrategy = None self._focusedRowId = None self._hierarchyColumnId = None # The item id that was expanded or collapsed during this request. Reset # at the end of paint and only used for determining if a partial or # full paint should be done. # # Can safely be reset to null whenever a change occurs that would # prevent a partial update from rendering the correct result, e.g. rows # added or removed during an expand operation. self._toggledItemId = None self._animationsEnabled = None self._clearFocusedRowPending = None
def testHierarchicalContainer(self): hc = HierarchicalContainer() self.populateContainer(hc) hc.sort(["name"], [True]) self.verifyOrder( hc, [ "Audi", "C++", "Call of Duty", "Cars", "English", "Fallout", "Finnish", "Ford", "Games", "Java", "Might and Magic", "Natural languages", "PHP", "Programming languages", "Python", "Red Alert", "Swedish", "Toyota", "Volvo", ], ) self.assertArrays( list(hc.rootItemIds()), [ self._nameToId["Cars"], self._nameToId["Games"], self._nameToId["Natural languages"], self._nameToId["Programming languages"], ], ) self.assertArrays( list(hc.getChildren(self._nameToId["Games"])), [ self._nameToId["Call of Duty"], self._nameToId["Fallout"], self._nameToId["Might and Magic"], self._nameToId["Red Alert"], ], )
def removeItemRecursively(self, itemId): """Removes the Item identified by given itemId and all its children. @see: L{removeItem} @param itemId: the identifier of the Item to be removed @return: true if the operation succeeded """ return HierarchicalContainer.removeItemRecursively(self, itemId)
def testHierarchicalContainer(self): hc = HierarchicalContainer() self.populateContainer(hc) hc.sort(['name'], [True]) self.verifyOrder(hc, [ 'Audi', 'C++', 'Call of Duty', 'Cars', 'English', 'Fallout', 'Finnish', 'Ford', 'Games', 'Java', 'Might and Magic', 'Natural languages', 'PHP', 'Programming languages', 'Python', 'Red Alert', 'Swedish', 'Toyota', 'Volvo' ]) self.assertArrays(list(hc.rootItemIds()), [ self._nameToId['Cars'], self._nameToId['Games'], self._nameToId['Natural languages'], self._nameToId['Programming languages'] ]) self.assertArrays(list(hc.getChildren(self._nameToId['Games'])), [ self._nameToId['Call of Duty'], self._nameToId['Fallout'], self._nameToId['Might and Magic'], self._nameToId['Red Alert'] ])
def testRemoveLastChild(self): c = HierarchicalContainer() c.addItem('root') self.assertEquals(False, c.hasChildren('root')) c.addItem('child') c.setParent('child', 'root') self.assertEquals(True, c.hasChildren('root')) c.removeItem('child') self.assertFalse(c.containsId('child')) self.assertIsNone(c.getChildren('root')) self.assertIsNone(c.getChildren('child')) self.assertFalse(c.hasChildren('child')) self.assertFalse(c.hasChildren('root'))
def testHierarchicalFilteringWithParents(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(True) # Filter by "contains ab" container.addContainerFilter(self.FULLY_QUALIFIED_NAME, 'ab', False, False) # 20 items match the filters and the have 8 parents that should also be # included # only one root "com" should exist # filtered expectedSize = 29 expectedRoots = 1 self.validateHierarchicalContainer(container, 'com', 'com.vaadin.ui.TabSheet', 'com.vaadin.terminal.gwt.client.Focusable', 'blah', True, expectedSize, expectedRoots, True) # only include .gwt.client classes container.removeAllContainerFilters() container.addContainerFilter(self.FULLY_QUALIFIED_NAME, '.gwt.client.', False, False) packages = 6 classes = 112 expectedSize = packages + classes expectedRoots = 1 self.validateHierarchicalContainer(container, 'com', 'com.vaadin.terminal.gwt.client.WidgetSet', 'com.vaadin.terminal.gwt.client.ui.VSplitPanelVertical', 'blah', True, expectedSize, expectedRoots, True) # Additionally remove all without 'm' in the simple name. container.addContainerFilter(self.SIMPLE_NAME, 'm', False, False) expectedSize = 7 + 18 expectedRoots = 1 self.validateHierarchicalContainer(container, 'com', 'com.vaadin.terminal.gwt.client.ui.VUriFragmentUtility', 'com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer', 'blah', True, expectedSize, expectedRoots, True)
def testRemoveLastChildFromFiltered(self): c = HierarchicalContainer() c.addItem('root') self.assertEquals(False, c.hasChildren('root')) c.addItem('child') c.setParent('child', 'root') self.assertEquals(True, c.hasChildren('root')) # Dummy filter that does not remove any items class DummyFilter(IFilter): def passesFilter(self, itemId, item): return True def appliesToProperty(self, propertyId): return True c.addContainerFilter(DummyFilter()) c.removeItem('child') self.assertFalse(c.containsId('child')) self.assertIsNone(c.getChildren('root')) self.assertIsNone(c.getChildren('child')) self.assertFalse(c.hasChildren('child')) self.assertFalse(c.hasChildren('root'))
def testHierarchicalFilteringWithoutParents(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(False) # Filter by "contains ab" container.addContainerFilter(self.SIMPLE_NAME, 'ab', False, False) # 20 items match the filter. # com.vaadin.data.BufferedValidatable # com.vaadin.data.Validatable # com.vaadin.terminal.gwt.client.Focusable # com.vaadin.terminal.gwt.client.Paintable # com.vaadin.terminal.gwt.client.ui.Table # com.vaadin.terminal.gwt.client.ui.VLabel # com.vaadin.terminal.gwt.client.ui.VScrollTable # com.vaadin.terminal.gwt.client.ui.VTablePaging # com.vaadin.terminal.gwt.client.ui.VTabsheet # com.vaadin.terminal.gwt.client.ui.VTabsheetBase # com.vaadin.terminal.gwt.client.ui.VTabsheetPanel # com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent # com.vaadin.terminal.Paintable # com.vaadin.terminal.Scrollable # com.vaadin.terminal.Sizeable # com.vaadin.terminal.VariableOwner # com.vaadin.ui.Label # com.vaadin.ui.Table # com.vaadin.ui.TableFieldFactory # com.vaadin.ui.TabSheet # all become roots. expectedSize = 20 expectedRoots = 20 self.validateHierarchicalContainer( container, 'com.vaadin.data.BufferedValidatable', 'com.vaadin.ui.TabSheet', 'com.vaadin.terminal.gwt.client.ui.VTabsheetBase', 'blah', True, expectedSize, expectedRoots, False) # only include .gwt.client classes container.removeAllContainerFilters() container.addContainerFilter(self.FULLY_QUALIFIED_NAME, '.gwt.client.', False, False) packages = 3 classes = 110 expectedSize = packages + classes expectedRoots = 35 + 1 # com.vaadin.terminal.gwt.client.ui + # com.vaadin.terminal.gwt.client.* # Sorting is case insensitive self.validateHierarchicalContainer( container, 'com.vaadin.terminal.gwt.client.ApplicationConfiguration', 'com.vaadin.terminal.gwt.client.WidgetSet', 'com.vaadin.terminal.gwt.client.ui.VOptionGroup', 'blah', True, expectedSize, expectedRoots, False) # Additionally remove all without 'P' in the simple name. container.addContainerFilter(self.SIMPLE_NAME, 'P', False, False) expectedSize = 13 expectedRoots = expectedSize self.validateHierarchicalContainer( container, 'com.vaadin.terminal.gwt.client.Paintable', 'com.vaadin.terminal.gwt.client.ui.VTabsheetPanel', 'com.vaadin.terminal.gwt.client.ui.VPopupCalendar', 'blah', True, expectedSize, expectedRoots, False)
def testRemovingItemsFromFilteredContainer(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(True) container.addContainerFilter(self.FULLY_QUALIFIED_NAME, 'ab', False, False) p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertEquals('com.vaadin.ui', p1) container.removeItem('com.vaadin.ui.TabSheet') # Parent for the removed item must be null because the item is no # longer in the container p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertIsNone(p1, 'Parent should be null, is ' + str(p1)) container.removeAllItems() p1 = container.getParent('com.vaadin.terminal.gwt.client.Focusable') self.assertIsNone(p1, 'Parent should be null, is ' + str(p1))
def testFiltering(self): self._testContainerFiltering(HierarchicalContainer())
def testHierarchicalSorting(self): self._testHierarchicalSorting(HierarchicalContainer())
def testChangeParentInFilteredContainer(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(True) container.addContainerFilter(self.FULLY_QUALIFIED_NAME, 'Tab', False, False) # Change parent of filtered item p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertEquals('com.vaadin.ui', p1) container.setParent('com.vaadin.ui.TabSheet', 'com.vaadin') p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertEquals('com.vaadin', p1) container.setParent('com.vaadin.ui.TabSheet', 'com') p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertEquals('com', p1) container.setParent('com.vaadin.ui.TabSheet', None) p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertIsNone(p1) # root -> non-root container.setParent('com.vaadin.ui.TabSheet', 'com') p1 = container.getParent('com.vaadin.ui.TabSheet') self.assertEquals('com', p1)
def testHierarchicalFilteringWithParents(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(True) # Filter by "contains ab" container.addContainerFilter(self.FULLY_QUALIFIED_NAME, 'ab', False, False) # 20 items match the filters and the have 8 parents that should also be # included # only one root "com" should exist # filtered expectedSize = 29 expectedRoots = 1 self.validateHierarchicalContainer( container, 'com', 'com.vaadin.ui.TabSheet', 'com.vaadin.terminal.gwt.client.Focusable', 'blah', True, expectedSize, expectedRoots, True) # only include .gwt.client classes container.removeAllContainerFilters() container.addContainerFilter(self.FULLY_QUALIFIED_NAME, '.gwt.client.', False, False) packages = 6 classes = 112 expectedSize = packages + classes expectedRoots = 1 self.validateHierarchicalContainer( container, 'com', 'com.vaadin.terminal.gwt.client.WidgetSet', 'com.vaadin.terminal.gwt.client.ui.VSplitPanelVertical', 'blah', True, expectedSize, expectedRoots, True) # Additionally remove all without 'm' in the simple name. container.addContainerFilter(self.SIMPLE_NAME, 'm', False, False) expectedSize = 7 + 18 expectedRoots = 1 self.validateHierarchicalContainer( container, 'com', 'com.vaadin.terminal.gwt.client.ui.VUriFragmentUtility', 'com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer', 'blah', True, expectedSize, expectedRoots, True)
def testOrdered(self): self._testContainerOrdered(HierarchicalContainer())
def testHierarchicalFilteringWithoutParents(self): container = HierarchicalContainer() self.initializeHierarchicalContainer(container) container.setIncludeParentsWhenFiltering(False) # Filter by "contains ab" container.addContainerFilter(self.SIMPLE_NAME, 'ab', False, False) # 20 items match the filter. # com.vaadin.data.BufferedValidatable # com.vaadin.data.Validatable # com.vaadin.terminal.gwt.client.Focusable # com.vaadin.terminal.gwt.client.Paintable # com.vaadin.terminal.gwt.client.ui.Table # com.vaadin.terminal.gwt.client.ui.VLabel # com.vaadin.terminal.gwt.client.ui.VScrollTable # com.vaadin.terminal.gwt.client.ui.VTablePaging # com.vaadin.terminal.gwt.client.ui.VTabsheet # com.vaadin.terminal.gwt.client.ui.VTabsheetBase # com.vaadin.terminal.gwt.client.ui.VTabsheetPanel # com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent # com.vaadin.terminal.Paintable # com.vaadin.terminal.Scrollable # com.vaadin.terminal.Sizeable # com.vaadin.terminal.VariableOwner # com.vaadin.ui.Label # com.vaadin.ui.Table # com.vaadin.ui.TableFieldFactory # com.vaadin.ui.TabSheet # all become roots. expectedSize = 20 expectedRoots = 20 self.validateHierarchicalContainer(container, 'com.vaadin.data.BufferedValidatable', 'com.vaadin.ui.TabSheet', 'com.vaadin.terminal.gwt.client.ui.VTabsheetBase', 'blah', True, expectedSize, expectedRoots, False) # only include .gwt.client classes container.removeAllContainerFilters() container.addContainerFilter(self.FULLY_QUALIFIED_NAME, '.gwt.client.', False, False) packages = 3 classes = 110 expectedSize = packages + classes expectedRoots = 35 + 1 # com.vaadin.terminal.gwt.client.ui + # com.vaadin.terminal.gwt.client.* # Sorting is case insensitive self.validateHierarchicalContainer(container, 'com.vaadin.terminal.gwt.client.ApplicationConfiguration', 'com.vaadin.terminal.gwt.client.WidgetSet', 'com.vaadin.terminal.gwt.client.ui.VOptionGroup', 'blah', True, expectedSize, expectedRoots, False) # Additionally remove all without 'P' in the simple name. container.addContainerFilter(self.SIMPLE_NAME, 'P', False, False) expectedSize = 13 expectedRoots = expectedSize self.validateHierarchicalContainer(container, 'com.vaadin.terminal.gwt.client.Paintable', 'com.vaadin.terminal.gwt.client.ui.VTabsheetPanel', 'com.vaadin.terminal.gwt.client.ui.VPopupCalendar', 'blah', True, expectedSize, expectedRoots, False)
def getHardwareContainer(cls): item = None itemId = 0 # Increasing numbering for itemId:s # Create new container hwContainer = HierarchicalContainer() # Create containerproperty for name hwContainer.addContainerProperty(cls.hw_PROPERTY_NAME, str, None) # Create containerproperty for icon hwContainer.addContainerProperty( cls.hw_PROPERTY_ICON, ThemeResource, ThemeResource('../runo/icons/16/document.png')) for i in range(len(cls._hardware)): # Add new item item = hwContainer.addItem(itemId) # Add name property for item v = cls._hardware[i][0] item.getItemProperty(cls.hw_PROPERTY_NAME).setValue(v) # Allow children hwContainer.setChildrenAllowed(itemId, True) itemId += 1 for j in range(1, len(cls._hardware[i])): if j == 1: v = ThemeResource('../runo/icons/16/folder.png') item.getItemProperty(cls.hw_PROPERTY_ICON).setValue(v) # Add child items item = hwContainer.addItem(itemId) v = cls._hardware[i][j] item.getItemProperty(cls.hw_PROPERTY_NAME).setValue(v) hwContainer.setParent(itemId, itemId - j) hwContainer.setChildrenAllowed(itemId, False) itemId += 1 return hwContainer
def testBasicOperations(self): self._testBasicContainerOperations(HierarchicalContainer())
def testSortingAndFiltering(self): self._testContainerSortingAndFiltering(HierarchicalContainer())
def getHardwareContainer(cls): item = None itemId = 0 # Increasing numbering for itemId:s # Create new container hwContainer = HierarchicalContainer() # Create containerproperty for name hwContainer.addContainerProperty(cls.hw_PROPERTY_NAME, str, None) # Create containerproperty for icon hwContainer.addContainerProperty( cls.hw_PROPERTY_ICON, ThemeResource, ThemeResource("../runo/icons/16/document.png") ) for i in range(len(cls._hardware)): # Add new item item = hwContainer.addItem(itemId) # Add name property for item v = cls._hardware[i][0] item.getItemProperty(cls.hw_PROPERTY_NAME).setValue(v) # Allow children hwContainer.setChildrenAllowed(itemId, True) itemId += 1 for j in range(1, len(cls._hardware[i])): if j == 1: v = ThemeResource("../runo/icons/16/folder.png") item.getItemProperty(cls.hw_PROPERTY_ICON).setValue(v) # Add child items item = hwContainer.addItem(itemId) v = cls._hardware[i][j] item.getItemProperty(cls.hw_PROPERTY_NAME).setValue(v) hwContainer.setParent(itemId, itemId - j) hwContainer.setChildrenAllowed(itemId, False) itemId += 1 return hwContainer
class FeatureSet(Feature): """Contains the FeatureSet implementation and the structure for the feature 'tree'. Each set is implemented as it's own class to facilitate linking to sets in the same way as linking to individual features. """ FEATURES = None _pathnameToFeature = None def getSinceVersion(self): return Version.OLD def __init__(self, *args): super(FeatureSet, self).__init__() self._pathname = None self._name = None self._desc = None self._icon = 'folder.gif' self._content = None self._container = None self._containerRecursive = False nargs = len(args) if nargs == 2: pathname, content = args FeatureSet.__init__(self, pathname, pathname, '', content) elif nargs == 3: pathname, name, content = args FeatureSet.__init__(self, pathname, name, '', content) elif nargs == 4: pathname, name, desc, content = args self._pathname = pathname self._name = name self._desc = desc self._content = content FeatureSet.addFeature(self) if content is not None: for f in content: if isinstance(f, FeatureSet): continue FeatureSet.addFeature(f) else: raise ValueError @classmethod def addFeature(cls, f): if cls._pathnameToFeature is None: cls._pathnameToFeature = dict() if f.getFragmentName() in cls._pathnameToFeature: raise ValueError, ('Duplicate pathname for ' + f.getFragmentName() + ': ' + cls._pathnameToFeature[f.getFragmentName()].__class__ + ' / ' + f.__class__) cls._pathnameToFeature[f.getFragmentName()] = f def getFeature(self, pathname): return self._pathnameToFeature.get(pathname) def getFeatures(self): return self._content def getContainer(self, recurse): if self._container is None or self._containerRecursive != recurse: self._container = HierarchicalContainer() self._container.addContainerProperty(self.PROPERTY_NAME, str, '') self._container.addContainerProperty(self.PROPERTY_DESCRIPTION, str, '') # fill self.addFeatures(self, self._container, recurse) return self._container def addFeatures(self, f, c, recurse): features = f.getFeatures() for i in range(len(features)): item = c.addItem(features[i]) prop = item.getItemProperty(self.PROPERTY_NAME) prop.setValue(features[i].getName()) prop = item.getItemProperty(self.PROPERTY_DESCRIPTION) prop.setValue(features[i].getDescription()) if recurse: c.setParent(features[i], f) if isinstance(features[i], FeatureSet): self.addFeatures(features[i], c, recurse) if not isinstance(features[i], FeatureSet): c.setChildrenAllowed(features[i], False) def getDescription(self): return self._desc def getFragmentName(self): return self._pathname def getName(self): return self._name def getIconName(self): return self._icon def getRelatedAPI(self): return None def getRelatedFeatures(self): return None def getRelatedResources(self): return None
class FeatureSet(Feature): """Contains the FeatureSet implementation and the structure for the feature 'tree'. Each set is implemented as it's own class to facilitate linking to sets in the same way as linking to individual features. """ FEATURES = None _pathnameToFeature = None def getSinceVersion(self): return Version.OLD def __init__(self, *args): super(FeatureSet, self).__init__() self._pathname = None self._name = None self._desc = None self._icon = 'folder.gif' self._content = None self._container = None self._containerRecursive = False nargs = len(args) if nargs == 2: pathname, content = args FeatureSet.__init__(self, pathname, pathname, '', content) elif nargs == 3: pathname, name, content = args FeatureSet.__init__(self, pathname, name, '', content) elif nargs == 4: pathname, name, desc, content = args self._pathname = pathname self._name = name self._desc = desc self._content = content FeatureSet.addFeature(self) if content is not None: for f in content: if isinstance(f, FeatureSet): continue FeatureSet.addFeature(f) else: raise ValueError @classmethod def addFeature(cls, f): if cls._pathnameToFeature is None: cls._pathnameToFeature = dict() if f.getFragmentName() in cls._pathnameToFeature: raise ValueError, ( 'Duplicate pathname for ' + f.getFragmentName() + ': ' + cls._pathnameToFeature[f.getFragmentName()].__class__ + ' / ' + f.__class__) cls._pathnameToFeature[f.getFragmentName()] = f def getFeature(self, pathname): return self._pathnameToFeature.get(pathname) def getFeatures(self): return self._content def getContainer(self, recurse): if self._container is None or self._containerRecursive != recurse: self._container = HierarchicalContainer() self._container.addContainerProperty(self.PROPERTY_NAME, str, '') self._container.addContainerProperty(self.PROPERTY_DESCRIPTION, str, '') # fill self.addFeatures(self, self._container, recurse) return self._container def addFeatures(self, f, c, recurse): features = f.getFeatures() for i in range(len(features)): item = c.addItem(features[i]) prop = item.getItemProperty(self.PROPERTY_NAME) prop.setValue(features[i].getName()) prop = item.getItemProperty(self.PROPERTY_DESCRIPTION) prop.setValue(features[i].getDescription()) if recurse: c.setParent(features[i], f) if isinstance(features[i], FeatureSet): self.addFeatures(features[i], c, recurse) if not isinstance(features[i], FeatureSet): c.setChildrenAllowed(features[i], False) def getDescription(self): return self._desc def getFragmentName(self): return self._pathname def getName(self): return self._name def getIconName(self): return self._icon def getRelatedAPI(self): return None def getRelatedFeatures(self): return None def getRelatedResources(self): return None