List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:fr.ifpen.emptooling.reverse.ui.handlers.ReverseToEcoreHandler.java
License:Open Source License
/** * the command has been executed, so extract extract the needed information * from the application context.// www . java 2 s . c o m */ public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); Shell activeShell = HandlerUtil.getActiveShell(event); StructuredSelection sSelection = (StructuredSelection) window.getSelectionService().getSelection(); if (!sSelection.isEmpty()) { Object selection = sSelection.getFirstElement(); if (selection instanceof IJavaProject) { javaProject = (IJavaProject) selection; if (javaPackages.isEmpty()) { try { for (IPackageFragment pf : javaProject.getPackageFragments()) { if (pf.getKind() == IPackageFragmentRoot.K_SOURCE && pf.hasChildren()) { javaPackages.add(pf); } } } catch (JavaModelException e) { e.printStackTrace(); } } } else { if (selection instanceof IPackageFragment && ((IPackageFragment) selection).getElementType() == IJavaElement.PACKAGE_FRAGMENT) { this.javaPackages.add((IPackageFragment) selection); this.javaProject = ((IPackageFragment) selection).getJavaProject(); } } ReverseToEcoreWizard wizard = new ReverseToEcoreWizard(); WizardDialog dialog = new WizardDialog(activeShell, wizard); wizard.setWindowTitle("Reverse configuration"); if (dialog.open() == Window.OK) { final ReverseSettings reverseSettings = new ReverseSettings(); reverseSettings.rootNsPrefix = wizard.getBaseNSPrefix(); reverseSettings.rootNsURI = wizard.getBaseURI(); reverseSettings.rootPackageName = javaProject.getElementName(); final IContainer target = wizard.getTargetContainer(); IRunnableWithProgress operation = new ReverseToEcoreRunnable(javaProject, javaPackages, reverseSettings, target); try { PlatformUI.getWorkbench().getProgressService().run(true, true, operation); } catch (InvocationTargetException e) { IStatus status = new Status(IStatus.ERROR, ReverseUIPlugin.PLUGIN_ID, e.getMessage(), e); ReverseUIPlugin.getPlugin().getLog().log(status); } catch (InterruptedException e) { IStatus status = new Status(IStatus.ERROR, ReverseUIPlugin.PLUGIN_ID, e.getMessage(), e); ReverseUIPlugin.getPlugin().getLog().log(status); } } } return null; }
From source file:fr.inria.atlanmod.emfviews.ui.linkingviewprordelegate.ProrDelegate.java
License:Open Source License
@Override public EObject getSelectedElement() { EObject selectedEobject = null;//from ww w .jav a 2s . co m IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor(); if (activeEditor instanceof SpecificationEditor) { SpecificationEditor specificationEditor = (SpecificationEditor) activeEditor; ISelection currentSelection = specificationEditor.getSelection(); if (!currentSelection.isEmpty()) { currentSelection.getClass(); if (currentSelection instanceof StructuredSelection) { SpecObject selectedElement = null; StructuredSelection structuredSelection = (StructuredSelection) currentSelection; Object selectedElementTemp = structuredSelection.getFirstElement(); if (selectedElementTemp instanceof SpecHierarchyImpl) { SpecHierarchyImpl specHierarchy = (SpecHierarchyImpl) selectedElementTemp; selectedElement = specHierarchy.getObject(); selectedEobject = (EObject) selectedElement; } } } } return selectedEobject; }
From source file:fr.inria.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader.java
License:Open Source License
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); if ((sel != null) && (sel instanceof StructuredSelection)) { StructuredSelection stSel = (StructuredSelection) sel; if (stSel.getFirstElement() instanceof TmfSyncMessage) { TmfSyncMessage syncMsg = ((TmfSyncMessage) stSel.getFirstElement()); broadcast(new TmfTimeSynchSignal(this, syncMsg.getStartTime())); }// w w w .jav a2 s. c o m } }
From source file:fr.liglab.adele.cilia.workbench.common.ui.view.graphview.GraphView.java
License:Apache License
public Object getFirstSelectedElement() { // ISelection sel = // getSite().getWorkbenchWindow().getSelectionService().getSelection(); ISelection sel = viewer.getSelection(); if (sel != null && sel instanceof StructuredSelection) { StructuredSelection ss = (StructuredSelection) sel; return ss.getFirstElement(); }//from w w w. j av a2 s .c om return null; }
From source file:fr.liglab.adele.cilia.workbench.restmonitoring.view.platformview.PlatformView.java
License:Apache License
@Override public void selectionChanged(String partId, ISelection selection) { if (selection != null && selection instanceof StructuredSelection) { StructuredSelection ss = (StructuredSelection) selection; Object elm = ss.getFirstElement(); // A Platform chain has been selected... if (elm != null && elm instanceof PlatformChain) { PlatformChain pc = (PlatformChain) elm; try { PlatformRepoService.getInstance().updateChain(pc.getPlatform(), pc.getName()); } catch (Exception e) { e.printStackTrace();//from w w w .j a v a2 s .c om } } } }
From source file:fr.liglab.adele.cilia.workbench.restmonitoring.view.runningchainview.RunningChainView.java
License:Apache License
private static ComponentRef getComponentRefFromSelection(ISelection selection) { if (selection != null && selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; Object element = sel.getFirstElement(); if (element != null && element instanceof ComponentRef) { return (ComponentRef) element; }//from w w w. j a v a 2 s.co m } return null; }
From source file:gitLink.GLinkTreeViewer.java
License:Open Source License
private IAction newDiscardAction() { final Action n = new Action() { @Override/*from w w w . j a v a 2 s. co 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", "checkout", "--", item.text()); builder.directory(file); builder.start(); doRefreshAction(); } } catch (final Exception e) { throw new RuntimeException(e); } } }; n.setText("Discard"); n.setImageDescriptor(GLinkPlugin.id_gitLink); return n; }
From source file:gitLink.GLinkTreeViewer.java
License:Open Source License
/** * @return Action to launch GITK//ww w .ja v a2s . c o m */ private IAction newHistoryAction() { final Action n = new Action() { @Override public void run() { try { final ISelection sel = view.viewer.getSelection(); final ProcessBuilder builder = new ProcessBuilder("gitk"); final StructuredSelection ss = (StructuredSelection) sel; final GLinkRepositoryNode item = (GLinkRepositoryNode) ss.getFirstElement(); final File file = item.file(); builder.directory(file); builder.start(); } catch (final Exception e) { throw new RuntimeException(e); } } }; n.setText("Show history using \"gitk\""); n.setImageDescriptor(GLinkPlugin.id_gitLink); return n; }
From source file:gitLink.GLinkTreeViewer.java
License:Open Source License
/** * @return Action to open git gui/*from ww w.j av a 2 s .c o m*/ */ private Action newOpenAction() { final Action n = new Action() { @Override public void run() { try { final ISelection sel = view.viewer.getSelection(); final ProcessBuilder builder = new ProcessBuilder("git", "gui"); if (sel instanceof StructuredSelection) { final StructuredSelection ss = (StructuredSelection) sel; GLinkNode node = (GLinkNode) ss.getFirstElement(); while (!(node instanceof GLinkRepositoryNode)) node = node.parent(); final GLinkRepositoryNode item = (GLinkRepositoryNode) node; final File file = item.file(); builder.directory(file); } builder.start(); } catch (final Exception e) { throw new RuntimeException(e); } } }; n.setText("Open with \"git gui\""); n.setImageDescriptor(GLinkPlugin.id_gitLink); return n; }
From source file:gitLink.GLinkTreeViewer.java
License:Open Source License
private IAction newStageAction() { final Action n = new Action() { @Override/*from w ww . j a va 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", "add", "-A", item.text()); builder.directory(file); builder.start(); doRefreshAction(); } } catch (final Exception e) { throw new RuntimeException(e); } } }; n.setText("Stage"); n.setImageDescriptor(GLinkPlugin.id_gitLink); return n; }