Search in sources :

Example 1 with TreeEditor

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

the class UIManager method changeSchemasDetailView.

/**
     * 
     * cLi Comment method "refreshSchemasDetailView".
     * 
     * refresh schema details view by different provider.
     */
public void changeSchemasDetailView(final TreeViewer schemaDetailsViewer, boolean model) {
    if (schemaDetailsViewer == null || schemaDetailsViewer.getTree().isDisposed()) {
        return;
    }
    final Tree tree = schemaDetailsViewer.getTree();
    // removed all columns
    final TreeColumn[] columns = tree.getColumns();
    for (TreeColumn col : columns) {
        col.dispose();
    }
    if (columnTreeEditor != null) {
        columnTreeEditor.dispose();
        final Control editor = columnTreeEditor.getEditor();
        if (editor != null && !editor.isDisposed()) {
            editor.setVisible(false);
            editor.dispose();
        }
        columnTreeEditor = null;
    }
    if (columnMouseListener != null) {
        tree.removeMouseListener(columnMouseListener);
        columnMouseListener = null;
    }
    SchemaDetailsProvider provider = null;
    if (model) {
        // is properties model
        provider = new SchemaDetailsPropertiesProvider(this);
        List<String> columnProperties = new ArrayList<String>();
        List<CellEditor> cellEidors = new ArrayList<CellEditor>();
        for (EPropertyName pName : EPropertyName.values()) {
            columnProperties.add(pName.name());
            TreeColumn pColumn = new TreeColumn(tree, SWT.NONE);
            pColumn.setWidth(100);
            pColumn.setText(pName.getName());
            final CellEditor cellEditor;
            switch(pName) {
                case NAME:
                case LENGTH:
                case TAGLEVEL:
                // case CARD:
                case PATTERN:
                    cellEditor = new SchemaDetailsTextCellEditor(schemaDetailsViewer, pName);
                    break;
                case KEY:
                    pColumn.setToolTipText("Only one column can be set as key.");
                    cellEditor = new SchemaDetailsCheckBoxCellEditor(tree);
                    break;
                // break;
                case TYPE:
                    cellEditor = new ComboBoxCellEditor(tree, MultiSchemasUtil.getTalendTypeLabel(), SWT.READ_ONLY);
                    break;
                default:
                    cellEditor = null;
            }
            if (cellEditor != null) {
                cellEidors.add(cellEditor);
            }
        }
        schemaDetailsViewer.setColumnProperties(columnProperties.toArray(new String[0]));
        schemaDetailsViewer.setCellEditors(cellEidors.toArray(new CellEditor[0]));
        schemaDetailsViewer.setCellModifier(new SchemaDetailsPropertiesCellModifier(schemaDetailsViewer, this));
        // set sorter
        TreeColumn sorterColumn = tree.getColumn(0);
        sorterColumn.addListener(SWT.Selection, new SchemaDetailsViewerSorterListener(schemaDetailsViewer));
        tree.setSortColumn(sorterColumn);
        tree.setSortDirection(SWT.UP);
        schemaDetailsViewer.setSorter(new SchemaDetailsViewerSorter(schemaDetailsViewer, sorterColumn, tree.getSortDirection() == SWT.UP));
    } else {
        // is column model
        provider = new SchemaDetailsColumnsProvider(this);
        // first columm is fixed.
        TreeColumn propertyColumn = new TreeColumn(tree, SWT.NONE);
        propertyColumn.setWidth(80);
        propertyColumn.setResizable(false);
        //
        columnTreeEditor = new TreeEditor(tree);
        columnTreeEditor.horizontalAlignment = SWT.LEFT;
        columnTreeEditor.grabHorizontal = true;
        columnMouseListener = new SchemaDetailsColumnMouseAdapter(schemaDetailsViewer, columnTreeEditor, this);
        tree.addMouseListener(columnMouseListener);
    }
    schemaDetailsViewer.setContentProvider(provider);
    schemaDetailsViewer.setLabelProvider(provider);
//
}
Also used : SchemaDetailsTextCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsTextCellEditor) SchemaDetailsPropertiesCellModifier(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsPropertiesCellModifier) SchemaDetailsColumnsProvider(org.talend.designer.filemultischemas.ui.provider.column.SchemaDetailsColumnsProvider) SchemaDetailsPropertiesProvider(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsPropertiesProvider) TreeEditor(org.eclipse.swt.custom.TreeEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SchemaDetailsTextCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsTextCellEditor) SchemaDetailsCheckBoxCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsCheckBoxCellEditor) ArrayList(java.util.ArrayList) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SchemaDetailsViewerSorterListener(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsViewerSorterListener) SchemaDetailsColumnMouseAdapter(org.talend.designer.filemultischemas.ui.provider.column.SchemaDetailsColumnMouseAdapter) SchemaDetailsCheckBoxCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsCheckBoxCellEditor) Control(org.eclipse.swt.widgets.Control) SchemaDetailsViewerSorter(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsViewerSorter) EPropertyName(org.talend.designer.filemultischemas.data.EPropertyName) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) SchemaDetailsProvider(org.talend.designer.filemultischemas.ui.provider.SchemaDetailsProvider)

