List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:de.berlios.svgcompost.editor.SVGEditor.java
License:Apache License
public Element getFirstSelectedElement(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection structured = (StructuredSelection) selection; Object selected = structured.getFirstElement(); Element element = null;// w w w . j av a 2s .com if (selected instanceof Element) element = (Element) selected; else if (selected instanceof EditPart) element = (Element) ((EditPart) selected).getModel(); return element; } return null; }
From source file:de.berlios.svgcompost.provider.SVGTreeOutlinePage.java
License:Apache License
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection structured = (StructuredSelection) selection; Object selected = structured.getFirstElement(); Element element = null;/*from ww w. ja v a 2 s .c o m*/ if (selected instanceof EditablePart) element = (Element) ((EditablePart) selected).getModel(); else if (selected instanceof BackgroundPart) element = (Element) ((BackgroundPart) selected).getEditRoot(); if (element != null) setSelection(new StructuredSelection(element)); else setSelection(new StructuredSelection()); } }
From source file:de.jcup.egradle.eclipse.ui.SelectConfigurationDialog2.java
License:Apache License
@Override protected void openSelectionImpl(ISelection selection, String filterText) { if (selection instanceof StructuredSelection) { StructuredSelection ss = (StructuredSelection) selection; Object firstElement = ss.getFirstElement(); if (firstElement != null) { configuration = firstElement.toString(); }//from w w w . j ava 2s.c om } else { configuration = filterText; } }
From source file:de.uka.ilkd.key.casetool.eclipse.ProjectPOAction.java
License:Open Source License
private IJavaProject getSelectedJavaProject() { if (selection != null && selection instanceof StructuredSelection) { final StructuredSelection structuredSelection = (StructuredSelection) selection; Object tmpSelected = structuredSelection.getFirstElement(); if (tmpSelected instanceof IJavaProject) { return (IJavaProject) tmpSelected; }/* ww w .ja v a 2 s .c o m*/ } return null; }
From source file:de.unistuttgart.ipvs.pmp.editor.ui.editors.internals.localetable.LocaleTable.java
License:Apache License
/** * Create the add and remove button//from w ww . java2s .co m * * @param toolkit */ private void createButtons(FormToolkit toolkit) { Composite buttonCompo = toolkit.createComposite(this.outerCompo); buttonCompo.setLayout(new FillLayout(SWT.VERTICAL)); GridData buttonLayout = new GridData(); buttonLayout.verticalAlignment = SWT.BEGINNING; buttonCompo.setLayoutData(buttonLayout); Button addButton = toolkit.createButton(buttonCompo, I18N.general_add, SWT.PUSH); addButton.setToolTipText(I18N.general_add_tooltip); addButton.setImage(Images.IMG_OBJ_ADD); final Button removeButton = toolkit.createButton(buttonCompo, I18N.general_remove, SWT.PUSH); removeButton.setToolTipText(I18N.general_remove_tooltip); removeButton.setEnabled(false); removeButton.setImage(Images.IMG_ETOOL_DELETE); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { LocalizedString ls = new LocalizedString(); switch (LocaleTable.this.type) { case NAME: LocaleTable.this.data.addName(ls); break; case DESCRIPTION: LocaleTable.this.data.addDescription(ls); break; case CHANGE_DESCRIPTION: ((IRGISPrivacySetting) LocaleTable.this.data).addChangeDescription(ls); break; } setDirty(true); refresh(); } }); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection sl = (StructuredSelection) LocaleTable.this.tableViewer.getSelection(); LocalizedString selection = (LocalizedString) sl.getFirstElement(); switch (LocaleTable.this.type) { case NAME: LocaleTable.this.data.removeName(selection); break; case DESCRIPTION: LocaleTable.this.data.removeDescription(selection); break; case CHANGE_DESCRIPTION: ((IRGISPrivacySetting) LocaleTable.this.data).removeChangeDescription(selection); break; } setDirty(true); refresh(); } }); this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { removeButton.setEnabled(!event.getSelection().isEmpty()); } }); }
From source file:de.walware.ecommons.ui.breadcrumb.AbstractBreadcrumb.java
License:Open Source License
private boolean doOpen(final ISelection selection) { if (!(selection instanceof StructuredSelection)) { return false; }//from w w w.j a v a 2s . c o m final StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) { return false; } return open(structuredSelection.getFirstElement()); }
From source file:de.walware.ecommons.ui.breadcrumb.AbstractBreadcrumb.java
License:Open Source License
private boolean doReveal(final ISelection selection) { if (!(selection instanceof StructuredSelection)) { return false; }/* ww w. j av a 2 s . c o m*/ final StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) { return false; } return reveal(structuredSelection.getFirstElement()); }
From source file:edu.duke.submit.internal.eclipse.SubmitWindow.java
License:Open Source License
private void createFileTreeGroup() { mySashForm = new SashForm(Form, SWT.HORIZONTAL | SWT.NULL); myTreeViewer = new CheckboxTreeViewer(mySashForm); myProvider = new FileTreeContentProvider(); myTreeViewer.setContentProvider(myProvider); IWorkspaceRoot workRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject[] projects = workRoot.getProjects(); myRoot = null;//from www . ja va 2s . co m if (projects != null && projects.length != 0) { try { for (int i = 0; i < projects.length; i++) { IPath path = projects[0].getDescription().getLocation(); if (path != null) { path = path.makeAbsolute(); myRoot = path.toFile(); break; } } } catch (CoreException e) { System.out.println("invalid project path"); } } if (myRoot == null) { myRoot = new File(System.getProperty("user.dir")); } myTreeViewer.setInput(myRoot); myTreeViewer.setLabelProvider(new FileTreeLabelProvider()); myTreeViewer.setSorter(new FileTreeSorter()); myTreeViewer.addCheckStateListener(this); myTreeViewer.expandToLevel(myRoot, 1); myTreeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { StructuredSelection i = (StructuredSelection) event.getSelection(); File root = (File) i.getFirstElement(); if (root.isDirectory()) { mySelectedList.removeAll(); Object[] children = myProvider.getChildren(root); ArrayList checked = new ArrayList(); addCheckedChildren(children, checked); myRootText.setText(((File) i.getFirstElement()).toString()); int size = checked.size(); int pos = myRoot.toString().length() + 1; for (int j = 0; j < size; j++) { myTreeViewer.setExpandedState(((File) checked.get(j)), true); myTreeViewer.setChecked(((File) checked.get(j)), true); mySelectedList.add(((File) checked.get(j)).toString().substring(pos)); } if (size > 0) { mySubmitButton.setEnabled(true); } } } }); myScroller = new ScrolledComposite(mySashForm, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); myScroller.setLayout(new GridLayout(1, false)); myScroller.setExpandHorizontal(true); myScroller.setExpandVertical(true); mySelectedList = new List(myScroller, SWT.NONE); mySelectedList.setSize(mySelectedList.computeSize(SWT.DEFAULT, SWT.DEFAULT)); myScroller.setContent(mySelectedList); myScroller.setMinSize(mySelectedList.computeSize(SWT.DEFAULT, SWT.DEFAULT)); }
From source file:edu.tum.in.bruegge.epd.emfstore.dialog.LoginDialog.java
License:Open Source License
private boolean loadSessionFromSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; Usersession session = null;/*from w w w. j a va2 s . c om*/ if (structuredSelection.getFirstElement() instanceof Usersession) { session = (Usersession) structuredSelection.getFirstElement(); loadSession(session); return true; } } return false; }
From source file:edu.uchicago.cs.hao.texdojo.bibeditor.editors.EditorUI.java
License:Open Source License
public BibEntry selected() { StructuredSelection sel = (StructuredSelection) table.getSelection(); if (sel.isEmpty()) return null; return (BibEntry) sel.getFirstElement(); }