In Eclipse, there are 2 closely related core
technologies that support development of Graphical User Interface (GUI)
applications. The Standard Widget Toolkit (SWT) provides the fundamental
building blocks. The JFace framework provides a set of patterns and
component abstractions.
Action.java is the standard abstract implementation
of an action. Its subclasses must implement the IAction.run() to carry
out the action's semantics.
Actions represent user-invokable functions,
accessible through menus, toolbars, and the status line. They
encapsulate the non-UI portion of the function, which is called when the
user invokes the action by means of the associated widget, such as a
toolbar button. This allows you to decouple your logic from any specific
UI widget and reuse it in multiple locations as needed.
E.g. Implement an open external Java source action in a customized view.
-
public class CustomizedView extends ViewPart
-
-
{
-
-
public void createPartControl( Composite parent )
-
-
{
-
-
final IActionBars actionBars = getViewSite( ).getActionBars( );
-
-
IToolBarManager toolbarManager = actionBars.getToolBarManager( );
-
-
toolbarManager.add( new OpenSourceAction( getViewSite( ).getWorkbenchWindow( ) ) );
-
-
actionBars.updateActionBars( );
-
-
}
-
......
-
-
}
-
-
public class OpenSourceAction extends Action
-
-
{
-
-
private IWorkbenchWindow window ;
-
......
-
-
public void run( )
-
-
{
-
-
IFileStore fileStore = EFS.getLocalFileSystem( )
-
-
.getStore( new Path( filePath ) );
-
-
fileStore = fileStore.getChild( fileName );
-
-
if ( !fileStore.fetchInfo( ).isDirectory( )
-
-
&& fileStore.fetchInfo( ).exists( ) )
-
-
{
-
-
IEditorInput input = createEditorInput( fileStore );
-
-
String editorId = getEditorId( fileStore );
-
-
try
-
-
{
-
-
window .getActivePage( ).openEditor( input, editorId );
-
-
}
-
-
catch ( PartInitException e )
-
-
{
-
-
e.printStackTrace( );
-
-
}
-
-
}
-
-
}
-
-
}
For more detials about opening an external file, please see org.eclipse.ui.internal.editors.text.OpenExternalFileAction.
转自:http://www.blogjava.net/NinaFromTheBlock/archive/2006/09/04/67631.html
阅读(1169) | 评论(0) | 转发(0) |