Search in sources :

Example 11 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project arduino-eclipse-plugin by Sloeber.

the class LibrarySelectionPage method createTree.

public void createTree(Composite parent) {
    // filtering applied to all columns
    PatternFilter filter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
            int numberOfColumns = ((TreeViewer) viewer1).getTree().getColumnCount();
            boolean isMatch = false;
            for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
                String labelText = LibraryLabelProvider.getColumnText(element, columnIndex);
                isMatch |= wordMatches(labelText);
            }
            return isMatch;
        }
    };
    this.tree = new FilteredTree(parent, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true) {

        @SuppressWarnings("synthetic-access")
        @Override
        protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
            CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
            viewer1.setCheckStateProvider(new LibraryCheckProvider());
            viewer1.setLabelProvider(new LibraryLabelProvider());
            viewer1.setContentProvider(new LibraryContentProvider());
            return viewer1;
        }
    };
    this.viewer = this.tree.getViewer();
    this.viewer.setInput(this.libs);
    TreeColumn name = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
    name.setWidth(400);
    TreeColumn version = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
    version.setWidth(100);
    // create the editor and set its attributes
    this.editor = new TreeEditor(this.viewer.getTree());
    this.editor.horizontalAlignment = SWT.LEFT;
    this.editor.grabHorizontal = true;
    this.editor.setColumn(1);
    // this ensures the tree labels are displayed correctly
    this.viewer.refresh(true);
    // enable tooltips
    ColumnViewerToolTipSupport.enableFor(this.viewer);
    // tree interactions listener
    this.viewer.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (LibrarySelectionPage.this.editor.getEditor() != null) {
                LibrarySelectionPage.this.editor.getEditor().dispose();
            }
            final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null;
            if (item != null && event.detail == SWT.CHECK) {
                if (item.getData() instanceof LibraryTree.Category) {
                    item.setGrayed(false);
                    for (LibraryTree.Library child : ((LibraryTree.Category) item.getData()).getLibraries()) {
                        if (item.getChecked()) {
                            child.setVersion(child.getLatest());
                        } else {
                            child.setVersion(null);
                        }
                    }
                    for (TreeItem child : item.getItems()) {
                        child.setChecked(item.getChecked());
                        if (item.getChecked()) {
                            child.setText(1, ((LibraryTree.Library) child.getData()).getLatest());
                        } else {
                            child.setText(1, emptyString);
                        }
                    }
                } else {
                    if (item.getChecked()) {
                        ((LibraryTree.Library) item.getData()).setVersion(((LibraryTree.Library) item.getData()).getLatest());
                        item.setText(1, ((LibraryTree.Library) item.getData()).getLatest());
                    } else {
                        ((LibraryTree.Library) item.getData()).setVersion(null);
                        item.setText(1, emptyString);
                    }
                    verifySubtreeCheckStatus(item.getParentItem());
                }
            }
            if (item != null && item.getItemCount() == 0 && item.getChecked()) {
                // Create the dropdown and add data to it
                final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY);
                for (VersionNumber version1 : ((LibraryTree.Library) item.getData()).getVersions()) {
                    combo.add(version1.toString());
                }
                // Select the previously selected item from the cell
                combo.select(combo.indexOf(item.getText(1)));
                // Compute the width for the editor
                // Also, compute the column width, so that the dropdown fits
                // Set the focus on the dropdown and set into the editor
                combo.setFocus();
                LibrarySelectionPage.this.editor.setEditor(combo, item, 1);
                // Add a listener to set the selected item back into the
                // cell
                combo.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event1) {
                        ((LibraryTree.Library) item.getData()).setVersion(combo.getText());
                        item.setText(1, combo.getText());
                        // Item selected: end the editing session
                        combo.dispose();
                    }
                });
            }
        }
    });
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) TreeItem(org.eclipse.swt.widgets.TreeItem) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) LibraryTree(io.sloeber.core.api.LibraryManager.LibraryTree) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) VersionNumber(io.sloeber.core.api.VersionNumber) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CCombo(org.eclipse.swt.custom.CCombo)