Example 2 with TreeEditor

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

the class MetadataActionProvider method setup.

/**
 * Adds the action to the certain TreeViewer cell
 */
public void setup() {
    final TreeEditor metaEditor = new TreeEditor(treeViewer.getTree());
    metaEditor.horizontalAlignment = SWT.LEFT;
    metaEditor.verticalAlignment = SWT.TOP;
    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 || metaEditor.getItem() != cell.getItem() || metaEditor.getColumn() != cell.getColumnIndex()) {
                // Clean up any previous editor control
                Control oldmetaEditor = metaEditor.getEditor();
                if (oldmetaEditor != null) {
                    oldmetaEditor.dispose();
                    metaEditor.setEditor(null, null, 0);
                }
            }
            // No selected cell or selected cell didn't change.
            if (cell == null || cell.getColumnIndex() == 0 || (metaEditor.getItem() == cell.getItem() && metaEditor.getColumn() == cell.getColumnIndex())) {
                return;
            }
            // Initiate the extension-point
            MetadataActionExtension mae = MetadataActionExtension.getInstance();
            final Pair<Object, Object> data = retrieveMetadata(cell);
            if (data == null) {
                return;
            }
            // get all defined actions
            final List<MetadataActionFactory> actionSources = mae.getMetadataActions(data.getFirst().toString());
            if (actionSources == null || actionSources.isEmpty()) {
                return;
            }
            // Tool-bar used to view and trigger the different possible
            // actions
            ToolBar tooli = new ToolBar(treeViewer.getTree(), SWT.NONE);
            for (final MetadataActionFactory source : actionSources) {
                ToolItem actionItem = new ToolItem(tooli, SWT.PUSH);
                // get the Icon of the action
                URL iconURL = source.getIconURL();
                Image image = ImageDescriptor.createFromURL(iconURL).createImage();
                actionItem.setImage(image);
                actionItem.setToolTipText(source.getDisplayName());
                actionItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        try {
                            source.createExtensionObject().execute(data.getFirst(), data.getSecond());
                        } catch (Exception e1) {
                            _log.userError("error creating metadata action", e1);
                        }
                    }
                });
            }
            metaEditor.setEditor(tooli, (TreeItem) cell.getItem(), cell.getColumnIndex());
            tooli.pack();
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeEditor(org.eclipse.swt.custom.TreeEditor) MetadataActionExtension(eu.esdihumboldt.hale.common.instance.extension.metadata.MetadataActionExtension) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) ViewerCell(org.eclipse.jface.viewers.ViewerCell) URL(java.net.URL) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MetadataActionFactory(eu.esdihumboldt.hale.common.instance.extension.metadata.MetadataActionFactory) Control(org.eclipse.swt.widgets.Control) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(eu.esdihumboldt.util.Pair)

Example 3 with TreeEditor

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

the class InstanceExplorer method createControls.

/**
 * @see InstanceViewer#createControls(Composite, SchemaSpaceID)
 */
