Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2342185
  • 博文数量: 321
  • 博客积分: 3440
  • 博客等级: 中校
  • 技术积分: 2992
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-24 09:08
个人简介

我就在这里

文章分类

全部博文(321)

文章存档

2015年(9)

2014年(84)

2013年(101)

2012年(25)

2011年(29)

2010年(21)

2009年(6)

2008年(23)

2007年(23)

分类: Java

2014-11-26 21:45:12

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.

  1. public class CustomizedView extends ViewPart

  2. {

  3.    public void createPartControl( Composite parent )

  4.    {

  5.        final IActionBars actionBars = getViewSite( ).getActionBars( );

  6.        IToolBarManager toolbarManager = actionBars.getToolBarManager( );

  7.        toolbarManager.add( new OpenSourceAction( getViewSite( ).getWorkbenchWindow( ) ) );

  8.        actionBars.updateActionBars( );

  9.    }
  10.    ......

  11. }

  12. public class OpenSourceAction extends Action

  13. {

  14.    private IWorkbenchWindow window ;
  15.    ......

  16.    public void run( )

  17.     {

  18.         IFileStore fileStore = EFS.getLocalFileSystem( )

  19.                   .getStore( new Path( filePath ) );

  20.        fileStore = fileStore.getChild( fileName );

  21.         if ( !fileStore.fetchInfo( ).isDirectory( )

  22.                   && fileStore.fetchInfo( ).exists( ) )

  23.        {

  24.           IEditorInput input = createEditorInput( fileStore );

  25.           String editorId = getEditorId( fileStore );

  26.            try

  27.           {

  28.                window .getActivePage( ).openEditor( input, editorId );

  29.           }

  30.            catch ( PartInitException e )

  31.           {

  32.               e.printStackTrace( );

  33.           }

  34.        }

  35.     }

  36. }

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) |
给主人留下些什么吧!~~