Пример #1
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()
class DragDropServerValidationExample(HorizontalLayout):

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

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._table = Table('Drag persons onto their relatives')
        self._table.setWidth('100%')

        self._container = ExampleUtil.getPersonContainer()
        self._table.setContainerDataSource(self._container)

        # Drag and drop support
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler( TableDropHandler(self) )
        self.addComponent(self._table)


    def getFullName(self, itemId):
        item = self._container.getItem(itemId)
        if item is None:
            # should not happen in this example
            return None
        fn = item.getItemProperty(
                ExampleUtil.PERSON_PROPERTY_FIRSTNAME).getValue()
        ln = item.getItemProperty(
                ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
        return fn + ' ' + ln


    def getLastName(self, itemId):
        item = self._container.getItem(itemId)

        if item is None:
            # should not happen in this example
            return None

        return item.getItemProperty(
                ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
Пример #3
0
class DragDropServerValidationExample(HorizontalLayout):
    def __init__(self):
        super(DragDropServerValidationExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._table = Table('Drag persons onto their relatives')
        self._table.setWidth('100%')

        self._container = ExampleUtil.getPersonContainer()
        self._table.setContainerDataSource(self._container)

        # Drag and drop support
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler(TableDropHandler(self))
        self.addComponent(self._table)

    def getFullName(self, itemId):
        item = self._container.getItem(itemId)
        if item is None:
            # should not happen in this example
            return None
        fn = item.getItemProperty(
            ExampleUtil.PERSON_PROPERTY_FIRSTNAME).getValue()
        ln = item.getItemProperty(
            ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
        return fn + ' ' + ln

    def getLastName(self, itemId):
        item = self._container.getItem(itemId)

        if item is None:
            # should not happen in this example
            return None

        return item.getItemProperty(
            ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
Пример #4
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()