org.eclipse.jface.viewers.ISelectionProvider Java Examples

The following examples show how to use org.eclipse.jface.viewers.ISelectionProvider. 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: CustomPopupMenuExtender.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public CustomPopupMenuExtender(final String id, final MenuManager menu,
        final ISelectionProvider prov, final IWorkbenchPart part, IEclipseContext context,
        final boolean includeEditorInput) {
    super();
    this.menu = menu;
    this.selProvider = prov;
    this.part = part;
    this.context = context;
    this.modelPart = part.getSite().getService(MPart.class);
    if (includeEditorInput) {
        bitSet |= INCLUDE_EDITOR_INPUT;
    }
    menu.addMenuListener(this);
    if (!menu.getRemoveAllWhenShown()) {
        menuWrapper = new SubMenuManager(menu);
        menuWrapper.setVisible(true);
    }
    createModelFor(id);
    addMenuId(id);

    Platform.getExtensionRegistry().addRegistryChangeListener(this);
}
 
Example #2
Source File: WriteReferencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new <code>WriteReferencesSearchGroup</code>. The group requires
 * that the selection provided by the given selection provider is of type
 * {@link IStructuredSelection}.
 *
 * @param site the site that will own the action group.
 * @param specialSelectionProvider the selection provider used instead of the
 *  sites selection provider.
 *
 * @since 3.4
 */
public WriteReferencesSearchGroup(IWorkbenchSite site, ISelectionProvider specialSelectionProvider) {
	fSite= site;
	fGroupId= IContextMenuConstants.GROUP_SEARCH;

	fFindWriteReferencesAction= new FindWriteReferencesAction(site);
	fFindWriteReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);

	fFindWriteReferencesInProjectAction= new FindWriteReferencesInProjectAction(site);
	fFindWriteReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_PROJECT);

	fFindWriteReferencesInHierarchyAction= new FindWriteReferencesInHierarchyAction(site);
	fFindWriteReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);

	fFindWriteReferencesInWorkingSetAction= new FindWriteReferencesInWorkingSetAction(site);
	fFindWriteReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);

	// register the actions as selection listeners
	ISelectionProvider provider= specialSelectionProvider == null ? fSite.getSelectionProvider() : specialSelectionProvider;
	ISelection selection= provider.getSelection();
	registerAction(fFindWriteReferencesAction, provider, selection, specialSelectionProvider);
	registerAction(fFindWriteReferencesInProjectAction, provider, selection, specialSelectionProvider);
	registerAction(fFindWriteReferencesInHierarchyAction, provider, selection, specialSelectionProvider);
	registerAction(fFindWriteReferencesInWorkingSetAction, provider, selection, specialSelectionProvider);
}
 
Example #3
Source File: WriteReferencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void dispose() {
	ISelectionProvider provider= fSite.getSelectionProvider();
	if (provider != null) {
		disposeAction(fFindWriteReferencesAction, provider);
		disposeAction(fFindWriteReferencesInProjectAction, provider);
		disposeAction(fFindWriteReferencesInHierarchyAction, provider);
		disposeAction(fFindWriteReferencesInWorkingSetAction, provider);
	}
	fFindWriteReferencesAction= null;
	fFindWriteReferencesInProjectAction= null;
	fFindWriteReferencesInHierarchyAction= null;
	fFindWriteReferencesInWorkingSetAction= null;
	updateGlobalActionHandlers();
	super.dispose();
}
 
Example #4
Source File: GamlSearchField.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public void search() {
	final IWorkbenchPart part = WorkbenchHelper.getActivePart();
	if (part instanceof IEditorPart) {
		final IEditorPart editor = (IEditorPart) part;
		final IWorkbenchPartSite site = editor.getSite();
		if (site != null) {
			final ISelectionProvider provider = site.getSelectionProvider();
			if (provider != null) {
				final ISelection viewSiteSelection = provider.getSelection();
				if (viewSiteSelection instanceof TextSelection) {
					final TextSelection textSelection = (TextSelection) viewSiteSelection;
					text.setText(textSelection.getText());
				}
			}
		}

	}
	activate(null);
	text.setFocus();

}
 
