Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.embedded;
  
 
 import  org.eclipse.jface.text.ITextOperationTarget;
 import  org.eclipse.jface.text.ITextViewer;
 import  org.eclipse.swt.custom.BusyIndicator;
 import  org.eclipse.swt.widgets.Display;
 import  org.eclipse.swt.widgets.Shell;

An action which gets a text operation target from its text editor.

The action is initially associated with a text editor via the constructor, but can subsequently be changed using setEditor.

If this class is used as is, it works by asking the text editor for its text operation target adapter (using getAdapter(ITextOperationTarget.class). The action runs this operation with the pre-configured opcode.

Author(s):
Sebastian Zarnekow - Initial contribution and API
Since:
2.3
 
 public class TextViewerOperationAction extends TextViewerAction {

The text operation code
 
 	private int fOperationCode = -1;
The text operation target
 
 	private ITextOperationTarget fOperationTarget;
Indicates whether this action can be executed on read only editors
 
 	private boolean fRunsOnReadOnly = false;

Flag to prevent running twice trough update() when creating this action.
 
 	private boolean fAllowUpdate = false;

Creates and initializes the action for the given text editor and operation code. The action configures its visual representation from the given resource bundle. The action works by asking the text editor at the time for its text operation target adapter (using getAdapter(ITextOperationTarget.class). The action runs that operation with the given opcode.

Parameters:
bundle the resource bundle
prefix a prefix to be prepended to the various resource keys (described in ResourceAction constructor), or null if none
viewer the text viewer
operationCode the operation code
See also:
TextViewerAction.TextViewerAction(ResourceBundle, String, ITextViewer)
 
 	public TextViewerOperationAction(ResourceBundle bundleString prefix, ITextViewer viewerint operationCode) {
 		this(bundleprefixvieweroperationCodefalse);
 	}

Creates and initializes the action for the given text editor and operation code. The action configures its visual representation from the given resource bundle. The action works by asking the text editor at the time for its text operation target adapter (using getAdapter(ITextOperationTarget.class). The action runs that operation with the given opcode.

Parameters:
bundle the resource bundle
prefix a prefix to be prepended to the various resource keys (described in ResourceAction constructor), or null if none
viewer the text viewer
operationCode the operation code
runsOnReadOnly true if action can be executed on read-only files
See also:
TextViewerAction.TextViewerAction(ResourceBundle, String, ITextViewer)
 
 	public TextViewerOperationAction(ResourceBundle bundleString prefix, ITextViewer viewerint operationCode,
 			boolean runsOnReadOnly) {
 		super(bundleprefix);
 		setViewer(viewer);
 		 = operationCode;
 		 = runsOnReadOnly;
 		 = true;
 		update();
 	}

The TextOperationAction implementation of this IAction method runs the operation with the current operation code.
	public void run() {
		if ( == -1 ||  == null)
			return;
		ITextViewer viewer = getTextViewer();
		if (viewer == null)
			return;
			return;
		Display display = null;
		Shell shell = viewer.getTextWidget().getShell();
		if (shell != null && !shell.isDisposed())
			display = shell.getDisplay();
		BusyIndicator.showWhile(displaynew Runnable() {
			public void run() {
			}
		});
	}

The TextOperationAction implementation of this IUpdate method discovers the operation through the current editor's ITextOperationTarget adapter, and sets the enabled state accordingly.
	public void update() {
			return;
		super.update();
			setEnabled(false);
			return;
		}
		ITextViewer viewer = getTextViewer();
		if ( == null && viewer != null &&  != -1)
			 = viewer.getTextOperationTarget();
		boolean isEnabled = ( != null && .canDoOperation());
		setEnabled(isEnabled);
	}
	public void setViewer(ITextViewer viewer) {
		super.setViewer(viewer);
	}
New to GrepCode? Check out our FAQ X