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

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

Introduction

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

Prototype

public int getColumnIndex() 

Source Link

Document

Get the index of the cell.

Usage

From source file:com.contrastsecurity.ide.eclipse.ui.internal.views.VulnerabilitiesView.java

License:Open Source License

/**
 * Determines what action should be performed based on the mouse event.
 * /* ww  w .  j a v  a2 s.c o m*/
 * @param isDoubleClick
 *            Whether the mouse event that triggered this was a double click
 *            event.
 * @param point
 *            The position of the click on the TableView.
 * @return Action constant that represents what should be done based on the
 *         mouse event.
 */
private int getActionFromClick(boolean isDoubleClick, Point point) {
    ViewerCell cell = table.getCell(point);

    if (cell != null) {
        int columnIndex = cell.getColumnIndex();
        if (isDoubleClick && (columnIndex == 0 || columnIndex == 1))
            return VIEW_VULNERABILITY_EVENTS_ACTION;
        else if (columnIndex == 2)
            return VIEW_VULNERABILITY_OVERVIEW_ACTION;
        else if (columnIndex == 3)
            return SHOW_VULNERABILITY_IN_BROWSER_ACTION;
    }

    return NO_ACTION;
}

From source file:com.freescale.deadlockpreventer.agent.StatisticsDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    parent.setLayout(new GridLayout(2, false));

    viewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.horizontalSpan = 2;//from  w ww.java2s .co  m
    viewer.getTable().setLayoutData(layoutData);
    viewer.setContentProvider(new ViewContentProvider());
    ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
    viewer.setInput(locks);

    IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);

    service.addFocusTracker(viewer.getTable(), StatisticsDialog.class.getPackage().getName() + ".table");

    viewer.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Row element = (Row) cell.getElement();
            if (cell.getColumnIndex() == 0)
                cell.setText(element.id);
            if (cell.getColumnIndex() == 1)
                cell.setText(Integer.toString(element.folllowersCount));
            if (cell.getColumnIndex() == 2)
                cell.setText(Integer.toString(element.precedentsCount));
            if (cell.getColumnIndex() == 3)
                cell.setText(element.location);
        }

        public String getToolTipText(Object element) {
            Row row = (Row) element;
            ILock[] locks = transaction.getLocks(row.index, row.index + 1);
            CharArrayWriter writer = new CharArrayWriter();
            Logger.dumpLockInformation(locks, writer);
            return writer.toString();
        }

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

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

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

    createTableViewerColumn("Lock", 200, 0);
    createTableViewerColumn("Followers", 70, 1);
    createTableViewerColumn("Precedents", 70, 2);
    createTableViewerColumn("Location", 250, 3);

    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);

    comparator = new TableViewerComparator();
    viewer.setComparator(comparator);

    Button button = new Button(parent, SWT.PUSH);
    button.setText("Export...");
    layoutData = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
    layoutData.widthHint = 80;
    button.setLayoutData(layoutData);
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StatisticsUtil.export(transaction);
        }
    });

    Label label = new Label(parent, 0);
    label.setText("Total locks: " + locks.length);
    label.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false));

    return super.createDialogArea(parent);
}

From source file:com.gorillalogic.monkeyconsole.tableview.MonkeyTalkTabularEditor.java

License:Open Source License

private static ViewerCell getNeighbor(ViewerCell currentCell, int directionMask, boolean sameLevel) {
    ViewerRow row;//w  w w.j  a va 2s .c  o  m

    if ((directionMask & ViewerCell.ABOVE) == ViewerCell.ABOVE) {
        row = currentCell.getViewerRow().getNeighbor(ViewerRow.ABOVE, sameLevel);
    } else if ((directionMask & ViewerCell.BELOW) == ViewerCell.BELOW) {
        row = currentCell.getViewerRow().getNeighbor(ViewerRow.BELOW, sameLevel);
    } else {
        row = currentCell.getViewerRow();
    }

    if (row != null) {
        int columnIndex;
        columnIndex = getVisualIndex(row, currentCell.getColumnIndex());

        int modifier = 0;

        if ((directionMask & ViewerCell.LEFT) == ViewerCell.LEFT) {
            modifier = -1;
        } else if ((directionMask & ViewerCell.RIGHT) == ViewerCell.RIGHT) {
            modifier = 1;
        }

        columnIndex += modifier;

        if (columnIndex >= 0 && columnIndex < row.getColumnCount()) {
            ViewerCell cell = getCellAtVisualIndex(row, columnIndex);
            if (cell != null) {
                while (cell != null && columnIndex < row.getColumnCount() - 1 && columnIndex > 0) {
                    if (isVisible(cell)) {
                        break;
                    }

                    columnIndex += modifier;
                    cell = getCellAtVisualIndex(row, columnIndex);
                    if (cell == null) {
                        break;
                    }
                }
            }

            return cell;
        }
    }
    return null;
}

From source file:com.gorillalogic.monkeyconsole.tableview.MonkeyTalkTabularEditor.java

License:Open Source License

private static int getWidth(ViewerCell cell) {
    TableItem item = (TableItem) cell.getViewerRow().getItem();
    return item.getParent().getColumn(cell.getColumnIndex()).getWidth();
}

