Ejemplo n.º 1
0
    def __init__(self):
        super(TreeMultiSelectExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                          ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(
            AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)
Ejemplo n.º 2
0
    def __init__(self):
        super(TreeMouseEventsExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._t = Tree('Hardware Inventory',
                       ExampleUtil.getHardwareContainer())

        # Add ItemClickListener to the tree
        self._t.addListener(self, IItemClickListener)
        self._t.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Starting itemId # for new items
        self._itemId = len(self._t.getContainerDataSource())

        # Expand whole tree
        for i in range(self._itemId):
            self._t.expandItemsRecursively(i)

        # Disallow selecting items from the tree
        self._t.setSelectable(False)

        self.addComponent(self._t)
Ejemplo n.º 3
0
    def __init__(self):
        super(WebLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setMargin(True)
        main.setSpacing(True)
        self.setContent(main)

        # Tree to the left
        tree = Tree()
        tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        self.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSpacing(True)
        self.addComponent(left)

        # table on top
        tbl = Table()
        tbl.setWidth('500px')
        tbl.setContainerDataSource(ExampleUtil.getISO3166Container())
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        left.addComponent(text)
Ejemplo n.º 4
0
    def __init__(self):
        super(WebLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setMargin(True)
        main.setSpacing(True)
        self.setContent(main)

        # Tree to the left
        tree = Tree()
        tree.setContainerDataSource( ExampleUtil.getHardwareContainer() )
        tree.setItemCaptionPropertyId( ExampleUtil.hw_PROPERTY_NAME )
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        self.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSpacing(True)
        self.addComponent(left)

        # table on top
        tbl = Table()
        tbl.setWidth('500px')
        tbl.setContainerDataSource( ExampleUtil.getISO3166Container() )
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        left.addComponent(text)
Ejemplo n.º 5
0
    def __init__(self):
        super(TreeMultiSelectExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)
Ejemplo n.º 6
0
    def __init__(self):
        super(TreeMouseEventsExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._t = Tree('Hardware Inventory', ExampleUtil.getHardwareContainer())

        # Add ItemClickListener to the tree
        self._t.addListener(self, IItemClickListener)
        self._t.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Starting itemId # for new items
        self._itemId = len(self._t.getContainerDataSource())

        # Expand whole tree
        for i in range(self._itemId):
            self._t.expandItemsRecursively(i)

        # Disallow selecting items from the tree
        self._t.setSelectable(False)

        self.addComponent(self._t)
Ejemplo n.º 7
0
    def __init__(self):
        super(TreeSingleSelectExample, self).__init__()

        self.setSpacing(True)

        # Create the Tree,a dd to layout
        self._tree = Tree('Hardware Inventory')
        self.addComponent(self._tree)

        # Contents from a (prefilled example) hierarchical container:
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())

        # Add Valuechangelistener and Actionhandler
        self._tree.addListener(self, IValueChangeListener)

        # Add actions (context menu)
        self._tree.addActionHandler(self)

        # Cause valueChange immediately when the user selects
        self._tree.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(
            AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'editor bar' (textfield and button in a horizontallayout)
        self._editBar = HorizontalLayout()
        self._editBar.setMargin(False, False, False, True)
        self._editBar.setEnabled(False)
        self.addComponent(self._editBar)

        # textfield
        self._editor = TextField('Item name')
        self._editor.setImmediate(True)
        self._editBar.addComponent(self._editor)

        # apply-button
        self._change = Button('Apply', self)  #, 'buttonClick') FIXME: listener
        self._editBar.addComponent(self._change)
        self._editBar.setComponentAlignment(self._change,
                                            Alignment.BOTTOM_LEFT)
Ejemplo n.º 8
0
    def __init__(self):
        super(ApplicationLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setSizeFull()
        self.setContent(main)

        # Tree to the left
        treePanel = Panel()  # for scrollbars
        treePanel.setStyleName(Reindeer.PANEL_LIGHT)
        treePanel.setHeight('100%')
        treePanel.setWidth(None)
        treePanel.getContent().setSizeUndefined()
        self.addComponent(treePanel)

        tree = Tree()
        tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        treePanel.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSizeFull()
        self.addComponent(left)
        main.setExpandRatio(left, 1.0)  # use all available space

        # table on top
        tbl = Table()
        tbl.setWidth('100%')
        tbl.setContainerDataSource(ExampleUtil.getISO3166Container())
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        textPanel = Panel()  # for scrollbars
        textPanel.setStyleName(Reindeer.PANEL_LIGHT)
        textPanel.setSizeFull()
        left.addComponent(textPanel)
        left.setExpandRatio(textPanel, 1.0)  # use all available space

        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        textPanel.addComponent(text)
Ejemplo n.º 9
0
    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)
Ejemplo n.º 10
0
    def __init__(self):
        super(ApplicationLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setSizeFull()
        self.setContent(main)

        # Tree to the left
        treePanel = Panel()  # for scrollbars
        treePanel.setStyleName(Reindeer.PANEL_LIGHT)
        treePanel.setHeight('100%')
        treePanel.setWidth(None)
        treePanel.getContent().setSizeUndefined()
        self.addComponent(treePanel)

        tree = Tree()
        tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        treePanel.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSizeFull()
        self.addComponent(left)
        main.setExpandRatio(left, 1.0)  # use all available space

        # table on top
        tbl = Table()
        tbl.setWidth('100%')
        tbl.setContainerDataSource(ExampleUtil.getISO3166Container())
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        textPanel = Panel()  # for scrollbars
        textPanel.setStyleName(Reindeer.PANEL_LIGHT)
        textPanel.setSizeFull()
        left.addComponent(textPanel)
        left.setExpandRatio(textPanel, 1.0)  # use all available space

        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        textPanel.addComponent(text)
Ejemplo n.º 11
0
    def __init__(self):
        super(TreeSingleSelectExample, self).__init__()

        self.setSpacing(True)

        # Create the Tree,a dd to layout
        self._tree = Tree('Hardware Inventory')
        self.addComponent(self._tree)

        # Contents from a (prefilled example) hierarchical container:
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())

        # Add Valuechangelistener and Actionhandler
        self._tree.addListener(self, IValueChangeListener)

        # Add actions (context menu)
        self._tree.addActionHandler(self)

        # Cause valueChange immediately when the user selects
        self._tree.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'editor bar' (textfield and button in a horizontallayout)
        self._editBar = HorizontalLayout()
        self._editBar.setMargin(False, False, False, True)
        self._editBar.setEnabled(False)
        self.addComponent(self._editBar)

        # textfield
        self._editor = TextField('Item name')
        self._editor.setImmediate(True)
        self._editBar.addComponent(self._editor)

        # apply-button
        self._change = Button('Apply', self)#, 'buttonClick') FIXME: listener
        self._editBar.addComponent(self._change)
        self._editBar.setComponentAlignment(self._change, Alignment.BOTTOM_LEFT)
Ejemplo n.º 12
0
    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)
Ejemplo n.º 13
0
    def __init__(self):
        super(DragDropTreeSortingExample, self).__init__()

        self.setSpacing(True)

        tree = Tree('Tree sortable using drag\'n\'drop')

        # Populate the tree
        container = ExampleUtil.getHardwareContainer()
        tree.setContainerDataSource(container)
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        tree.setItemIconPropertyId(ExampleUtil.hw_PROPERTY_ICON)

        # Allow all nodes to have children
        for itemId in tree.getItemIds():
            tree.setChildrenAllowed(itemId, True)

        # Expand all nodes
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)

        tree.setDragMode(TreeDragMode.NODE)
        tree.setDropHandler(TreeSortDropHandler(tree, container))

        self.addComponent(tree)
Ejemplo n.º 14
0
class TreeSingleSelectExample(HorizontalLayout, IValueChangeListener,
            button.IClickListener, action.IHandler):

    # Actions for the context menu
    _ACTION_ADD = Action('Add child item')
    _ACTION_DELETE = Action('Delete')

    def __init__(self):
        super(TreeSingleSelectExample, self).__init__()

        self.setSpacing(True)

        # Create the Tree,a dd to layout
        self._tree = Tree('Hardware Inventory')
        self.addComponent(self._tree)

        # Contents from a (prefilled example) hierarchical container:
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())

        # Add Valuechangelistener and Actionhandler
        self._tree.addListener(self, IValueChangeListener)

        # Add actions (context menu)
        self._tree.addActionHandler(self)

        # Cause valueChange immediately when the user selects
        self._tree.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'editor bar' (textfield and button in a horizontallayout)
        self._editBar = HorizontalLayout()
        self._editBar.setMargin(False, False, False, True)
        self._editBar.setEnabled(False)
        self.addComponent(self._editBar)

        # textfield
        self._editor = TextField('Item name')
        self._editor.setImmediate(True)
        self._editBar.addComponent(self._editor)

        # apply-button
        self._change = Button('Apply', self)#, 'buttonClick') FIXME: listener
        self._editBar.addComponent(self._change)
        self._editBar.setComponentAlignment(self._change, Alignment.BOTTOM_LEFT)


    def valueChange(self, event):
        if event.getProperty().getValue() is not None:
            # If something is selected from the tree, get it's 'name' and
            # insert it into the textfield
            val = self._tree.getItem(
                    event.getProperty().getValue()).getItemProperty(
                            ExampleUtil.hw_PROPERTY_NAME)
            self._editor.setValue(val)
            self._editor.requestRepaint()
            self._editBar.setEnabled(True)
        else:
            self._editor.setValue('')
            self._editBar.setEnabled(False)


    def buttonClick(self, event):
        # If the edited value contains something, set it to be the item's new
        # 'name' property
        if not (self._editor.getValue() == ''):
            item = self._tree.getItem(self._tree.getValue())
            name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            name.setValue(self._editor.getValue())


    # Returns the set of available actions
    def getActions(self, target, sender):
        return [self._ACTION_ADD, self._ACTION_DELETE]


    # Handle actions
    def handleAction(self, a, sender, target):
        if a == self._ACTION_ADD:
            # Allow children for the target item, and expand it
            self._tree.setChildrenAllowed(target, True)
            self._tree.expandItem(target)
            # Create new item, set parent, disallow children (= leaf node)
            itemId = self._tree.addItem()
            self._tree.setParent(itemId, target)
            self._tree.setChildrenAllowed(itemId, False)
            # Set the name for this item (we use it as item caption)
            item = self._tree.getItem(itemId)
            name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            name.setValue('New Item')
        elif a == self._ACTION_DELETE:
            parent = self._tree.getParent(target)
            self._tree.removeItem(target)
            # If the deleted object's parent has no more children, set it's
            # childrenallowed property to false (= leaf node)
            if parent is not None and len(self._tree.getChildren(parent)) == 0:
                self._tree.setChildrenAllowed(parent, False)
Ejemplo n.º 15
0
    def createMenuTree(self):
        tree = Tree()
        tree.setImmediate(True)
        tree.setStyleName('menu')
        tree.setContainerDataSource(self._app._allFeatures)

        self._currentFeature.addListener(FeatureChangeListener(self, tree),
                prop.IValueChangeListener)
        for f in FeatureSet.FEATURES.getFeatures():
            tree.expandItemsRecursively(f)
        tree.expandItemsRecursively(FeatureSet.FEATURES)

        tree.addListener(TreeChangeListener(self),
                prop.IValueChangeListener)

        tree.setItemStyleGenerator(TreeStyleGenerator())
        return tree
Ejemplo n.º 16
0
    def createMenuTree(self):
        tree = Tree()
        tree.setImmediate(True)
        tree.setStyleName('menu')
        tree.setContainerDataSource(self._app._allFeatures)

        self._currentFeature.addListener(FeatureChangeListener(self, tree),
                                         prop.IValueChangeListener)
        for f in FeatureSet.FEATURES.getFeatures():
            tree.expandItemsRecursively(f)
        tree.expandItemsRecursively(FeatureSet.FEATURES)

        tree.addListener(TreeChangeListener(self), prop.IValueChangeListener)

        tree.setItemStyleGenerator(TreeStyleGenerator())
        return tree
Ejemplo n.º 17
0
class DragDropTableTreeExample(HorizontalLayout):
    """Demonstrate moving data back and forth between a table and a tree using
    drag and drop.

    The tree and the table use different data structures: The category is a
    separate node in the tree and each item just has a String, whereas the
    table contains items with both a name and a category. Data conversions
    between these representations are made during drop processing.
    """

    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)


    def initializeTree(self, acceptCriterion):
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)

        # Expand all nodes
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        self._tree.setDragMode(TreeDragMode.NODE)

        self._tree.setDropHandler( TreeDropHandler(self) )


    def initializeTable(self, acceptCriterion):
        tableContainer = BeanItemContainer(Hardware)
        tableContainer.addItem(Hardware('Dell OptiPlex 380', 'Desktops'))
        tableContainer.addItem(Hardware('Benq T900HD', 'Monitors'))
        tableContainer.addItem(Hardware('Lenovo ThinkPad T500', 'Laptops'))
        self._table.setContainerDataSource(tableContainer)
        self._table.setVisibleColumns(['category', 'name'])

        # Handle drop in table: move hardware item or subtree to the table
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler( TableDropHandler(self) )


    @classmethod
    def getTreeNodeName(cls, source, sourceId):
        return source.getItem(sourceId).getItemProperty(
                ExampleUtil.hw_PROPERTY_NAME).getValue()
