/** {@inheritDoc} */ @Override public int getCreationIndex(int visualIndex) { if (item != null && !item.isDisposed() && hasColumns() && isValidOrderIndex(visualIndex)) { return item.getParent().getColumnOrder()[visualIndex]; } return super.getCreationIndex(visualIndex); }
/** {@inheritDoc} */ @Override public void setText(int columnIndex, String text) { if (columnIndex == Integer.MAX_VALUE) { item.setHeaderText(text); } else { item.setText(columnIndex, text == null ? "" : text); // $NON-NLS-1$ } }
/** {@inheritDoc} */ @Override public void setImage(int columnIndex, Image image) { if (columnIndex == Integer.MAX_VALUE) { item.setHeaderImage(image); } else { item.setImage(columnIndex, image); } }
/** {@inheritDoc} */ @Override public void setForeground(int columnIndex, Color color) { if (columnIndex == Integer.MAX_VALUE) { item.setHeaderForeground(color); } else { item.setForeground(columnIndex, color); } }
/** {@inheritDoc} */ @Override public String getText(int columnIndex) { if (columnIndex == Integer.MAX_VALUE) { return item.getHeaderText(); } else { return item.getText(columnIndex); } }
/** * ************************************************************************* Clear the highlight * of the given ranges ************************************************************************ */ public void clearMatches() { m_search.clear(); getGrid().setRedraw(false); getGrid().deselectAll(); for (GridItem item : getGrid().getItems()) { item.setData("DATA_SEARCH_MATCH", null); } getGrid().setRedraw(true); }
private ViewerRow getRowAbove() { int index = item.getParent().indexOf(item) - 1; if (index >= 0) { return new GridViewerRow(item.getParent().getItem(index)); } return null; }
/** * ************************************************************************* Highlight the given * ranges ************************************************************************ */ private void showMatches(SearchMatch[] matches) { getGrid().setRedraw(false); for (SearchMatch match : matches) { GridItem item = getGrid().getItem(match.lineNo - 1); item.setData("DATA_SEARCH_MATCH", match); } getGrid().deselectAll(); getGrid().setRedraw(true); getGrid().select(matches[0].lineNo - 1); showLine(matches[0].lineNo, false); }
private String getToolTipText(final GridItem item, final int column) { String result = null; final IBaseLabelProvider labelProvider = getTableViewer().getLabelProvider(); if (labelProvider != null) { final Object element = item.getData(); result = ((TableRidgetLabelProvider) labelProvider).getToolTipText(element, column); } if (result == null) { result = item.getText(column); } return result; }
/** {@inheritDoc} */ @Override public Rectangle getBounds(int columnIndex) { if (columnIndex == Integer.MAX_VALUE) { // TODO Provide implementation for GridItem return null; } else { if (!item.getParent().getColumn(columnIndex).isVisible()) { return new Rectangle(0, 0, 0, 0); } else { return item.getBounds(columnIndex); } } }
/** {@inheritDoc} */ @Override public void setFont(int columnIndex, Font font) { if (columnIndex == Integer.MAX_VALUE) { // TODO Provide implementation for GridItem } else { item.setFont(columnIndex, font); } }
/** * ************************************************************************* Copy selected source * rows ************************************************************************ */ public void copySelected() { GridItem[] selection = getGrid().getSelection(); Clipboard clipboard = new Clipboard(Display.getCurrent()); String data = ""; for (GridItem item : selection) { if (!data.isEmpty()) data += "\n"; String line = item.getText(CodeViewerColumn.CODE.ordinal()); if (line != null) { line = line.trim(); } else { line = ""; } data += line; } clipboard.setContents(new Object[] {data}, new Transfer[] {TextTransfer.getInstance()}); clipboard.dispose(); }
/** {@inheritDoc} */ @Override public Color getForeground(int columnIndex) { if (columnIndex == Integer.MAX_VALUE) { // TODO Provide implementation for GridItem return null; } else { return item.getForeground(columnIndex); } }
/** {@inheritDoc} */ @Override public Image getImage(int columnIndex) { if (columnIndex == Integer.MAX_VALUE) { // TODO Provide implementation for GridItem return null; } else { return item.getImage(columnIndex); } }
/** * {@inheritDoc} * * <p>Sets for every item the tool tip text. The text can be configured with the {@link * IColumnFormatter}. * * <p><i>note: The tool tip of a grid is only shown, if in a cell not the complete text can be * displayed.</i> */ @Override protected final void updateToolTipSupport() { final Grid control = getUIControl(); if (control == null) { return; } int colCount = getColumnCount(); final GridItem[] items = control.getItems(); for (final GridItem item : items) { for (final int colIndex = 0; colCount < colCount; colCount++) { String toolTip = null; if (toolTip == null) { toolTip = getToolTipText(item, colIndex); } item.setToolTipText(colIndex, toolTip); } } }
/** {@inheritDoc} */ @Override public int getVisualIndex(int creationIndex) { int[] order = item.getParent().getColumnOrder(); for (int i = 0; i < order.length; i++) { if (order[i] == creationIndex) { return i; } } return super.getVisualIndex(creationIndex); }
private ViewerRow getRowBelow() { int index = item.getParent().indexOf(item) + 1; if (index < item.getParent().getItemCount()) { GridItem tmp = item.getParent().getItem(index); // Maybe this is a dummy item!! if (tmp != null && !tmp.isDisposed() && tmp.isVisible() && tmp.getData() != null) { return new GridViewerRow(tmp); } } return null; }
/** {@inheritDoc} */ @Override public TreePath getTreePath() { return new TreePath(new Object[] {item.getData()}); }
/** Updates this cell - delayed. */ protected void updateCellValuesDelayed() { /* * Check if the cell has been disposed */ if (getColumn() == null) return; // LogUtils.debug(GridBindingCellInformationImpl.this, ""); final IGridBinding grid = getGrid(); final GridColumn gridColumn = getColumn().getGridColumn(); final GridItem gridItem = getRow().getGridItem(); /* * Update the cell */ final IUIAttribute attr = getLabelUIAttribute(); final IObservableValue currentValue = attr.getCurrentValue(); if (currentValue.isDisposed()) return; final IObservableValue v = getObjectValue(); final String text = (String) currentValue.getValue(); final Color foreground = attr.getForeground(); final Color background = attr.getBackground(); final Image image = attr.getImage(); final Font font = attr.getFont(); final String tooltip = attr.getTooltip(); // TODO: the rest: cursor, enabled, style range if (gridItem == null) { /* * Column header: */ gridColumn.setText(text == null ? "" : text); gridColumn.setImage(image); // TODO gridColumn.set /* * The changes in the column name and image only take effect when the table is redrawn */ grid.getGrid().redraw(); } else if (gridColumn == null) { /* * Row Header */ gridItem.setHeaderText(text == null ? "" : text); gridItem.setHeaderImage(image); gridItem.setHeaderForeground(foreground); gridItem.setHeaderBackground(background); } else { /* * Normal cell */ final int index = grid.getGrid().indexOf(gridColumn); Assert.isTrue(index != -1); // gridItem.setChecked(index, v.getValue() == Boolean.TRUE); // gridItem.setText(index, null); // gridItem.setImage(index, null); // gridItem.setFont(index, null); gridItem.setText(index, text == null ? "" : text); gridItem.setImage(index, image); gridItem.setFont(index, font); gridItem.setForeground(index, foreground); gridItem.setBackground(index, background); gridItem.setToolTipText(index, tooltip); } }
/** {@inheritDoc} */ @Override public Control getControl() { return item.getParent(); }
/** {@inheritDoc} */ @Override public int getColumnCount() { return item.getParent().getColumnCount(); }
/** {@inheritDoc} */ @Override public Rectangle getBounds() { // TODO This is not correct. Update once item returns the correct information. return item.getBounds(0); }
/** * Check if the column of the cell is part of is visible * * @param columnIndex the column index * @return <code>true</code> if the column is visible */ @Override protected boolean isColumnVisible(int columnIndex) { return item.getParent().getColumn(columnIndex).isVisible(); }
@Override public void testAddClickListener() { final ITableRidget ridget = getRidget(); ridget.updateFromModel(); final Grid control = getWidget(); final RowData rowData = new RowData(); rowData.width = 300; rowData.height = 300; control.setLayoutData(rowData); control.getColumn(0).setWidth(100); control.getColumn(1).setWidth(100); control.getShell().pack(); control.getParent().update(); try { ridget.addClickListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final FTClickListener listener1 = new FTClickListener(); ridget.addClickListener(listener1); final FTClickListener listener2 = new FTClickListener(); ridget.addClickListener(listener2); ridget.addClickListener(listener2); final Event mdEvent = new Event(); mdEvent.widget = control; mdEvent.type = SWT.MouseDown; mdEvent.button = 2; final GridItem row2 = control.getItem(2); mdEvent.item = row2; mdEvent.x = row2.getBounds(0).x + 1; mdEvent.y = row2.getBounds(0).y + 1; control.notifyListeners(SWT.MouseDown, mdEvent); assertEquals(0, listener1.getCount()); assertEquals(0, listener2.getCount()); mdEvent.type = SWT.MouseUp; control.notifyListeners(SWT.MouseUp, mdEvent); assertEquals(1, listener1.getCount()); assertEquals(1, listener2.getCount()); final ClickEvent event = listener2.getEvent(); assertEquals(ridget, event.getSource()); assertEquals(2, event.getButton()); assertEquals(0, event.getColumnIndex()); assertEquals(row2.getData(), event.getRow()); ridget.removeClickListener(listener1); mdEvent.type = SWT.MouseDown; control.notifyListeners(SWT.MouseDown, mdEvent); mdEvent.type = SWT.MouseUp; control.notifyListeners(SWT.MouseUp, mdEvent); assertEquals(1, listener1.getCount()); }
/** {@inheritDoc} */ @Override public Object getElement() { return item.getData(); }