List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:msi.gama.core.web.workspace.ui.wizards.AbstractNewResourceWizardPage.java
License:Open Source License
protected void createContainerArea(Composite composite) { Composite result = new Composite(composite, SWT.NONE); result.setLayout(new GridLayout()); Label label = new Label(result, SWT.NONE); label.setText("&Select the parent folder:"); fViewer = createViewer(result);//from w ww .j av a 2 s . c o m GridData data = new GridData(GridData.FILL_BOTH); result.setLayoutData(data); fViewer.getControl().setLayoutData(data); StructuredSelection initialSelection = (StructuredSelection) getInitialElementSelections().get(0); getContainerViewer().setSelection(initialSelection); getContainerViewer().setExpandedElements(new Object[] { initialSelection.getFirstElement() }); getContainerViewer().addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { viewerSelectionChanged(event); } }); }
From source file:name.schedenig.eclipse.grepconsole.view.items.ItemsTreePanel.java
License:Open Source License
/** * Returns the currently selected element. If multiple elements are selected, * the first one is returned.//from w w w . java 2s . com * * @return Element. May be <code>null</code>. */ public AbstractGrepModelElement getSelectedElement() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection.isEmpty()) { return null; } return (AbstractGrepModelElement) selection.getFirstElement(); }
From source file:net.bioclipse.reaction.editor.ReactionEditor.java
License:Open Source License
public Object getAdapter(Class adapter) { if (adapter == ZoomManager.class) return ((ScalableRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager(); System.out.println("getAdapter redi" + adapter); if (IContentOutlinePage.class.equals(adapter)) { if (fOutlinePage == null) { fOutlinePage = new ReactionOutLinePage(this); }/*from w w w . j av a 2s . c o m*/ return fOutlinePage; } if (IChemObject.class.equals(adapter)) { StructuredSelection sele = (StructuredSelection) this.getEditorGraphicalViewer().getSelection(); if (sele.getFirstElement() instanceof CompoundObjectEditPart) { Object model = ((CompoundObjectEditPart) sele.getFirstElement()).getModel(); if (model instanceof CompoundObjectModel) return ((CompoundObjectModel) model).getIMolecule(); } else if (sele.getFirstElement() instanceof ReactionObjectEditPart) { Object model = ((ReactionObjectEditPart) sele.getFirstElement()).getModel(); if (model instanceof ReactionObjectModel) return ((ReactionObjectModel) model).getIReaction(); } } return super.getAdapter(adapter); }
From source file:net.cryptea.view.BuddiesView.java
License:Open Source License
@PostConstruct public void createComposite(Composite parent) { parent.setLayout(new GridLayout(1, false)); tree = new TreeViewer(parent); tree.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tree.setContentProvider(new BuddyContentProvider()); tree.setLabelProvider(new BuddyLabelProvider()); tree.addDoubleClickListener(new IDoubleClickListener() { @Override// w w w. ja v a 2 s . c o m public void doubleClick(DoubleClickEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); BuddyModel bm = (BuddyModel) selection.getFirstElement(); openPart(bm); } }); }
From source file:net.efano.sandbox.jface.snippets.TableViewerColors.java
License:Open Source License
/** * @param args/*from w ww . j av a 2 s.c o m*/ */ public static void main(String[] args) { final List<Person> persons = new ArrayList<Person>(); persons.add(new Person("Fiona Apple", Person.FEMALE)); persons.add(new Person("Elliot Smith", Person.MALE)); persons.add(new Person("Diana Krall", Person.FEMALE)); persons.add(new Person("David Gilmour", Person.MALE)); final Display display = new Display(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { Shell shell = new Shell(display); shell.setText("Gender Bender"); shell.setLayout(new GridLayout()); Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, false); gd_table.heightHint = 352; table.setLayoutData(gd_table); table.setHeaderVisible(true); table.setLinesVisible(true); TableColumn column = new TableColumn(table, SWT.NONE); column.setText("No"); column.setWidth(20); column = new TableColumn(table, SWT.NONE); column.setText("Name"); column.setWidth(100); final TableViewer viewer = new TableViewer(table); IObservableList observableList = Observables.staticObservableList(persons); ObservableListContentProvider contentProvider = new ObservableListContentProvider(); viewer.setContentProvider(contentProvider); // this does not have to correspond to the columns in the table, // we just list all attributes that affect the table content. IObservableSet oset = contentProvider.getKnownElements(); IObservableMap[] attributes = BeansObservables.observeMaps(contentProvider.getKnownElements(), Person.class, new String[] { "name", "gender" }); class ColorLabelProvider extends ObservableMapLabelProvider implements ITableColorProvider { Color male = display.getSystemColor(SWT.COLOR_BLUE); Color female = new Color(display, 255, 192, 203); ColorLabelProvider(IObservableMap[] attributes) { super(attributes); } // to drive home the point that attributes does not have to // match // the columns // in the table, we change the column text as follows: @Override public String getColumnText(Object element, int index) { if (index == 0) { return Integer.toString(persons.indexOf(element) + 1); } return ((Person) element).getName(); } @Override public Color getBackground(Object element, int index) { return null; } @Override public Color getForeground(Object element, int index) { if (index == 0) return null; Person person = (Person) element; return (person.getGender() == Person.MALE) ? male : female; } @Override public void dispose() { super.dispose(); female.dispose(); } } viewer.setLabelProvider(new ColorLabelProvider(attributes)); viewer.setInput(observableList); table.getColumn(0).pack(); Button button = new Button(shell, SWT.PUSH); button.setText("Toggle Gender"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection != null && !selection.isEmpty()) { Person person = (Person) selection.getFirstElement(); person.setGender((person.getGender() == Person.MALE) ? Person.FEMALE : Person.MALE); } } }); shell.setSize(380, 713); Button btnAddRow = new Button(shell, SWT.NONE); btnAddRow.setText("Add Row"); newRowNameText = new Text(shell, SWT.BORDER); newRowNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Composite composite = new Composite(shell, SWT.NONE); composite.setLayout(new FillLayout(SWT.HORIZONTAL)); GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); gd_composite.widthHint = 129; gd_composite.heightHint = 26; composite.setLayoutData(gd_composite); Button maleRadioButton = new Button(composite, SWT.RADIO); maleRadioButton.setText("Male"); Button femaleRadioButton = new Button(composite, SWT.RADIO); femaleRadioButton.setText("Female"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }); display.dispose(); }
From source file:net.enilink.komma.edit.ui.dialogs.FilteredList.java
License:Open Source License
public Control createControl(Composite parent) { composite = new Composite(parent, SWT.NONE); composite.addDisposeListener(new DisposeListener() { @Override/*w w w .j a va2 s . co m*/ public void widgetDisposed(DisposeEvent e) { filterJob.cancel(); refreshCacheJob.cancel(); refreshProgressMessageJob.cancel(); } }); filterHistoryJob = new FilterHistoryJob(); filterJob = new FilterJob(); contentProvider = new ContentProvider(); refreshCacheJob = new RefreshCacheJob(); refreshProgressMessageJob = new RefreshProgressMessageJob(); itemsListSeparator = new ItemsListSeparator(DialogMessages.FilteredItemsSelectionDialog_separatorLabel); selectionMode = NONE; GridLayout gridLayout = new GridLayout(1, false); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; composite.setLayout(gridLayout); createPatternAndMenu(composite); createLabels(composite); list = new TableViewer(composite, (multi ? SWT.MULTI : SWT.SINGLE) | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL); list.setContentProvider(contentProvider); list.setLabelProvider(getItemsListLabelProvider()); list.setInput(new Object[0]); list.setItemCount(contentProvider.getElements(null).length); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); list.getTable().setLayoutData(gd); createPopupMenu(); pattern.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { applyFilter(); } }); pattern.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { if (list.getTable().getItemCount() > 0) { list.getTable().setFocus(); } } } }); list.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); handleSelected(selection); } }); list.getTable().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL) { List<?> selectedElements = ((StructuredSelection) list.getSelection()).toList(); boolean isSelectedHistory = true; for (Object item : selectedElements) { if (item instanceof ItemsListSeparator || !isHistoryElement(item)) { isSelectedHistory = false; break; } } if (isSelectedHistory) removeSelectedItems(selectedElements); } if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) { StructuredSelection selection = (StructuredSelection) list.getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element.equals(list.getElementAt(0))) { pattern.setFocus(); } if (list.getElementAt( list.getTable().getSelectionIndex() - 1) instanceof ItemsListSeparator) list.getTable().setSelection(list.getTable().getSelectionIndex() - 1); list.getTable().notifyListeners(SWT.Selection, new Event()); } } if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) { if (list.getElementAt(list.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) list.getTable().setSelection(list.getTable().getSelectionIndex() + 1); list.getTable().notifyListeners(SWT.Selection, new Event()); } } }); details = new DetailsContentViewer(composite, SWT.BORDER | SWT.FLAT); details.setVisible(toggleStatusLineAction.isChecked()); details.setContentProvider(new NullContentProvider()); details.setLabelProvider(getDetailsLabelProvider()); if (initialPatternText != null) { pattern.setText(initialPatternText); } switch (selectionMode) { case CARET_BEGINNING: pattern.setSelection(0, 0); break; case FULL_SELECTION: pattern.setSelection(0, initialPatternText.length()); break; } // apply filter even if pattern is empty (display history) applyFilter(); pattern.setFocus(); return composite; }
From source file:net.enilink.komma.edit.ui.dialogs.FilteredList.java
License:Open Source License
/** * Refreshes the details field according to the current selection in the * items list./* ww w . j a v a 2 s. com*/ */ private void refreshDetails() { StructuredSelection selection = getSelectedItems(); switch (selection.size()) { case 0: details.setInput(null); break; case 1: details.setInput(selection.getFirstElement()); break; default: details.setInput(NLS.bind(DialogMessages.FilteredItemsSelectionDialog_nItemsSelected, new Integer(selection.size()))); break; } }
From source file:net.geoprism.oda.driver.ui.editors.GeoprismDataSetEditorPage.java
License:Open Source License
private String getValue(ComboViewer viewer) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); LabelValuePair datasetType = (LabelValuePair) selection.getFirstElement(); return datasetType.getValue(); }
From source file:net.jmesnil.jmx.ui.internal.editors.AttributeDetails.java
License:Open Source License
public void selectionChanged(IFormPart part, ISelection selection) { StructuredSelection structured = (StructuredSelection) selection; this.wrapper = (MBeanAttributeInfoWrapper) structured.getFirstElement(); update(wrapper);/*from w w w. java2 s . c o m*/ }
From source file:net.jmesnil.jmx.ui.internal.views.explorer.MBeanExplorer.java
License:Open Source License
@Override public void createPartControl(Composite parent) { makeActions();//from w w w . ja v a 2 s.c o m fillActionBars(); PatternFilter patternFilter = new NodePatternFilter(); patternFilter.setIncludeLeadingWildcard(true); final FilteredTree filter = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter); viewer = filter.getViewer(); contentProvider = new MBeanExplorerContentProvider(); contentProvider.setFlatLayout(currentLayoutIsFlat); viewer.setContentProvider(contentProvider); labelProvider = new MBeanExplorerLabelProvider(); labelProvider.setFlatLayout(currentLayoutIsFlat); viewer.setLabelProvider(labelProvider); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); StructuredSelection structured = (StructuredSelection) selection; Object element = structured.getFirstElement(); IEditorInput editorInput = EditorUtils.getEditorInput(element); if (editorInput != null) { IEditorPart editor = EditorUtils.openMBeanEditor(editorInput); if (editor != null) { EditorUtils.revealInEditor(editor, element); } } else { boolean expanded = viewer.getExpandedState(element); if (expanded) { viewer.collapseToLevel(element, 1); } else { viewer.expandToLevel(element, 1); } } } }); viewer.addPostSelectionChangedListener(postSelectionListener); // workaround for issue #19 (observed on linux/gtk only) viewer.getControl().addListener(SWT.FocusIn, new Listener() { public void handleEvent(Event event) { JMXUIActivator.getActivePage().activate(getSite().getPart()); } }); getViewSite().setSelectionProvider(viewer); }