List of usage examples for org.eclipse.jface.viewers TableViewer getElementAt
public Object getElementAt(int index)
From source file:hydrograph.ui.propertywindow.widgets.listeners.grid.transform.ELTTransforAddSelectionListener.java
License:Apache License
@Override public void createDefaultSchema(List grids, TableViewer tableViewer, Label errorLabel) { OperationField operationField = new OperationField(); operationField.setName(""); if (!grids.contains(operationField)) { grids.add(operationField);/*w w w. j a v a2 s . c om*/ tableViewer.setInput(grids); tableViewer.refresh(); tableViewer.editElement(tableViewer.getElementAt(grids.size() == 0 ? grids.size() : grids.size() - 1), 0); } }
From source file:hydrograph.ui.propertywindow.widgets.utility.WidgetUtility.java
License:Apache License
/** * Set the cursor on delete the row from table. * @param tableViewer/* w w w . j a v a 2s . c o m*/ * @param gridList */ public static void setCursorOnDeleteRow(TableViewer tableViewer, List<?> gridList) { Table table = tableViewer.getTable(); int[] indexes = table.getSelectionIndices(); if (table.getSelectionIndex() == -1) { WidgetUtility.errorMessage(ERROR_MESSAGE); } else { table.remove(indexes); List listOfItemsToRemove = new ArrayList(); for (int index : indexes) { listOfItemsToRemove.add(gridList.get(index)); } gridList.removeAll(listOfItemsToRemove); //highlight after deletion if (indexes.length == 1 && gridList.size() > 0) {//only one item is deleted if (gridList.size() == 1) {//list contains only one element table.select(0);// select the first element tableViewer.editElement(tableViewer.getElementAt(0), 0); } else if (gridList.size() == indexes[0]) {//deleted last item table.select(gridList.size() - 1);//select the last element which now at the end of the list tableViewer.editElement(tableViewer.getElementAt(gridList.size() - 1), 0); } else if (gridList.size() > indexes[0]) {//deleted element from middle of the list table.select(indexes[0] == 0 ? 0 : (indexes[0] - 1));//select the element from at the previous location tableViewer.editElement(tableViewer.getElementAt(indexes[0] == 0 ? 0 : (indexes[0] - 1)), 0); } } else if (indexes.length >= 2) {//multiple items are selected for deletion if (indexes[0] == 0) {//delete from 0 to ... if (gridList.size() >= 1) {//list contains only one element table.select(0);//select the remaining element tableViewer.editElement(tableViewer.getElementAt(0), 0); } } else {//delete started from element other than 0th element table.select((indexes[0]) - 1);//select element before the start of selection tableViewer.editElement(tableViewer.getElementAt((indexes[0]) - 1), 0); } } } }
From source file:net.rim.ejde.internal.ui.editors.model.BlackBerryProjectPropertiesPage.java
License:Open Source License
/** * Searches the given viewer for the given object and returns its index or -1 if the object was not found * * @param viewer// w w w.jav a 2 s. co m * @param obj * @return */ public Integer getObjectIndexInViewer(TableViewer viewer, Object obj) { for (int i = 0; i < viewer.getTable().getItemCount(); i++) { Object element = viewer.getElementAt(i); if ((obj instanceof Icon) && (element instanceof Icon)) { IProject project = _blackBerryProject.getProject(); IPath iconPath = new Path(((Icon) element).getCanonicalFileName()); IResource iconRes = project.findMember(iconPath); IPath projectPath = project.getLocation(), iconRelPath, iconAbsPath; if (iconRes != null) { iconRelPath = projectPath.append(iconRes.getProjectRelativePath()); iconAbsPath = iconRes.getLocation(); } else { iconRelPath = null; iconAbsPath = projectPath.append(iconPath); } IPath newIconPath = projectPath.append(((Icon) obj).getCanonicalFileName()); if (newIconPath.equals(iconRelPath) || newIconPath.equals(iconAbsPath)) { return i; } } else if ((obj instanceof PreprocessorTag) && (element instanceof PreprocessorTag)) { PreprocessorTag o1 = (PreprocessorTag) obj; PreprocessorTag o2 = (PreprocessorTag) element; if (o1.getPreprocessorDefine().equals(o2.getPreprocessorDefine())) { return i; } } else { if (obj.equals(element)) { return i; } } } return -1; }
From source file:org.eclipse.bpel.ui.util.BPELUtil.java
License:Open Source License
/** creates a table cursor that can be used to navigate tables for keyboard accessibility **/ public static TableCursor createTableCursor(final Table table, final TableViewer tableViewer) { // create a TableCursor to navigate around the table final TableCursor cursor = new TableCursor(table, SWT.NONE); cursor.addSelectionListener(new SelectionAdapter() { // when the TableEditor is over a cell, select the corresponding row in the table @Override/*from www . j ava 2 s. co m*/ public void widgetSelected(SelectionEvent e) { if (cursor.getRow() != null) table.setSelection(new TableItem[] { cursor.getRow() }); } // when the user hits "ENTER" in the TableCursor, pop up an editor @Override public void widgetDefaultSelected(SelectionEvent e) { TableItem row = cursor.getRow(); if (row != null) { int nRow = table.indexOf(row); int column = cursor.getColumn(); Object obj = tableViewer.getElementAt(nRow); tableViewer.editElement(obj, column); } } }); // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" key. // This alows the user to select multiple items in the table. cursor.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if ((e.keyCode == SWT.CTRL) || (e.keyCode == SWT.SHIFT) || (e.stateMask & SWT.CONTROL) != 0 || (e.stateMask & SWT.SHIFT) != 0) { cursor.setVisible(false); } } }); cursor.addMouseListener(new MouseListener() { public void mouseDoubleClick(MouseEvent e) { } public void mouseDown(MouseEvent e) { TableItem row = cursor.getRow(); if (row != null) { int nRow = table.indexOf(row); int column = cursor.getColumn(); Object obj = tableViewer.getElementAt(nRow); tableViewer.editElement(obj, column); } } public void mouseUp(MouseEvent e) { } }); // Show the TableCursor when the user releases the "SHIFT" or "CTRL" key. // This signals the end of the multiple selection task. table.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.CONTROL && (e.stateMask & SWT.SHIFT) != 0) return; if (e.keyCode == SWT.SHIFT && (e.stateMask & SWT.CONTROL) != 0) return; if (e.keyCode != SWT.CONTROL && (e.stateMask & SWT.CONTROL) != 0) return; if (e.keyCode != SWT.SHIFT && (e.stateMask & SWT.SHIFT) != 0) return; if (table.getItemCount() == 0) return; TableItem[] selection = table.getSelection(); TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0]; table.showItem(row); cursor.setSelection(row, 0); cursor.setVisible(true); cursor.setFocus(); } }); return cursor; }
From source file:org.eclipse.bpmn2.modeler.core.merrimac.providers.TableCursor.java
License:Open Source License
/** * Creates a table cursor that can be used to navigate tables for keyboard accessibility * @param table//from ww w. j ava2 s . co m * @param tableViewer * @return */ public static TableCursor create(final Table table, final TableViewer tableViewer) { // create a TableCursor to navigate around the table final TableCursor cursor = new TableCursor(table, SWT.NONE); cursor.addSelectionListener(new SelectionAdapter() { // when the TableEditor is over a cell, select the corresponding row in the table @Override public void widgetSelected(SelectionEvent e) { if (cursor.getRow() != null) table.setSelection(new TableItem[] { cursor.getRow() }); } // when the user hits "ENTER" in the TableCursor, pop up an editor @Override public void widgetDefaultSelected(SelectionEvent e) { TableItem row = cursor.getRow(); if (row != null) { int nRow = table.indexOf(row); int column = cursor.getColumn(); Object obj = tableViewer.getElementAt(nRow); tableViewer.editElement(obj, column); } } }); // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" key. // This alows the user to select multiple items in the table. cursor.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if ((e.keyCode == SWT.CTRL) || (e.keyCode == SWT.SHIFT) || (e.stateMask & SWT.CONTROL) != 0 || (e.stateMask & SWT.SHIFT) != 0) { cursor.setVisible(false); } } }); cursor.addMouseListener(new MouseListener() { public void mouseDoubleClick(MouseEvent e) { } public void mouseDown(MouseEvent e) { TableItem row = cursor.getRow(); if (row != null) { int nRow = table.indexOf(row); int column = cursor.getColumn(); Object obj = tableViewer.getElementAt(nRow); tableViewer.editElement(obj, column); } } public void mouseUp(MouseEvent e) { } }); // Show the TableCursor when the user releases the "SHIFT" or "CTRL" key. // This signals the end of the multiple selection modelObject. table.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.CONTROL && (e.stateMask & SWT.SHIFT) != 0) return; if (e.keyCode == SWT.SHIFT && (e.stateMask & SWT.CONTROL) != 0) return; if (e.keyCode != SWT.CONTROL && (e.stateMask & SWT.CONTROL) != 0) return; if (e.keyCode != SWT.SHIFT && (e.stateMask & SWT.SHIFT) != 0) return; if (table.getItemCount() == 0) return; TableItem[] selection = table.getSelection(); TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0]; table.showItem(row); cursor.setSelection(row, 0); cursor.setVisible(true); cursor.setFocus(); } }); return cursor; }
From source file:org.eclipse.edt.ide.ui.internal.deployment.ui.EGLDDBaseFormPage.java
License:Open Source License
/** * /*from w w w.j a v a 2s .c o m*/ * @param selectionIndex - the index of the removed item, which is the selected index * @param viewer * @param removeBtn */ public static void updateTableViewerAfterRemove(int selectionIndex, TableViewer viewer, Button removeBtn) { //remove it from UI viewer.refresh(); int itemCnts = viewer.getTable().getItemCount(); if (selectionIndex >= itemCnts) selectionIndex = itemCnts - 1; if (itemCnts > 0) { Object item = viewer.getElementAt(selectionIndex); StructuredSelection selection = new StructuredSelection(item); viewer.setSelection(selection); } else removeBtn.setEnabled(false); }
From source file:org.eclipse.edt.ide.ui.internal.deployment.ui.EGLDDBaseFormPage.java
License:Open Source License
public static void selectFristElementInTable(TableViewer tableViewer) { ISelection currSel = tableViewer.getSelection(); if (currSel.isEmpty()) { //select the 1st element in the table if there is any int itemCnts = tableViewer.getTable().getItemCount(); if (itemCnts > 0) { Object item = tableViewer.getElementAt(0); StructuredSelection firstSel = new StructuredSelection(item); tableViewer.setSelection(firstSel); }/* ww w.j a va 2s . c o m*/ } else tableViewer.setSelection(currSel); }
From source file:org.eclipse.linuxtools.internal.valgrind.massif.birt.ChartControl.java
License:Open Source License
public void callback(Object event, Object source, CallBackValue value) { // give Valgrind view focus showView();//from w w w. java 2 s.co m MouseEvent mEvent = (MouseEvent) event; DataPointHints point = ((DataPointHints) ((WrappedStructureSource) source).getSource()); // select the corresponding snapshot in the TableViewer TableViewer viewer = view.getTableViewer(); view.setTopControl(viewer.getControl()); MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(point.getIndex()); switch (mEvent.count) { case 1: // single click viewer.setSelection(new StructuredSelection(snapshot)); break; case 2: // double click if (snapshot.isDetailed()) { ChartLocationsDialog dialog = new ChartLocationsDialog(getShell()); dialog.setInput(snapshot); if (dialog.open() == Window.OK) { dialog.openEditorForResult(); } } } }
From source file:org.eclipse.linuxtools.internal.valgrind.massif.birt.ChartSVG.java
License:Open Source License
public void callback(Object event, Object source, CallBackValue value) { // give Valgrind view focus showView();//w ww . ja v a 2 s.co m MouseEvent mEvent = (MouseEvent) event; DataPointHints point = ((DataPointHints) ((WrappedStructureSource) source).getSource()); // select the corresponding snapshot in the TableViewer TableViewer viewer = view.getTableViewer(); view.setTopControl(viewer.getControl()); MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(point.getIndex()); switch (mEvent.count) { case 1: // single click viewer.setSelection(new StructuredSelection(snapshot)); break; case 2: // double click // if (snapshot.isDetailed()) { // ChartLocationsDialog dialog = new ChartLocationsDialog(getShell()); // dialog.setInput(snapshot); // // if (dialog.open() == Window.OK) { // dialog.openEditorForResult(); // } // } } }
From source file:org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditor.java
License:Open Source License
@Override public void createPartControl(Composite parent) { final ChartEditorInput input = (ChartEditorInput) getEditorInput(); final HeapChart heapChart = input.getChart(); control = new Chart(parent, SWT.FILL); heapChart.setChartControl(control);/* w w w.j a v a2s.com*/ final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225); final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED); final Color ORANGE = new Color(Display.getDefault(), 255, 165, 0); final Color GREEN = Display.getDefault().getSystemColor(SWT.COLOR_GREEN); final Color DARK_BLUE = new Color(Display.getDefault(), 64, 128, 128); final int TICK_GAP = 40; control.setBackground(WHITE); control.setBackgroundInPlotArea(LIGHTYELLOW); FontData fd = JFaceResources.getDialogFont().getFontData()[0]; fd.setStyle(SWT.BOLD); Font font = new Font(Display.getDefault(), fd); fd.setHeight(fd.getHeight() + 2); Font titleFont = new Font(Display.getDefault(), fd); ITitle title = control.getTitle(); title.setFont(titleFont); title.setForeground(BLACK); title.setText(heapChart.title); IAxis xAxis = control.getAxisSet().getXAxis(0); xAxis.getGrid().setStyle(LineStyle.NONE); xAxis.getTick().setForeground(BLACK); ITitle xTitle = xAxis.getTitle(); xTitle.setFont(font); xTitle.setForeground(BLACK); xTitle.setText(heapChart.xUnits); IAxis yAxis = control.getAxisSet().getYAxis(0); yAxis.getGrid().setStyle(LineStyle.SOLID); yAxis.getTick().setForeground(BLACK); yAxis.getTick().setTickMarkStepHint(TICK_GAP); ITitle yTitle = yAxis.getTitle(); yTitle.setFont(font); yTitle.setText(heapChart.yUnits); yTitle.setForeground(BLACK); control.getLegend().setPosition(SWT.BOTTOM); // data final ILineSeries lsUseful = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, Messages.getString("HeapChart.Useful_Heap")); //$NON-NLS-1$; lsUseful.setXSeries(heapChart.time); lsUseful.setYSeries(heapChart.dataUseful); lsUseful.setSymbolType(PlotSymbolType.DIAMOND); lsUseful.setSymbolColor(RED); lsUseful.setLineColor(RED); final ILineSeries lsExtra = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, Messages.getString("HeapChart.Extra_Heap")); //$NON-NLS-1$; lsExtra.setXSeries(heapChart.time); lsExtra.setYSeries(heapChart.dataExtra); lsExtra.setSymbolType(PlotSymbolType.DIAMOND); lsExtra.setSymbolColor(ORANGE); lsExtra.setLineColor(ORANGE); if (heapChart.dataStacks != null) { final ILineSeries lsStack = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, Messages.getString("HeapChart.Stacks")); //$NON-NLS-1$; lsStack.setXSeries(heapChart.time); lsStack.setYSeries(heapChart.dataStacks); lsStack.setSymbolType(PlotSymbolType.DIAMOND); lsStack.setSymbolColor(DARK_BLUE); lsStack.setLineColor(DARK_BLUE); } final ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, Messages.getString("HeapChart.Total_Heap")); //$NON-NLS-1$; lsTotal.setXSeries(heapChart.time); lsTotal.setYSeries(heapChart.dataTotal); lsTotal.setSymbolType(PlotSymbolType.DIAMOND); lsTotal.setSymbolColor(GREEN); lsTotal.setLineColor(GREEN); // adjust axes control.getAxisSet().adjustRange(); IAxisSet axisSet = control.getAxisSet(); Range xRange = axisSet.getXAxis(0).getRange(); Range yRange = axisSet.getYAxis(0).getRange(); double xExtra = 0.05 * (xRange.upper - xRange.lower); double yExtra = 0.05 * (yRange.upper - yRange.lower); axisSet.getXAxis(0).setRange(new Range(xRange.lower, xRange.upper + xExtra)); axisSet.getYAxis(0).setRange(new Range(yRange.lower, yRange.upper + yExtra)); // listeners control.getPlotArea().addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { showView(); TableViewer viewer = input.getView().getTableViewer(); input.getView().setTopControl(viewer.getControl()); Point p = new Point(e.x, e.y); int closest = 0; double d1, d2, d3, currMin; double globalMin = Double.MAX_VALUE; for (int i = 0; i < heapChart.time.length; i++) { // get distance from click event to data points for the given index d1 = distance(lsUseful.getPixelCoordinates(i), p); d2 = distance(lsExtra.getPixelCoordinates(i), p); d3 = distance(lsTotal.getPixelCoordinates(i), p); // find the closest data point to the click event currMin = Math.min(Math.min(d1, d2), d3); if (currMin < globalMin) { closest = i; globalMin = currMin; } } MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(closest); viewer.setSelection(new StructuredSelection(snapshot), true); if (e.count == 2 && snapshot.isDetailed()) { ChartLocationsDialog dialog = new ChartLocationsDialog(Display.getCurrent().getActiveShell()); dialog.setInput(snapshot); if (dialog.open() == Window.OK) { dialog.openEditorForResult(); } } } }); }