List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:gitLink.GLinkTreeViewer.java
License:Open Source License
private IAction newUnstageAction() { final Action n = new Action() { @Override//w w w. ja v a 2s . c o m public void run() { try { final ISelection sel = view.viewer.getSelection(); if (sel instanceof StructuredSelection) { final StructuredSelection ss = (StructuredSelection) sel; final GLinkNode item = (GLinkNode) ss.getFirstElement(); GLinkNode node = item; while (!(node instanceof GLinkRepositoryNode)) node = node.parent(); final GLinkRepositoryNode repo = (GLinkRepositoryNode) node; final File file = repo.file(); final ProcessBuilder builder = new ProcessBuilder("git", "reset", item.text()); builder.directory(file); builder.start(); doRefreshAction(); } } catch (final Exception e) { throw new RuntimeException(e); } } }; n.setText("Unstage"); n.setImageDescriptor(GLinkPlugin.id_gitLink); return n; }
From source file:gov.redhawk.eclipsecorba.library.ui.IdlInterfaceSelectionDialog.java
License:Open Source License
/** * Handle a selection change in the viewer. Ensures that the correct number of items * of the correct type are selected./* w w w . j av a 2 s . c o m*/ */ protected void handleSelected(StructuredSelection selection) { IStatus s = new Status(IStatus.OK, LibraryUIPlugin.PLUGIN_ID, IStatus.OK, "", null); // You can only select one item and it must be an interface if (selection.size() != 1) { s = new Status(IStatus.ERROR, LibraryUIPlugin.PLUGIN_ID, IStatus.ERROR, "", null); } else { if (!(selection.getFirstElement() instanceof IdlInterfaceDcl)) { s = new Status(IStatus.ERROR, LibraryUIPlugin.PLUGIN_ID, IStatus.ERROR, "", null); } } updateStatus(s); }
From source file:gov.redhawk.explorer.wizard.SelectDomainPage.java
License:Open Source License
@Override public void createControl(final Composite parent) { final Composite container = new Composite(parent, SWT.NULL); final GridLayout layout = new GridLayout(3, false); container.setLayout(layout);// ww w. ja va 2 s . c om this.patternFilter = new MyPatternFilter(); this.domainList = new FormFilteredTree(container, SWT.SINGLE | SWT.V_SCROLL, this.patternFilter); this.domainList.setBackground(container.getBackground()); this.domainList.setLayoutData( GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(2, 1).create()); this.domainList.getViewer().setContentProvider(new AdapterFactoryContentProvider(getAdapterFactory())); this.domainList.getViewer().setLabelProvider(new AdapterFactoryLabelProvider(getAdapterFactory()) { @Override public String getText(final Object object) { String text = super.getText(object); if (object instanceof ScaDomainManager) { text += " (" + ((ScaDomainManager) object).getState().getLiteral().toUpperCase() + ")"; } return text; } }); this.domainList.getViewer().setFilters(createDomainViewerFilter()); this.domainList.getViewer().setInput(ScaPlugin.getDefault().getDomainManagerRegistry()); this.domainList.getViewer().addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { boolean domainSelected = false; boolean appsRunning = false; final StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty() && selection.getFirstElement() instanceof ScaDomainManager) { if (connect(selection)) { domainSelected = true; try { appsRunning = SelectDomainPage.this.mgr.applications().length > 0; } catch (final Exception e) { // PASS - You can connect to a domain that isn't up but is in the NameService } } } SelectDomainPage.this.setPageComplete(domainSelected); SelectDomainPage.this.parent.appsRunning(appsRunning); } }); final Composite buttonBox = new Composite(container, SWT.NULL); buttonBox.setLayoutData( GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.FILL).grab(false, true).create()); final GridLayout l = new GridLayout(); l.marginWidth = 0; buttonBox.setLayout(l); final Button newButton = new Button(buttonBox, SWT.PUSH); newButton.setText(" New... "); newButton.setLayoutData(GridDataFactory.fillDefaults().create()); newButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { widgetSelected(e); } @Override public void widgetSelected(final SelectionEvent e) { final ScaDomainManagerRegistry registry = ScaPlugin.getDefault().getDomainManagerRegistry(); final DomainEntryWizard wizard = new DomainEntryWizard(); wizard.setShowExtraSettings(false); wizard.setRegistry(registry); wizard.setWindowTitle("Add Domain Manager"); final WizardDialog dialog = new WizardDialog(getShell(), wizard); if (dialog.open() == IStatus.OK) { final Map<String, String> connectionProperties = Collections .singletonMap(ScaDomainManager.NAMING_SERVICE_PROP, wizard.getNameServiceInitRef()); ScaModelCommand.execute(registry, new ScaModelCommand() { @Override public void execute() { registry.createDomain(wizard.getDomainName(), false, connectionProperties); } }); } } }); setControl(container); }
From source file:gov.redhawk.explorer.wizard.SelectDomainPage.java
License:Open Source License
public boolean connect(final StructuredSelection selection) { final IStatus[] status = new IStatus[1]; status[0] = null;//from ww w . jav a2s . co m this.mgr = (ScaDomainManager) selection.getFirstElement(); try { getContainer().run(true, true, new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Connecting to the domain", 2); try { if (SelectDomainPage.this.mgr.getState() .getValue() != DomainConnectionState.CONNECTED_VALUE) { SelectDomainPage.this.mgr.connect(new NullProgressMonitor(), RefreshDepth.CHILDREN); } } catch (final DomainConnectionException e) { status[0] = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to connect to Domain: " + SelectDomainPage.this.mgr.getName()); } monitor.worked(1); monitor.done(); } }); } catch (final InvocationTargetException e) { status[0] = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to connect to Domain: " + this.mgr.getName()); } catch (final InterruptedException e) { status[0] = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to connect to Domain: " + this.mgr.getName()); } if (status[0] != null) { setErrorMessage("Unable to connect to Domain: " + this.mgr.getName()); this.domainList.getViewer().setSelection(new StructuredSelection()); StatusManager.getManager().handle(status[0]); } else { setErrorMessage(null); if (this.mgr.getState().getValue() == DomainConnectionState.CONNECTED_VALUE) { setPageComplete(true); getContainer().updateButtons(); } } this.domainList.getViewer().refresh(); return (status[0] == null); }
From source file:gov.redhawk.frontend.ui.internal.section.FrontendSection.java
License:Open Source License
@Override public void setInput(IWorkbenchPart part, ISelection selection) { super.setInput(part, selection); inputPart = part;/*from ww w .j a va2s .co m*/ if (page == null) { return; } if (selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; if (sel.getFirstElement() instanceof EObject) { theInput = (EObject) sel.getFirstElement(); viewer.getViewer().setInput(theInput); if (theInput instanceof TunerStatus) { viewer.setTuner((TunerStatus) theInput); } } else { theInput = null; viewer.getViewer().setInput(null); viewer.setTuner(null); } showRightToolbarButtons(theInput); } }
From source file:gov.redhawk.ide.dcd.ui.wizard.ScaNodeProjectDevicesWizardPage.java
License:Open Source License
/** * {@inheritDoc}//from w ww. j ava2 s . c om */ @Override public void createControl(final Composite parent) { // The top-level composite for this page final Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); // Top Heading final Label directionsLabel = new Label(composite, SWT.NONE); directionsLabel.setText("Check the boxes next to the devices to include in this node:"); GridDataFactory.generate(directionsLabel, 2, 1); this.tableViewer = new CheckboxTableViewer(new Table(composite, SWT.CHECK | SWT.BORDER)); this.tableViewer.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1)); final ComposedAdapterFactory factory = new ComposedAdapterFactory(); factory.addAdapterFactory(new SpdItemProviderAdapterFactory()); this.tableViewer.setContentProvider(new ArrayContentProvider()); this.tableViewer.setLabelProvider(new DecoratingLabelProvider(new AdapterFactoryLabelProvider(factory), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()) { @Override public String getText(final Object element) { if (element instanceof SoftPkgImpl) { final SoftPkgImpl softPkg = (SoftPkgImpl) element; final URI uri = softPkg.eResource().getURI(); return softPkg.getName() + " (" + uri.path().replace(uri.lastSegment(), "") + ")"; } return ""; } }); this.tableViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(final DoubleClickEvent event) { final StructuredSelection ss = (StructuredSelection) event.getSelection(); final SoftPkg selected = (SoftPkg) ss.getFirstElement(); ScaNodeProjectDevicesWizardPage.this.tableViewer.setChecked(selected, !ScaNodeProjectDevicesWizardPage.this.tableViewer.getChecked(selected)); } }); this.tableViewer.setInput(this.devices); this.tableViewer.setCheckedElements(Collections.EMPTY_LIST.toArray()); setControl(composite); }
From source file:gov.redhawk.ide.idl.ui.wizard.ScaIDLProjectPropertiesWizardPage.java
License:Open Source License
/** * Method that removes all selected idl file(s) from the table */// ww w . j a va 2s .c om private void removeButtonPressed() { if (this.idlTableViewer.getSelection() != null) { final StructuredSelection ss = (StructuredSelection) this.idlTableViewer.getSelection(); this.idlFiles.remove(ss.getFirstElement()); this.idlTableViewer.refresh(); } }
From source file:gr.osmosis.rcpsamples.contact.View.java
License:Open Source License
public Contact getSelection() { StructuredSelection sel = (StructuredSelection) this.viewer.getSelection(); if (sel.getFirstElement() == null) { return null; }/*w w w. ja v a 2s .c o m*/ if (sel.getFirstElement() instanceof Contact) { return (Contact) sel.getFirstElement(); } else { return null; } }
From source file:hydrograph.ui.graph.editor.ComponentsEditorContextMenuProvider.java
License:Apache License
@Override protected void doItemFill(IContributionItem ci, int index) { StructuredSelection s = (StructuredSelection) SubJobUtility.getCurrentEditor().getViewer().getSelection(); if (s.getFirstElement() instanceof ComponentEditPart && (StringUtils.equalsIgnoreCase(ci.getId(), team) || StringUtils.equalsIgnoreCase(ci.getId(), replaceWith) || StringUtils.equalsIgnoreCase(ci.getId(), separator))) { return;//from ww w. j a v a2 s . c om } if ((StringUtils.equalsIgnoreCase(ci.getId(), runAs) || StringUtils.equalsIgnoreCase(ci.getId(), debugAs) || StringUtils.equalsIgnoreCase(ci.getId(), compareWith) || StringUtils.equalsIgnoreCase(ci.getId(), validate))) { return; } super.doItemFill(ci, index); }
From source file:hydrograph.ui.graph.editor.ELTGraphicalEditor.java
License:Apache License
public ISelectionChangedListener createISelectionChangedListener() { return new ISelectionChangedListener() { @Override//from w w w . j a v a2s. co m public void selectionChanged(SelectionChangedEvent event) { StructuredSelection sSelection = (StructuredSelection) event.getSelection(); AbstractGraphicalEditPart selectedEditPart = (AbstractGraphicalEditPart) sSelection .getFirstElement(); defaultComponentLocation.setLocation(selectedEditPart.getFigure().getBounds().x, selectedEditPart.getFigure().getBounds().y); } }; }