List of usage examples for org.eclipse.jface.viewers StructuredSelection toArray
@Override
public Object[] toArray()
From source file:org.eclipse.dirigible.ide.extensions.ui.view.ExtensionsManagerView.java
License:Open Source License
private void makeActions() { actionRemove = new Action() { /**/* w ww .j a va2s .com*/ * */ private static final long serialVersionUID = 1336014167502247774L; @Override public void run() { if (!viewer.getSelection().isEmpty()) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); Object[] selectedElements = selection.toArray(); if (MessageDialog.openConfirm(viewer.getControl().getShell(), Messages.ExtensionsManagerView_DELETE_EXTENSIONS_TITLE, Messages.ExtensionsManagerView_DELETE_EXTENSIONS_DIALOG_DESCRIPTION)) { String extensionToDelete = ""; //$NON-NLS-1$ try { for (Object element : selectedElements) { SimpleTreeNode simpleTreeNode = (SimpleTreeNode) element; extensionToDelete = simpleTreeNode.getName(); if (simpleTreeNode.isRootElement()) { extensionManager.removeExtensionPoint(simpleTreeNode.getName()); } else { extensionManager.removeExtension(simpleTreeNode.getName(), simpleTreeNode.getParent().getName()); } } } catch (EExtensionException e) { MessageDialog.openError(viewer.getControl().getShell(), Messages.ExtensionsManagerView_FAILED_TO_DELETE_EXTENSION + extensionToDelete, e.getMessage()); } finally { viewer.refresh(); } } } } }; actionRemove.setText(Messages.ExtensionsManagerView_DELETE_LABEL); actionRemove.setToolTipText(Messages.ExtensionsManagerView_DELETE_ACTION_TOOL_TIP); actionRemove.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE)); actionRefresh = new Action() { /** * */ private static final long serialVersionUID = 506492927597193506L; @Override public void run() { viewer.refresh(); } }; actionRefresh.setText(Messages.ExtensionsManagerView_REFRESH_LABEL); actionRefresh.setToolTipText(Messages.ExtensionsManagerView_REFRESH_ACTION_TOOLTIP); actionRefresh.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED)); }
From source file:org.eclipse.e4.demo.e4photo.Library.java
License:Open Source License
@Inject public Library(Composite parent, final IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.workspace = workspace; initializeWorkspace();//w w w . ja va 2 s.co m viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer.getTree().setData("org.eclipse.e4.ui.css.id", "library"); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService .setSelection(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()); // Button button = new Button(parent, SWT.PUSH); // button.setText("Create Project"); // button.addSelectionListener(new SelectionListener() { // public void widgetSelected(SelectionEvent e) { // String projectName = "Project" + (counter++); // final IProject project = workspace.getRoot().getProject( // projectName); // final IProjectDescription pd = workspace // .newProjectDescription(projectName); // try { // workspace.run(new IWorkspaceRunnable() { // public void run(IProgressMonitor monitor) // throws CoreException { // project.create(pd, monitor); // project.open(monitor); // } // }, new NullProgressMonitor()); // } catch (CoreException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // } // // public void widgetDefaultSelected(SelectionEvent e) { // } // }); GridLayoutFactory.fillDefaults().generateLayout(parent); }
From source file:org.eclipse.e4.demo.simpleide.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/* w w w .j av a2s .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) { MSimpleIDEApplication app = (MSimpleIDEApplication) application; 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 (MEditorPartDescriptor desc : app.getEditorPartDescriptors()) { for (String ext : desc.getFileextensions()) { if (ext.equals(fExt)) { context.set(MEditorPartDescriptor.class, desc); System.err.println("Opening with: " + desc); Command cmd = commandService.getCommand("simpleide.command.openeditor"); ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null); handlerService.executeHandler(pCmd); break EDITOR; } } } } } } }); setupContextMenu(viewer, parent.getShell()); workspace.addResourceChangeListener(listener); }
From source file:org.eclipse.emf.refactor.refactoring.runtime.ui.ApplicationMenu.java
License:Open Source License
/** * Returns a list of relevant objects from the given selection. * @param selection Origin selection in the workbench. * @return List of relevant objects from the given selection. *///from www .ja va 2 s . com @SuppressWarnings("rawtypes") private Object[] getSelection(ISelection selection) { if (null != selection && selection instanceof StructuredSelection) { StructuredSelection ss = (StructuredSelection) selection; if (null == ss.getFirstElement()) { return ss.toArray(); } List<Object> list = new ArrayList<Object>(); final Iterator i = ss.iterator(); while (i.hasNext()) { final Object selectedEObject = i.next(); final Class cl = selectedEObject.getClass(); //Usual EMF-Tree: boolean added = checkEMFTree(list, selectedEObject); if (!added) { added = checkGmf(list, selectedEObject, cl); } } return list.toArray(); } return new Object[0]; }
From source file:org.eclipse.epf.authoring.ui.wizards.SynchronizationSelectConfigPage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *//*from ww w . j a v a2s. c o m*/ public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object[] config = selection.toArray(); syncChoices.setSelectedConfig((MethodConfiguration) config[0]); } // System.out.println("$$$ config =" + syncChoices.toString()); }
From source file:org.eclipse.epf.export.wizards.ExportConfigSelectConfigPage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *//*from w w w . j a va 2s.com*/ public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object[] configs = selection.toArray(); setDisplayAttributes((MethodConfiguration) configs[0]); } }
From source file:org.eclipse.epf.export.wizards.ExportConfigSelectSpecsPage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *//*from www . j a v a2 s.c o m*/ public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object[] configs = selection.toArray(); setDisplayAttributes((MethodConfiguration) configs[0]); } }
From source file:org.eclipse.epf.export.wizards.PluginInfoPage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *//*from ww w . jav a 2s . c o m*/ public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object[] plugin = selection.toArray(); displayRelatedInfo((MethodPlugin) plugin[0]); } }
From source file:org.eclipse.epf.export.wizards.SelectPluginPage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */// www . j ava 2 s . c om public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object[] plugin = selection.toArray(); setDisplayAttributes((MethodPlugin) plugin[0]); } }
From source file:org.eclipse.epf.importing.wizards.SelectConfigSpecsToImportPage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *///from w w w . jav a 2 s.co m public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object[] configs = selection.toArray(); setDisplayAttributes((ConfigSpecs.Entry) configs[0]); } else { clearDisplayAttributes(); } }