Search in sources :

Example 11 with TreeEvent

use of org.eclipse.swt.events.TreeEvent in project pentaho-kettle by pentaho.

the class Spoon method addCoreObjectsTree.

public void addCoreObjectsTree() {
    if (designTreeComposite == null) {
        return;
    }
    // Now create a new expand bar inside that item
    // We're going to put the core object in there
    // 
    coreObjectsTree = new Tree(designTreeComposite, SWT.V_SCROLL | SWT.SINGLE);
    props.setLook(coreObjectsTree);
    coreObjectsTree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // 
            if (props.getAutoCollapseCoreObjectsTree()) {
                TreeItem[] selection = coreObjectsTree.getSelection();
                if (selection.length == 1) {
                    // expand if clicked on the the top level entry only...
                    // 
                    TreeItem top = selection[0];
                    while (top.getParentItem() != null) {
                        top = top.getParentItem();
                    }
                    if (top == selection[0]) {
                        boolean expanded = top.getExpanded();
                        for (TreeItem item : coreObjectsTree.getItems()) {
                            item.setExpanded(false);
                        }
                        top.setExpanded(!expanded);
                    }
                }
            }
        }
    });
    coreObjectsTree.addTreeListener(new TreeAdapter() {

        @Override
        public void treeExpanded(TreeEvent treeEvent) {
            if (props.getAutoCollapseCoreObjectsTree()) {
                TreeItem treeItem = (TreeItem) treeEvent.item;
                /*
           * Trick for WSWT on Windows systems: a SelectionEvent is called after the TreeEvent if setSelection() is not
           * used here. Otherwise the first item in the list is selected as default and collapsed again but wrong, see
           * PDI-1480
           */
                coreObjectsTree.setSelection(treeItem);
                // 
                for (TreeItem item : coreObjectsTree.getItems()) {
                    if (item != treeItem) {
                        item.setExpanded(false);
                    } else {
                        treeItem.setExpanded(true);
                    }
                }
            }
        }
    });
    coreObjectsTree.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent move) {
            // don't show tooltips in the tree if the option is not set
            if (!getProperties().showToolTips()) {
                return;
            }
            toolTip.hide();
            TreeItem item = searchMouseOverTreeItem(coreObjectsTree.getItems(), move.x, move.y);
            if (item != null) {
                String name = item.getText();
                String tip = coreStepToolTipMap.get(name);
                if (tip != null) {
                    PluginInterface plugin = PluginRegistry.getInstance().findPluginWithName(StepPluginType.class, name);
                    if (plugin != null) {
                        Image image = GUIResource.getInstance().getImagesSteps().get(plugin.getIds()[0]).getAsBitmapForSize(display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
                        if (image == null) {
                            toolTip.hide();
                        }
                        toolTip.setImage(image);
                        toolTip.setText(name + Const.CR + Const.CR + tip);
                        toolTip.setBackgroundColor(GUIResource.getInstance().getColor(255, 254, 225));
                        toolTip.setForegroundColor(GUIResource.getInstance().getColor(0, 0, 0));
                        toolTip.show(new org.eclipse.swt.graphics.Point(move.x + 10, move.y + 10));
                    }
                }
                tip = coreJobToolTipMap.get(name);
                if (tip != null) {
                    PluginInterface plugin = PluginRegistry.getInstance().findPluginWithName(JobEntryPluginType.class, name);
                    if (plugin != null) {
                        Image image = GUIResource.getInstance().getImagesJobentries().get(plugin.getIds()[0]).getAsBitmapForSize(display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
                        toolTip.setImage(image);
                        toolTip.setText(name + Const.CR + Const.CR + tip);
                        toolTip.setBackgroundColor(GUIResource.getInstance().getColor(255, 254, 225));
                        toolTip.setForegroundColor(GUIResource.getInstance().getColor(0, 0, 0));
                        toolTip.show(new org.eclipse.swt.graphics.Point(move.x + 10, move.y + 10));
                    }
                }
            }
        }
    });
    addDragSourceToTree(coreObjectsTree);
    addDefaultKeyListeners(coreObjectsTree);
    coreObjectsTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            boolean shift = (event.stateMask & SWT.SHIFT) != 0;
            doubleClickedInTree(coreObjectsTree, shift);
        }
    });
    toolTip = new DefaultToolTip(viewTreeComposite, ToolTip.RECREATE, true);
    toolTip.setRespectMonitorBounds(true);
    toolTip.setRespectDisplayBounds(true);
    toolTip.setPopupDelay(350);
    toolTip.setHideDelay(5000);
    toolTip.setShift(new org.eclipse.swt.graphics.Point(ConstUI.TOOLTIP_OFFSET, ConstUI.TOOLTIP_OFFSET));
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) DefaultToolTip(org.eclipse.jface.window.DefaultToolTip) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) MouseAdapter(org.eclipse.swt.events.MouseAdapter) TreeAdapter(org.eclipse.swt.events.TreeAdapter) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Image(org.eclipse.swt.graphics.Image) JobEntryPluginType(org.pentaho.di.core.plugins.JobEntryPluginType) TreeEvent(org.eclipse.swt.events.TreeEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree)

