Example usage for org.eclipse.jface.viewers ViewerCell getItem

List of usage examples for org.eclipse.jface.viewers ViewerCell getItem

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell getItem.

Prototype

public Widget getItem() 

Source Link

Document

Return the item for the receiver.

Usage

From source file:com.agynamix.simidude.clipboard.ClipboardTable.java

License:Open Source License

private TableViewer createTableViewer(final Composite parent) {
    tableParent = parent;/*from w  ww  .  j  ava  2s .com*/
    final TableViewer tableViewer = new TableViewer(tableParent,
            SWT.SINGLE | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.FLAT | SWT.BORDER | SWT.V_SCROLL);

    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(false);

    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);

    final OptimizedIndexSearcher searcher = new OptimizedIndexSearcher();

    itemColumn = new TableViewerColumn(tableViewer, SWT.LEFT, NAME_COL);
    itemColumn.getColumn().setText("Item");
    itemColumn.setLabelProvider(new ColumnLabelProvider() {
        boolean even = true;
        Color oddColor = null;

        @Override
        public String getText(Object element) {
            String text = "";
            IClipboardItem item = (IClipboardItem) element;
            text = item.getShortDescription();
            return text;
        }

        @Override
        /**
         * Display an icon depending of the type of clipboard entry.
         */
        public Image getImage(Object element) {
            return ((IClipboardItem) element).getImage();
        }

        public Color getBackground(Object element) {
            if (even) {
                return null;
            } else {
                if (oddColor == null) {
                    oddColor = PlatformColors.get(PlatformColors.TRANSFER_TABLE_ALT_COLOR);
                }
                return oddColor;
            }
        }

        public String getToolTipText(Object element) {
            IClipboardItem item = (IClipboardItem) element;
            return item.getTooltip();
        }

        public Point getToolTipShift(Object object) {
            return new Point(5, 5);
        }

        public int getToolTipDisplayDelayTime(Object object) {
            return 200;
        }

        public int getToolTipTimeDisplayed(Object object) {
            return 10000;
        }

        public void update(ViewerCell cell) {
            even = searcher.isEven((TableItem) cell.getItem());
            super.update(cell);
        }
    });

    tableViewer.setContentProvider(new ClipboardTableContentProvider());
    //    tableViewer.setLabelProvider(new ClipboardTableLabelProvider());

    tableParent.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent e) {
            adjustTableSize();
        }
    });

    tableViewer.getTable().setMenu(createPopupMenu(tableViewer));
    hookListeners(tableViewer);

    return tableViewer;
}

From source file:com.astra.ses.spell.tabbed.ui.table.actions.DeleteRowAction.java

License:Open Source License

@Override
public void run() {
    /*// w  ww. jav  a2  s.c  o m
     * Get selected cell
     */
    ViewerCell cell = m_viewer.getCell(Display.getCurrent().getCursorLocation());
    TableItem row = (TableItem) cell.getItem();
    if (row != null) {
        Table table = m_viewer.getTable();
        int rowPosition = table.indexOf(row);
        TabularEditorInput input = (TabularEditorInput) m_viewer.getInput();
        /*
         * Delete line
         */
        input.removeLine(rowPosition);
    }
}

From source file:com.astra.ses.spell.tabbed.ui.table.actions.InsertRowAction.java

License:Open Source License

@Override
public void run() {
    /*/*from   ww  w.j a  v a 2 s.c  o m*/
     * Get selected cell
     */
    ViewerCell cell = m_viewer.getCell(Display.getCurrent().getCursorLocation());
    TableItem row = (TableItem) cell.getItem();
    if (row != null) {
        Table table = m_viewer.getTable();
        int rowPosition = table.indexOf(row);
        TabularEditorInput input = (TabularEditorInput) m_viewer.getInput();
        /*
         * add line
         */
        input.addBlankLine(rowPosition);
    }
}

From source file:com.google.gapid.widgets.MeasuringViewLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    // Adjusted from the DelegatingStyledCellLabelProvider implementation.

    StyledString styledString = format(cell.getItem(), cell.getElement(), LinkableStyledString.ignoring(theme))
            .getString();//from www.j  av a  2 s.c  o  m
    String newText = styledString.toString();

    StyleRange[] oldStyleRanges = cell.getStyleRanges();
    StyleRange[] newStyleRanges = styledString.getStyleRanges();

    if (!Arrays.equals(oldStyleRanges, newStyleRanges)) {
        cell.setStyleRanges(newStyleRanges);
        if (cell.getText().equals(newText)) {
            cell.setText("");
        }
    }
    Color bgcolor = getBackgroundColor(cell.getElement());
    if (bgcolor != null) {
        cell.setBackground(bgcolor);
    }
    cell.setImage(getImage(cell.getElement()));
    cell.setText(newText);
}

From source file:com.google.gapid.widgets.MeasuringViewLabelProvider.java

License:Apache License

public Object getFollow(Point point) {
    ViewerCell cell = viewer.getCell(point);
    if (cell == null || !isFollowable(cell.getElement())) {
        return null;
    }//from   w  ww  .ja v  a2 s .c o m

    LinkableStyledString string = format(cell.getItem(), cell.getElement(), LinkableStyledString.create(theme));
    string.endLink();
    string.append("dummy", string.defaultStyle());
    updateLayout(cell, string.getString());

    Rectangle bounds = cell.getTextBounds();
    int offset = layout.getOffset(point.x - bounds.x, point.y - bounds.y, null);
    return string.getLinkTarget(offset);
}