Example 12 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AbstractColumnDropTree method removeItemBranch.

protected void removeItemBranch(TreeItem item) {
    TreeEditor[] editors = (TreeEditor[]) item.getData(ITEM_EDITOR_KEY);
    if (editors != null) {
        for (TreeEditor editor : editors) {
            editor.getEditor().dispose();
            editor.dispose();
        }
    }
    if (item.getItemCount() == 0) {
        item.dispose();
        this.setDirty(true);
        return;
    }
    TreeItem[] items = item.getItems();
    for (TreeItem item2 : items) {
        removeItemBranch(item2);
    }
    item.dispose();
    this.setDirty(true);
}
Also used : TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 13 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AnalysisTableTreeViewer method createOneUnit.

public void createOneUnit(final TreeItem treeItem, TableIndicatorUnit indicatorUnit) {
    final TreeItem indicatorItem = new TreeItem(treeItem, SWT.NONE);
    final TableIndicatorUnit unit = indicatorUnit;
    IndicatorEnum type = indicatorUnit.getType();
    final IndicatorEnum indicatorEnum = type;
    indicatorItem.setData(TABLE_INDICATOR_KEY, treeItem.getData(TABLE_INDICATOR_KEY));
    indicatorItem.setData(INDICATOR_UNIT_KEY, unit);
    indicatorItem.setData(VIEWER_KEY, this);
    String label = indicatorUnit.getIndicatorName();
    // $NON-NLS-1$
    label = label != null ? label : "Unknown indicator";
    SysIndicatorDefinitionRepNode recursiveFindIndicatorDefinition = RepositoryNodeHelper.recursiveFindIndicatorDefinition(indicatorUnit.getIndicator().getIndicatorDefinition());
    if (recursiveFindIndicatorDefinition != null && !recursiveFindIndicatorDefinition.getProject().isMainProject()) {
        label = label + recursiveFindIndicatorDefinition.getDisplayProjectName();
    }
    if (IndicatorEnum.WhereRuleIndicatorEnum.compareTo(type) == 0) {
        indicatorItem.setImage(0, ImageLib.getImage(ImageLib.DQ_RULE));
    } else if (IndicatorEnum.RowCountIndicatorEnum.compareTo(type) == 0) {
        indicatorItem.setImage(0, ImageLib.getImage(ImageLib.IND_DEFINITION));
    }
    indicatorItem.setText(0, label);
    TreeEditor optionEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    final Label optionLabel = createTreeItemLabel(tree, ImageLib.OPTION, "AnalysisTableTreeViewer.options");
    optionLabel.setData(indicatorUnit);
    optionLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            boolean hasIndicatorParameters = openIndicatorOptionDialog(Display.getCurrent().getActiveShell(), indicatorItem);
            if (hasIndicatorParameters) {
                optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
            }
        }
    });
    optionEditor.minimumWidth = optionLabel.getImage().getBounds().width;
    optionEditor.horizontalAlignment = SWT.CENTER;
    optionEditor.setEditor(optionLabel, indicatorItem, 1);
    TreeEditor delEditor = null;
    if (!(unit.getIndicator() instanceof RowCountIndicator)) {
        delEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisTableTreeViewer.delete");
        delLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                deleteIndicatorItems((TableIndicator) treeItem.getData(TABLE_INDICATOR_KEY), unit);
                if (indicatorItem.getParentItem() != null && indicatorItem.getParentItem().getData(INDICATOR_UNIT_KEY) != null) {
                    setElements(tableIndicators);
                } else {
                    removeItemBranch(indicatorItem);
                    indicatorTreeItemMap.remove(unit);
                }
            }
        });
        delEditor.minimumWidth = delLabel.getImage().getBounds().width;
        delEditor.horizontalAlignment = SWT.CENTER;
        delEditor.setEditor(delLabel, indicatorItem, 2);
    }
    if (delEditor == null) {
        indicatorItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { optionEditor });
    } else {
        indicatorItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { optionEditor, delEditor });
    }
    if (indicatorEnum != null && indicatorEnum.hasChildren()) {
        indicatorItem.setData(treeItem.getData(TABLE_INDICATOR_KEY));
        createIndicatorItems(indicatorItem, indicatorUnit.getChildren());
    }
    if (hasIndicatorParameters(indicatorUnit)) {
        optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
    }
    // ADD xqliu 2009-04-30 bug 6808
    this.indicatorTreeItemMap.put(unit, indicatorItem);
}
Also used : TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) MouseEvent(org.eclipse.swt.events.MouseEvent) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) TableIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator)

