List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:eu.geclipse.traceview.internal.CauseEffectAction.java
License:Open Source License
public void selectionChanged(final IAction action, final ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; this.selectedObj = structuredSelection.getFirstElement(); }/*from ww w . j a v a 2 s . c o m*/ }
From source file:eu.geclipse.ui.dialogs.ConfigureFiltersDialog.java
License:Open Source License
ISelectionChangedListener createTableSelectionListener() { return new ISelectionChangedListener() { private IGridFilterConfiguration selectedConfiguration; public void selectionChanged(final SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection != null) { if (saveFilter()) { this.selectedConfiguration = (IGridFilterConfiguration) selection.getFirstElement(); enableConfiguration(this.selectedConfiguration); for (IFilterComposite filterComposite : ConfigureFiltersDialog.this.composites) { filterComposite.setFilter(this.selectedConfiguration); }/*ww w. j av a 2 s . c o m*/ } else { ConfigureFiltersDialog.this.tableViewer.removeSelectionChangedListener(this); ConfigureFiltersDialog.this.tableViewer.setSelection(this.selectedConfiguration != null ? new StructuredSelection(this.selectedConfiguration) : null); ConfigureFiltersDialog.this.tableViewer.addSelectionChangedListener(this); } } setEnabledComposites(selection != null && !selection.isEmpty()); } }; }
From source file:eu.geclipse.ui.dialogs.ConfigureFiltersDialog.java
License:Open Source License
private void createDeleteButton(final Composite parent) { Button button = createButton(parent, Messages.getString("ConfigureFiltersDialog.delete_button")); //$NON-NLS-1$ button.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) *//* ww w .j a v a2s . c o m*/ @Override public void widgetSelected(final SelectionEvent e) { if (saveFilter()) { StructuredSelection selection = (StructuredSelection) ConfigureFiltersDialog.this.tableViewer .getSelection(); if (selection == null || selection.isEmpty()) { MessageDialog.openWarning(getShell(), Messages.getString("ConfigureFiltersDialog.delete_filter"), //$NON-NLS-1$ Messages.getString("ConfigureFiltersDialog.select_filter")); //$NON-NLS-1$ } else { IGridFilterConfiguration configuration = (IGridFilterConfiguration) selection .getFirstElement(); ConfigureFiltersDialog.this.tableViewer.remove(configuration); ConfigureFiltersDialog.this.configurations.remove(configuration); selectDefaultConfiguration(); } } } }); }
From source file:eu.geclipse.ui.wizards.ConnectionWizard.java
License:Open Source License
private IGridContainer getMountPoint() { IGridContainer result = null;//from w ww.java2 s.c o m if ((this.initialSelection != null) && (this.initialSelection instanceof StructuredSelection)) { StructuredSelection sSelection = (StructuredSelection) this.initialSelection; Object object = sSelection.getFirstElement(); if (object instanceof IGridContainer) { result = (IGridContainer) object; } else if (object instanceof IResource) { IGridElement element = GridModel.getRoot().findElement((IResource) object); if ((element != null) && (element instanceof IGridContainer)) { result = (IGridContainer) element; } } else if (object instanceof IAdaptable) { result = (IGridContainer) ((IAdaptable) object).getAdapter(IGridContainer.class); } } return result; }
From source file:eu.modelwriter.marker.ui.internal.wizards.mappingwizard.RelationsWizardPage.java
License:Open Source License
/** * Create contents of the wizard./* w ww. ja va2 s. c o m*/ * * @param parent */ @Override public void createControl(final Composite parent) { final Composite container = new Composite(parent, SWT.NULL); this.setControl(container); container.setLayout(new FillLayout(SWT.HORIZONTAL)); this.tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION); this.table = this.tableViewer.getTable(); this.tableViewer.setContentProvider(ArrayContentProvider.getInstance()); new RefColumn().addColumnTo(this.tableViewer); this.tableViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(final DoubleClickEvent event) { if (RelationsWizardPage.this.getNextPage() != null) { RelationsWizardPage.this.getContainer().showPage(RelationsWizardPage.this.getNextPage()); } } }); final String rels = MarkerPage.settings.get("rels"); if (rels != null) { try { String markerType = MarkUtilities.getType(this.selectedMarker); final ArrayList<String> suitableRelationTypes = AlloyUtilities .getRelationTypesForFirstSide(markerType); final ArrayList<String> relsList = Serialization.getInstance().fromString(rels); final ArrayList<String> filteredRelations = new ArrayList<String>(); for (final String rel : relsList) { for (final String suitableRel : suitableRelationTypes) { ArrayList<Integer> allParentIds = AlloyUtilities .getAllParentIds(AlloyUtilities.getSigTypeIdByName(markerType)); for (int id : allParentIds) { String sigName = AlloyUtilities.getSigNameById(id); if (rel.substring(0, rel.indexOf(":")).trim().equals(suitableRel) && rel .substring(rel.indexOf(":") + 1, rel.indexOf("->")).trim().equals(sigName)) { filteredRelations.add(rel); } } } } this.tableViewer.setInput(filteredRelations); final TableColumn[] columns = this.tableViewer.getTable().getColumns(); for (int i = 0; i < columns.length; i++) { columns[i].pack(); } } catch (final ClassNotFoundException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } } this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { final StructuredSelection sel = (StructuredSelection) event.getSelection(); RelationsWizardPage.selectedRelation = sel.getFirstElement().toString(); RelationsWizardPage.this.setPageComplete(true); } }); }
From source file:ext.org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb.java
License:Open Source License
private boolean doOpen(ISelection selection) { if (!(selection instanceof StructuredSelection)) return false; StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) return false; return open(structuredSelection.getFirstElement()); }
From source file:ext.org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb.java
License:Open Source License
private boolean doReveal(ISelection selection) { if (!(selection instanceof StructuredSelection)) return false; StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) return false; if (fOldTextSelection != null) { getTextEditor().getSelectionProvider().setSelection(fOldTextSelection); boolean result = reveal(structuredSelection.getFirstElement()); fOldTextSelection = getTextEditor().getSelectionProvider().getSelection(); getTextEditor().getSelectionProvider().setSelection(new StructuredSelection(this)); return result; } else {/*from ww w .j a v a 2s. c om*/ return reveal(structuredSelection.getFirstElement()); } }
From source file:fr.gouv.mindef.safran.database.ui.actions.AbstractScaffoldHandler.java
License:Open Source License
protected void executeFromScaffoldModel(StructuredSelection structuredSelection) { ScaffoldInfo info = ScaffoldingUtils.getScaffoldInfoFromSelection(structuredSelection.getFirstElement()); executeFromScaffoldModel(info);// ww w. j a va 2s . c o m }
From source file:fr.gouv.mindef.safran.database.ui.actions.GenerateSQLFromDatabaseHandler.java
License:Open Source License
private TableContainer getFirstTableContainer(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof IResource) { IResource iResource = (IResource) firstElement; ResourceSet set = new ResourceSetImpl(); URI uri = URI.createPlatformResourceURI(iResource.getFullPath().toString(), true); Resource resource = set.getResource(uri, true); return getFirstTableContainer(resource); } else if (firstElement instanceof Resource) { return getFirstTableContainer((Resource) firstElement); }/* w w w . j a v a 2 s.co m*/ } return null; }
From source file:fr.gouv.mindef.safran.database.ui.actions.testers.TestScaffoldingInput.java
License:Open Source License
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) receiver; if (selection.size() == 1) { Object element = selection.getFirstElement(); if (args != null && args.length >= 1) { String kind = (String) args[0]; if (element instanceof Resource) { Resource resource = (Resource) element; if (ENTITY_TO_LOGICAL_DATABASE.equals(kind)) { return handleEntityToLogicalDatabase(resource); } else if (LOGICAL_DATABASE_TO_ENTITY.equals(kind)) { return handleLogicalDatabaseToEntity(resource); } else if (LOGICAL_DATABASE_TO_PHYSICAL_DATABASE.equals(kind)) { return handleLogicalDatabaseToPhysicalDatabase(resource); } else if (PHYSICAL_DATABASE_TO_LOGICAL_DATABASE.equals(kind)) { return handlePhysicalDatabaseToLogicalDatabase(resource); }//ww w . j a va 2s . c o m } else { URI uri = getModelURI(element); if (uri != null) { if (ENTITY_TO_LOGICAL_DATABASE.equals(kind)) { return handleEntityToLogicalDatabase(uri); } else if (LOGICAL_DATABASE_TO_ENTITY.equals(kind)) { return handleLogicalDatabaseToEntity(uri); } else if (LOGICAL_DATABASE_TO_PHYSICAL_DATABASE.equals(kind)) { return handleLogicalDatabaseToPhysicalDatabase(uri); } else if (PHYSICAL_DATABASE_TO_LOGICAL_DATABASE.equals(kind)) { return handlePhysicalDatabaseToLogicalDatabase(uri); } } } } } } return false; }