Example #5
Source File: AbstractNewSarlElementWizard.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performFinish() {
	final int size = this.page.asyncCreateType();
	final IResource resource = this.page.getResource();
	if (resource != null) {
		selectAndReveal(resource);
		final Display display = getShell().getDisplay();
		display.asyncExec(() -> {
			final IEditorPart editor;
			try {
				editor = IDE.openEditor(JavaPlugin.getActivePage(), (IFile) resource);
				if (editor instanceof ITextEditor) {
					final ITextEditor textEditor = (ITextEditor) editor;
					final ISelectionProvider selectionProvider = textEditor.getSelectionProvider();
					final ISelection selection = new TextSelection(size - 2, 0);
					selectionProvider.setSelection(selection);
				}
			} catch (PartInitException e) {
				throw new RuntimeException(e);
			}
		});
		return true;
	}
	return false;
}
 
Example #6
Source File: TLAEditor.java    From tlaplus with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Object getAdapter(@SuppressWarnings("rawtypes") Class required)
   {
       /* adapt to projection support */
       if (projectionSupport != null)
       {
           Object adapter = projectionSupport.getAdapter(getSourceViewer(), required);
           if (adapter != null)
               return adapter;
       }

       if (ISelectionProvider.class.equals(required))
       {
           return getSelectionProvider();
       }

       return super.getAdapter(required);
   }
 
Example #7
Source File: MarkOccurrencesTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testMarkOccurrencesCrossFile() throws Exception {
	String model1 = "Zonk { Bar(Foo) {} Baz(Foo Bar) {} }";
	String model2 = "Foo {}";
	IFile modelFile1 = IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test1.outlinetestlanguage", model1);
	IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test2.outlinetestlanguage", model2);
	IResourcesSetupUtil.waitForBuild();
	XtextEditor editor = openEditor(modelFile1);
	ISelectionProvider selectionProvider = editor.getSelectionProvider();
	selectionProvider.setSelection(new TextSelection(model1.indexOf("Foo"), 1));
	IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
	ExpectationBuilder listener = new ExpectationBuilder(editor, annotationModel)
			.added(OCCURRENCE_ANNOTATION_TYPE, model1.indexOf("Foo", 3), 3)
			.added(OCCURRENCE_ANNOTATION_TYPE, model1.lastIndexOf("Foo"), 3);
	listener.start();
	annotationModel.addAnnotationModelListener(listener);
	setMarkOccurrences(true);
	listener.verify(TIMEOUT);
}
 
Example #8
Source File: DelegatingSelectionProvider.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets a new selection provider to delegate to. Selection listeners registered with the
 * previous delegate are removed before.
 * 
 * @param newDelegate
 *            new selection provider
 */
public void setSelectionProviderDelegate(ISelectionProvider newDelegate){
	if (delegate == newDelegate) {
		return;
	}
	if (delegate != null) {
		delegate.removeSelectionChangedListener(selectionListener);
		if (delegate instanceof IPostSelectionProvider) {
			((IPostSelectionProvider) delegate)
				.removePostSelectionChangedListener(postSelectionListener);
		}
	}
	delegate = newDelegate;
	if (newDelegate != null) {
		newDelegate.addSelectionChangedListener(selectionListener);
		if (newDelegate instanceof IPostSelectionProvider) {
			((IPostSelectionProvider) newDelegate)
				.addPostSelectionChangedListener(postSelectionListener);
		}
		fireSelectionChanged(newDelegate.getSelection());
		firePostSelectionChanged(newDelegate.getSelection());
	}
}
 
Example #9
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public ITextViewer getSourceViewer(final String currentModelToParse, final IXtextDocument xtextDocument) {
	ITextViewer result = new MockableTextViewer() {
		@Override
		public IDocument getDocument() {
			return xtextDocument;
		}
		
		@Override
		public ISelectionProvider getSelectionProvider() {
			return new MockableSelectionProvider() {
				@Override
				public ISelection getSelection() {
					return TextSelection.emptySelection();
				}
			};
		}
		
		@Override
		public StyledText getTextWidget() {
			return null;
		}
	};
	return result;
}
 
