List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:au.gov.ga.earthsci.layer.ui.LayerTreePart.java
License:Apache License
@Inject private void select(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) ILayerTreeNode[] nodes) { if (nodes == null || structureViewer == null || settingSelection) { return;//from w w w. j av a 2 s . com } StructuredSelection selection = new StructuredSelection(nodes); structureViewer.setSelection(selection, true); for (ILayerTreeNode node : nodes) { structureViewer.expandToLevel(node, 1); } tabFolder.setSelection(structureTabItem); }
From source file:automaticexperiment.presentation.AutomaticexperimentEditor.java
License:Open Source License
/** * This is the method used by the framework to install your own controls. * <!-- begin-user-doc -->/*from www . j a v a2s. c om*/ * <!-- end-user-doc --> * @generated NOT */ @Override public void createPages() { // Creates the model from the editor input // createModel(); // Only creates the other pages if there is something that can be edited // if (!getEditingDomain().getResourceSet().getResources().isEmpty()) { // Create a page for the selection tree view. // Tree tree = new Tree(getContainer(), SWT.MULTI); selectionViewer = new TreeViewer(tree); setCurrentViewer(selectionViewer); selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); // selectionViewer.setInput(editingDomain.getResourceSet()); selectionViewer.setInput(editingDomain.getResourceSet().getResources().get(0)); selectionViewer.setSelection( new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true); new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory); createContextMenuFor(selectionViewer); int pageIndex = addPage(tree); setPageText(pageIndex, getString("_UI_SelectionPage_label")); getSite().getShell().getDisplay().asyncExec(new Runnable() { public void run() { setActivePage(0); } }); } // Ensures that this editor will only display the page's tab // area if there are more than one page // getContainer().addControlListener(new ControlAdapter() { boolean guard = false; @Override public void controlResized(ControlEvent event) { if (!guard) { guard = true; hideTabs(); guard = false; } } }); getSite().getShell().getDisplay().asyncExec(new Runnable() { public void run() { updateProblemIndication(); } }); }
From source file:automaticexperiment.presentation.AutomaticexperimentEditor.java
License:Open Source License
/** * This deals with how we want selection in the outliner to affect the other views. * <!-- begin-user-doc -->/* w ww . j a va 2s. c o m*/ * <!-- end-user-doc --> * @generated */ public void handleContentOutlineSelection(ISelection selection) { if (selectionViewer != null && !selection.isEmpty() && selection instanceof IStructuredSelection) { Iterator<?> selectedElements = ((IStructuredSelection) selection).iterator(); if (selectedElements.hasNext()) { // Get the first selected element. // Object selectedElement = selectedElements.next(); ArrayList<Object> selectionList = new ArrayList<Object>(); selectionList.add(selectedElement); while (selectedElements.hasNext()) { selectionList.add(selectedElements.next()); } // Set the selection to the widget. // selectionViewer.setSelection(new StructuredSelection(selectionList)); } } }
From source file:automaticexperiment.presentation.AutomaticexperimentModelWizard.java
License:Open Source License
/** * Do the work after everything is specified. * <!-- begin-user-doc -->/*from www.j av a2s .c o m*/ * <!-- end-user-doc --> * @generated */ @Override public boolean performFinish() { try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { AutomaticexperienceEditPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell().getDisplay().asyncExec(new Runnable() { public void run() { ((ISetSelectionTarget) activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); } catch (PartInitException exception) { MessageDialog.openError(workbenchWindow.getShell(), AutomaticexperienceEditPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); return false; } return true; } catch (Exception exception) { AutomaticexperienceEditPlugin.INSTANCE.log(exception); return false; } }
From source file:bndtools.editor.components.ComponentListPart.java
License:Open Source License
void createSection(Section section, FormToolkit toolkit) { section.setText(Messages.ComponentListPart_listSectionTitle); Composite composite = toolkit.createComposite(section); section.setClient(composite);//from w w w . ja v a 2s.co m table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); viewer = new TableViewer(table); viewer.setUseHashlookup(true); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new ServiceComponentLabelProvider()); final Button btnAdd = toolkit.createButton(composite, Messages.ComponentListPart_addButton, SWT.PUSH); final Button btnRemove = toolkit.createButton(composite, Messages.ComponentListPart_RemoveButton, SWT.PUSH); toolkit.paintBordersFor(section); // Listeners viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); ArrayList<ServiceComponent> selectedComponents = new ArrayList<ServiceComponent>(selection.size()); @SuppressWarnings("rawtypes") Iterator iterator = selection.iterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); ServiceComponent component = componentMap.get(name); if (component != null) selectedComponents.add(component); } managedForm.fireSelectionChanged(ComponentListPart.this, new StructuredSelection(selectedComponents)); btnRemove.setEnabled(!selection.isEmpty()); } }); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement(); if (name != null) { doOpenComponent(name); } } }); viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new ComponentListDropAdapter(viewer)); btnAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { doAdd(); } catch (Exception x) { Plugin.logError("Error adding component", x); } } }); btnRemove.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doRemove(); } }); // Layout GridData gd; section.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout(2, false)); gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3); gd.widthHint = 250; table.setLayoutData(gd); btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); }
From source file:bndtools.editor.components.ComponentListPart.java
License:Open Source License
void doAdd() throws Exception { String name;// w w w. j a v a 2 s . c om ServiceComponent component; int i = 0; while (true) { if (i == 0) name = ""; //$NON-NLS-1$ else name = String.format("%d", i); //$NON-NLS-1$ if (!componentMap.containsKey(name)) { component = new ServiceComponent(name, new Attrs()); componentMap.put(name, component); componentNames.add(name); break; } if (i > 100) throw new Exception("Unable to find a free component name after 100 tries!"); } viewer.add(name); viewer.setSelection(new StructuredSelection(name), true); checkComponentPackagesIncluded(); markDirty(); }
From source file:bndtools.editor.components.ComponentListPart.java
License:Open Source License
void setSelectedComponent(ServiceComponent component) { viewer.setSelection(new StructuredSelection(component.getName())); }
From source file:bndtools.editor.contents.PrivatePackagesPart.java
License:Open Source License
void createSection(Section section, FormToolkit toolkit) { section.setText("Private Packages"); section.setDescription("The listed packages will be included in the bundle but not exported."); ToolBar toolbar = new ToolBar(section, SWT.FLAT); section.setTextClient(toolbar);/* w w w . j av a 2 s . co m*/ final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH); addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD)); addItem.setToolTipText("Add"); final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH); removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE)); removeItem.setDisabledImage( PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED)); removeItem.setToolTipText("Remove"); removeItem.setEnabled(false); Composite composite = toolkit.createComposite(section); section.setClient(composite); table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER); viewer = new TableViewer(table); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new PrivatePackageTableLabelProvider()); // Listeners viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { managedForm.fireSelectionChanged(PrivatePackagesPart.this, event.getSelection()); removeItem.setEnabled(!viewer.getSelection().isEmpty()); } }); viewer.addDropSupport( DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance(), ResourceTransfer.getInstance() }, new PackageDropAdapter<String>(viewer) { @Override protected String createNewEntry(String packageName) { return packageName; } @Override protected void addRows(int index, Collection<String> rows) { if (rows.isEmpty()) return; // skip marking dirty if (index == -1) { packages.addAll(rows); viewer.add(rows.toArray()); } else { packages.addAll(index, rows); viewer.refresh(); } viewer.setSelection(new StructuredSelection(rows)); markDirty(); } @Override protected int indexOf(Object object) { return 0; } }); table.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.character == SWT.DEL) { doRemovePackages(); } else if (e.character == '+') { doAddPackages(); } } }); addItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doAddPackages(); } }); removeItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doRemovePackages(); } }); // Layout GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); GridData gd; gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = 75; gd.widthHint = 75; table.setLayoutData(gd); }
From source file:bndtools.editor.pages.BundleContentPage.java
License:Open Source License
public void setSelectedExport(ExportedPackage export) { exportPatternListPart.getSelectionProvider().setSelection(new StructuredSelection(export)); }
From source file:bndtools.editor.pages.BundleContentPage.java
License:Open Source License
public void setSelectedPrivatePkg(String pkg) { privPkgsPart.getSelectionProvider().setSelection(new StructuredSelection(pkg)); }