List of usage examples for org.eclipse.jface.viewers StructuredSelection toArray
@Override
public Object[] toArray()
From source file:net.tourbook.ui.views.tourSegmenter.TourSegmenterView.java
License:Open Source License
private void onSelect_Segment(final SelectionChangedEvent event) { final StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection != null) { /*//from w ww . j a v a 2 s . c om * select the chart sliders according to the selected segment(s) */ final Object[] segments = selection.toArray(); if (segments.length > 0) { if (_tourChart == null) { _tourChart = TourManager.getActiveTourChart(_tourData); } final TourSegment firstTourSegment = (TourSegment) (segments[0]); final int serieStartIndex = firstTourSegment.serieIndex_Start; if (segments.length == 1 && firstTourSegment.isTotal) { // only the totals item is selected, do nothing return; } int lastIndex = segments.length - 1; TourSegment lastTourSegment = (TourSegment) (segments[lastIndex]); if (lastTourSegment.isTotal) { // the last index is the totals item, ignore this item lastIndex--; lastTourSegment = (TourSegment) (segments[lastIndex]); } final int serieEndIndex = lastTourSegment.serieIndex_End; final SelectionChartXSliderPosition selectionSliderPosition = new SelectionChartXSliderPosition( _tourChart, serieStartIndex, serieEndIndex, true); /* * Add custom data but only when the segment layer is visible */ if (isSegmentLayerVisible()) { /* * Extend default selection with the segment positions */ final SelectedTourSegmenterSegments selectedSegments = new SelectedTourSegmenterSegments(); selectedSegments.tourData = _tourData; selectedSegments.xSliderSerieIndexLeft = serieStartIndex; selectedSegments.xSliderSerieIndexRight = serieEndIndex; selectionSliderPosition.setCustomData(selectedSegments); } _postSelectionProvider.setSelection(selectionSliderPosition); } } }
From source file:net.tourbook.ui.views.TourSegmenterView.java
License:Open Source License
private void createUI80SegmentViewer(final Composite parent) { final Table table = new Table(parent, // SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI /* | SWT.BORDER */); table.setHeaderVisible(true);//from w w w.j av a 2 s . c o m table.setLinesVisible(true); GridDataFactory.fillDefaults().grab(true, true).applyTo(table); _segmentViewer = new TableViewer(table); _columnManager.createColumns(_segmentViewer); _segmentViewer.setContentProvider(new ViewContentProvider()); _segmentViewer.setSorter(new ViewSorter()); _segmentViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { final StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection != null) { /* * select the chart sliders according to the selected segment(s) */ final Object[] segments = selection.toArray(); if (segments.length > 0) { if (_tourChart == null) { _tourChart = getActiveTourChart(_tourData); } final int startIndex = ((TourSegment) (segments[0])).serieIndexStart; final int endIndex = ((TourSegment) (segments[segments.length - 1])).serieIndexEnd; final SelectionChartXSliderPosition selectionSliderPosition = new SelectionChartXSliderPosition( _tourChart, startIndex, endIndex, true); _postSelectionProvider.setSelection(selectionSliderPosition); } } } }); createUI90ContextMenu(); }
From source file:no.hib.dpf.editor.DPFEditorPaletteFactory.java
License:Open Source License
@Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection str = (StructuredSelection) selection; Object[] selectedParObjects = str.toArray(); if (selectedParObjects.length == 0) return; EList<DArrow> selectionDArrows = new BasicEList<DArrow>(); EList<DNode> selectionDNodes = new BasicEList<DNode>(); getSelectElements(Arrays.asList(str.toArray()), selectionDNodes, selectionDArrows); EList<Arrow> selectionArrows = getArrows(selectionDArrows); EList<Node> selectionNodes = getNodes(selectionDNodes); for (CreateConstraintToolEntry entry : entries) { Predicate cur = entry.getDPredicate().getPredicate(); boolean keep = (cur.getShape().getArrows().size() >= selectionArrows.size()) && (cur.getShape().getNodes().size() >= selectionNodes.size()); if (keep) { for (Node node : selectionNodes) { for (Constraint constraint : node.getConstraints()) { if (constraint.getPredicate() == cur) { boolean repeat = constraint.getArrows().equals(selectionArrows) && constraint.getNodes().equals(selectionNodes); if (repeat) { keep = false; break; }/*from w w w. j av a 2 s .co m*/ } } if (!keep) break; } } if (keep) { keep = entry.getDPredicate().getPredicate().canCreateConstraint(selectionNodes, selectionArrows); if (keep) { entry.setNodes(selectionDNodes, selectionNodes); entry.setArrows(selectionDArrows, selectionArrows); } } boolean in = constraintGroup.getChildren().contains(entry); if (keep && !in) constraintGroup.add(entry); if (!keep && in) constraintGroup.remove(entry); } } }
From source file:org.adorsys.plh.pkix.workbench.navigator.internal.ResourceNavigator.java
License:Open Source License
@Inject public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.context = context; parent.setLayout(new FillLayout()); TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService//from ww w . jav a 2 s. c o m .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); // context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); IObservableFactory setFactory = new IObservableFactory() { public IObservable createObservable(Object element) { if (element instanceof IContainer && ((IContainer) element).exists()) { IObservableSet observableSet = observableSets.get(element); if (observableSet == null) { observableSet = new WritableSet(realm); try { observableSet.addAll(Arrays.asList(((IContainer) element).members())); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } observableSets.put((IContainer) element, observableSet); } return observableSet; } return Observables.emptyObservableSet(); } }; viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() { public Boolean hasChildren(Object element) { return Boolean.valueOf(element instanceof IContainer); } })); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof IResource) return ((IResource) element).getName(); return element == null ? "" : element.toString(); } }); viewer.setSorter(new ViewerSorter()); viewer.setInput(workspace.getRoot()); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); for (Object o : s.toArray()) { if (o instanceof IFile) { IFile f = (IFile) o; context.set(IFile.class, f); String fExt = f.getFileExtension(); EDITOR: for (MPartDescriptor desc : application.getDescriptors()) { String category = desc.getCategory(); if (category == null) continue; String[] categories = category.split(","); for (String ext : categories) { if (ext.equalsIgnoreCase(fExt)) { context.set(MPartDescriptor.class, desc); System.err.println("Opening with: " + desc); Command cmd = commandService.getCommand("desktop.command.openeditor"); ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null); handlerService.executeHandler(pCmd); break EDITOR; } } } } } } }); setupContextMenu(viewer, parent.getShell()); workspace.addResourceChangeListener(listener); }
From source file:org.camunda.bpm.modeler.ui.views.ViewContentProvider.java
License:Open Source License
@SuppressWarnings("restriction") public Object[] getSelected(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; List<Object> selected = Arrays.asList(sel.toArray()); if (selected.size() == 0 || !(selected.get(0) instanceof ContainerShapeEditPart)) { return null; }//from w w w .j a v a 2s. com PictogramLink link = ((ContainerShapeEditPart) selected.get(0)).getPictogramElement().getLink(); if (link == null) { return null; } EList<EObject> businessObjects = link.getBusinessObjects(); TreeObject[] children = invisibleRoot.getChildren(); ArrayList<TreeObject> list = getSelectionFromList(businessObjects, children); return list.toArray(); } return null; }
From source file:org.csstudio.utility.adlconverter.ui.ADLConverterMainView.java
License:Open Source License
private void makeRemoveSelection(Menu menu) { MenuItem showItem = new MenuItem(menu, SWT.PUSH); showItem.addSelectionListener(new SelectionListener() { @Override/* w w w. ja v a2 s . c om*/ public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) _avaibleFiles.getSelection(); _avaibleFiles.remove(selection.toArray()); } @Override public void widgetDefaultSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) _avaibleFiles.getSelection(); _avaibleFiles.remove(selection.toArray()); } }); showItem.setText(Messages.ADLConverterMainView_RemoveSelectedFiels); showItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_REMOVE)); }
From source file:org.dawb.common.ui.wizard.ResourceChoosePage.java
License:Open Source License
protected List<String> getSelectedFiles() { if (selectedFiles != null) return selectedFiles; try {// w w w .j av a2 s.co m ISelection selection = EclipseUtils.getActivePage().getSelection(); StructuredSelection s = (StructuredSelection) selection; if (s.isEmpty()) return null; if (s.toArray() == null) return null; final Object[] oa = s.size() > 1 ? s.toArray() : getObjects(s.getFirstElement()); final List<String> ret = new ArrayList<String>(oa.length); for (final Object object : oa) { final File file = FileUtils.getFile(object); if (!file.isFile()) continue; ret.add(file.getAbsolutePath()); } return ret.size() > 0 ? ret : null; } catch (Throwable ignored) { return null; } }
From source file:org.dawb.workbench.ui.diffraction.table.DiffractionDelegate.java
License:Open Source License
private void initialize() { detectorPropertyListener = new IDetectorPropertyListener() { @Override/*from w w w .ja va2 s . c o m*/ public void detectorPropertiesChanged(DetectorPropertyEvent evt) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { viewer.refresh(); } }); } }; dropListener = new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Object dropData = event.data; if (dropData instanceof IResource[]) { IResource[] res = (IResource[]) dropData; for (int i = 0; i < res.length; i++) { manager.loadData(res[i].getRawLocation().toOSString(), null); } } else if (dropData instanceof TreeSelection) { TreeSelection selectedNode = (TreeSelection) dropData; Object obj[] = selectedNode.toArray(); for (int i = 0; i < obj.length; i++) { if (obj[i] instanceof NodeLink) { NodeLink node = (NodeLink) obj[i]; if (node == null || !(node.getTree() instanceof TreeFile)) return; manager.loadData(((TreeFile) node.getTree()).getFilename(), node.getFullName()); } else if (obj[i] instanceof IFile) { IFile file = (IFile) obj[i]; manager.loadData(file.getLocation().toOSString(), null); } } } else if (dropData instanceof String[]) { String[] selectedData = (String[]) dropData; for (int i = 0; i < selectedData.length; i++) { manager.loadData(selectedData[i], null); } } } }; deleteAction = new Action("Delete item", Activator.getImageDescriptor("icons/delete_obj.png")) { @Override public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); Object[] selected = selection.toArray(); for (int i = 0; i < selected.length; i++) { DiffractionTableData selectedData = (DiffractionTableData) selected[i]; if (manager.getSize() > 0) { if (manager.remove(selectedData)) { if (selectedData.getMetaData() != null) selectedData.getMetaData().getDetector2DProperties() .removeDetectorPropertyListener(detectorPropertyListener); } } } if (manager.getSize() > 0) { viewer.setSelection(new StructuredSelection((DiffractionTableData) viewer.getElementAt(0))); } else { viewer.setSelection(new StructuredSelection()); } updateTableColumnsAndLayout(tabIndex); } }; }
From source file:org.dawnsci.fileviewer.table.FileTableExplorer.java
License:Open Source License
/** * Returns the selected files in the table * @return/*from ww w.ja v a2s .co m*/ */ public File[] getSelectedFiles() { StructuredSelection selection = (StructuredSelection) tviewer.getSelection(); return Arrays.copyOf(selection.toArray(), selection.size(), File[].class); }
From source file:org.eclipse.birt.report.designer.internal.ui.editors.script.JSEditor.java
License:Open Source License
private void setComboViewerInput(Object model) { cmbExprListViewer.setInput(model);/*from w w w . j a v a 2s . c o m*/ Object oldSelection = selectionMap.get(model); if (oldSelection == null) { selectItemInComboExpList(new StructuredSelection()); } else { StructuredSelection selection = (StructuredSelection) oldSelection; selectItemInComboExpList(new StructuredSelection(selection.getFirstElement())); } cmbSubFunctionsViewer.setInput(model); int itemCount = cmbSubFunctions.getItemCount(); if (itemCount > 0) { if (oldSelection instanceof StructuredSelection && ((StructuredSelection) oldSelection).size() > 1) { StructuredSelection selection = (StructuredSelection) oldSelection; cmbSubFunctionsViewer.setSelection(new StructuredSelection(selection.toArray()[1])); } else cmbSubFunctionsViewer.setSelection(new StructuredSelection(cmbSubFunctionsViewer.getElementAt(0))); } cmbSubFunctions.setEnabled(itemCount > 0); return; }