Java Code Examples for org.eclipse.jface.viewers.TreeSelection#getFirstElement()
The following examples show how to use
org.eclipse.jface.viewers.TreeSelection#getFirstElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BundleView.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * fillContextMenu * * @param manager */ private void fillContextMenu(IMenuManager manager) { ISelection selection = treeViewer.getSelection(); if (selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; Object item = treeSelection.getFirstElement(); if (item instanceof BaseNode) { BaseNode<?> node = (BaseNode<?>) item; Action[] actions = node.getActions(); if (actions != null) { for (Action action : actions) { manager.add(action); } } } } }
Example 2
Source File: IndexView.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * fillContextMenu * * @param manager */ private void fillContextMenu(IMenuManager manager) { ISelection selection = treeViewer.getSelection(); if (selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; Object item = treeSelection.getFirstElement(); if (item != null) { IAction[] actions = actionProvider.getActions(this, item); if (actions != null) { for (IAction action : actions) { manager.add(action); } } } } }
Example 3
Source File: RemoveConnectionHandler.java From slr-toolkit with Eclipse Public License 1.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event) .getActivePage().getSelection(); if(selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; if(treeSelection.getFirstElement() instanceof File) { File file = (File) treeSelection.getFirstElement(); if(file.getFileExtension().equals("bib")){ WorkspaceBibTexEntry entry = wm.getWorkspaceBibTexEntryByUri(file.getLocationURI()); if(entry != null) { if(entry.getMendeleyFolder() != null) { // by setting the MendeleyFolder of a WorkspaceBibTexEntry to null, the connection will be removed entry.setMendeleyFolder(null); decoratorManager.update("de.tudresden.slr.model.mendeley.decorators.MendeleyOverlayDecorator"); } } } } } return null; }
Example 4
Source File: UpgradePluginVersionsAction.java From developer-studio with Apache License 2.0 | 6 votes |
@Override public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; if (treeSelection.getFirstElement() instanceof IProject) { IProject project = (IProject) treeSelection.getFirstElement(); action.setEnabled(project.isOpen()); this.project = project; mavenProjectFile = project.getFile("pom.xml"); if (mavenProjectFile.exists()) { action.setText("Upgrade Plugin Versions in pom.xml"); } } else { action.setEnabled(false); } } }
Example 5
Source File: SyncDependenciesAction.java From developer-studio with Apache License 2.0 | 6 votes |
public void selectionChanged(IAction arg0, ISelection arg1) { if (arg1 instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) arg1; if (treeSelection.getFirstElement() instanceof IProject) { IProject project = (IProject) treeSelection.getFirstElement(); arg0.setEnabled(project.isOpen()); this.project = project; mavenProjectFile = project.getFile("pom.xml"); if (mavenProjectFile.exists()) { arg0.setText("Sync Project Dependencies with pom.xml"); } } else { arg0.setEnabled(false); } } }
Example 6
Source File: XMLAnalysesManagerPreferencePage.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Refresh the selected project elements. This is useful after XML files * importing/deletion/enabling/disabling. * * @param elements * the elements to re-open */ private static void refreshProject(Collection<TmfCommonProjectElement> elements) { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return; } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part == null) { return; } ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return; } ISelection selection = selectionProvider.getSelection(); if (selection instanceof TreeSelection) { TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml Object element = sel.getFirstElement(); if (element instanceof TmfProjectModelElement) { ((TmfProjectModelElement) element).getProject().refresh(); } } // Re-open given elements elements.forEach(TmfOpenTraceHelper::openFromElement); }
Example 7
Source File: RenameExperimentHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } ISelection selection = selectionProvider.getSelection(); // Make sure there is only selection and that it is an experiment fExperiment = null; if (selection instanceof TreeSelection) { TreeSelection sel = (TreeSelection) selection; Object element = sel.getFirstElement(); if (element instanceof TmfExperimentElement) { fExperiment = (TmfExperimentElement) element; } } return (fExperiment != null); }
Example 8
Source File: OpenAnalysisHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { /* Check if we are closing down */ final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } /* Get the selection */ final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); /* Make sure there is only one selection and that it is an analysis output */ fAnalysisElement = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfAnalysisElement) { fAnalysisElement = (TmfAnalysisElement) element; } } return (fAnalysisElement != null); }
Example 9
Source File: OpenExperimentHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment fExperiment = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfExperimentElement) { fExperiment = (TmfExperimentElement) element; } } // We only enable opening from the Traces folder for now return ((fExperiment != null) && (!fExperiment.getTraces().isEmpty())); }
Example 10
Source File: OpenAnalysisOutputHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { /* Check if we are closing down */ final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } /* Get the selection */ final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); /* Make sure there is only one selection and that it is an analysis output */ fOutputElement = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfAnalysisOutputElement) { fOutputElement = (TmfAnalysisOutputElement) element; } } return (fOutputElement != null); }
Example 11
Source File: NewExperimentHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part == null) { return Boolean.FALSE; } ISelection selection = part.getSite().getSelectionProvider().getSelection(); TmfExperimentFolder experimentFolder = null; if (selection instanceof TreeSelection) { TreeSelection sel = (TreeSelection) selection; Object element = sel.getFirstElement(); if (element instanceof TmfExperimentFolder) { experimentFolder = (TmfExperimentFolder) element; } } if (experimentFolder == null) { return null; } // Fire the New Experiment dialog Shell shell = window.getShell(); NewExperimentDialog dialog = new NewExperimentDialog(shell, experimentFolder); dialog.open(); return null; }
Example 12
Source File: OpenAnalysisHelpHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is a trace fAnalysis = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfAnalysisElement) { fAnalysis = (TmfAnalysisElement) element; } } return (fAnalysis != null); }
Example 13
Source File: OpenTraceHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is a trace fTrace = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfTraceElement) { fTrace = (TmfTraceElement) element; } } // We only enable opening from the Traces folder for now return (fTrace != null); }
Example 14
Source File: SelectTracesHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment fExperiment = null; if (selection instanceof TreeSelection) { TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml Object element = sel.getFirstElement(); if (element instanceof TmfExperimentElement) { fExperiment = (TmfExperimentElement) element; } } return (fExperiment != null); }
Example 15
Source File: HandlerUtils.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Get the current selected UI element. Can be used instead of * {@link org.eclipse.ui.handlers.HandlerUtil#getCurrentSelection} when an * ExecutionEvent is not available. * * @return The element consisting of the selection */ public static @Nullable Object getSelectedModelElement() { // Check if we are closing down final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; } // Get the selection final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return null; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return null; } final ISelection selection = selectionProvider.getSelection(); if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml return sel.getFirstElement(); } return null; }