Search in sources :

Example 6 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell 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 7 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell 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 8 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.

the class AbstractFunctionParameterSection method createControls.

/**
 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite,
 *      org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
 */
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);
    Composite compparent = getWidgetFactory().createComposite(parent);
    compparent.setLayout(new FormLayout());
    Composite composite = getWidgetFactory().createComposite(compparent);
    TableColumnLayout columnLayout = new TableColumnLayout();
    composite.setLayout(columnLayout);
    FormData data = new FormData();
    data.width = 100;
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, -0);
    data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
    data.bottom = new FormAttachment(100, -ITabbedPropertyConstants.VSPACE);
    composite.setLayoutData(data);
    tableViewer = new TableViewer(composite, SWT.FULL_SELECTION);
    Table table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    TableViewerColumn nameviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn namecol = nameviewercol.getColumn();
    columnLayout.setColumnData(namecol, new ColumnWeightData(20));
    namecol.setText("Name");
    nameviewercol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((FunctionParameter) cell.getElement()).getName());
        }
    });
    TableViewerColumn lableviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn lablecol = lableviewercol.getColumn();
    columnLayout.setColumnData(lablecol, new ColumnWeightData(20));
    lablecol.setText("Label");
    lableviewercol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((FunctionParameter) cell.getElement()).getDisplayName());
        }
    });
    TableViewerColumn occurenceviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn occurencecol = occurenceviewercol.getColumn();
    columnLayout.setColumnData(occurencecol, new ColumnWeightData(10));
    occurencecol.setText("Occurence");
    occurenceviewercol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            FunctionParameter cellparameter = ((FunctionParameter) cell.getElement());
            cell.setText(String.valueOf(cellparameter.getMinOccurrence()) + ".." + (String.valueOf(cellparameter.getMaxOccurrence())));
        }
    });
    TableViewerColumn descriptionviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn descriptioncol = descriptionviewercol.getColumn();
    columnLayout.setColumnData(descriptioncol, new ColumnWeightData(40));
    descriptioncol.setText("Description");
    descriptionviewercol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(String.valueOf(((FunctionParameter) cell.getElement()).getDescription()));
        }
    });
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableColumn(org.eclipse.swt.widgets.TableColumn) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) FunctionParameter(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameter)

Example 9 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project sling by apache.

the class MVPEditor method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    // now add the node type dropbox-combo
    Composite header = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.numColumns = 3;
    header.setLayout(layout);
    Label label = new Label(header, SWT.WRAP);
    label.setText("Modify property " + property.getName() + ":");
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(data);
    label.setFont(parent.getFont());
    ToolBar buttonBar = new ToolBar(header, SWT.NONE);
    ToolItem invisible = new ToolItem(buttonBar, SWT.NONE);
    ToolItem plus = new ToolItem(buttonBar, SWT.NONE);
    plus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD).createImage());
    plus.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            plus();
        }
    });
    final ToolItem minus = new ToolItem(buttonBar, SWT.NONE);
    minus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE).createImage());
    minus.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            minus();
        }
    });
    minus.setEnabled(false);
    Composite tableParent = new Composite(composite, SWT.NONE);
    final GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 150;
    tableParent.setLayoutData(layoutData);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableParent.setLayout(tableLayout);
    viewer = new TableViewer(tableParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    // accessing property here directly, instead of going via (JcrProperty)inputElement;
    String[] rawLines = property.getValuesAsString();
    // convert raw lines to Line objects for easier editing management
    for (int i = 0; i < rawLines.length; i++) {
        lines.add(new Line(rawLines[i]));
    }
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return lines.toArray();
        }
    });
    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setText("Type");
    column0.getColumn().setResizable(true);
    column0.getColumn().setWidth(100);
    tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(20, 100));
    column0.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            try {
                cell.setText(property.getTypeAsString());
                cell.setForeground(greyColor);
            } catch (Exception e) {
                cell.setText("n/a");
                cell.setForeground(greyColor);
            }
        }
    });
    TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setText("Value");
    column1.getColumn().setResizable(true);
    column1.getColumn().setWidth(200);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(80, 200));
    column1.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Line line = (Line) cell.getElement();
            cell.setText(line.getValue());
        }
    });
    column1.setEditingSupport(new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            Line line = (Line) element;
            line.setValue(String.valueOf(value));
            // trigger a refresh:
            viewer.setInput(property);
        }

        @Override
        protected Object getValue(Object element) {
            final Line line = (Line) element;
            final String value = line.getValue();
            System.out.println("Value=" + value);
            return value;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(viewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            // all values are editable
            return true;
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                if (iss.isEmpty()) {
                    minus.setEnabled(false);
                } else {
                    minus.setEnabled(true);
                }
            } else {
                minus.setEnabled(false);
            }
        }
    });
    viewer.setInput(property);
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 10 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project liferay-ide by liferay.

the class MigrationProblemPreferencePage method _createColumns.

private void _createColumns(final TableViewer problemsViewer) {
    final String[] titles = { "Tickets", "Problem" };
    final int[] bounds = { 65, 55 };
    TableViewerColumn col = _createTableViewerColumn(titles[0], bounds[0], problemsViewer);
    col.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Problem p = (Problem) element;
            return p.getTicket();
        }
    });
    col = _createTableViewerColumn(titles[1], bounds[1], problemsViewer);
    col.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Problem p = (Problem) element;
            return p.getTitle();
        }

        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            Table table = problemsViewer.getTable();
            table.getColumn(1).pack();
        }
    });
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Table(org.eclipse.swt.widgets.Table) Problem(com.liferay.blade.api.Problem) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ViewerCell (org.eclipse.jface.viewers.ViewerCell)54 TableViewer (org.eclipse.jface.viewers.TableViewer)21 Composite (org.eclipse.swt.widgets.Composite)21 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)18 GridData (org.eclipse.swt.layout.GridData)18 Table (org.eclipse.swt.widgets.Table)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Button (org.eclipse.swt.widgets.Button)12 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)11 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)11 Label (org.eclipse.swt.widgets.Label)11 StyledString (org.eclipse.jface.viewers.StyledString)10 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 Point (org.eclipse.swt.graphics.Point)9 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)8 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)8