@Override
public void createControls(Composite parent, SchemaSpaceID schemaSpace) {
    main = new Composite(parent, SWT.NONE);
    main.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
    // selector composite
    selectorComposite = new Composite(main, SWT.NONE);
    selectorComposite.setLayoutData(GridDataFactory.swtDefaults().create());
    selectorComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    // viewer composite
    Composite viewerComposite = new Composite(main, SWT.NONE);
    viewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    TreeColumnLayout layout = new TreeColumnLayout();
    viewerComposite.setLayout(layout);
    viewer = new TreeViewer(viewerComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    viewer.getTree().setLinesVisible(true);
    // set content provider
    viewer.setContentProvider(new InstanceContentProvider());
    viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    // TODO set label provider?
    // add definition columns
    TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText("Definition");
    column.setLabelProvider(new TreeColumnViewerLabelProvider(new PairLabelProvider(true, new DefinitionMetaLabelProvider(viewer, false, true))));
    layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
    // add value column
    column = new TreeViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText("Value");
    final InstanceValueLabelProvider instanceLabelProvider = new InstanceValueLabelProvider();
    column.setLabelProvider(instanceLabelProvider);
    // new PairLabelProvider(false, new LabelProvider())));
    ColumnViewerToolTipSupport.enableFor(viewer);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
    MetadataActionProvider maep = new MetadataExploreActionProvider(viewer);
    maep.setup();
    // Add an editor for copying instance values
    editor = new TreeEditor(viewer.getTree());
    editor.horizontalAlignment = SWT.RIGHT;
    viewer.getTree().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            final ViewerCell cell = viewer.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;
            }
            // determine instance value
            Object value = ((Pair<?, ?>) cell.getViewerRow().getTreePath().getLastSegment()).getSecond();
            if (value instanceof Instance) {
                value = ((Instance) value).getValue();
            }
            // copy button
            if (value != null) {
                final String textValue = value.toString();
                if (!textValue.isEmpty()) {
                    // empty string invalid for
                    // clipboard
                    Button button = new Button(viewer.getTree(), 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) {
                            // 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 = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    editor.minimumHeight = size.y;
                    editor.minimumWidth = size.x;
                    editor.setEditor(button, (TreeItem) cell.getItem(), cell.getColumnIndex());
                }
            }
        }
    });
    update();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PairLabelProvider(eu.esdihumboldt.hale.ui.util.viewer.PairLabelProvider) TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) MetadataActionProvider(eu.esdihumboldt.hale.ui.views.data.internal.MetadataActionProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 4 with TreeEditor

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

the class RepositoryExplorerDialog method renameJob.

public void renameJob(TreeItem treeitem, String jobname, RepositoryDirectoryInterface repositorydir) {
    final TreeItem ti = treeitem;
    final String name = jobname;
    final RepositoryDirectoryInterface repdir = repositorydir;
    TreeEditor editor = new TreeEditor(wTree);
    editor.setItem(ti);
    final Text text = new Text(wTree, SWT.NONE);
    props.setLook(text);
    text.setText(name);
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent arg0) {
            // Focus is lost: apply changes
            String newname = text.getText();
            if (renameJob(name, repdir, newname)) {
                ti.setText(newname);
            }
            text.dispose();
        }
    });
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            // ESC --> Don't change tree item...
            if (e.keyCode == SWT.ESC) {
                text.dispose();
            }
            // ENTER --> Save changes...
            if (e.character == SWT.CR) {
                String newname = text.getText();
                if (renameJob(name, repdir, newname)) {
                    ti.setText(newname);
                }
                text.dispose();
            }
        }
    });
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    editor.grabVertical = true;
    editor.minimumWidth = 50;
    text.selectAll();
    text.setFocus();
    editor.layout();
    editor.setEditor(text);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) FocusAdapter(org.eclipse.swt.events.FocusAdapter) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 5 with TreeEditor

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

the class RepositoryExplorerDialog method renameDatabase.

public boolean renameDatabase() {
    boolean retval = false;
    final TreeItem ti = wTree.getSelection()[0];
    if (ti.getItemCount() == 0) {
        final String name = ti.getText();
        TreeEditor editor = new TreeEditor(wTree);
        editor.setItem(ti);
        final Text text = new Text(wTree, SWT.NONE);
        props.setLook(text);
        text.setText(name);
        text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent arg0) {
                // Focus is lost: apply changes
                String newname = text.getText();
                if (renameDatabase(name, newname)) {
                    ti.setText(newname);
                }
                text.dispose();
            }
        });
        text.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                // ESC --> Don't change tree item...
                if (e.keyCode == SWT.ESC) {
                    text.dispose();
                }
                // ENTER --> Save changes...
                if (e.character == SWT.CR) {
                    if (ti.getText().equals(name)) {
                        // Only if the name wasn't changed already.
                        String newname = text.getText();
                        if (renameDatabase(name, newname)) {
                            ti.setText(newname);
                        }
                        text.dispose();
                    }
                }
            }
        });
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        editor.grabVertical = true;
        editor.minimumWidth = 50;
        text.selectAll();
        text.setFocus();
        editor.layout();
        editor.setEditor(text);
    }
    return retval;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

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