Ejemplo n.º 18
0
class TreeMouseEventsExample(VerticalLayout, IItemClickListener):

    def __init__(self):
        super(TreeMouseEventsExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._t = Tree('Hardware Inventory', ExampleUtil.getHardwareContainer())

        # Add ItemClickListener to the tree
        self._t.addListener(self, IItemClickListener)
        self._t.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Starting itemId # for new items
        self._itemId = len(self._t.getContainerDataSource())

        # Expand whole tree
        for i in range(self._itemId):
            self._t.expandItemsRecursively(i)

        # Disallow selecting items from the tree
        self._t.setSelectable(False)

        self.addComponent(self._t)


    def itemClick(self, event):
        # Indicate which modifier keys are pressed
        modifiers = ''
        if event.isAltKey():
            modifiers += 'Alt '
        if event.isCtrlKey():
            modifiers += 'Ctrl '
        if event.isMetaKey():
            modifiers += 'Meta '
        if event.isShiftKey():
            modifiers += 'Shift '
        if len(modifiers) > 0:
            modifiers = 'Modifiers: ' + modifiers
        else:
            modifiers = 'Modifiers: none'

        b = event.getButton()
        if b == ItemClickEvent.BUTTON_LEFT:
            self.getWindow().showNotification('Selected item: '
                    + str(event.getItem()), modifiers)
        elif b == ItemClickEvent.BUTTON_MIDDLE:
            parent = self._t.getParent(event.getItemId())
            self.getWindow().showNotification('Removed item: '
                    + str(event.getItem()), modifiers)
            self._t.removeItem(event.getItemId())  # FIXME: refresh
            if (parent is not None) and \
                    (self._t.getChildren(parent) == None  # FIXME: null children
                     or len(self._t.getChildren(parent)) == 0):
                self._t.setChildrenAllowed(parent, False)
        elif b == ItemClickEvent.BUTTON_RIGHT:
            self.getWindow().showNotification('Added item: New Item # '
                    + str(self._itemId), modifiers)
            self._t.setChildrenAllowed(event.getItemId(), True)
            i = self._t.addItem(self._itemId)
            self._t.setChildrenAllowed(self._itemId, False)
            newItemName = 'New Item # ' + str(self._itemId)
            i.getItemProperty(ExampleUtil.hw_PROPERTY_NAME).setValue(newItemName)
            self._t.setParent(self._itemId, event.getItemId())
            self._t.expandItem(event.getItemId())
            self._itemId += 1
Ejemplo n.º 19
0
class TreeSingleSelectExample(HorizontalLayout, IValueChangeListener,
                              button.IClickListener, action.IHandler):

    # Actions for the context menu
    _ACTION_ADD = Action('Add child item')
    _ACTION_DELETE = Action('Delete')

    def __init__(self):
        super(TreeSingleSelectExample, self).__init__()

        self.setSpacing(True)

        # Create the Tree,a dd to layout
        self._tree = Tree('Hardware Inventory')
        self.addComponent(self._tree)

        # Contents from a (prefilled example) hierarchical container:
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())

        # Add Valuechangelistener and Actionhandler
        self._tree.addListener(self, IValueChangeListener)

        # Add actions (context menu)
        self._tree.addActionHandler(self)

        # Cause valueChange immediately when the user selects
        self._tree.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(
            AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'editor bar' (textfield and button in a horizontallayout)
        self._editBar = HorizontalLayout()
        self._editBar.setMargin(False, False, False, True)
        self._editBar.setEnabled(False)
        self.addComponent(self._editBar)

        # textfield
        self._editor = TextField('Item name')
        self._editor.setImmediate(True)
        self._editBar.addComponent(self._editor)

        # apply-button
        self._change = Button('Apply', self)  #, 'buttonClick') FIXME: listener
        self._editBar.addComponent(self._change)
        self._editBar.setComponentAlignment(self._change,
                                            Alignment.BOTTOM_LEFT)

    def valueChange(self, event):
        if event.getProperty().getValue() is not None:
            # If something is selected from the tree, get it's 'name' and
            # insert it into the textfield
            val = self._tree.getItem(
                event.getProperty().getValue()).getItemProperty(
                    ExampleUtil.hw_PROPERTY_NAME)
            self._editor.setValue(val)
            self._editor.requestRepaint()
            self._editBar.setEnabled(True)
        else:
            self._editor.setValue('')
            self._editBar.setEnabled(False)

    def buttonClick(self, event):
        # If the edited value contains something, set it to be the item's new
        # 'name' property
        if not (self._editor.getValue() == ''):
            item = self._tree.getItem(self._tree.getValue())
            name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            name.setValue(self._editor.getValue())

    # Returns the set of available actions
    def getActions(self, target, sender):
        return [self._ACTION_ADD, self._ACTION_DELETE]

    # Handle actions
    def handleAction(self, a, sender, target):
        if a == self._ACTION_ADD:
            # Allow children for the target item, and expand it
            self._tree.setChildrenAllowed(target, True)
            self._tree.expandItem(target)
            # Create new item, set parent, disallow children (= leaf node)
            itemId = self._tree.addItem()
            self._tree.setParent(itemId, target)
            self._tree.setChildrenAllowed(itemId, False)
            # Set the name for this item (we use it as item caption)
            item = self._tree.getItem(itemId)
            name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            name.setValue('New Item')
        elif a == self._ACTION_DELETE:
            parent = self._tree.getParent(target)
            self._tree.removeItem(target)
            # If the deleted object's parent has no more children, set it's
            # childrenallowed property to false (= leaf node)
            if parent is not None and len(self._tree.getChildren(parent)) == 0:
                self._tree.setChildrenAllowed(parent, False)
Ejemplo n.º 20
0
class TreeMultiSelectExample(VerticalLayout, action.IHandler):

    _ACTION_ADD = Action('Add child item')
    _ACTION_DELETE = Action('Delete')
    _ACTIONS = [_ACTION_ADD, _ACTION_DELETE]

    def __init__(self):
        super(TreeMultiSelectExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)


    # Returns the set of available actions
    def getActions(self, target, sender):
        return self._ACTIONS


    # Handle actions
    def handleAction(self, a, sender, target):
        if a == self._ACTION_ADD:
            # Allow children for the target item
            self._tree.setChildrenAllowed(target, True)
            # Create new item, disallow children, add name, set parent
            itemId = self._tree.addItem()
            self._tree.setChildrenAllowed(itemId, False)
            newItemName = 'New Item # %d' % itemId
            item = self._tree.getItem(itemId)
            p = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            p.setValue(newItemName)
            self._tree.setParent(itemId, target)
            self._tree.expandItem(target)
        elif a == self._ACTION_DELETE:
            parent = self._tree.getParent(target)
            self._tree.removeItem(target)
            # If the deleted object's parent has no more children, set it's
            # childrenallowed property to false
            if parent is not None and len(self._tree.getChildren(parent)) == 0:
                self._tree.setChildrenAllowed(parent, False)
Ejemplo n.º 21
0
    def __init__(self):
        super(DragDropTreeSortingExample, self).__init__()

        self.setSpacing(True)

        tree = Tree('Tree sortable using drag\'n\'drop')

        # Populate the tree
        container = ExampleUtil.getHardwareContainer()
        tree.setContainerDataSource(container)
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        tree.setItemIconPropertyId(ExampleUtil.hw_PROPERTY_ICON)

        # Allow all nodes to have children
        for itemId in tree.getItemIds():
            tree.setChildrenAllowed(itemId, True)

        # Expand all nodes
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)

        tree.setDragMode(TreeDragMode.NODE)
        tree.setDropHandler(TreeSortDropHandler(tree, container))

        self.addComponent(tree)