From source file:com.microsoft.tfs.client.common.ui.framework.celleditor.accessibility.CellEditorAccessibility.java

License:Open Source License

public static final Point getFocusCellIndex(final TableViewer viewer) {
    try {/* w w w  .j a v a 2  s. com*/
        if (viewer.getColumnViewerEditor() != null) {
            final ViewerCell focusCell = viewer.getColumnViewerEditor().getFocusCell();

            if (focusCell != null) {
                final int x = focusCell.getColumnIndex();
                final int y = viewer.getTable().indexOf((TableItem) focusCell.getItem());

                return new Point(x, y);
            }
        }
    } catch (final Exception e) {
        log.warn("Could not determine cell index", e); //$NON-NLS-1$
    }

    return new Point(-1, -1);
}

From source file:com.netxforge.screens.editing.base.tables.FocusBlockOwnerDrawHighlighterForMultiselection.java

License:Open Source License

private void markFocusedBlock(Event event, List<ViewerCell> block) {

    // iterate through the cell, and draw a rectangle.
    for (ViewerCell cell : block) {
        Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell)
                : getSelectedCellBackgroundColorNoFocus(cell);
        Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell)
                : getSelectedCellForegroundColorNoFocus(cell);

        if (foreground != null || background != null || onlyTextHighlighting(cell)) {
            GC gc = event.gc;//from www .  j  a  va2s.  com

            if (background == null) {
                background = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
            }

            if (foreground == null) {
                foreground = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
            }

            gc.setBackground(background);
            gc.setForeground(foreground);

            if (onlyTextHighlighting(cell)) {
                Rectangle area = event.getBounds();
                Rectangle rect = cell.getTextBounds();
                if (rect != null) {
                    area.x = rect.x;
                }
                gc.fillRectangle(area);
            } else {
                gc.fillRectangle(event.getBounds());

            }

        }
    }
    drawBorder(event, block);
    event.detail &= ~SWT.SELECTED;
}

From source file:com.netxforge.screens.editing.base.tables.TreeViewerFocusBlockManager.java

License:Open Source License

public ViewerCell getFocusCell() {
    ViewerCell cell = super.getFocusCell();
    Tree t = (Tree) getViewer().getControl();

    // It is possible that the selection has changed under the hood
    if (cell != null) {
        if (t.getSelection().length == 1 && t.getSelection()[0] != cell.getItem()) {

            OpenTreeViewer v = (OpenTreeViewer) this.getViewer();
            setFocusCell(v.getViewerRowFromItemExposed(t.getSelection()[0]).getCell(cell.getColumnIndex()));
        }/*from   w ww. j a  va  2 s. c  om*/
    }

    return super.getFocusCell();
}

From source file:com.peergreen.eclipse.osgi.preferences.provider.column.ActionsColumnLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    PeergreenServerEntry serverEntry = (PeergreenServerEntry) cell.getElement();

    TableItem item = (TableItem) cell.getItem();

    composite = new Composite((Composite) cell.getViewerRow().getControl(), SWT.BORDER_DASH);
    composite.setLayout(new FillLayout());

    // Download button if assembly not installed
    if (serverEntry.isDownloadable()) {
        Button downloadButton = new Button(composite, SWT.NONE);
        downloadButton.setText("Download...");
        downloadButton.setToolTipText("Download this version");
    }//from w  ww  . ja  v  a2  s  .  c o  m

    // Remove button if assembly is installed
    if (!serverEntry.isDownloadable() && (serversConfiguration.getDefaultEntry() != null
            && !serversConfiguration.getDefaultEntry().equals(serverEntry))) {
        Button removeButton = new Button(composite, SWT.NONE);
        removeButton.setText("Remove");
        removeButton.setToolTipText("Remove this assembly");
        removeButton
                .addSelectionListener(new RemoveEntryListener(serversConfiguration, serverEntry, tableViewer));

    }

    // Update button if assembly has a new version available
    if (serverEntry.isUpdatable()) {
        Button updateButton = new Button(composite, SWT.NONE);
        updateButton.setText("Update...");
        updateButton.setToolTipText("Update this assembly to a newer version");
    }

    // Create editor
    TableEditor editor = new TableEditor(item.getParent());

    editor.grabHorizontal = true;
    editor.grabVertical = true;
    editor.setEditor(composite, item, cell.getColumnIndex());
    editor.layout();

}

From source file:com.peergreen.eclipse.osgi.preferences.provider.column.RadioButtonColumnLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    final PeergreenServerEntry serverEntry = (PeergreenServerEntry) cell.getElement();

    TableItem item = (TableItem) cell.getItem();

    TableEditor editor = new TableEditor(item.getParent());
    Button radioButton = new Button((Composite) cell.getViewerRow().getControl(), SWT.RADIO);

    // It's the default selection
    if (serversConfiguration.getDefaultEntry() != null
            && serversConfiguration.getDefaultEntry().equals(serverEntry)) {
        radioButton.setSelection(true);//from   www  .  j a v  a2  s .  com
    }

    // Downloadable so not ready, greyed
    radioButton.setEnabled(!serverEntry.isDownloadable());
    radioButton.addSelectionListener(
            new RadioButtonSelectionListener(serversConfiguration, serverEntry, tableViewer, radioButton));
    radioButton.pack();
    editor.minimumWidth = radioButton.getSize().x;
    editor.horizontalAlignment = SWT.CENTER;
    editor.setEditor(radioButton, item, cell.getColumnIndex());
    editor.layout();

}