Exemplo n.º 1
0
    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 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'))
Exemplo n.º 3
0
 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 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 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 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))
Exemplo n.º 9
0
 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']
     ])
Exemplo n.º 10
0
    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 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 testSortingAndFiltering(self):
     self._testContainerSortingAndFiltering(HierarchicalContainer())
 def testFiltering(self):
     self._testContainerFiltering(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 testOrdered(self):
     self._testContainerOrdered(HierarchicalContainer())
 def testHierarchicalSorting(self):
     self._testHierarchicalSorting(HierarchicalContainer())
 def testBasicOperations(self):
     self._testBasicContainerOperations(HierarchicalContainer())