List of usage examples for org.eclipse.jface.viewers ViewerCell getViewerRow
public ViewerRow getViewerRow()
From source file:Snippet048TreeViewerTabWithCheckboxFor3_3.java
License:Open Source License
public Snippet048TreeViewerTabWithCheckboxFor3_3(final Shell shell) { final TreeViewer v = new TreeViewer(shell, SWT.BORDER | SWT.FULL_SELECTION); v.getTree().setLinesVisible(true);/*w w w .j a va 2 s . c o m*/ v.getTree().setHeaderVisible(true); final TreeViewerFocusCellManager mgr = new TreeViewerFocusCellManager(v, new FocusCellOwnerDrawHighlighter(v)); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) { protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && (event.keyCode == SWT.CR || event.character == ' ')) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; } }; TreeViewerEditor.create(v, mgr, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); final TextCellEditor textCellEditor = new TextCellEditor(v.getTree()); final CheckboxCellEditor checkboxCellEditor = new CheckboxCellEditor(v.getTree()); TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE); column.getColumn().setWidth(200); column.getColumn().setMoveable(true); column.getColumn().setText("Column 1"); column.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { return "Column 1 => " + element.toString(); } }); column.setEditingSupport(new EditingSupport(v) { protected boolean canEdit(Object element) { return false; } protected CellEditor getCellEditor(Object element) { return textCellEditor; } protected Object getValue(Object element) { return ((MyModel) element).counter + ""; } protected void setValue(Object element, Object value) { ((MyModel) element).counter = Integer.parseInt(value.toString()); v.update(element, null); } }); column = new TreeViewerColumn(v, SWT.NONE); column.getColumn().setWidth(200); column.getColumn().setMoveable(true); column.getColumn().setText("Column 2"); column.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { return "Column 2 => " + element.toString(); } }); column.setEditingSupport(new EditingSupport(v) { protected boolean canEdit(Object element) { return true; } protected CellEditor getCellEditor(Object element) { return textCellEditor; } protected Object getValue(Object element) { return ((MyModel) element).counter + ""; } protected void setValue(Object element, Object value) { ((MyModel) element).counter = Integer.parseInt(value.toString()); v.update(element, null); } }); column = new TreeViewerColumn(v, SWT.NONE); column.getColumn().setWidth(200); column.getColumn().setMoveable(true); column.getColumn().setText("Column 3"); column.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { return ((MyModel) element).bool + ""; } }); column.setEditingSupport(new EditingSupport(v) { protected boolean canEdit(Object element) { return true; } protected CellEditor getCellEditor(Object element) { return checkboxCellEditor; } protected Object getValue(Object element) { return new Boolean(((MyModel) element).bool); } protected void setValue(Object element, Object value) { ((MyModel) element).bool = ((Boolean) value).booleanValue(); v.update(element, null); } }); v.setContentProvider(new MyContentProvider()); v.setInput(createModel()); v.getControl().addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if ((e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) && mgr.getFocusCell().getColumnIndex() == 2) { ColumnViewerEditor editor = v.getColumnViewerEditor(); ViewerCell cell = mgr.getFocusCell(); try { Method m = ColumnViewerEditor.class.getDeclaredMethod("processTraverseEvent", new Class[] { int.class, ViewerRow.class, TraverseEvent.class }); m.setAccessible(true); m.invoke(editor, new Object[] { new Integer(cell.getColumnIndex()), cell.getViewerRow(), e }); } catch (SecurityException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (NoSuchMethodException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalArgumentException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); }
From source file:br.ufes.inf.nemo.ontouml.transformation.onto2info.ui.util.BooleanCellEditor.java
License:Open Source License
public void activate(ColumnViewerEditorActivationEvent activationEvent) { ViewerCell cell = (ViewerCell) activationEvent.getSource(); index = cell.getColumnIndex();//from ww w . ja va 2s .c o m row = (ViewerRow) cell.getViewerRow().clone(); restoredImage = row.getImage(index); restoredText = row.getText(index); row.setImage(index, null); row.setText(index, ""); //$NON-NLS-1$ if (activationEvent.eventType != ColumnViewerEditorActivationEvent.TRAVERSAL && changeOnActivation) { //System.out.println("!!!!!!!! activate() !!!!!!!!\n"); //button.setSelection(!button.getSelection()); // original code // rcarraretto (this almost works) /* The problem is: the class that calls [Boolean]CellEditor.activate() also calls, further on, other methods of CellEditor * So, since I programmed this SWT.Selection to fireApplyEditorValue() * This will deactivate() this CellEditor and will generate a NullPointerException * Perhaps, a way to solve this is to extend and override the class and the method that calls [Boolean]CellEditor.activate() */ //button.notifyListeners(SWT.Selection, new Event()); } // TODO Add a way to enable key traversal when CheckBoxes don't get focus // if( Util.isMac() ) { // button.getParent().addKeyListener(macSelectionListener); // } super.activate(activationEvent); }
From source file:com.cloudbees.eclipse.dev.ui.views.build.BuildHistoryView.java
License:Open Source License
@Override public void createPartControl(final Composite parent) { initImages();//from w w w . j a va 2 s. c o m this.table = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION /*SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL*/); //Tree tree = viewer.getTree(); //tree.setHeaderVisible(true); //table.getTable().setLinesVisible(true); this.table.getTable().setHeaderVisible(true); TableViewerColumn statusCol = createColumn("S", 22, BuildSorter.STATE, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); String key = build.result; /* ImageData[] imageDatas = new ImageLoader().load(new FileInputStream("myAnimated.gif")); Image[] images = new Image[imageDatas.length]; for (int n = 0; n < imageDatas.length; n++) { // images[n] = new Image(myTable.getDislay(), imageDatas[n]); } */ // if (job.color != null && job.color.contains("_")) { // key = job.color.substring(0, job.color.indexOf("_")); // } Image img = BuildHistoryView.this.stateIcons.get(key); if (img != null) { cell.setText(""); cell.setImage(img); } else { cell.setImage(null); cell.setText(build.result); } } }); statusCol.getColumn().setToolTipText("Status"); //TODO i18n TableViewerColumn namecol = createColumn("Build", 50, BuildSorter.BUILD, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); String val; try { if (build.building) { val = "building"; } else { val = build.number.toString(); } } catch (Exception e) { val = ""; } cell.setText(val); } }); createColumn("When", 100, BuildSorter.TIME, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); if (build.timestamp != null) { try { cell.setText( Utils.humanReadableTime(System.currentTimeMillis() - build.timestamp) + " ago"); } catch (Exception e) { cell.setText(""); } } else { cell.setText(""); } cell.setImage(null); } }); createColumn("Build Duration", 100, BuildSorter.DURATION, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); if (build.duration != null) { try { cell.setText(Utils.humanReadableTime(build.duration)); } catch (Throwable t) { cell.setText(""); } } else { cell.setText(""); } } }); createColumn("Tests", 200, BuildSorter.TESTS, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); try { long total = 0; long failed = 0; long skipped = 0; for (com.cloudbees.eclipse.core.jenkins.api.JenkinsBuild.Action action : build.actions) { if ("testReport".equalsIgnoreCase(action.urlName)) { total += action.totalCount; failed += action.failCount; skipped += action.skipCount; } } if (total > 0 || failed > 0 || skipped > 0) { String val = "Passed: " + (total - failed - skipped); if (failed > 0) { val += ", failed: " + failed; } if (skipped > 0) { val += ", skipped: " + skipped; } cell.setText(val); } else { cell.setText(""); } } catch (Throwable t) { cell.setText(""); } } }); createColumn("Cause", 250, BuildSorter.CAUSE, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); String val = null; try { for (com.cloudbees.eclipse.core.jenkins.api.JenkinsBuild.Action action : build.actions) { if (action.causes != null && action.causes.length > 0) { val = action.causes[0].shortDescription; break; } } if (val == null) { val = ""; } cell.setText(val); } catch (Throwable t) { cell.setText(""); } } }); this.contentProvider = new BuildHistoryContentProvider(); this.table.setContentProvider(this.contentProvider); BuildSorter sorter = new BuildSorter(BuildSorter.BUILD); sorter.setDirection(SWT.UP); this.table.setSorter(sorter); this.table.setInput(getViewSite()); /* table.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return true; } });*/ this.table.addOpenListener(new IOpenListener() { public void open(final OpenEvent event) { ISelection sel = event.getSelection(); if (sel instanceof IStructuredSelection) { Object el = ((IStructuredSelection) sel).getFirstElement(); if (el instanceof JenkinsBuild) { CloudBeesDevUiPlugin.getDefault().showBuild(((JenkinsBuild) el)); } } } }); this.table.getTable().setSortColumn(namecol.getColumn()); this.table.getTable().setSortDirection(SWT.DOWN); makeActions(); contributeToActionBars(); MenuManager popupMenu = new MenuManager(); popupMenu.add(this.actionOpenBuild); popupMenu.add(this.actionOpenLog); popupMenu.add(new Separator("cloudActions")); popupMenu.add(this.actionOpenBuildInBrowser); popupMenu.add(this.actionInvokeBuild); popupMenu.add(new Separator("reloadActions")); popupMenu.add(this.actionReloadJobs); Menu menu = popupMenu.createContextMenu(this.table.getTable()); this.table.getTable().setMenu(menu); this.table.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { StructuredSelection sel = (StructuredSelection) event.getSelection(); BuildHistoryView.this.selectedBuild = sel.getFirstElement(); boolean enable = BuildHistoryView.this.selectedBuild != null; BuildHistoryView.this.actionInvokeBuild.setJob(BuildHistoryView.this.selectedBuild); BuildHistoryView.this.actionOpenBuildInBrowser.setEnabled(enable); BuildHistoryView.this.actionOpenBuild.setBuild(BuildHistoryView.this.selectedBuild); BuildHistoryView.this.actionOpenLog.setBuild(BuildHistoryView.this.selectedBuild); getViewSite().getActionBars().getToolBarManager().update(true); } }); this.jenkinsChangeListener = new CBRemoteChangeAdapter() { public void activeJobHistoryChanged(final JenkinsJobAndBuildsResponse newView) { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { BuildHistoryView.this.setInput(newView); } }); } }; CloudBeesUIPlugin.getDefault().addCBRemoteChangeListener(this.jenkinsChangeListener); }
From source file:com.cloudbees.eclipse.dev.ui.views.jobs.JobsView.java
License:Open Source License
private void initColumns() { TreeViewerColumn namecol = createColumn("Job", 250, JobSorter.JOB, new ColumnLabelProvider() { @Override//w ww .j ava 2 s .co m public void update(final ViewerCell cell) { Object el = cell.getViewerRow().getElement(); if (el instanceof PendingUpdateAdapter) { PendingUpdateAdapter uel = (PendingUpdateAdapter) el; cell.setText(uel.getLabel(null)); cell.setImage(null); return; } JobViewGeneric vg = ((JobHolder) cell.getViewerRow().getElement()).job; if (vg instanceof JenkinsJobsResponse.Job) { JenkinsJobsResponse.Job job = (Job) vg; String val = job.getDisplayName(); if (job.inQueue != null && job.inQueue) { val = val + " (in queue)"; } else if (job.color != null && job.color.indexOf('_') > 0) { val = val + " (running)"; } cell.setText(val); String key = job.color; if (job.color != null && job.color.contains("_")) { key = job.color.substring(0, job.color.indexOf("_")); } // Assuming for now that these are all folders as thers's no API to tell the difference if (job.color == null) { key = "folder"; } Image img = JobsView.this.stateIcons.get(key); if (img != null) { cell.setImage(img); } else if (job.color != null) { cell.setText(val + "[" + job.color + "]"); } } if (vg instanceof View) { cell.setImage(CloudBeesDevUiPlugin.getImage(CBDEVImages.IMG_VIEWR2)); cell.setText(vg.getName()); } } }); createColumn("Build stability", 250, JobSorter.BUILD_STABILITY, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; cell.setText(""); cell.setImage(null); try { if (job.healthReport != null) { for (int h = 0; h < job.healthReport.length; h++) { String icon = job.healthReport[h].iconUrl; String desc = job.healthReport[h].description; String matchStr = "Build stability: "; if (desc != null && desc.startsWith(matchStr)) { cell.setText(" " + desc.substring(matchStr.length())); cell.setImage(CloudBeesDevUiPlugin .getImage(CBDEVImages.IMG_HEALTH_PREFIX + CBDEVImages.IMG_16 + icon)); } } } } catch (Throwable t) { t.printStackTrace(); } } }); createColumn("Last build", 150, JobSorter.LAST_BUILD, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; try { cell.setText(JobsView.this.formatBuildInfo(job.lastBuild)); } catch (Throwable t) { cell.setText(""); } } }); createColumn("Last success", 150, JobSorter.LAST_SUCCESS, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; try { cell.setText(JobsView.this.formatBuildInfo(job.lastSuccessfulBuild)); } catch (Throwable t) { cell.setText(""); } } }); createColumn("Last failure", 150, JobSorter.LAST_FAILURE, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; try { cell.setText(JobsView.this.formatBuildInfo(job.lastFailedBuild)); } catch (Throwable t) { cell.setText(""); } } }); }
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;/*from ww w . j a va 2s . co 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.mentor.nucleus.bp.ui.sem.viewers.SEMFocusCellHighlighter.java
License:Open Source License
private void hookListener(final ColumnViewer viewer) { Listener listener = new Listener() { public void handleEvent(Event event) { if ((event.detail & SWT.SELECTED) > 0 || (event.detail & SWT.FocusOut) > 0) { ViewerCell focusCell = getFocusCell(); if (focusCell != null) { ViewerRow row = focusCell.getViewerRow(); ViewerCell cell = row.getCell(event.index); removeSelectionInformation(event, cell); }/*w w w. ja va 2s .c om*/ } } }; viewer.getControl().addListener(SWT.EraseItem, listener); }
From source file:com.mentor.nucleus.bp.ui.sem.viewers.SEMFocusCellHighlighter.java
License:Open Source License
private void removeSelectionInformation(Event event, ViewerCell cell) { GC gc = event.gc;/* w w w .j ava 2 s .c om*/ gc.setBackground(cell.getViewerRow().getBackground(cell.getColumnIndex())); gc.setForeground(cell.getViewerRow().getForeground(cell.getColumnIndex())); gc.fillRectangle(cell.getBounds()); // This is a workaround for an SWT-Bug on WinXP bug 169517 gc.drawText(" ", cell.getBounds().x, cell.getBounds().y, false); //$NON-NLS-1$ event.detail &= ~SWT.SELECTED; }
From source file:com.microsoft.tfs.client.common.ui.framework.celleditor.accessibility.MultiRowHighlighter.java
License:Open Source License
@Override protected void focusCellChanged(final ViewerCell newCell, final ViewerCell oldCell) { super.focusCellChanged(newCell, oldCell); /*/* w w w . j a v a 2 s . c o m*/ * When the focus is changed, we merely tell the table to redraw the * affected row(s). */ if (newCell != null) { newCell.getViewerRow().getControl().redraw(); } if (oldCell != null) { oldCell.getViewerRow().getControl().redraw(); } }
From source file:com.motorola.studio.android.emulator.core.emulationui.AbstractEmuLabelProvider.java
License:Apache License
/** * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) *///from www . jav 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); } } } }