Search in sources :

Example 31 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project cubrid-manager by CUBRID.

the class TableFocusHighLighter method hookListener.

private void hookListener(final EditableTableViewer viewer) {
    Listener listener = new Listener() {

        public void handleEvent(Event event) {
            if ((event.detail & SWT.SELECTED) > 0) {
                ViewerCell focusCell = getFocusCell();
                ViewerRow row = viewer.getViewerRowByItem(event.item);
                ViewerCell cell = row.getCell(event.index);
                if (focusCell == null || !cell.equals(focusCell)) {
                    removeSelectionInformation(event, cell);
                } else {
                    markFocusedCell(event, cell);
                }
            }
        }
    };
    viewer.getControl().addListener(SWT.EraseItem, listener);
}
Also used : Listener(org.eclipse.swt.widgets.Listener) Event(org.eclipse.swt.widgets.Event) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 32 with ViewerCell

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

the class BrowserColumnViewerTip method showToolTip.

/**
 * Show tooltip for the cell at the given position
 *
 * @param x the widget relative x ordinate
 * @param y the widget relative y ordinate
 */
protected void showToolTip(int x, int y) {
    ViewerCell cell = viewer.getCell(new Point(x, y));
    if (toolCell != null && toolCell.equals(cell) && BrowserTip.toolTipVisible(toolShell)) {
        // tooltip already visible -> do nothing
        return;
    }
    toolCell = cell;
    BrowserTip.hideToolTip(toolShell);
    if (cell != null) {
        Object element = cell.getElement();
        int col = cell.getColumnIndex();
        /**
         * It would be very nice if we could get the column from the viewer
         * and the attached label provider, but the getViewerColumn method
         * is only package visible
         */
        String text = cell.getText();
        String tipText = getToolTip(element, col, text);
        if (tipText != null && !tipText.isEmpty() && tipText.length() >= tipCharThreshold) {
            Rectangle cellBounds = cell.getBounds();
            // toolShell = tip.showToolTip(viewer.getControl(), x, y, tipText);
            toolShell = tip.showToolTip(viewer.getControl(), cellBounds.x, cellBounds.y + cellBounds.height, tipText, cellBounds, viewer.getControl());
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Point(org.eclipse.swt.graphics.Point)

Example 33 with ViewerCell

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

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

the class WebTemplatesDialog method setupViewer.

@Override
protected void setupViewer(final TreeViewer viewer, WebTemplate initialSelection) {
    // this label provider is used for filtering (I guess)
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof WebTemplate) {
                return ((WebTemplate) element).getName();
            }
            return super.getText(element);
        }
    });
    viewer.getTree().setHeaderVisible(true);
    // viewer.getTree().setLinesVisible(true);
    // main column
    TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE);
    mainColumn.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            StyledString text = new StyledString();
            if (element instanceof WebTemplate) {
                WebTemplate template = (WebTemplate) element;
                text.append(template.getName());
            } else {
                text.append(element.toString());
            }
            cell.setText(text.getString());
            cell.setStyleRanges(text.getStyleRanges());
            super.update(cell);
        }
    });
    mainColumn.getColumn().setText("Template");
    layout.setColumnData(mainColumn.getColumn(), new ColumnWeightData(7));
    // link column
    if (Desktop.isDesktopSupported()) {
        TreeViewerColumn linkColumn = new TreeViewerColumn(viewer, SWT.CENTER);
        linkColumn.setLabelProvider(new LinkLabels());
        // listener that reacts on link cell clicks
        viewer.getTree().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (e.button == 1) {
                    ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
                    if (cell != null && cell.getColumnIndex() == 1 && cell.getTextBounds().contains(e.x, e.y)) {
                        Object element = cell.getElement();
                        if (element instanceof WebTemplate) {
                            try {
                                Desktop.getDesktop().browse(((WebTemplate) element).getSite());
                            } catch (IOException e1) {
                                log.error("Could not launch browser", e1);
                            }
                        }
                    }
                }
            }
        });
        layout.setColumnData(linkColumn.getColumn(), new ColumnWeightData(1));
    }
    viewer.setComparator(new ViewerComparator());
    viewer.setContentProvider(new WebTemplatesContentProvider());
    viewer.setInput(templates);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) MouseEvent(org.eclipse.swt.events.MouseEvent) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) IOException(java.io.IOException) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 35 with ViewerCell

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

the class LookupTablePage method addPreview.

// add table for the preview to the given composite
private void addPreview(Composite page) {
    tableContainer = new Composite(page, SWT.NONE);
    tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
    sourceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
            return entry.getKey().getStringRepresentation();
        }
    });
    targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
    targetColumn.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
            if (entry.getValue() == null) {
                StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
                cell.setText(styledString.getString());
                cell.setStyleRanges(styledString.getStyleRanges());
            } else {
                cell.setText(entry.getValue().getStringRepresentation());
                cell.setStyleRanges(null);
            }
            super.update(cell);
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Entry(java.util.Map.Entry) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) Value(eu.esdihumboldt.hale.common.core.io.Value) TableViewer(org.eclipse.jface.viewers.TableViewer) 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