Ejemplo n.º 22
0
class DragDropTableTreeExample(HorizontalLayout):
    """Demonstrate moving data back and forth between a table and a tree using
    drag and drop.

    The tree and the table use different data structures: The category is a
    separate node in the tree and each item just has a String, whereas the
    table contains items with both a name and a category. Data conversions
    between these representations are made during drop processing.
    """
    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)

    def initializeTree(self, acceptCriterion):
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)

        # Expand all nodes
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        self._tree.setDragMode(TreeDragMode.NODE)

        self._tree.setDropHandler(TreeDropHandler(self))

    def initializeTable(self, acceptCriterion):
        tableContainer = BeanItemContainer(Hardware)
        tableContainer.addItem(Hardware('Dell OptiPlex 380', 'Desktops'))
        tableContainer.addItem(Hardware('Benq T900HD', 'Monitors'))
        tableContainer.addItem(Hardware('Lenovo ThinkPad T500', 'Laptops'))
        self._table.setContainerDataSource(tableContainer)
        self._table.setVisibleColumns(['category', 'name'])

        # Handle drop in table: move hardware item or subtree to the table
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler(TableDropHandler(self))

    @classmethod
    def getTreeNodeName(cls, source, sourceId):
        return source.getItem(sourceId).getItemProperty(
            ExampleUtil.hw_PROPERTY_NAME).getValue()