Example #10
Source File: OpenEditorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void assertActiveEditor(String expectedEditorID, String expectedEditorTitle, final String expectedSelection) {
	IEditorPart editorPart = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	assertEquals(expectedEditorTitle, editorPart.getTitle());
	IEditorSite editorSite = editorPart.getEditorSite();
	assertEquals(expectedEditorID, editorSite.getId());
	final ISelectionProvider selectionProvider = editorSite.getSelectionProvider();
	assertTrue(selectionProvider.getSelection() instanceof ITextSelection);
	
	// The selection may be updated asynchronously, so we may have to wait until the selection changes
	workbenchTestHelper.awaitUIUpdate(new Functions.Function0<Boolean>() {
		@Override
		public Boolean apply() {
			return expectedSelection.equals(((ITextSelection) selectionProvider.getSelection()).getText());
		}
	}, SELECTION_TIMEOUT);
	assertEquals(expectedSelection, ((ITextSelection) selectionProvider.getSelection()).getText());
}
 
Example #11
Source File: DeclarationsSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void dispose() {
	ISelectionProvider provider= fSite.getSelectionProvider();
	if (provider != null) {
		disposeAction(fFindDeclarationsAction, provider);
		disposeAction(fFindDeclarationsInProjectAction, provider);
		disposeAction(fFindDeclarationsInHierarchyAction, provider);
		disposeAction(fFindDeclarationsInWorkingSetAction, provider);
	}
	fFindDeclarationsAction= null;
	fFindDeclarationsInProjectAction= null;
	fFindDeclarationsInHierarchyAction= null;
	fFindDeclarationsInWorkingSetAction= null;
	updateGlobalActionHandlers();
	super.dispose();
}
 
