在eclipse RCP中如何添加standard actions

先看代码,看明白如何添加标准动作:

 

package pytest;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.internal.views.markers.FileMarkerPropertyTester;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
	private IWorkbenchAction iExitAction;
	private IWorkbenchAction iAboutAction;
	private IWorkbenchAction iNewWindowAction;
	private IWorkbenchAction iSaveAction;
	private IWorkbenchAction iPreferenceAction;
	
    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    protected void makeActions(IWorkbenchWindow window) {
    	iExitAction = ActionFactory.QUIT.create(window);
    	register(iExitAction);
    	iSaveAction = ActionFactory.SAVE.create(window);
    	register(iSaveAction);
    	iAboutAction = ActionFactory.ABOUT.create(window);
    	register(iAboutAction);
    	iNewWindowAction = ActionFactory.NEW_EDITOR.create(window);
    	register(iNewWindowAction);
    	iPreferenceAction = ActionFactory.PREFERENCES.create(window);
    	register(iPreferenceAction);
    }

    protected void fillMenuBar(IMenuManager menuBar) {
    	MenuManager fileMenu = new MenuManager("&File",IWorkbenchActionConstants.M_PROJECT);
    	MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
    	MenuManager windowMenu = new MenuManager("&Window",IWorkbenchActionConstants.M_WINDOW);
    	menuBar.add(fileMenu);
    	menuBar.add(helpMenu);
    	menuBar.add(windowMenu);
    	//File Menu
    	fileMenu.add(iNewWindowAction);
    	fileMenu.add(iSaveAction);
    	fileMenu.add(new Separator());
    	fileMenu.add(iExitAction);
    	//Help Menu
    	helpMenu.add(iAboutAction);
    	//Window Meun
    	windowMenu.add(iPreferenceAction);
    }
}

 

 

  • workbench提供的标准动作都有什么呢?
org.eclipse.ui.actions.ActionFactory

Access to standard actions provided by the workbench.

Most of the functionality of this class is provided by static methods and fields. Example usage:

 MenuManager menu = ...;
 ActionFactory.IWorkbenchAction closeEditorAction
    = ActionFactory.CLOSE.create(window);
 menu.add(closeEditorAction);
 

 

Clients may declare other classes that provide additional application-specific action factories. 

 

Field Summary
static ActionFactory ABOUT
          Workbench action (id: "about", commandId: "org.eclipse.ui.help.aboutAction"): Displays the About dialog.
static ActionFactory ACTIVATE_EDITOR
          Workbench action (id: "activateEditor", commandId: "org.eclipse.ui.window.activateEditor"): Activate the most recently used editor.
static ActionFactory BACK
          Workbench action (id: "back", commandId: "org.eclipse.ui.navigate.back"): Back.
static ActionFactory BACKWARD_HISTORY
          Workbench action (id: "backardHistory", commandId: "org.eclipse.ui.navigate.backwardHistory"): Backward in the navigation history.
static ActionFactory CLOSE
          Workbench action (id: "close", commandId: "org.eclipse.ui.file.close"): Close the active editor.
static ActionFactory CLOSE_ALL
          Workbench action (id: "closeAll", commandId: "org.eclipse.ui.file.closeAll"): Close all open editors.
static ActionFactory CLOSE_ALL_PERSPECTIVES
          Workbench action (id: "closeAllPerspectives", commandId: "org.eclipse.ui.window.closeAllPerspectives"): Closes all perspectives.
static ActionFactory CLOSE_ALL_SAVED
          Workbench action (id: "closeAllSaved"): Close all open editors except those with unsaved changes.
static ActionFactory CLOSE_OTHERS
          Workbench action (id: "closeOthers", commandId: "org.eclipse.ui.file.closeOthers"): Close all editors except the one that is active.
static ActionFactory CLOSE_PERSPECTIVE
          Workbench action (id: "closePerspective", commandId: "org.eclipse.ui.window.closePerspective"): Closes the current perspective.
static ActionFactory COPY
          Workbench action (id: "copy", commandId: "org.eclipse.ui.edit.copy"): Copy.
static ActionFactory CUT
          Workbench action (id: "cut", commandId: "org.eclipse.ui.edit.cut"): Cut.
static ActionFactory DELETE
          Workbench action (id: "delete", commandId: "org.eclipse.ui.edit.delete"): Delete.
static ActionFactory DYNAMIC_HELP
          Workbench action (id: "dynamicHelp", commandId: "org.eclipse.ui.help.dynamicHelp"): Open the dynamic help.
static ActionFactory EDIT_ACTION_SETS
          Workbench action (id: "editActionSets", commandId: "org.eclipse.ui.window.customizePerspective"): Edit the action sets.
static ActionFactory EXPORT
          Workbench action (id: "export", commandId: "org.eclipse.ui.file.export"): Opens the export wizard.
static ActionFactory FIND
          Workbench action (id: "find", commandId: "org.eclipse.ui.edit.findReplace"): Find.