Example 14 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AnalysisTableTreeViewer method addItemElements.

private void addItemElements(final TableIndicator[] elements) {
    for (final TableIndicator tableIndicator : elements) {
        final TreeItem treeItem = new TreeItem(tree, SWT.NONE);
        if (tableIndicator.isTable()) {
            treeItem.setImage(ImageLib.getImage(ImageLib.TABLE));
        } else if (tableIndicator.isView()) {
            treeItem.setImage(ImageLib.getImage(ImageLib.VIEW));
        }
        ModelElement columnSet = tableIndicator.getColumnSet();
        if (columnSet.eIsProxy()) {
            // try to resolve the proxy
            columnSet = (ModelElement) EObjectHelper.resolveObject(columnSet);
        }
        String columnSetName = columnSet.getName();
        if (columnSetName == null) {
            // $NON-NLS-1$
            columnSetName = "Unknown name";
        }
        treeItem.setText(0, columnSetName);
        treeItem.setData(TABLE_INDICATOR_KEY, tableIndicator);
        TreeEditor addDQRuleEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label addDQRuleLabl = createTreeItemLabel(tree, ImageLib.ADD_DQ, "AnalysisColumnTreeViewer.addDQRule");
        addDQRuleLabl.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                showAddDQRuleDialog(treeItem, tableIndicator);
            }
        });
        addDQRuleEditor.minimumWidth = addDQRuleLabl.getImage().getBounds().width;
        addDQRuleEditor.setEditor(addDQRuleLabl, treeItem, 1);
        TreeEditor delLabelEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisColumnTreeViewer.delete");
        delLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                deleteTableItems(tableIndicator);
                if (treeItem.getParentItem() != null && treeItem.getParentItem().getData(INDICATOR_UNIT_KEY) != null) {
                    setElements(tableIndicators);
                } else {
                    deleteIndicatorItems(tableIndicator);
                    removeItemBranch(treeItem);
                    indicatorTreeItemMap.remove(tableIndicator);
                }
            // MOD mzhao 2005-05-05 bug 6587.
            // MOD mzhao 2009-06-8, bug 5887.
            // updateBindConnection(masterPage, getTableIndicator(),
            // tree);
            }
        });
        delLabelEditor.minimumWidth = delLabel.getImage().getBounds().width;
        delLabelEditor.horizontalAlignment = SWT.CENTER;
        delLabelEditor.setEditor(delLabel, treeItem, 2);
        treeItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { addDQRuleEditor, delLabelEditor });
        if (tableIndicator.hasIndicators()) {
            createIndicatorItems(treeItem, tableIndicator.getIndicatorUnits());
        }
        treeItem.setExpanded(true);
        // ADD xqliu 2009-04-30 bug 6808
        this.indicatorTreeItemMap.put(tableIndicator, treeItem);
    }
    this.setDirty(true);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) MouseEvent(org.eclipse.swt.events.MouseEvent) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Example 15 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project BiglyBT by BiglySoftware.

the class WebSeedsEditor method createWindow.