From source file:com.hydra.project.myplugin_nebula.xviewer.XViewerStyledTextLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();

    StyledString styledString = getStyledText(element, cell.getColumnIndex());
    String newText = styledString.toString();

    StyleRange[] oldStyleRanges = cell.getStyleRanges();
    StyleRange[] newStyleRanges = isOwnerDrawEnabled() ? styledString.getStyleRanges() : null;

    if (!Arrays.equals(oldStyleRanges, newStyleRanges)) {
        cell.setStyleRanges(newStyleRanges);
        //         if (cell.getText().equals(newText)) {
        //            // make sure there will be a refresh from a change
        //            cell.setText(""); //$NON-NLS-1$
        //         }
    }/*ww  w  .  j a va2s .  co  m*/

    cell.setText(newText);
    cell.setImage(getColumnImage(element, cell.getColumnIndex()));
    cell.setFont(getFont(element, cell.getColumnIndex()));
    cell.setForeground(getForeground(element, cell.getColumnIndex()));
    cell.setBackground(getBackground(element, cell.getColumnIndex()));

    // no super call required. changes on item will trigger the refresh.
}

From source file:com.ibm.etools.mft.conversion.esb.editor.parameter.GlobalOptionsEditor.java

License:Open Source License

@Override
public void doubleClick(DoubleClickEvent event) {

    if (event.getSelection().isEmpty()) {
        return;/*from ww w  .jav  a  2  s.com*/
    }

    Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();

    TableViewer viewer = (o instanceof PrimitiveConverter) ? primtiveConverterViewer
            : ((o instanceof BindingConverter) ? bindingConverterViewer : null);

    if (viewer != null) {

        boolean showUsage = false;
        Control c = null;

        if (viewer == primtiveConverterViewer) {
            ViewerCell vc = primitiveHighlighter.getFocusCell();
            int index = vc.getColumnIndex();

            if (index == 2)
                showUsage = true;// only show usage dialog for 3rd column
            else if (index == 3)// 4th column is being acted on, get the
                // (...) control
                c = vc.getControl();

        } else if (viewer == bindingConverterViewer) {
            ViewerCell vc = bindingHighlighter.getFocusCell();
            int index = vc.getColumnIndex();
            if (index == 2)
                showUsage = true;// only show usage dialog for 3rd column
            else if (index == 3) // 4th column is being acted on, get the
                                 // (...) control
                c = vc.getControl();
        }

        if (showUsage) {// usage dialog will come up if cell column 3 is
            // double-clicked or ENTER is pressed on it

            Converter converter = (Converter) o;
            String message = null;
            String desc = (o instanceof PrimitiveConverter)
                    ? WESBConversionMessages.GlobalOptionsEditor_primitiveConvertersDescription
                    : ((o instanceof BindingConverter)
                            ? WESBConversionMessages.GlobalOptionsEditor_bindingConvertersDescription
                            : ""); //$NON-NLS-2$     //$NON-NLS-1$
            String title = (o instanceof PrimitiveConverter)
                    ? WESBConversionMessages.GlobalOptionsEditor_MPUsage_Title
                    : ((o instanceof BindingConverter)
                            ? WESBConversionMessages.GlobalOptionsEditor_BindingUsage_Title
                            : ""); //$NON-NLS-2$     //$NON-NLS-1$
            String heading = WESBConversionMessages.GlobalOptionsEditor_UsageHeading;
            message = WESBConversionMessages.GlobalOptionsEditor_UsageMessage;
            UsageDialog d = new UsageDialog(heading, title, desc,
                    NLS.bind(message,
                            (o instanceof PrimitiveConverter) ? WESBConversionMessages.GlobalOptionsEditor_MP
                                    : ((o instanceof BindingConverter)
                                            ? WESBConversionMessages.GlobalOptionsEditor_binding
                                            : ""), //$NON-NLS-1$
                            ((ITableLabelProvider) viewer //$NON-NLS-2$     
                                    .getLabelProvider()).getColumnText(converter, 0)),
                    converter.getUsages());
            d.open();

        } // if
        else if (null != c) {
            c.setFocus();// 4th column is being acted on, so show the (...)
                         // button
        }

    }
}

From source file:com.jaspersoft.studio.property.dataset.dialog.DataPreviewTable.java

License:Open Source License