static ActionFactory FORWARD
          Workbench action (id: "forward", commandId: "org.eclipse.ui.navigate.forward"): Forward.
static ActionFactory FORWARD_HISTORY
          Workbench action (id: "forwardHistory", commandId: "org.eclipse.ui.navigate.forwardHistory"): Forward in the navigation history.
static ActionFactory GO_INTO
          Workbench action (id: "goInto", commandId: "org.eclipse.ui.navigate.goInto"): Go Into.
static ActionFactory HELP_CONTENTS
          Workbench action (id: "helpContents", commandId: "org.eclipse.ui.help.helpContents"): Open the help contents.
static ActionFactory HELP_SEARCH
          Workbench action (id: "helpSearch", commandId: "org.eclipse.ui.help.helpSearch"): Open the help search.
static ActionFactory IMPORT
          Workbench action (id: "import", commandId: "org.eclipse.ui.file.import"): Opens the import wizard.
static ActionFactory INTRO
          Workbench action (id: "intro", commandId: "org.eclipse.ui.help.quickStartAction"): Activate the introduction extension.
static ActionFactory LOCK_TOOL_BAR
          Workbench action (id: "lockToolBar"): Lock/unlock the workbench window tool bar.
static ActionFactory MAXIMIZE
          Workbench action (id: "maximize", commandId: "org.eclipse.ui.window.maximizePart"): Maximize/restore the active part.
static ActionFactory MINIMIZE
          Workbench action (id: "minimize", commandId: "org.eclipse.ui.window.minimizePart"): Minimizes the active part.
static ActionFactory MOVE
          Workbench action (id: "move", commandId: "org.eclipse.ui.edit.move"): Move.
static ActionFactory NEW
          Workbench action (id: "new", commandId: "org.eclipse.ui.newWizard"): Opens the new wizard dialog.
static ActionFactory NEW_EDITOR
          Workbench action (id: "newEditor", commandId: "org.eclipse.ui.window.newEditor"): Open a new editor on the active editor's input.
static ActionFactory NEW_WIZARD_DROP_DOWN
          Workbench action (id: "newWizardDropDown"): Drop-down action which shows shows the new wizard drop down, or opens the new wizard dialog when pressed.
static ActionFactory NEXT
          Workbench action (id: "next", commandId: "org.eclipse.ui.navigate.next"): Next.
static ActionFactory NEXT_EDITOR
          Workbench action (id: "nextEditor", commandId: "org.eclipse.ui.window.nextEditor"): Next editor.
static ActionFactory NEXT_PART
          Workbench action (id: "nextPart", commandId: "org.eclipse.ui.window.nextView"): Next part.
static ActionFactory NEXT_PERSPECTIVE
          Workbench action (id: "nextPerspective", commandId: "org.eclipse.ui.window.nextPerspective"): Next perspective.
static ActionFactory OPEN_NEW_WINDOW
          Workbench action (id: "openNewWindow", commandId: "org.eclipse.ui.window.newWindow"): Open a new workbench window.
static ActionFactory OPEN_PERSPECTIVE_DIALOG
          Workbench action (id: "openPerspectiveDialog", commandId: "org.eclipse.ui.perspectives.showPerspective"): Open the Open Perspective dialog.
static ActionFactory PASTE
          Workbench action (id: "paste", commandId: "org.eclipse.ui.edit.paste"): Paste.
static ActionFactory PREFERENCES
          Workbench action (id: "preferences", commandId: "org.eclipse.ui.window.preferences"): Displays the Preferences dialog.
static ActionFactory PREVIOUS
          Workbench action (id: "previous", commandId: "org.eclipse.ui.navigate.previous"): Previous.
static ActionFactory PREVIOUS_EDITOR
          Workbench action (id: "previousEditor", commandId: "org.eclipse.ui.window.previousEditor"): Previous editor.
static ActionFactory PREVIOUS_PART
          Workbench action (id: "previousPart", commandId: "org.eclipse.ui.window.previousView"): Previous part.
static ActionFactory PREVIOUS_PERSPECTIVE
          Workbench action (id: "previousPerspective", commandId: "org.eclipse.ui.window.previousPerspective"): Previous perspective.
static ActionFactory PRINT
          Workbench action (id: "print", commandId: "org.eclipse.ui.file.print"): Print.
static ActionFactory PROPERTIES
          Workbench action (id: "properties", commandId: "org.eclipse.ui.file.properties"): Properties.
static ActionFactory QUIT
          Workbench action (id: "quit", commandId: "org.eclipse.ui.file.exit"): Quit (close the workbench).
static ActionFactory REDO
          Workbench action (id: "redo", commandId: "org.eclipse.ui.edit.redo"): Redo.
static ActionFactory REFRESH
          Workbench action (id: "refresh", commandId: "org.eclipse.ui.file.refresh"): Refresh.
static ActionFactory RENAME
          Workbench action (id: "rename", commandId: "org.eclipse.ui.edit.rename"): Rename.
