List of usage examples for org.eclipse.jface.viewers ViewerCell getColumnIndex
public int getColumnIndex()
From source file:org.csstudio.ui.util.swt.stringtable.StringMultiColumnsLabelProvider.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//ww w .j a v a 2 s . c o m public void update(ViewerCell cell) { final List<String[]> items = (List<String[]>) tableViewer.getInput(); final int index = ((Integer) cell.getElement()).intValue(); //if this is the extra row if (index < 0) if (editable) cell.setText(Messages.StringTableEditor_AddRowText); else cell.setText(""); //$NON-NLS-1$ //if not else { // For multi-line text, only show the first line final int column = cell.getColumnIndex(); String text = ""; if (column < items.get(index).length) text = items.get(index)[column]; // Not sure whether to look for '\r' or '\n'. Try both int nl = text.indexOf('\r'); if (nl < 0) nl = text.indexOf('\n'); if (nl > 0) text = text.substring(0, nl) + "..."; //$NON-NLS-1$ cell.setText(text); } }
From source file:org.dawb.common.ui.widgets.DoubleClickModifier.java
License:Open Source License
protected DoubleClickModifier(final ColumnViewer viewer) { viewer.getControl().addListener(SWT.MouseDown, new Listener() { @Override/*from w w w .ja v a2 s . c o m*/ public void handleEvent(Event event) { setEnabled(false); } }); viewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() { @Override public void handleEvent(Event event) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.toList().size() != 1) { return; } final ViewerCell cell = viewer.getCell(new Point(event.x, event.y)); setEnabled(true); viewer.editElement(selection.getFirstElement(), cell != null ? cell.getColumnIndex() : 0); } }); }
From source file:org.dawnsci.breadcrumb.navigation.table.AbstractLazyLabelProvider.java
License:Open Source License
public void update(ViewerCell cell) { if (disposed) return;//from w w w . j a v a 2 s . c o m if (cell.getItem().isDisposed()) return; Object element = cell.getElement(); try { final int index = cell.getColumnIndex(); final String fastText = getFastText(element, index - columnOffset); if (fastText != null) { cell.setText(fastText); } else if (allowLazyText) { viewerCellTextQueue.add(new ViewCellBean(cell, element, index)); } else { cell.setText(getSlowText(element, index - columnOffset)); } Image image = getImage(element, index - columnOffset); cell.setImage(image); cell.setBackground(getBackground(element)); //cell.setForeground(getForeground(element)); //cell.setFont(getFont(element)); } catch (Exception ne) { logger.error("Error in table ", ne); } }
From source file:org.eclipse.andmore.android.emulator.core.emulationui.AbstractEmuLabelProvider.java
License:Apache License
/** * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) *///from www.j av a 2 s . c o m @Override public void update(ViewerCell cell) { // The instance column index is set with the current cell column index, // as the logic // contained in this class depends on this information. Then after the // cell is // updated according to the standard procedure, the column index field // is reset so that // it does not interfere with subsequent updates. columnIndex = cell.getColumnIndex(); super.update(cell); columnIndex = firstColumnIndex; // Checks if the cell needs to be highlighted. This will be true if the // values of // alternativeColorHost and alternativeColorBeanId are different from // null and -1 if ((alternativeColorHost != null) && (alternativeColorBeanId != -1)) { Object element = cell.getElement(); // Only leaf nodes can be highlighted if (element instanceof EmuViewerLeafNode) { // The next lines are used to check if the current element is // the one to be // highlighted. For that, the host and bean id needs to be // compared to the // alternativeColorHost and alternativeColorBeanId instance // field values EmuViewerLeafNode node = (EmuViewerLeafNode) element; long beanId = node.getBeanId(); EmuViewerRootNode root = (EmuViewerRootNode) node.getParent().getParent(); String host = root.getEmulatorIdentifier(); if ((beanId == alternativeColorBeanId) && (host.equals(alternativeColorHost))) { // Highlighting the node cell.setBackground(alternativeColor); // Putting the node at the visible part of the tree ViewerRow highlightedRow = cell.getViewerRow(); TreeItem highlightedItem = (TreeItem) highlightedRow.getItem(); Tree tree = (Tree) cell.getControl(); tree.showItem(highlightedItem); } } } }
From source file:org.eclipse.babel.runtime.actions.TranslatableTreeComposite.java
License:Open Source License
public void updateButtonEnablement(ViewerCell newCell) { if (newCell == null) { revertButton.setEnabled(false);/*w w w. ja va2 s .c o m*/ } else { ITranslatableText translatableText = getTranslatableText(newCell.getElement()); Locale locale = (Locale) treeControl.getColumn(newCell.getColumnIndex()).getData(); if (translatableText instanceof TranslatableText) { revertButton.setEnabled(((TranslatableText) translatableText).isDirty(locale)); } else { revertButton.setEnabled(false); } } }
From source file:org.eclipse.babel.tapiji.tools.core.ui.widgets.provider.KeyTreeLabelProvider.java
License:Open Source License
/** * {@inheritDoc}// ww w . j av a 2 s . c o m */ @Override public void update(ViewerCell cell) { cell.setText(getColumnText(cell.getElement(), cell.getColumnIndex())); cell.setImage(getColumnImage(cell.getElement(), cell.getColumnIndex())); super.update(cell); }
From source file:org.eclipse.babel.tapiji.tools.core.ui.widgets.provider.ResKeyTreeLabelProvider.java
License:Open Source License
private void updateCell(ViewerCell cell) { Object element = cell.getElement(); int columnIndex = cell.getColumnIndex(); if (isSearchEnabled(element)) { if (isMatchingToPattern(element, columnIndex)) { List<StyleRange> styleRanges = new ArrayList<StyleRange>(); FilterInfo filterInfo = (FilterInfo) ((IValuedKeyTreeNode) element).getInfo(); if (columnIndex > 0) { for (Region reg : filterInfo.getFoundInLocaleRanges(locales.get(columnIndex - 1))) { styleRanges/*from www . j a v a2 s.com*/ .add(new StyleRange(reg.getOffset(), reg.getLength(), black, info_color, SWT.BOLD)); } } else { // check if the pattern has been found within the key // section if (filterInfo.isFoundInKey()) { for (Region reg : filterInfo.getKeyOccurrences()) { StyleRange sr = new StyleRange(reg.getOffset(), reg.getLength(), black, info_color, SWT.BOLD); styleRanges.add(sr); } } } cell.setStyleRanges(styleRanges.toArray(new StyleRange[styleRanges.size()])); } else { cell.setForeground(gray); } } else if (columnIndex == 0) { super.update(cell); } }
From source file:org.eclipse.cdt.debug.internal.ui.views.executables.ExecutablesContentProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { super.update(cell); Object element = cell.getElement(); if (element instanceof Executable) { Executable exe = (Executable) element; String cellText = exe.getName(); if (cell.getColumnIndex() == 1) cellText = exe.getProject().getName(); else if (cell.getColumnIndex() == 2) cellText = exe.getPath().toOSString(); else if (cell.getColumnIndex() == 3) { cellText = ""; //$NON-NLS-1$ IPath path = exe.getPath();//from w ww . j a va2 s .co m if (path != null && path.toFile().exists()) { long fileLength = path.toFile().length(); cellText = Long.toString(fileLength); } cell.setImage(null); } else if (cell.getColumnIndex() == 4) { cellText = ""; //$NON-NLS-1$ IPath path = exe.getPath(); if (path != null && path.toFile().exists()) { long modified = path.toFile().lastModified(); cellText = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date(modified)); } cell.setImage(null); } else if (cell.getColumnIndex() == 5) { cellText = ""; //$NON-NLS-1$ String fileExtension = exe.getPath().getFileExtension(); if (fileExtension != null) cellText = fileExtension; } cell.setText(cellText); } }
From source file:org.eclipse.cdt.debug.internal.ui.views.executables.SourceFilesLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { super.update(cell); SourceFilesViewer.TranslationUnitInfo tuInfo = null; Object element = cell.getElement(); if (element instanceof ITranslationUnit) { tuInfo = SourceFilesViewer.fetchTranslationUnitInfo((Executable) viewer.getInput(), element); }/*from w w w . j ava 2s . c o m*/ int orgColumnIndex = cell.getColumnIndex(); if (orgColumnIndex == 0) { if (element instanceof String) { cell.setText((String) element); Font italicFont = resourceManager .createFont(FontDescriptor.createFrom(viewer.getTree().getFont()).setStyle(SWT.ITALIC)); cell.setFont(italicFont); } else { cell.setFont(viewer.getTree().getFont()); } } else if (orgColumnIndex == 1) { cell.setText(null); if (tuInfo != null) { if (tuInfo.location != null) { cell.setText(tuInfo.location.toOSString()); if (tuInfo.exists) cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); else cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY)); } } cell.setImage(null); } else if (orgColumnIndex == 2) { cell.setText(null); if (tuInfo != null && tuInfo.originalLocation != null) { cell.setText(tuInfo.originalLocation.toOSString()); if (tuInfo.originalExists) cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); else cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY)); } cell.setImage(null); } else if (orgColumnIndex == 3) { cell.setText(null); if (tuInfo != null) { if (tuInfo.exists) { cell.setText(Long.toString(tuInfo.fileLength)); } } cell.setImage(null); } else if (orgColumnIndex == 4) { cell.setText(null); if (tuInfo != null) { if (tuInfo.exists) { String dateTimeString = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date(tuInfo.lastModified)); cell.setText(dateTimeString); } } cell.setImage(null); } else if (orgColumnIndex == 5) { cell.setText(null); if (tuInfo != null) { if (tuInfo.location != null) { String fileExtension = tuInfo.location.getFileExtension(); if (fileExtension != null) cell.setText(fileExtension.toLowerCase()); } } cell.setImage(null); } }
From source file:org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.TableViewerUtil.java
License:Open Source License
public static boolean isColumnClicked(TableViewer viewer, MouseEvent e, TableViewerColumn tvColumn) { boolean ret;/*from w w w . ja va 2 s . c o m*/ ViewerCell cell = viewer.getCell(new Point(e.x, e.y)); if (cell == null) { ret = false; } else { int index = Arrays.asList(viewer.getTable().getColumns()).indexOf(tvColumn.getColumn()); if (index == -1) { ret = false; } else { ret = index == cell.getColumnIndex(); } } return ret; }