Example 12 with TreeEvent

use of org.eclipse.swt.events.TreeEvent in project translationstudio8 by heartsome.

the class Grid method initAccessible.

/**
     * Initialize accessibility.
     */
private void initAccessible() {
    final Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter() {

        public void getDescription(AccessibleEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                String descrption = "";
                for (int i = 0; i < columns.size(); i++) {
                    if (i != 0) {
                        descrption += ((GridColumn) columns.get(i)).getText() + " : ";
                        descrption += ((GridItem) items.get(childID)).getText(i) + " ";
                    }
                }
                e.result = descrption;
            }
        }

        public void getName(AccessibleEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // Name of the items
                e.result = ((GridItem) items.get(childID)).getText();
            } else if (childID >= items.size() && childID < items.size() + columns.size()) {
                // Name of the column headers
                e.result = ((GridColumn) columns.get(childID - items.size())).getText();
            } else if (childID >= items.size() + columns.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // Name of the column group headers
                e.result = ((GridColumnGroup) columnGroups[childID - items.size() - columns.size()]).getText();
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // Name of the toggle button for column group headers
                e.result = ACC_TOGGLE_BUTTON_NAME;
            }
        }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter() {

        public void getChildAtPoint(AccessibleControlEvent e) {
            Point location = toControl(e.x, e.y);
            e.childID = ACC.CHILDID_SELF;
            // Grid Items
            GridItem item = getItem(location);
            if (item != null) {
                for (int i = 0; i < getItems().length; i++) {
                    if (item.equals(getItem(i))) {
                        e.childID = i;
                        return;
                    }
                }
            } else {
                // Column Headers
                GridColumn column = overColumnHeader(location.x, location.y);
                if (column != null) {
                    for (int i = 0; i < getColumns().length; i++) {
                        if (column.equals(getColumn(i))) {
                            e.childID = getItems().length + i;
                            return;
                        }
                    }
                } else {
                    // Column Group headers
                    GridColumnGroup columnGroup = overColumnGroupHeader(location.x, location.y);
                    if (columnGroup != null) {
                        for (int i = 0; i < getColumnGroups().length; i++) {
                            if (columnGroup.equals(getColumnGroup(i))) {
                                Rectangle toggle = ((DefaultColumnGroupHeaderRenderer) columnGroup.getHeaderRenderer()).getToggleBounds();
                                if (toggle.contains(location.x, location.y)) {
                                    // Toggle button for column group
                                    // header
                                    e.childID = getItems().length + getColumns().length + getColumnGroups().length + i;
                                } else {
                                    // Column Group header
                                    e.childID = getItems().length + getColumns().length + i;
                                }
                                return;
                            }
                        }
                    }
                }
            }
        }

        public void getChildCount(AccessibleControlEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                int length = items.size();
                if (isTree) {
                    // it is consider as children of Grid
                    for (int i = 0; i < items.size(); i++) {
                        if (((GridItem) items.get(i)).getParentItem() != null) {
                            length--;
                        }
                    }
                }
                e.detail = length;
            }
        }

        public void getChildren(AccessibleControlEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                int length = items.size();
                if (isTree) {
                    for (int i = 0; i < items.size(); i++) {
                        if (((GridItem) items.get(i)).getParentItem() != null) {
                            length--;
                        }
                    }
                    Object[] children = new Object[length];
                    int j = 0;
                    for (int i = 0; i < items.size(); i++) {
                        if (((GridItem) items.get(i)).getParentItem() == null) {
                            children[j] = new Integer(i);
                            j++;
                        }
                    }
                    e.children = children;
                } else {
                    Object[] children = new Object[length];
                    for (int i = 0; i < items.size(); i++) {
                        children[i] = new Integer(i);
                    }
                    e.children = children;
                }
            }
        }

        public void getDefaultAction(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                if (getItem(childID).hasChildren()) {
                    // Action of tree items
                    if (getItem(childID).isExpanded()) {
                        e.result = ACC_ITEM_ACTION_COLLAPSE;
                    } else {
                        e.result = ACC_ITEM_ACTION_EXPAND;
                    }
                } else {
                    // action of default items
                    e.result = ACC_ITEM_DEFAULT_ACTION;
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // action of column and column group header
                e.result = ACC_COLUMN_DEFAULT_ACTION;
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // action of toggle button of column group header
                e.result = SWT.getMessage("SWT_Press");
            }
        }

        public void getLocation(AccessibleControlEvent e) {
            // location of parent
            Rectangle location = getBounds();
            location.x = 0;
            location.y = 0;
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // location of items
                GridItem item = getItem(childID);
                if (item != null) {
                    Point p = getOrigin((GridColumn) columns.get(0), item);
                    location.y = p.y;
                    location.height = item.getHeight();
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size()) {
                // location of columns headers
                GridColumn column = getColumn(childID - items.size());
                if (column != null) {
                    location.x = getColumnHeaderXPosition(column);
                    if (column.getColumnGroup() == null) {
                        location.y = 0;
                    } else {
                        location.y = groupHeaderHeight;
                    }
                    location.height = headerHeight;
                    location.width = column.getWidth();
                }
            } else if (childID >= items.size() + columns.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // location of column group header
                GridColumnGroup columnGroup = getColumnGroup(childID - items.size() - columns.size());
                if (columnGroup != null) {
                    location.y = 0;
                    location.height = groupHeaderHeight;
                    location.x = getColumnHeaderXPosition(columnGroup.getFirstVisibleColumn());
                    int width = 0;
                    for (int i = 0; i < columnGroup.getColumns().length; i++) {
                        if (columnGroup.getColumns()[i].isVisible()) {
                            width += columnGroup.getColumns()[i].getWidth();
                        }
                    }
                    location.width = width;
                }
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // location of toggle button of column group header
                GridColumnGroup columnGroup = getColumnGroup(childID - items.size() - columns.size() - columnGroups.length);
                location = ((DefaultColumnGroupHeaderRenderer) columnGroup.getHeaderRenderer()).getToggleBounds();
            }
            if (location != null) {
                Point pt = toDisplay(location.x, location.y);
                e.x = pt.x;
                e.y = pt.y;
                e.width = location.width;
                e.height = location.height;
            }
        }

        public void getRole(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // role of items
                if (isTree) {
                    e.detail = ACC.ROLE_TREEITEM;
                } else {
                    e.detail = ACC.ROLE_LISTITEM;
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // role of columns headers and column group headers
                e.detail = ACC.ROLE_TABLECOLUMNHEADER;
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // role of toggle button of column group headers
                e.detail = ACC.ROLE_PUSHBUTTON;
            } else if (childID == ACC.CHILDID_SELF) {
                // role of parent
                if (isTree) {
                    e.detail = ACC.ROLE_TREE;
                } else {
                    e.detail = ACC.ROLE_TABLE;
                }
            }
        }

        public void getSelection(AccessibleControlEvent e) {
            e.childID = ACC.CHILDID_NONE;
            if (selectedItems.size() == 1) {
                // Single selection
                e.childID = indexOf(((GridItem) selectedItems.get(0)));
            } else if (selectedItems.size() > 1) {
                // multiple selection
                e.childID = ACC.CHILDID_MULTIPLE;
                int length = selectedItems.size();
                Object[] children = new Object[length];
                for (int i = 0; i < length; i++) {
                    GridItem item = (GridItem) selectedItems.get(i);
                    children[i] = new Integer(indexOf(item));
                }
                e.children = children;
            }
        }

        public void getState(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // state of items
                e.detail = ACC.STATE_SELECTABLE;
                if (getDisplay().getActiveShell() == getParent().getShell()) {
                    e.detail |= ACC.STATE_FOCUSABLE;
                }
                if (selectedItems.contains(getItem(childID))) {
                    e.detail |= ACC.STATE_SELECTED;
                    if (getDisplay().getActiveShell() == getParent().getShell()) {
                        e.detail |= ACC.STATE_FOCUSED;
                    }
                }
                if (getItem(childID).getChecked()) {
                    e.detail |= ACC.STATE_CHECKED;
                }
                // only for tree type items
                if (getItem(childID).hasChildren()) {
                    if (getItem(childID).isExpanded()) {
                        e.detail |= ACC.STATE_EXPANDED;
                    } else {
                        e.detail |= ACC.STATE_COLLAPSED;
                    }
                }
                if (!getItem(childID).isVisible()) {
                    e.detail |= ACC.STATE_INVISIBLE;
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // state of column headers and column group headers
                e.detail = ACC.STATE_READONLY;
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // state of toggle button of column group headers
                if (getColumnGroup(childID - items.size() - columns.size() - columnGroups.length).getExpanded()) {
                    e.detail = ACC.STATE_EXPANDED;
                } else {
                    e.detail = ACC.STATE_COLLAPSED;
                }
            }
        }

        public void getValue(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // value for tree items
                if (isTree) {
                    e.result = "" + getItem(childID).getLevel();
                }
            }
        }
    });
    addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (selectedItems.size() > 0) {
                accessible.setFocus(items.indexOf(selectedItems.get(selectedItems.size() - 1)));
            }
        }
    });
    addTreeListener(new TreeListener() {

        public void treeCollapsed(TreeEvent e) {
            if (getFocusItem() != null) {
                accessible.setFocus(items.indexOf(getFocusItem()));
            }
        }

        public void treeExpanded(TreeEvent e) {
            if (getFocusItem() != null) {
                accessible.setFocus(items.indexOf(getFocusItem()));
            }
        }
    });
}
Also used : TreeListener(org.eclipse.swt.events.TreeListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) SelectionListener(org.eclipse.swt.events.SelectionListener) PaintListener(org.eclipse.swt.events.PaintListener) FocusListener(org.eclipse.swt.events.FocusListener) TypedListener(org.eclipse.swt.widgets.TypedListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TreeListener(org.eclipse.swt.events.TreeListener) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleControlAdapter(org.eclipse.swt.accessibility.AccessibleControlAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TreeEvent(org.eclipse.swt.events.TreeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Accessible(org.eclipse.swt.accessibility.Accessible)

Example 13 with TreeEvent

use of org.eclipse.swt.events.TreeEvent in project translationstudio8 by heartsome.

the class ColumnChooserDialog method populateDialogArea.

@Override
public void populateDialogArea(Composite parent) {
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
    parent.setLayout(new GridLayout(4, false));
    createLabels(parent, availableLabel, selectedLabel);
    availableTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
    GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
    availableTree.setLayoutData(gridData);
    availableTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            addSelected();
        }
    });
    availableTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                addSelected();
        }
    });
    Composite buttonComposite = new Composite(parent, SWT.NONE);
    buttonComposite.setLayout(new GridLayout(1, true));
    Button addButton = new Button(buttonComposite, SWT.PUSH);
    addButton.setImage(GUIHelper.getImage("arrow_right"));
    gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
    addButton.setLayoutData(gridData);
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            addSelected();
        }
    });
    Button removeButton = new Button(buttonComposite, SWT.PUSH);
    removeButton.setImage(GUIHelper.getImage("arrow_left"));
    gridData = GridDataFactory.copyData(gridData);
    removeButton.setLayoutData(gridData);
    removeButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            removeSelected();
        }
    });
    selectedTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
    gridData = GridDataFactory.fillDefaults().grab(true, true).create();
    selectedTree.setLayoutData(gridData);
    selectedTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            removeSelected();
        }
    });
    selectedTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
            if (controlMask && e.keyCode == SWT.ARROW_UP) {
                moveSelectedUp();
                e.doit = false;
            } else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
                moveSelectedDown();
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                removeSelected();
        }
    });
    selectedTree.addTreeListener(new TreeListener() {

        public void treeCollapsed(TreeEvent event) {
            selectedTreeCollapsed(event);
        }

        public void treeExpanded(TreeEvent event) {
            selectedTreeExpanded(event);
        }
    });
    selectedTree.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            toggleColumnGroupSelection((TreeItem) event.item);
        }
    });
    Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
    upDownbuttonComposite.setLayout(new GridLayout(1, true));
    Button upButton = new Button(upDownbuttonComposite, SWT.PUSH);
    upButton.setImage(GUIHelper.getImage("arrow_up"));
    gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
    upButton.setLayoutData(gridData);
    upButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            moveSelectedUp();
        }
    });
    Button downButton = new Button(upDownbuttonComposite, SWT.PUSH);
    downButton.setImage(GUIHelper.getImage("arrow_down"));
    gridData = GridDataFactory.copyData(gridData);
    downButton.setLayoutData(gridData);
    downButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            moveSelectedDown();
        }
    });
}
Also used : ISelectionTreeListener(net.sourceforge.nattable.columnChooser.ISelectionTreeListener) TreeListener(org.eclipse.swt.events.TreeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 14 with TreeEvent

use of org.eclipse.swt.events.TreeEvent in project eclipse.platform.swt by eclipse.

the class Tab method log.

/**
 * Logs an untyped event to the event console.
 */
void log(Event event) {
    int i = 0;
    while (i < EVENT_INFO.length) {
        if (EVENT_INFO[i].type == event.type)
            break;
        i++;
    }
    String toString = EVENT_INFO[i].name + " [" + event.type + "]: ";
    if (!untypedEvents) {
        switch(event.type) {
            case SWT.KeyDown:
            case SWT.KeyUp:
                toString += new KeyEvent(event).toString();
                break;
            case SWT.MouseDown:
            case SWT.MouseUp:
            case SWT.MouseMove:
            case SWT.MouseEnter:
            case SWT.MouseExit:
            case SWT.MouseDoubleClick:
            case SWT.MouseWheel:
            case SWT.MouseHover:
                toString += new MouseEvent(event).toString();
                break;
            case SWT.Paint:
                toString += new PaintEvent(event).toString();
                break;
            case SWT.Move:
            case SWT.Resize:
                toString += new ControlEvent(event).toString();
                break;
            case SWT.Dispose:
                toString += new DisposeEvent(event).toString();
                break;
            case SWT.Selection:
            case SWT.DefaultSelection:
                toString += new SelectionEvent(event).toString();
                break;
            case SWT.FocusIn:
            case SWT.FocusOut:
                toString += new FocusEvent(event).toString();
                break;
            case SWT.Expand:
            case SWT.Collapse:
                toString += new TreeEvent(event).toString();
                break;
            case SWT.Iconify:
            case SWT.Deiconify:
            case SWT.Close:
            case SWT.Activate:
            case SWT.Deactivate:
                toString += new ShellEvent(event).toString();
                break;
            case SWT.Show:
            case SWT.Hide:
                toString += (event.widget instanceof Menu) ? new MenuEvent(event).toString() : event.toString();
                break;
            case SWT.Modify:
                toString += new ModifyEvent(event).toString();
                break;
            case SWT.Verify:
                toString += new VerifyEvent(event).toString();
                break;
            case SWT.Help:
                toString += new HelpEvent(event).toString();
                break;
            case SWT.Arm:
                toString += new ArmEvent(event).toString();
                break;
            case SWT.Traverse:
                toString += new TraverseEvent(event).toString();
                break;
            case SWT.HardKeyDown:
            case SWT.HardKeyUp:
            case SWT.DragDetect:
            case SWT.MenuDetect:
            case SWT.SetData:
            default:
                toString += event.toString();
        }
    } else {
        toString += event.toString();
    }
    log(toString);
    /* Return values for event fields. */
    int mask = EVENT_INFO[i].setFields;
    if (!ignore && mask != 0) {
        Event setFieldsEvent = EVENT_INFO[i].event;
        if ((mask & DOIT) != 0)
            event.doit = setFieldsEvent.doit;
        if ((mask & DETAIL) != 0)
            event.detail = setFieldsEvent.detail;
        if ((mask & TEXT) != 0)
            event.text = setFieldsEvent.text;
        if ((mask & X) != 0)
            event.x = setFieldsEvent.x;
        if ((mask & Y) != 0)
            event.y = setFieldsEvent.y;
        if ((mask & WIDTH) != 0)
            event.width = setFieldsEvent.width;
        if ((mask & HEIGHT) != 0)
            event.height = setFieldsEvent.height;
        eventConsole.append(ControlExample.getResourceString("Returning"));
        ignore = true;
        log(event);
        ignore = false;
    }
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TypedEvent(org.eclipse.swt.events.TypedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) HelpEvent(org.eclipse.swt.events.HelpEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 15 with TreeEvent

use of org.eclipse.swt.events.TreeEvent in project eclipse.platform.swt by eclipse.

the class LauncherView method createPartControl.

/**
 * Creates the example.
 *
 * @see ViewPart#createPartControl
 */
@Override
public void createPartControl(Composite parent) {
    workbenchShell = getSite().getShell();
    parent.setLayout(new SplitLayout());
    Group launchGroup = new Group(parent, SWT.NONE);
    launchGroup.setText(LauncherPlugin.getResourceString("view.launchGroup.text"));
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    launchGroup.setLayout(gridLayout);
    launchTree = new Tree(launchGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.horizontalSpan = 2;
    launchTree.setLayoutData(gridData);
    launchTree.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final ItemDescriptor item = getSelectedItem();
            setDescriptionByItem(item);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            final ItemDescriptor item = getSelectedItem();
            setDescriptionByItem(item);
            if (item.getMainType() == null && item.getView() == null) {
                // Category selected, so just expand/colapse the node
                TreeItem treeItem = (TreeItem) event.item;
                boolean expanded = treeItem.getExpanded();
                if (treeItem != null)
                    treeItem.setExpanded(!expanded);
                treeItem.setImage(LauncherPlugin.images[expanded ? LauncherPlugin.liClosedFolder : LauncherPlugin.liOpenFolder]);
            } else {
                launchItem(getSelectedItem());
            }
        }
    });
    launchTree.addTreeListener(new TreeListener() {

        @Override
        public void treeCollapsed(TreeEvent event) {
            final TreeItem item = (TreeItem) event.item;
            if (item == null)
                return;
            item.setImage(LauncherPlugin.images[LauncherPlugin.liClosedFolder]);
        }

        @Override
        public void treeExpanded(TreeEvent event) {
            final TreeItem item = (TreeItem) event.item;
            if (item == null)
                return;
            item.setImage(LauncherPlugin.images[LauncherPlugin.liOpenFolder]);
        }
    });
    runButton = new Button(launchGroup, SWT.PUSH);
    runButton.setText(LauncherPlugin.getResourceString("view.launchButton.text"));
    runButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            launchItem(getSelectedItem());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
        }
    });
    Group descriptionGroup = new Group(parent, SWT.NONE);
    descriptionGroup.setText(LauncherPlugin.getResourceString("view.descriptionGroup.text"));
    descriptionGroup.setLayout(new FillLayout());
    descriptionText = new Text(descriptionGroup, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
    setDescriptionByItem(null);
    setItemDescriptors(LauncherPlugin.getLaunchItemTree());
}
Also used : TreeListener(org.eclipse.swt.events.TreeListener) Group(org.eclipse.swt.widgets.Group) TreeItem(org.eclipse.swt.widgets.TreeItem) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) TreeEvent(org.eclipse.swt.events.TreeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

TreeEvent (org.eclipse.swt.events.TreeEvent)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 TreeItem (org.eclipse.swt.widgets.TreeItem)11 TreeListener (org.eclipse.swt.events.TreeListener)9 Tree (org.eclipse.swt.widgets.Tree)9 MouseEvent (org.eclipse.swt.events.MouseEvent)8 GridData (org.eclipse.swt.layout.GridData)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Composite (org.eclipse.swt.widgets.Composite)7 TreeAdapter (org.eclipse.swt.events.TreeAdapter)6 KeyEvent (org.eclipse.swt.events.KeyEvent)5 MouseAdapter (org.eclipse.swt.events.MouseAdapter)5 Button (org.eclipse.swt.widgets.Button)5 Point (org.eclipse.swt.graphics.Point)4 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 KeyAdapter (org.eclipse.swt.events.KeyAdapter)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 Event (org.eclipse.swt.widgets.Event)3