Ejemplo n.º 23
0
class TreeMultiSelectExample(VerticalLayout, action.IHandler):

    _ACTION_ADD = Action('Add child item')
    _ACTION_DELETE = Action('Delete')
    _ACTIONS = [_ACTION_ADD, _ACTION_DELETE]

    def __init__(self):
        super(TreeMultiSelectExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                          ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # Set tree to show the 'name' property as caption for items
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._tree.setItemCaptionMode(
            AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Expand whole tree
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        # Create the 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)

    # Returns the set of available actions
    def getActions(self, target, sender):
        return self._ACTIONS

    # Handle actions
    def handleAction(self, a, sender, target):
        if a == self._ACTION_ADD:
            # Allow children for the target item
            self._tree.setChildrenAllowed(target, True)
            # Create new item, disallow children, add name, set parent
            itemId = self._tree.addItem()
            self._tree.setChildrenAllowed(itemId, False)
            newItemName = 'New Item # %d' % itemId
            item = self._tree.getItem(itemId)
            p = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            p.setValue(newItemName)
            self._tree.setParent(itemId, target)
            self._tree.expandItem(target)
        elif a == self._ACTION_DELETE:
            parent = self._tree.getParent(target)
            self._tree.removeItem(target)
            # If the deleted object's parent has no more children, set it's
            # childrenallowed property to false
            if parent is not None and len(self._tree.getChildren(parent)) == 0:
                self._tree.setChildrenAllowed(parent, False)
Ejemplo n.º 24
0
class TreeMouseEventsExample(VerticalLayout, IItemClickListener):
    def __init__(self):
        super(TreeMouseEventsExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._t = Tree('Hardware Inventory',
                       ExampleUtil.getHardwareContainer())

        # Add ItemClickListener to the tree
        self._t.addListener(self, IItemClickListener)
        self._t.setImmediate(True)

        # Set tree to show the 'name' property as caption for items
        self._t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        self._t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY)

        # Starting itemId # for new items
        self._itemId = len(self._t.getContainerDataSource())

        # Expand whole tree
        for i in range(self._itemId):
            self._t.expandItemsRecursively(i)

        # Disallow selecting items from the tree
        self._t.setSelectable(False)

        self.addComponent(self._t)

    def itemClick(self, event):
        # Indicate which modifier keys are pressed
        modifiers = ''
        if event.isAltKey():
            modifiers += 'Alt '
        if event.isCtrlKey():
            modifiers += 'Ctrl '
        if event.isMetaKey():
            modifiers += 'Meta '
        if event.isShiftKey():
            modifiers += 'Shift '
        if len(modifiers) > 0:
            modifiers = 'Modifiers: ' + modifiers
        else:
            modifiers = 'Modifiers: none'

        b = event.getButton()
        if b == ItemClickEvent.BUTTON_LEFT:
            self.getWindow().showNotification(
                'Selected item: ' + str(event.getItem()), modifiers)
        elif b == ItemClickEvent.BUTTON_MIDDLE:
            parent = self._t.getParent(event.getItemId())
            self.getWindow().showNotification(
                'Removed item: ' + str(event.getItem()), modifiers)
            self._t.removeItem(event.getItemId())  # FIXME: refresh
            if (parent is not None) and \
                    (self._t.getChildren(parent) == None  # FIXME: null children
                     or len(self._t.getChildren(parent)) == 0):
                self._t.setChildrenAllowed(parent, False)
        elif b == ItemClickEvent.BUTTON_RIGHT:
            self.getWindow().showNotification(
                'Added item: New Item # ' + str(self._itemId), modifiers)
            self._t.setChildrenAllowed(event.getItemId(), True)
            i = self._t.addItem(self._itemId)
            self._t.setChildrenAllowed(self._itemId, False)
            newItemName = 'New Item # ' + str(self._itemId)
            i.getItemProperty(
                ExampleUtil.hw_PROPERTY_NAME).setValue(newItemName)
            self._t.setParent(self._itemId, event.getItemId())
            self._t.expandItem(event.getItemId())
            self._itemId += 1