static ActionFactory RESET_PERSPECTIVE
          Workbench action (id: "resetPerspective", commandId: "org.eclipse.ui.window.resetPerspective"): Resets the current perspective.
static ActionFactory REVERT
          Workbench action (id: "revert", commandId: "org.eclipse.ui.file.revert"): Revert.
static ActionFactory SAVE
          Workbench action (id: "save", commandId: "org.eclipse.ui.file.save"): Save the active editor.
static ActionFactory SAVE_ALL
          Workbench action (id: "saveAll", commandId: "org.eclipse.ui.file.saveAll"): Save all open editors with unsaved changes.
static ActionFactory SAVE_AS
          Workbench action (id: "saveAs", commandId: "org.eclipse.ui.file.saveAs"): Save As for the active editor.
static ActionFactory SAVE_PERSPECTIVE
          Workbench action (id: "savePerspective", commandId: "org.eclipse.ui.window.savePerspective"): Save the current perspective.
static ActionFactory SELECT_ALL
          Workbench action (id: "selectAll", commandId: "org.eclipse.ui.edit.selectAll"): Select All.
static ActionFactory SHOW_EDITOR
          Workbench action (id: "showEditor"): Show/hide the editor area.
static ActionFactory SHOW_OPEN_EDITORS
          Workbench action (id: "showOpenEditors"): Show a list of open (and recently closed) editors.
static ActionFactory SHOW_PART_PANE_MENU
          Workbench action (id: "showPartPaneMenu"): Show the part pane menu.
static ActionFactory SHOW_QUICK_ACCESS
          Workbench action (id: "showQuickAccess"): Shows a list of UI elements like editors, views, perspectives etc.
static ActionFactory SHOW_VIEW_MENU
          Workbench action (id: "showViewMenu", commandId: "org.eclipse.ui.window.showViewMenu"): Show the view menu.
static ActionFactory SHOW_WORKBOOK_EDITORS
          Workbench action (id: "showWorkbookEditors"): Shows a list of open editors in the current or last active workbook.
static ActionFactory TOGGLE_COOLBAR
          Workbench action (id: "toggleCoolbar"): Toggle the visibility of the coolbar and perspective switcher.
static ActionFactory UNDO
          Workbench action (id: "undo", commandId: "org.eclipse.ui.edit.undo"): Undo.
static ActionFactory UP
          Workbench action (id: "up", commandId: "org.eclipse.ui.navigate.up"): Up.

 

  • 添加标准菜单用什么呢?(注意:其中有些已经废弃的使用时再查文档)

org.eclipse.ui
Interface IWorkbenchActionConstants

 

Standard menus

  • File menu (M_FILE)
  • Edit menu (M_EDIT)
  • Window menu (M_WINDOW)
  • Help menu (M_HELP)

Standard group for adding top level menus

  • Extra top level menu group (MB_ADDITIONS)

Global actions

  • Undo (UNDO)
  • Redo (REDO)
  • Cut (CUT)
  • Copy (COPY)
  • Paste (PASTE)
  • Delete (DELETE)
  • Find (FIND)
  • Select All (SELECT_ALL)
  • Add Bookmark (BOOKMARK)

Standard File menu actions

  • Start group (FILE_START)
  • End group (FILE_END)
  • New action (NEW)
  • Extra New-like action group (NEW_EXT)
  • Close action (CLOSE)
  • Close All action (CLOSE_ALL)
  • Extra Close-like action group (CLOSE_EXT)
  • Save action (SAVE)
  • Save As action (SAVE_AS)
  • Save All action (SAVE_ALL)
  • Extra Save-like action group (SAVE_EXT)
  • Import action (IMPORT)
  • Export action (EXPORT)
  • Extra Import-like action group (IMPORT_EXT)
  • Quit action (QUIT)

Standard Edit menu actions

  • Start group (EDIT_START)
  • End group (EDIT_END)
  • Undo global action (UNDO)
  • Redo global action (REDO)
  • Extra Undo-like action group (UNDO_EXT)
  • Cut global action (CUT)
  • Copy global action (COPY)
  • Paste global action (PASTE)
  • Extra Cut-like action group (CUT_EXT)
  • Delete global action (DELETE)
  • Find global action (FIND)
  • Select All global action (SELECT_ALL)
  • Bookmark global action (BOOKMARK)

Standard Perspective menu actions

  • Extra Perspective-like action group (VIEW_EXT)

Standard Workbench menu actions

  • Start group (WB_START)
  • End group (WB_END)
  • Extra Build-like action group (BUILD_EXT)
  • Build action (BUILD)
  • Rebuild All action (REBUILD_ALL)

Standard Window menu actions

  • Extra Window-like action group (WINDOW_EXT)

Standard Help menu actions

  • Start group (HELP_START)
  • End group (HELP_END)
  • About action (ABOUT)

Standard pop-up menu groups

  • Managing group (GROUP_MANAGING)
  • Reorganize group (GROUP_REORGANIZE)
  • Add group (GROUP_ADD)
  • File group (GROUP_FILE)

你可能感兴趣的:(eclipse rcp)