private void createWindow() {
    this.display = Display.getCurrent();
    this.shell = com.biglybt.ui.swt.components.shell.ShellFactory.createShell(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    Messages.setLanguageText(this.shell, "wizard.webseedseditor.edit.title");
    Utils.setShellIcon(shell);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    shell.setLayout(layout);
    GridData gridData;
    if (!anonymous) {
        Label labelName = new Label(shell, SWT.NULL);
        Messages.setLanguageText(labelName, "wizard.multitracker.edit.name");
        textName = new Text(shell, SWT.BORDER);
        textName.setText(currentName);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        Utils.setLayoutData(textName, gridData);
        textName.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent arg0) {
                currentName = textName.getText();
                computeSaveEnable();
            }
        });
    }
    treeGroups = new Tree(shell, SWT.BORDER);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 3;
    gridData.heightHint = 150;
    Utils.setLayoutData(treeGroups, gridData);
    treeGroups.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            if (treeGroups.getSelectionCount() == 1) {
                TreeItem treeItem = treeGroups.getSelection()[0];
                String type = (String) treeItem.getData("type");
                if (type.equals("tracker")) {
                    editTreeItem(treeItem);
                }
            }
        }
    });
    Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    Utils.setLayoutData(labelSeparator, gridData);
    // button row
    Label label = new Label(shell, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, gridData);
    Composite cButtons = new Composite(shell, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    Utils.setLayoutData(cButtons, gridData);
    GridLayout layoutButtons = new GridLayout();
    layoutButtons.numColumns = 3;
    cButtons.setLayout(layoutButtons);
    label = new Label(cButtons, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, gridData);
    btnSave = new Button(cButtons, SWT.PUSH);
    gridData = new GridData();
    gridData.widthHint = 70;
    gridData.horizontalAlignment = GridData.END;
    Utils.setLayoutData(btnSave, gridData);
    Messages.setLanguageText(btnSave, "wizard.multitracker.edit.save");
    btnSave.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            update();
            shell.dispose();
        }
    });
    btnCancel = new Button(cButtons, SWT.PUSH);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    gridData.widthHint = 70;
    Utils.setLayoutData(btnCancel, gridData);
    Messages.setLanguageText(btnCancel, "Button.cancel");
    btnCancel.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            shell.dispose();
        }
    });
    shell.setDefaultButton(btnSave);
    shell.addListener(SWT.Traverse, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (e.character == SWT.ESC) {
                shell.dispose();
            }
        }
    });
    computeSaveEnable();
    refresh();
    constructMenu();
    editor = new TreeEditor(treeGroups);
    treeGroups.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (itemEdited != null && !editor.getEditor().isDisposed())
                itemEdited.setText(((Text) editor.getEditor()).getText());
            removeEditor();
        }
    });
    shell.pack();
    Point size = shell.computeSize(400, SWT.DEFAULT);
    shell.setSize(size);
    Utils.centreWindow(shell);
    shell.open();
}
Also used : TreeEditor(org.eclipse.swt.custom.TreeEditor) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData)

Aggregations

TreeEditor (org.eclipse.swt.custom.TreeEditor)37 TreeItem (org.eclipse.swt.widgets.TreeItem)24 MouseEvent (org.eclipse.swt.events.MouseEvent)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 MouseAdapter (org.eclipse.swt.events.MouseAdapter)10 FocusEvent (org.eclipse.swt.events.FocusEvent)8 KeyEvent (org.eclipse.swt.events.KeyEvent)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Point (org.eclipse.swt.graphics.Point)8 Label (org.eclipse.swt.widgets.Label)8 CCombo (org.eclipse.swt.custom.CCombo)5 Control (org.eclipse.swt.widgets.Control)5 FocusAdapter (org.eclipse.swt.events.FocusAdapter)4 KeyAdapter (org.eclipse.swt.events.KeyAdapter)4 Text (org.eclipse.swt.widgets.Text)4 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CTabFolderEvent (org.eclipse.swt.custom.CTabFolderEvent)3 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)3