Example #12
Source File: SelectionDispatchAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the selection provider managed by the site owning this action or the selection
 * provider explicitly set in {@link #setSpecialSelectionProvider(ISelectionProvider)}.
 *
 * @return the site's selection provider
 */
public ISelectionProvider getSelectionProvider() {
	if (fSpecialSelectionProvider != null) {
		return fSpecialSelectionProvider;
	}
	return fSite.getSelectionProvider();
}
 
Example #13
Source File: AbstractThemeableEditor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void uninstall(ISelectionProvider selectionProvider)
{
	if (selectionProvider == null)
	{
		return;
	}
	if (selectionProvider instanceof IPostSelectionProvider)
	{
		((IPostSelectionProvider) selectionProvider).removePostSelectionChangedListener(this);
	}
	else
	{
		selectionProvider.removeSelectionChangedListener(this);
	}
}
 
Example #14
Source File: CasEditorViewPage.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and shows the page, if page is null
 * the not available message will be shown.
 *
 * @param page the page
 */
protected void initializeAndShowPage(IPageBookViewPage page) {
  if (book != null) {
    if (page != null) {
      page.createControl(book);
      casViewPage = page;
      
      // Note: If page is in background event listening must be disabled!
      ISelectionProvider selectionProvider = page.getSite().getSelectionProvider();
      selectionProvider.addSelectionChangedListener(CasEditorViewPage.this::selectionChanged);
      
      subActionBar = (SubActionBars) casViewPage.getSite().getActionBars();
      
      casViewPage.setActionBars(subActionBar);

      subActionBar.activate();
      subActionBar.updateActionBars();

      refreshActionHandlers();
      
      book.showPage(page.getControl());
    }
    else {
      book.showPage(messageText);
      getSite().getActionBars().updateActionBars();
    }
  }
}
 
Example #15
Source File: OpenEditorActionGroup.java    From typescript.java with MIT License 5 votes vote down vote up
private void initialize(ISelectionProvider provider) {
	ISelection selection= provider.getSelection();
	fOpen.update(selection);
	if (!fIsEditorOwner) {
		provider.addSelectionChangedListener(fOpen);
	}
}
 
Example #16
Source File: FindBarDecorator.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void modifyText(ModifyEvent e)
{
	adjustEnablement();
	if (ignore > 0 || !searchOnModifyText)
	{
		return;
	}
	IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore();
	if (!preferenceStore.getBoolean(IPreferencesConstants.INCREMENTAL_SEARCH_ON_FIND_BAR))
	{
		return;
	}

	textFind.setBackground(null);
	boolean wrap = true;
	String text = textFind.getText();
	if (lastText.startsWith(text))
	{
		wrap = false;
	}
	lastText = text;
	if (StringUtil.EMPTY.equals(text))
	{
		ISelectionProvider selectionProvider = textEditor.getSelectionProvider();
		ISelection selection = selectionProvider.getSelection();
		if (selection instanceof TextSelection)
		{
			ITextSelection textSelection = (ITextSelection) selection;
			selectionProvider.setSelection(new TextSelection(textSelection.getOffset(), 0));
		}
	}
	else
	{
		findBarFinder.find(true, true, wrap);
	}
	showCountTotal();
}
 
Example #17
Source File: ViewActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dispose() {
	fFilterActionGroup.dispose();
	fShowActionGroup.dispose();
	fChangeListener= null;
	ISelectionProvider selectionProvider= fSite.getSelectionProvider();
	selectionProvider.removeSelectionChangedListener(fWorkingSetAssignementAction);
	super.dispose();
}
 
Example #18
Source File: OpenTraceHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@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 #19
Source File: ContextMenuProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructs a context menu for the specified EditPartViewer.
 * 
 * @param viewer
 *            the editpart viewer
 */
public ContextMenuProvider( ISelectionProvider viewer )
{
	setViewer( viewer );
	addMenuListener( this );
	setRemoveAllWhenShown( true );

}
 
Example #20
Source File: TypeScriptSearchResultPage.java    From typescript.java with MIT License 5 votes vote down vote up
public Object getAdapter(Class adapter) {
	if (IShowInTargetList.class.equals(adapter)) {
		return SHOW_IN_TARGET_LIST;
	}

	if (adapter == IShowInSource.class) {
		ISelectionProvider selectionProvider= getSite().getSelectionProvider();
		if (selectionProvider == null)
			return null;

		ISelection selection= selectionProvider.getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection= ((StructuredSelection)selection);
			final Set newSelection= new HashSet(structuredSelection.size());
			Iterator iter= structuredSelection.iterator();
			while (iter.hasNext()) {
				Object element= iter.next();
				if (element instanceof LineElement)
					element= ((LineElement)element).getParent();
				newSelection.add(element);
			}

			return new IShowInSource() {
				public ShowInContext getShowInContext() {
					return new ShowInContext(null, new StructuredSelection(new ArrayList(newSelection)));
				}
			};
		}
		return null;
	}

	return null;
}
 
Example #21
Source File: CommonOccurrencesUpdater.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent event) {
	final String property = event.getProperty();

	if (IPreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) {
		boolean newBooleanValue = false;
		Object newValue = event.getNewValue();

		if (newValue != null) {
			newBooleanValue = Boolean.valueOf(newValue.toString()).booleanValue();
		}

		if (newBooleanValue) {
			install();
		} else {
			uninstall();
		}

		// force update
		if (editor != null) {
			ISelectionProvider selectionProvider = editor.getSelectionProvider();

			if (selectionProvider != null) {
				updateAnnotations(selectionProvider.getSelection());
			}
		}
	}
}
 
Example #22
Source File: HandlerUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #23
Source File: GWTOpenEditorActionGroup.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void initialize(ISelectionProvider provider) {
  ISelection selection = provider.getSelection();
  openAction.update(selection);
  if (!isEditorOwner) {
    provider.addSelectionChangedListener(openAction);
  }
}
 