private void updateTableLayout() {
    if (composite.isVisible()) {
        // Remove all table items if any
        wtable.removeAll();//w ww  .  j av  a  2s.co m
        tviewer.setInput(null);

        // Dispose old columns if any
        for (TableColumn col : wtable.getColumns()) {
            col.dispose();
        }

        TableColumnLayout tColLayout = new TableColumnLayout();
        tableContainer.setLayout(tColLayout);

        List<JRDesignField> fields = previewInfoProvider.getFieldsForPreview();
        if (fields.size() > 0) {
            for (JRDesignField f : fields) {
                TableViewerColumn tvc = new TableViewerColumn(tviewer, SWT.NONE);
                tvc.getColumn().setText(f.getName());
                tvc.setLabelProvider(new ColumnLabelProvider());
                tColLayout.setColumnData(tvc.getColumn(),
                        new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
                tvc.setLabelProvider(new CellLabelProvider() {
                    @Override
                    public void update(ViewerCell cell) {
                        DataPreviewBean element = (DataPreviewBean) cell.getElement();
                        Object value = element.getValue(cell.getColumnIndex());
                        if (value != null) {
                            cell.setText(value.toString());
                        } else {
                            cell.setText(""); //$NON-NLS-1$
                        }
                    }
                });
            }

        }

        tableContainer.layout();
    }
}

From source file:com.kdmanalytics.toif.report.internal.providers.ReportLabelProvider.java

License:Open Source License

@Override
public void update(final ViewerCell cell) {
    Object element = cell.getElement();
    final StyledString styledString = new StyledString(getColumnText(element, cell.getColumnIndex()));

    if (element instanceof IFindingEntry) {
        final IFindingEntry entry = (IFindingEntry) element;

        if (Citing.UNKNOWN == entry.isOk()) {
            cell.setForeground(colorReg.get(FOREGROUND_BLACK));
            cell.setBackground(colorReg.get(BLUE));
        } else {/* w ww . j a va  2 s  . c o  m*/

            cell.setForeground(Citing.TRUE == entry.isOk() ? colorReg.get(FOREGROUND_GREEN)
                    : colorReg.get(FOREGROUND_RED));
            cell.setBackground(Citing.TRUE == entry.isOk() ? colorReg.get(GREEN) : colorReg.get(RED));
        }
    } else if (element instanceof IFileGroup) {
        cell.setFont(getFont(element));
    }
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    cell.setImage(cell.getColumnIndex() > 0 ? null : getImage(element));
}

From source file:com.kdmanalytics.toif.report.internal.providers.ReportStyledCellLabelProvider.java

License:Open Source License

@Override
public void update(final ViewerCell cell) {
    final IToifReportEntry entry = (IToifReportEntry) cell.getElement();
    final StyledString styledString = new StyledString(getColumnText(entry, cell.getColumnIndex()));
    final IFindingEntry findingEntry = entry.getFindingEntry();

    if (Citing.UNKNOWN == findingEntry.isOk()) {
        cell.setForeground(FOREGROUND_BLACK);
        cell.setBackground(WHITE);/*  w  w  w . j  a  v a2  s . c om*/
    } else {

        cell.setForeground(Citing.TRUE == findingEntry.isOk() ? FOREGROUND_RED : FOREGROUND_GREEN);
        cell.setBackground(Citing.TRUE == findingEntry.isOk() ? RED : GREEN);
    }
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    cell.setImage(getImage(entry, cell.getColumnIndex()));
}

From source file:com.kdmanalytics.toif.ui.views.DefectDescStyledLabelProvider.java

License:Open Source License

public void update(final ViewerCell cell) {
    final DefectNode entry = (DefectNode) cell.getElement();
    int index = cell.getColumnIndex();
    final StyledString styledString = new StyledString(getColumnText(entry, index));

    String desc = entry.getDescription();
    if (desc.startsWith("http://") || desc.startsWith("https://")) {
        cell.setForeground(FOREGROUND_BLUE);
    }//from   w  ww  .j  ava  2s  .c o  m

    String text = styledString.toString();

    // This removed code is used to split the string into a number of separate
    // lines suitable for wrapping.
    //
    //
    // // How many characters will we allow per line?
    // Tree tree = (Tree)cell.getControl();
    //
    // // Use the client area minus the first column to see how much room we have
    // // for text.
    // Rectangle area = viewer.getTree().getClientArea();
    // TreeColumn column = tree.getColumn(0);
    // int width = area.width - column.getWidth();
    // if (width < 50) width = 50;
    // width -= 10;
    // GC gc = new GC(tree);
    // FontMetrics fm = gc.getFontMetrics();
    // int charWidth = fm.getAverageCharWidth();
    // int charCount = width / charWidth;
    // if (charCount < 10) charCount = 10;
    //
    // List<String> lines = new LinkedList<String>();
    //
    // while (text.length() > 0) {
    // // Break at space
    // int lastSpace = text.lastIndexOf(' ', charCount);
    // if (lastSpace > 10) {
    // lines.add(text.substring(0, lastSpace));
    // text = text.substring(lastSpace + 1);
    // continue;
    // }
    //
    // // Break at next space
    // int nextSpace = text.indexOf(' ', charCount);
    // if (nextSpace > 10) {
    // lines.add(text.substring(0, nextSpace));
    // text = text.substring(nextSpace + 1);
    // continue;
    // }
    //
    // // Just use whole string
    // lines.add(text);
    // text = "";
    // }
    //
    // // Add in \n characters
    // StringBuilder sb = new StringBuilder();
    // for (int i = 0; i < lines.size(); i++) {
    // if (i > 0) sb.append("\n");
    // sb.append(lines.get(i));
    // }
    //
    // cell.setText(sb.toString());
    cell.setText(text);
    cell.setStyleRanges(styledString.getStyleRanges());
}