Search in sources :

Example 16 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project dbeaver by serge-rider.

the class PropertyTreeViewer method registerEditor.

private void registerEditor() {
    // Make an editor
    final Tree treeControl = super.getTree();
    treeEditor = new TreeEditor(treeControl);
    treeEditor.horizontalAlignment = SWT.CENTER;
    treeEditor.verticalAlignment = SWT.CENTER;
    treeEditor.minimumWidth = 50;
    treeControl.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // showEditor((TreeItem) e.item, true);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            TreeItem item = (TreeItem) e.item;
            if (GeneralUtils.isMacOS()) {
                // [#10279] [#10366] [#10361]
                showEditor(item, isMouseEventOnMacos);
                isMouseEventOnMacos = false;
                return;
            }
            showEditor(item, (e.stateMask & SWT.BUTTON_MASK) != 0);
        }
    });
    treeControl.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            TreeItem item = treeControl.getItem(new Point(e.x, e.y));
            if (GeneralUtils.isMacOS()) {
                // [#10279] [#10366] [#10361]
                isMouseEventOnMacos = true;
            }
            if (item != null) {
                selectedColumn = UIUtils.getColumnAtPos(item, e.x, e.y);
            } else {
                selectedColumn = -1;
                if (newPropertiesAllowed) {
                    TreeItem[] allItems = treeControl.getItems();
                    TreeItem lastItem = allItems[allItems.length - 1];
                    if (lastItem.getData() instanceof TreeNode) {
                        TreeNode lastNode = (TreeNode) lastItem.getData();
                        if (!CommonUtils.isEmpty(lastNode.children)) {
                            lastNode = lastNode.children.get(lastNode.children.size() - 1);
                        }
                        if (lastNode.property != null && CommonUtils.isEmpty(lastNode.property.getDisplayName())) {
                            return;
                        }
                        if (lastNode.parent != null)
                            lastNode = lastNode.parent;
                        addProperty(lastNode, new PropertyDescriptor(lastNode.category, "prop" + lastNode.children.size(), "", "", false, String.class, "", null), true);
                        allItems = treeControl.getItems();
                        TreeItem newItem = allItems[allItems.length - 1];
                        treeControl.setSelection(newItem);
                        selectedColumn = UIUtils.getColumnAtPos(newItem, e.x, e.y);
                    }
                }
            }
        }
    });
    treeControl.addTraverseListener(e -> {
        if (e.detail == SWT.TRAVERSE_RETURN) {
            // Set focus on editor
            if (curCellEditor != null) {
                curCellEditor.setFocus();
            } else {
                final TreeItem[] selection = treeControl.getSelection();
                if (selection.length == 0) {
                    return;
                }
                showEditor(selection[0], true);
            }
            e.doit = false;
            e.detail = SWT.TRAVERSE_NONE;
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeEditor(org.eclipse.swt.custom.TreeEditor) PropertyDescriptor(org.jkiss.dbeaver.model.impl.PropertyDescriptor) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 17 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project dbeaver by serge-rider.

the class DatabaseNavigatorTree method initEditor.

private void initEditor() {
    if (inlineRenameEnabled) {
        Tree treeControl = this.treeViewer.getTree();
        treeEditor = new TreeEditor(treeControl);
        treeEditor.horizontalAlignment = SWT.LEFT;
        treeEditor.verticalAlignment = SWT.TOP;
        treeEditor.grabHorizontal = false;
        treeEditor.minimumWidth = 50;
        if (!checkEnabled) {
            // Add rename listener only for non CHECK trees
            treeControl.addMouseListener(new TreeSelectionAdapter());
        }
    }
}
Also used : TreeEditor(org.eclipse.swt.custom.TreeEditor) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Example 18 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project yyl_example by Relucent.

the class DispelTreeEditorBug method setVisibilityTreeEditor.

private void setVisibilityTreeEditor(TreeItem treeItem, boolean visible) {
    for (String sEditorName : sEditorNames) {
        Object obj = treeItem.getData(sEditorName);
        if (obj instanceof TreeEditor) {
            TreeEditor oTreeEditor = (TreeEditor) obj;
            oTreeEditor.minimumWidth = visible ? 12 : 0;
            oTreeEditor.layout();
        }
    }
}
Also used : TreeEditor(org.eclipse.swt.custom.TreeEditor)

Example 19 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project hale by halestudio.

the class DefinitionInstanceTreeViewer method createControls.

/**
 * @see InstanceViewer#createControls(Composite, SchemaSpaceID)
 */
@Override
public void createControls(final Composite parent, SchemaSpaceID schemaSpace) {
    main = new Composite(parent, SWT.NONE);
    main.setLayout(new TreeColumnLayout());
    treeViewer = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    treeViewer.setContentProvider(new TypeMetaPairContentProvider(treeViewer, schemaSpace));
    treeViewer.setLabelProvider(new DefinitionMetaCompareLabelProvider(treeViewer));
    // Add an editor for selecting specific paths.
    editor = new TreeEditor(treeViewer.getTree());
    editor.horizontalAlignment = SWT.RIGHT;
    treeViewer.getTree().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            final ViewerCell cell = treeViewer.getCell(new Point(e.x, e.y));
            // Selected cell changed?
            if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
                // Clean up any previous editor control
                Control oldEditor = editor.getEditor();
                if (oldEditor != null) {
                    oldEditor.dispose();
                    editor.setEditor(null, null, 0);
                }
            }
            // No valid selected cell
            if (cell == null || cell.getColumnIndex() == 0) {
                return;
            }
            // cell didn't change
            if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
                return;
            }
            Composite editorControl = new Composite(treeViewer.getTree(), SWT.NONE);
            GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).numColumns(2).applyTo(editorControl);
            boolean hideCopy = false;
            // multi value selector
            // Quote the format first. Pattern.quote does the same, except,
            // that it checks the input for \Es.
            // Since we know that there will be no \Es in this case
            // do it ourselves to be safe from changes to Pattern.quote.
            String pattern = "\\Q" + DefinitionInstanceLabelProvider.MULTIPLE_VALUE_FORMAT + "\\E$";
            pattern = pattern.replace("{0}", "\\E(\\d+)\\Q").replace("{1}", "\\E(\\d+)\\Q");
            Matcher m = Pattern.compile(pattern).matcher(cell.getText());
            if (m.find()) {
                // multi value element
                int current = Integer.parseInt(m.group(1));
                int total = Integer.parseInt(m.group(2));
                // Create the selection control.
                ComboViewer combo = new ComboViewer(editorControl);
                Integer[] values = new Integer[total];
                for (int i = 1; i <= total; i++) values[i - 1] = i;
                combo.setContentProvider(ArrayContentProvider.getInstance());
                combo.setInput(values);
                combo.setSelection(new StructuredSelection(current));
                combo.addSelectionChangedListener(new ISelectionChangedListener() {

                    @Override
                    public void selectionChanged(SelectionChangedEvent event) {
                        if (event.getSelection() instanceof IStructuredSelection) {
                            // Update label provider and refresh viewer.
                            labelProviders.get(cell.getColumnIndex()).selectPath(cell.getViewerRow().getTreePath(), (Integer) (((IStructuredSelection) event.getSelection()).getFirstElement()));
                            treeViewer.refresh(cell.getElement(), true);
                        }
                    }
                });
            } else {
                /*
					 * only one value - so we can safely determine if the copy
					 * button should be shown
					 */
                Object value = labelProviders.get(cell.getColumnIndex()).findInstanceEntry(cell.getViewerRow().getTreePath()).getValue();
                if (value instanceof Instance) {
                    value = ((Instance) value).getValue();
                }
                hideCopy = value == null || value.toString().isEmpty();
            }
            // copy button
            if (!hideCopy) {
                Button button = new Button(editorControl, SWT.PUSH | SWT.FLAT);
                button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
                button.setToolTipText("Copy string value");
                button.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        // determine text value
                        Object value = labelProviders.get(cell.getColumnIndex()).findInstanceEntry(cell.getViewerRow().getTreePath()).getValue();
                        if (value instanceof Instance) {
                            value = ((Instance) value).getValue();
                        }
                        if (value != null) {
                            final String textValue = value.toString();
                            if (!textValue.isEmpty()) {
                                // empty string is
                                // invalid
                                // copy content to clipboard
                                Clipboard clipBoard = new Clipboard(Display.getCurrent());
                                clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
                                clipBoard.dispose();
                            }
                        }
                    }
                });
            }
            // calculate editor size
            Point size = editorControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            editor.minimumHeight = size.y;
            editor.minimumWidth = size.x;
            editor.setEditor(editorControl, (TreeItem) cell.getItem(), cell.getColumnIndex());
        }
    });
    maep = new MetadataCompareActionProvider(treeViewer);
    maep.setup();
    treeViewer.setComparator(new DefinitionComparator());
    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.getTree().setLinesVisible(true);
    ColumnViewerToolTipSupport.enableFor(treeViewer);
    setInput(null, null);
}
Also used : TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Matcher(java.util.regex.Matcher) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 20 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project pentaho-kettle by pentaho.

the class ScriptDialog method addRenameTowTreeScriptItems.

private void addRenameTowTreeScriptItems() {
    lastItem = new TreeItem[1];
    editor = new TreeEditor(wTree);
    wTree.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            final TreeItem item = (TreeItem) event.item;
            renameFunction(item);
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CTabFolderEvent(org.eclipse.swt.custom.CTabFolderEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

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