Example #24
Source File: Bug3524078.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ISelectionProvider getSelectionProvider() {
    if (editorPart == null) {
        return null;
    }
    if (editorPart instanceof ITextEditor) {
        return ((ITextEditor) editorPart).getSelectionProvider();
    }
    if (editorPart instanceof ISelectionProvider) {
        return (ISelectionProvider) editorPart; // <- Unchecked/unconfirmed cast from org.eclipse.ui.IEditorPart to org.eclipse.jface.viewers.ISelectionProvider in de.loskutov.anyedit.ui.editor.AbstractEditor.getSelectionProvider()
    }
    return null;
}
 
Example #25
Source File: AbstractDataSectionTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    when(sectionUnderTest.getActiveShell()).thenReturn(shell);
    when(sectionUnderTest.createWizardDialog(addWizard, IDialogConstants.FINISH_LABEL)).thenReturn(wizardDialog);
    when(sectionUnderTest.createWizardDialog(editWizard, IDialogConstants.OK_LABEL)).thenReturn(wizardDialog);

    final StructuredSelection selection = new StructuredSelection(aBusinessData().build());
    when(sectionUnderTest.getStructuredSelection((ISelectionProvider) anyObject())).thenReturn(selection);
}
 
Example #26
Source File: SelectionDispatchAction.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public ISelection getSelection() {
	ISelectionProvider selectionProvider= getSelectionProvider();
	if (selectionProvider != null)
		return selectionProvider.getSelection();
	else
		return null;
}
 
Example #27
Source File: RefactorActionGroup.java    From typescript.java with MIT License 5 votes vote down vote up
public RefactorActionGroup(TypeScriptEditor editor, String groupName) {
	fEditor = editor;
	fGroupName = groupName;
	fSite = editor.getEditorSite();
	fSelectionProvider = fSite.getSelectionProvider();

	ISelectionProvider provider = editor.getSelectionProvider();
	ISelection selection = provider.getSelection();

	fRenameAction = new RenameAction(editor);
	initAction(fRenameAction, selection, ITypeScriptEditorActionDefinitionIds.RENAME_ELEMENT);
	editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$

}
 
Example #28
Source File: OutlineWithEditorLinker.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void activate(OutlinePage outlinePage) {
	this.outlinePage = outlinePage;
	treeViewer = outlinePage.getTreeViewer();
	treeListener = new TreeListener();
	treeViewer.addPostSelectionChangedListener(treeListener);
	treeViewer.addDoubleClickListener(treeListener);
	textViewer = outlinePage.getSourceViewer();
	textListener = new TextListener();
	ISelectionProvider textSelectionProvider = textViewer.getSelectionProvider();
	if (textSelectionProvider instanceof IPostSelectionProvider)
		((IPostSelectionProvider) textSelectionProvider).addPostSelectionChangedListener(textListener);
	else
		textSelectionProvider.addSelectionChangedListener(textListener);
}
 
Example #29
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void installSelectionChangedListener() {
	selectionChangedListener = new ISelectionChangedListener() {
		@Override
		public void selectionChanged(final SelectionChangedEvent event) {
			updateStatusLine();
		}
	};
	final ISelectionProvider selectionProvider = getSelectionProvider();
	if (selectionProvider instanceof IPostSelectionProvider) {
		final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider;
		postSelectionProvider.addPostSelectionChangedListener(selectionChangedListener);
	} else {
		getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
	}
}
 
Example #30
Source File: SelectionUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Underlying implementation of <code>getSelectedResources</code>
 * 
 * @return the list of selected <code>IResource</code> objects, or empty list if none.
 */
protected static List<IResource> getSelectedResources0() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    List<IResource> resources = new ArrayList<IResource>();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part instanceof IEditorPart) {
                IEditorPart epart = (IEditorPart) part;
                IResource adaptee = (IResource) epart.getEditorInput().getAdapter(IResource.class);
                if (adaptee != null) {
                	resources.add(adaptee);
                }
            }
            else if (part != null) {
                IWorkbenchPartSite site = part.getSite();
                if(site != null) {
                    ISelectionProvider provider = site.getSelectionProvider();
                    if (provider != null) {
                        ISelection selection = provider.getSelection();
                        resources = getObjectsFromStructuredSelection(selection, IResource.class);
                    }
                }
            }
        }
    }
    return resources;
}