List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:org.csstudio.diag.pvutil.view.PVUtilView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { if (model == null) { new Label(parent, 0).setText("Cannot initialize"); //$NON-NLS-1$ return;/*from w ww . j av a2 s . com*/ } gui = new GUI(parent, model); // Allow Eclipse to listen to PV selection changes final TableViewer pv_table = gui.getPVTableViewer(); getSite().setSelectionProvider(pv_table); // Allow dragging PV names new ControlSystemDragSource(pv_table.getTable()) { @Override public Object getSelection() { final IStructuredSelection selection = (IStructuredSelection) pv_table.getSelection(); final Object[] objs = selection.toArray(); final PV[] pvs = Arrays.copyOf(objs, objs.length, PV[].class); return pvs; } }; // Enable 'Drop' final Text pv_filter = gui.getPVFilterText(); new ControlSystemDropTarget(pv_filter, ProcessVariable.class, String.class) { @Override public void handleDrop(final Object item) { if (item instanceof ProcessVariable) setPVFilter(((ProcessVariable) item).getName()); else if (item instanceof String) setPVFilter(item.toString().trim()); } }; // Add empty context menu so that other CSS apps can // add themselves to it MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); Menu menu = menuMgr.createContextMenu(pv_table.getControl()); pv_table.getControl().setMenu(menu); getSite().registerContextMenu(menuMgr, pv_table); // Add context menu to the name table. // One reason: Get object contribs for the NameTableItems. IWorkbenchPartSite site = getSite(); MenuManager manager = new MenuManager("#PopupMenu"); //$NON-NLS-1$ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); Menu contextMenu = manager.createContextMenu(pv_table.getControl()); pv_table.getControl().setMenu(contextMenu); site.registerContextMenu(manager, pv_table); }
From source file:org.csstudio.opibuilder.visualparts.PVTupleTableEditor.java
License:Open Source License
/** * Refreshes the enabled-state of the actions. *//*w w w. ja v a2s. c o m*/ private void refreshToolbarOnSelection() { IStructuredSelection selection = (IStructuredSelection) pvTupleListTableViewer.getSelection(); int num_tuple = 0; for (Object obj : selection.toArray()) { if (obj instanceof PVTuple) num_tuple++; } if (num_tuple == 0) { removeAction.setEnabled(false); moveUpAction.setEnabled(false); moveDownAction.setEnabled(false); checkTriggerAction.setEnabled(false); uncheckTriggerAction.setEnabled(false); } else if (num_tuple == 1) { removeAction.setEnabled(true); moveUpAction.setEnabled(true); moveDownAction.setEnabled(true); checkTriggerAction.setEnabled(true); uncheckTriggerAction.setEnabled(true); } else { removeAction.setEnabled(true); moveUpAction.setEnabled(false); moveDownAction.setEnabled(false); checkTriggerAction.setEnabled(true); uncheckTriggerAction.setEnabled(true); } }
From source file:org.csstudio.swt.chart.test.ChartDemo.java
License:Open Source License
private void run() { final Display display = new Display(); final Shell shell = new Shell(display); // Compare: JFrame shell.setBounds(100, 100, 800, 600); makeGUI(shell);// w w w .j a v a2 s . c o m // Add initial demo data addDemoTrace("y", chart.getYAxis(0)); // List is a drag source new ControlSystemDragSource(list_viewer.getControl()) { @Override public Object getSelection() { final IStructuredSelection selection = (IStructuredSelection) list_viewer.getSelection(); final Object[] objs = selection.toArray(); final ProcessVariable[] pvs = Arrays.copyOf(objs, objs.length, ProcessVariable[].class); return pvs; } }; // Listener Demo chart.addListener(new ChartListener() { @Override public void aboutToZoomOrPan(final String description) { System.out.println("ChartTest ChartListener: aboutToZoomOrPan " + description); } @Override public void changedXAxis(final XAxis xaxis) { System.out.println("ChartTest ChartListener: XAxis changed"); } @Override public void changedYAxis(final YAxisListener.Aspect what, final YAxis yaxis) { System.out.println("ChartTest ChartListener: " + yaxis + " has new " + what); } @Override public void pointSelected(final int x, final int y) { System.out.println("ChartTest ChartListener: Point " + x + ", " + y + " Selected"); } }); // Allow PV drops into the chart new ControlSystemDropTarget(chart, ProcessVariable[].class) { @Override public void handleDrop(final Object item) { if (!(item instanceof ProcessVariable[])) return; final ProcessVariable[] pvs = (ProcessVariable[]) item; for (ProcessVariable pv : pvs) addDemoTrace(pv.getName(), null); } }; shell.open(); display.timerExec(SCROLL_MS, sample_adder); // Message loop left to the application while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); // ! }
From source file:org.csstudio.swt.widgets.natives.SpreadSheetTable.java
License:Open Source License
/** * Get selected part./* ww w . j a v a 2 s. c o m*/ * * @return the 2D string array under selection. */ @SuppressWarnings("unchecked") public String[][] getSelection() { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); String[][] result = new String[selection.size()][getColumnCount()]; int i = 0; for (Object o : selection.toArray()) { for (int j = 0; j < getColumnCount(); j++) { result[i][j] = ((List<String>) o).get(j); } i++; } return result; }
From source file:org.csstudio.trends.databrowser2.propsheet.DataBrowserPropertySheetPage.java
License:Open Source License
/** Within SashForm of the "Traces" tab, create the Model Item table * @param sashform// ww w.j a v a 2s .c om */ private void createTracesTabItemPanel(final SashForm sashform) { // TableColumnLayout requires the TableViewer to be in its own Composite! final Composite model_item_top = new Composite(sashform, SWT.BORDER); final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10); model_item_top.setLayout(table_layout); // Would like to _not_ use FULL_SELECTION so that only the currently selected // cell gets highlighted, allowing the 'color' to still be visible // -> On Linux, you only get FULL_SELECTION behavior. // -> On Windows, editing is really odd, need to select a column before anything // can be edited, plus color still invisible // ---> Using FULL_SELECTION trace_table = new TableViewer(model_item_top, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); final Table table = trace_table.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); final TraceTableHandler tth = new TraceTableHandler(); tth.createColumns(table_layout, operations_manager, trace_table); trace_table.setContentProvider(tth); trace_table.setInput(model); new ControlSystemDragSource(trace_table.getControl()) { @Override public Object getSelection() { final IStructuredSelection selection = (IStructuredSelection) trace_table.getSelection(); final Object[] objs = selection.toArray(); final ModelItem[] items = Arrays.copyOf(objs, objs.length, ModelItem[].class); return items; } }; }
From source file:org.csstudio.trends.databrowser2.propsheet.DataBrowserPropertySheetPage.java
License:Open Source License
/** Create context menu for the archive table, * which depends on the currently selected PVs *//*from www . ja v a 2 s . co m*/ private void createArchiveMenu() { // Create dynamic context menu, content changes depending on selections final MenuManager menu = new MenuManager(); menu.setRemoveAllWhenShown(true); menu.addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(IMenuManager manager) { // Determine selected PV Items final PVItem pvs[] = getSelectedPVs(); if (pvs.length <= 0) return; menu.add(new AddArchiveAction(operations_manager, control.getShell(), pvs)); menu.add(new UseDefaultArchivesAction(operations_manager, pvs)); // Only allow removal of archives from single PV if (pvs.length == 1) { // Determine selected archives final IStructuredSelection arch_sel = (IStructuredSelection) archive_table.getSelection(); if (!arch_sel.isEmpty()) { final Object[] objects = arch_sel.toArray(); final ArchiveDataSource archives[] = new ArchiveDataSource[objects.length]; for (int i = 0; i < archives.length; i++) archives[i] = (ArchiveDataSource) objects[i]; menu.add(new DeleteArchiveAction(operations_manager, pvs[0], archives)); } } menu.add(new Separator()); menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); } }); final Table table = archive_table.getTable(); table.setMenu(menu.createContextMenu(table)); }
From source file:org.csstudio.trends.databrowser2.propsheet.DataBrowserPropertySheetPage.java
License:Open Source License
/** @return Currently selected PVs in the table of traces (items). Never <code>null</code> */ protected PVItem[] getSelectedPVs() { final IStructuredSelection selection = (IStructuredSelection) trace_table.getSelection(); if (selection.isEmpty()) return new PVItem[0]; final Object obj[] = selection.toArray(); final ArrayList<PVItem> pvs = new ArrayList<PVItem>(); for (int i = 0; i < obj.length; ++i) if (obj[i] instanceof PVItem) pvs.add((PVItem) obj[i]);/* ww w .ja va 2 s . c o m*/ return pvs.toArray(new PVItem[pvs.size()]); }
From source file:org.csstudio.trends.databrowser2.search.ArchiveListGUI.java
License:Open Source License
/** @return Selected archive data sources or 'all' when nothing selected. * Returns <code>null</code> if user decided not to search 'all', * or if connection to data server is not available. */// w w w. j a va2 s . c o m @SuppressWarnings("unchecked") public ArchiveDataSource[] getSelectedArchives() { if (url == null) return null; final ArrayList<ArchiveDataSource> archives; final IStructuredSelection sel = (IStructuredSelection) archive_table.getSelection(); if (sel.isEmpty()) { // Use 'all' archives, but prompt for confirmation archives = (ArrayList<ArchiveDataSource>) archive_table.getInput(); if (archives.size() > 1 && !MessageDialog.openConfirm(archive_table.getTable().getShell(), Messages.Search, NLS.bind(Messages.SearchArchiveConfirmFmt, archives.size()))) return null; } else { archives = new ArrayList<ArchiveDataSource>(); final Object[] objs = sel.toArray(); for (Object obj : objs) archives.add((ArchiveDataSource) obj); } return (ArchiveDataSource[]) archives.toArray(new ArchiveDataSource[archives.size()]); }
From source file:org.csstudio.trends.databrowser2.search.SearchView.java
License:Open Source License
/** React to selections, button presses, ... */ private void configureActions() { // Start a channel search search.addSelectionListener(new SelectionAdapter() { @Override/*ww w . ja v a2 s .com*/ public void widgetSelected(final SelectionEvent e) { searchForChannels(); } }); // Channel Table: Allow dragging of PVs with archive final Table table = channel_table.getTable(); new ControlSystemDragSource(table) { @Override public Object getSelection() { final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection(); // To allow transfer of array, the data must be // of the actual array type, not Object[] final Object[] objs = selection.toArray(); final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class); return channels; // return selection.getFirstElement(); } }; // Double-clicks should have the same effect as context menu -> Data Browser getSite().setSelectionProvider(channel_table); channel_table.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { //casting is needed for RAP IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); try { handlerService.executeCommand("org.csstudio.trends.databrowser.OpenDataBrowserPopup", null); } catch (CommandException ex) { Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex); //$NON-NLS-1$ } } }); // Add context menu for object contributions final MenuManager menu = new MenuManager(); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); table.setMenu(menu.createContextMenu(table)); getSite().registerContextMenu(menu, channel_table); }
From source file:org.csstudio.trends.databrowser3.search.SearchView.java
License:Open Source License
/** React to selections, button presses, ... */ private void configureActions() { // Start a channel search search.addSelectionListener(new SelectionAdapter() { @Override/*ww w . ja v a 2s. c o m*/ public void widgetSelected(final SelectionEvent e) { searchForChannels(); } }); // Channel Table: Allow dragging of PVs with archive final Table table = channel_table.getTable(); new ControlSystemDragSource(table) { @Override public Object getSelection() { final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection(); // To allow transfer of array, the data must be // of the actual array type, not Object[] final Object[] objs = selection.toArray(); final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class); return channels; } }; // Double-clicks should have the same effect as context menu -> Data Browser getSite().setSelectionProvider(channel_table); channel_table.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { //casting is needed for RAP IHandlerService handlerService = getSite().getService(IHandlerService.class); try { handlerService.executeCommand("org.csstudio.trends.databrowser3.OpenDataBrowserPopup", null); } catch (CommandException ex) { Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex); //$NON-NLS-1$ } } }); // Add context menu for object contributions final MenuManager menu = new MenuManager(); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); table.setMenu(menu.createContextMenu(table)); getSite().registerContextMenu(menu, channel_table); }