Java Code Examples for org.eclipse.ui.texteditor.ITextEditor#getAction()

The following examples show how to use org.eclipse.ui.texteditor.ITextEditor#getAction() . 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: MacroModeStateHandler.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void restore(ITextEditor textEditor, String actionId) {
    Boolean b = fMemento.get(actionId);
    if (b != null && b) {
        Control control = textEditor.getAdapter(Control.class);
        if (control != null && !control.isDisposed()) {
            // Do nothing if already disposed.
            IAction action = textEditor.getAction(actionId);
            if (action instanceof TextEditorAction) {
                TextEditorAction textEditorAction = (TextEditorAction) action;
                textEditorAction.setEditor(textEditor);
                textEditorAction.update();
            }
        }
    }
}
 
Example 2
Source File: MacroModeStateHandler.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void disable(ITextEditor textEditor, String actionId) {
    IAction action = textEditor.getAction(actionId);
    if (action != null && action instanceof TextEditorAction) {
        TextEditorAction textEditorAction = (TextEditorAction) action;
        fMemento.put(actionId, true);
        textEditorAction.setEditor(null);
        textEditorAction.update();
    }
}
 
Example 3
Source File: JavaElementHyperlinkDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
	ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
	if (region == null || !(textEditor instanceof JavaEditor))
		return null;

	IAction openAction= textEditor.getAction("OpenEditor"); //$NON-NLS-1$
	if (!(openAction instanceof SelectionDispatchAction))
		return null;

	int offset= region.getOffset();

	ITypeRoot input= EditorUtility.getEditorInputJavaElement(textEditor, false);
	if (input == null)
		return null;

	try {
		IDocumentProvider documentProvider= textEditor.getDocumentProvider();
		IEditorInput editorInput= textEditor.getEditorInput();
		IDocument document= documentProvider.getDocument(editorInput);
		IRegion wordRegion= JavaWordFinder.findWord(document, offset);
		if (wordRegion == null || wordRegion.getLength() == 0)
			return null;

		if (isInheritDoc(document, wordRegion) && getClass() != JavaElementHyperlinkDetector.class)
			return null;

		if (JavaElementHyperlinkDetector.class == getClass() && findBreakOrContinueTarget(input, region) != null)
			return new IHyperlink[] { new JavaElementHyperlink(wordRegion, (SelectionDispatchAction)openAction, null, false) };
		
		IJavaElement[] elements;
		long modStamp= documentProvider.getModificationStamp(editorInput);
		if (input.equals(fLastInput) && modStamp == fLastModStamp && wordRegion.equals(fLastWordRegion)) {
			elements= fLastElements;
		} else {
			elements= ((ICodeAssist) input).codeSelect(wordRegion.getOffset(), wordRegion.getLength());
			elements= selectOpenableElements(elements);
			fLastInput= input;
			fLastModStamp= modStamp;
			fLastWordRegion= wordRegion;
			fLastElements= elements;
		}
		if (elements.length == 0)
			return null;
		
		ArrayList<IHyperlink> links= new ArrayList<IHyperlink>(elements.length);
		for (int i= 0; i < elements.length; i++) {
			addHyperlinks(links, wordRegion, (SelectionDispatchAction)openAction, elements[i], elements.length > 1, (JavaEditor)textEditor);
		}
		if (links.size() == 0)
			return null;
		
		return CollectionsUtil.toArray(links, IHyperlink.class);

	} catch (JavaModelException e) {
		return null;
	}
}
 
Example 4
Source File: EditorAPI.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
private static void setEditorActionState(final IEditorPart editorPart, final boolean enabled) {

    final ITextEditor editor = editorPart.getAdapter(ITextEditor.class);

    if (editor == null) return;

    for (final String actionID : RESTRICTED_ACTION) {
      final IAction action = editor.getAction(actionID);

      if (action != null) action.setEnabled(enabled);
    }
  }
 
Example 5
Source File: MultiPageEditorContributor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the action registed with the given text editor.
 * 
 * @return IAction or null if editor is null.
 */
protected IAction getAction(ITextEditor editor, String actionID) {
	return (editor == null ? null : editor.getAction(actionID));
}
 
Example 6
Source File: BibtexContributor.java    From slr-toolkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the action registed with the given text editor.
 * @return IAction or null if editor is null.
 */
protected IAction getAction(ITextEditor editor, String actionID) {
	return (editor == null ? null : editor.getAction(actionID));
}
 
Example 7
Source File: MultiPageEditorContributor.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the action registed with the given text editor.
 *
 * @param editor the editor
 * @param actionID the action ID
 * @return IAction or null if editor is null.
 */
protected IAction getAction(MultiPageEditorPart editor, String actionID) {
  ITextEditor txtEditor = ((MultiPageEditor) editor).getSourcePageEditor();
  return (txtEditor == null ? null : txtEditor.getAction(actionID));
}
 
Example 8
Source File: MultiPageEditorContributor.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the action 1.
 *
 * @param editor the editor
 * @param actionID the action ID
 * @return the action 1
 */
protected IAction getAction1(ITextEditor editor, String actionID) {
  return (editor == null ? null : editor.getAction(actionID));
}