下面列出了怎么用org.eclipse.ui.actions.ActionFactory的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void setActiveEditor(final IEditorPart activeEditor) {
// XXX: We need to perform instance-of check here, even if
// FXEditorActionBarContributor is bound to AbstractFXEditor alone.
// This is because activeEditor may for instance also be of type
// org.eclipse.ui.internal.ErrorEditorPart when the opened resource is
// out of sync with the file system.
if (activeEditor instanceof AbstractFXEditor) {
registerUndoRedoActions(activeEditor);
DeleteAction deleteAction = (DeleteAction) activeEditor
.getAdapter(DeleteAction.class);
if (deleteAction != null) {
getActionBars().setGlobalActionHandler(
ActionFactory.DELETE.getId(), deleteAction);
}
IAction selectAllAction = (IAction) activeEditor
.getAdapter(SelectAllAction.class);
if (selectAllAction != null) {
getActionBars().setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(), selectAllAction);
}
}
}
protected void makeActions(IWorkbenchWindow window) {
this.window = window;
this.saveBTAction = ActionFactory.SAVE.create(this.window);
this.saveBTAsAction = ActionFactory.SAVE_AS.create(this.window);
this.exportAsCppAction = new DialogExportAsCppAction(this.window);
this.openBTAction = new DialogOpenBTAction(this.window);
this.newBTAction = new NewBTAction();
this.loadMMPMDomainAction = new DialogLoadMMPMDomainAction(this.window);
this.viewsList = ContributionItemFactory.VIEWS_SHORTLIST.create(this.window);
this.aboutAction = ActionFactory.ABOUT.create(this.window);
/* For key bindings and for copy and paste actions... */
this.register(this.saveBTAction);
this.register(ActionFactory.COPY.create(this.window));
this.register(ActionFactory.PASTE.create(this.window));
}
/**
* Reset the current perspective
*/
@After
public void resetPerspective() {
SWTBotView viewBot = fViewBot;
if (viewBot != null) {
viewBot.close();
}
/*
* UI Thread executes the reset perspective action, which opens a shell
* to confirm the action. The current thread will click on the 'Yes'
* button
*/
Runnable runnable = () -> SWTBotUtils.anyButtonOf(fBot, "Yes", "Reset Perspective").click();
UIThreadRunnable.asyncExec(() -> {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
ActionFactory.RESET_PERSPECTIVE.create(activeWorkbenchWindow).run();
});
runnable.run();
}
/**
* Constructs an action for pasting resource.
*
* @param page
* the resource explorer page
* @param clipboard
* the clipboard for pasting resource
*/
public PasteResourceAction( LibraryExplorerTreeViewPage page,
Clipboard clipboard )
{
super( Messages.getString( "PasteLibraryAction.Text" ), page ); //$NON-NLS-1$
this.clipboard = clipboard;
setId( ActionFactory.PASTE.getId( ) );
setAccelerator( SWT.CTRL | 'V' );
setImageDescriptor( PlatformUI.getWorkbench( )
.getSharedImages( )
.getImageDescriptor( ISharedImages.IMG_TOOL_PASTE ) );
setDisabledImageDescriptor( PlatformUI.getWorkbench( )
.getSharedImages( )
.getImageDescriptor( ISharedImages.IMG_TOOL_PASTE_DISABLED ) );
}
public void updateGlobalActionHandler() {
if (actionBar == null) {
return;
}
preCutAction = actionBar.getGlobalActionHandler(ActionFactory.CUT.getId());
actionBar.setGlobalActionHandler(ActionFactory.CUT.getId(), textCutAction);
preCopyAction = actionBar.getGlobalActionHandler(ActionFactory.COPY.getId());
actionBar.setGlobalActionHandler(ActionFactory.COPY.getId(), textCopyAction);
prePasteAction= actionBar.getGlobalActionHandler(ActionFactory.PASTE.getId());
actionBar.setGlobalActionHandler(ActionFactory.PASTE.getId(), textPasteAction);
preUndoAction = actionBar.getGlobalActionHandler(ActionFactory.UNDO.getId());
actionBar.setGlobalActionHandler(ActionFactory.UNDO.getId(), textUndoAction);
preRedoAction = actionBar.getGlobalActionHandler(ActionFactory.REDO.getId());
actionBar.setGlobalActionHandler(ActionFactory.REDO.getId(), textRedoAction);
// actionBar.setGlobalActionHandler(ActionFactory.FIND.getId(), textFindReplaceAction);
if (viewer != null && viewer.getTextWidget().isFocusControl()) {
updateActionsEnableState();
} else {
actionBar.updateActionBars();
}
}
private void makeActions() {
executeQueryAction = new ExecuteQueryAction(this, null, false);
explainQueryAction = new ExecuteQueryAction(this, null, true);
commentLineAction = new CommentLineAction(queryString);
IWorkbenchWindow window = this.getEditorSite().getWorkbenchWindow();
ActionFactory.IWorkbenchAction globalAction = ActionFactory.COPY.create(window);
this.copyQueryStringAction = new Action() {
public void run() {
CalcitePane.this.queryString.copy();
}
};
this.copyQueryStringAction.setAccelerator(globalAction.getAccelerator());
this.contentAssistAction = new Action() {
@Override
public void run() {
queryViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
}
};
}
@Override
public void setActionBars(IActionBars actionBars) {
// Override the undo and redo global action handlers
// to use the contributor action handlers
IActionBars partActionBars = null;
if (contributor instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart) contributor;
partActionBars = editorPart.getEditorSite().getActionBars();
} else if (contributor instanceof IViewPart) {
IViewPart viewPart = (IViewPart) contributor;
partActionBars = viewPart.getViewSite().getActionBars();
}
if (partActionBars != null) {
IAction action = partActionBars.getGlobalActionHandler(ActionFactory.UNDO
.getId());
if (action != null) {
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), action);
}
action = partActionBars.getGlobalActionHandler(ActionFactory.REDO
.getId());
if (action != null) {
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), action);
}
}
}
/**
* �R���X�g���N�^
*
* @param part
*/
public PasteAction(IWorkbenchPart part) {
super(part);
this.setText(ResourceString.getResourceString("action.title.paste"));
ISharedImages sharedImages = PlatformUI.getWorkbench()
.getSharedImages();
setImageDescriptor(sharedImages
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
setDisabledImageDescriptor(sharedImages
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
this.setId(ActionFactory.PASTE.getId());
ERDiagramEditor editor = (ERDiagramEditor) part;
this.editor = editor;
}
private void resetAction(ActionRegistry registry) {
if (getSite() == null) {
return;
}
final IActionBars bars = getSite().getActionBars();
String id = ActionFactory.UNDO.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
id = ActionFactory.REDO.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
id = ActionFactory.DELETE.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
bars.updateActionBars();
}
private void fillActionBars() {
IActionBars actionBars = getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshSingleElementAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), fRemoveFromViewAction);
IToolBarManager toolBar = actionBars.getToolBarManager();
fActionGroups.fillActionBars(actionBars);
toolBar.add(fRefreshViewAction);
toolBar.add(fCancelSearchAction);
for (int i = 0; i < fToggleCallModeActions.length; i++) {
toolBar.add(fToggleCallModeActions[i]);
}
toolBar.add(fHistoryDropDownAction);
toolBar.add(fPinViewAction);
}
public CopyNameAction(TreeViewer treeViewer) {
super(Messages.AbapGitStaging_action_copy);
updateSelection((IStructuredSelection) treeViewer.getSelection());
setToolTipText(Messages.AbapGitStaging_action_copy);
setActionDefinitionId(ActionFactory.COPY.getCommandId());
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
this.treeViewer = treeViewer;
}
private void makeActions() {
this.actionCopy = new Action() {
public void run() {
copy();
}
};
this.actionCopy.setText(Messages.AbapGitView_action_copy);
this.actionCopy.setToolTipText(Messages.AbapGitView_action_copy);
this.actionCopy.setActionDefinitionId(ActionFactory.COPY.getCommandId());
this.actionCopy.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
}
protected void makeActions(final IWorkbenchWindow window) {
// Creates the actions and registers them.
// Registering is needed to ensure that key bindings work.
// The corresponding commands keybindings are defined in the plugin.xml
// file.
// Registering also provides automatic disposal of the actions when
// the window is closed.
exitAction = ActionFactory.QUIT.create(window);
register(exitAction);
preferenceAction=ActionFactory.PREFERENCES.create(window);
register(preferenceAction);
}
/**
* Handles all global actions
*/
private void handleGlobalAction( )
{
IPageSite pageSite = page == null ? null : page.getSite( );
IActionBars actionBars = pageSite == null ? null
: pageSite.getActionBars( );
if ( actionBars != null )
{
String copyID = ActionFactory.COPY.getId( );
String pasteID = ActionFactory.PASTE.getId( );
String deleteID = ActionFactory.DELETE.getId( );
String moveID = ActionFactory.MOVE.getId( );
String renameID = ActionFactory.RENAME.getId( );
String refreshID = ActionFactory.REFRESH.getId( );
actionBars.setGlobalActionHandler( copyID, copyResourceAction );
actionBars.setGlobalActionHandler( pasteID, pasteResourceAction );
actionBars.setGlobalActionHandler( deleteID, deleteResourceAction );
actionBars.setGlobalActionHandler( moveID, moveResourceAction );
actionBars.setGlobalActionHandler( renameID, renameResourceAction );
actionBars.setGlobalActionHandler( refreshID, refreshExplorerAction );
IMenuManager menuManager = actionBars.getMenuManager( );
IToolBarManager toolBarManager = actionBars.getToolBarManager( );
if ( menuManager != null )
{
menuManager.add( filterAction );
}
if ( toolBarManager != null )
{
toolBarManager.add( refreshExplorerAction );
}
}
}
@Override
public void dispose() {
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
IActionBars bars = null;
if(part instanceof IViewPart){
bars = ((IViewPart)part).getViewSite().getActionBars();
if(bars != null){
bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), null);
bars.setGlobalActionHandler(ActionFactory.REDO.getId(), null);
}
}
if(!isDisposed()){
super.dispose();
}
}
protected void fillToolbar(IToolBarManager tbm) {
tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, showNextAction);
tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, showPreviousAction);
IActionBars actionBars = getSite().getActionBars();
if (actionBars != null) {
actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), showNextAction);
actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), showPreviousAction);
}
tbm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, expandAllAction);
tbm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, collapseAllAction);
}
protected void contextMenuAboutToShow(IMenuManager menuManager) {
super.contextMenuAboutToShow(menuManager);
menuManager.add(fScrollLockAction);
XdsConsoleViewer viewer = (XdsConsoleViewer) getViewer();
if (!viewer.isReadOnly()) {
menuManager.remove(ActionFactory.CUT.getId());
menuManager.remove(ActionFactory.PASTE.getId());
}
}
/**
* Create actions for this view and registers at the action bars of the
* view's site.
*/
protected void createActions() {
IViewSite site = getViewSite();
IActionBars actionBars = site.getActionBars();
undoRedoActionGroup = new UndoRedoActionGroup(getSite(),
(IUndoContext) getAdapter(IUndoContext.class), true);
undoRedoActionGroup.fillActionBars(actionBars);
deleteAction = new DeleteAction();
getContentViewer().setAdapter(deleteAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
deleteAction);
selectAllAction = new SelectAllAction();
getContentViewer().setAdapter(selectAllAction);
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
selectAllAction);
zoomActionGroup = new ZoomActionGroup(new FitToViewportAction());
getContentViewer().setAdapter(zoomActionGroup);
fitToViewportActionGroup = new FitToViewportActionGroup();
getContentViewer().setAdapter(fitToViewportActionGroup);
scrollActionGroup = new ScrollActionGroup();
getContentViewer().setAdapter(scrollActionGroup);
IToolBarManager mgr = actionBars.getToolBarManager();
zoomActionGroup.fillActionBars(actionBars);
mgr.add(new Separator());
fitToViewportActionGroup.fillActionBars(actionBars);
mgr.add(new Separator());
scrollActionGroup.fillActionBars(actionBars);
}
private void resetAction(final ActionRegistry registry) {
// アウトライン・ページで有効にするアクション
final IActionBars bars = getSite().getActionBars();
String id = ActionFactory.UNDO.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
id = ActionFactory.REDO.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
id = ActionFactory.DELETE.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
bars.updateActionBars();
}
/**
* Sets global action handlers for: delete select all.
*
* @param actionBars the new action bars
*/
@Override
public void setActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), mDeleteAction);
getSite().getSelectionProvider().addSelectionChangedListener(mDeleteAction);
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), mSelectAllAction);
super.setActionBars(actionBars);
}
public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
// actionBars.setGlobalActionHandler(IDEActionFactory.BUILD_PROJECT.getId(), buildAction);
actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), openProjectAction);
actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), closeProjectAction);
// actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId(),
// closeUnrelatedProjectsAction);
updateActionBars();
}
/**
* �R���X�g���N�^
*
* @param part
*/
public CopyAction(IWorkbenchPart part) {
super(part);
this.setText(ResourceString.getResourceString("action.title.copy"));
ISharedImages sharedImages = PlatformUI.getWorkbench()
.getSharedImages();
setImageDescriptor(sharedImages
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
setDisabledImageDescriptor(sharedImages
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
this.setId(ActionFactory.COPY.getId());
}
@Override
public void partActivated(IWorkbenchPart part) {
if (part == this) {
final Object service = PlatformUI.getWorkbench().getService(IHandlerService.class);
fPrintHandlerActivation = ((IHandlerService) service).activateHandler(ActionFactory.PRINT.getCommandId(), fPrintActionHandler);
}
}
private void saveCurrentActions(IActionBars _actionBars) {
copy = _actionBars.getGlobalActionHandler(ActionFactory.COPY.getId());
paste = _actionBars.getGlobalActionHandler(ActionFactory.PASTE.getId());
delete = _actionBars.getGlobalActionHandler(ActionFactory.DELETE.getId());
selectAll = _actionBars.getGlobalActionHandler(ActionFactory.SELECT_ALL.getId());
cut = _actionBars.getGlobalActionHandler(ActionFactory.CUT.getId());
find = _actionBars.getGlobalActionHandler(ActionFactory.FIND.getId());
undo = _actionBars.getGlobalActionHandler(ActionFactory.UNDO.getId());
redo = _actionBars.getGlobalActionHandler(ActionFactory.REDO.getId());
}
private void restoreSavedActions(IActionBars _actionBars) {
_actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copy);
_actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), paste);
_actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), delete);
_actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAll);
_actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), cut);
_actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), find);
_actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undo);
_actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redo);
}
public void fillActionBars(IActionBars actionBars) {
// renameAction.setTextActionHandler(textActionHandler);
updateActionBars();
actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
}
public void init(ICommonActionExtensionSite anExtensionSite) {
if (anExtensionSite.getViewSite() instanceof ICommonViewerWorkbenchSite) {
IWorkbenchWindow window = ((ICommonViewerWorkbenchSite) anExtensionSite.getViewSite()).getWorkbenchWindow();
showDlgAction = ActionFactory.NEW_WIZARD_DROP_DOWN.create(window);
showDlgAction.setText(WorkbenchNavigatorMessages.actions_NewActionProvider_NewMenu_label);
contribute = true;
}
}
@Override
protected void makeActions(IWorkbenchWindow window) {
// save
saveAction = ActionFactory.SAVE.create(window);
saveAction.setText(M.Save);
saveAction.setImageDescriptor(Icon.SAVE.descriptor());
saveAction.setDisabledImageDescriptor(Icon.SAVE_DISABLED.descriptor());
// save as
saveAsAction = ActionFactory.SAVE_AS.create(window);
saveAsAction.setText(M.SaveAs);
saveAsAction.setImageDescriptor(Icon.SAVE_AS.descriptor());
saveAsAction.setDisabledImageDescriptor(Icon.SAVE_AS_DISABLED.descriptor());
// save all
saveAllAction = ActionFactory.SAVE_ALL.create(window);
saveAllAction.setText(M.SaveAll);
saveAllAction.setImageDescriptor(Icon.SAVE_ALL.descriptor());
saveAllAction.setDisabledImageDescriptor(Icon.SAVE_ALL_DISABLED.descriptor());
// close & close all
closeAction = ActionFactory.CLOSE.create(window);
closeAction.setText(M.Close);
closeAllAction = ActionFactory.CLOSE_ALL.create(window);
closeAllAction.setText(M.CloseAll);
// preferences
preferencesAction = ActionFactory.PREFERENCES.create(window);
preferencesAction.setImageDescriptor(Icon.PREFERENCES.descriptor());
preferencesAction.setText(M.Settings);
// other
exitAction = ActionFactory.QUIT.create(window);
exitAction.setText(M.Exit);
showViews = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
aboutAction = ActionFactory.ABOUT.create(window);
aboutAction.setText(M.AboutOpenLCA);
}
private void createBodyMenu() {
MenuManager menuMgr = new MenuManager();
bodyMenu = menuMgr.createContextMenu(table.getShell());
menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
ActionFactory.CUT.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages
.getString("tmxedtior.bodyMenuConfiguration.cut"), null, null,
CommandContributionItem.STYLE_PUSH, null, false)));
menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
ActionFactory.COPY.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages
.getString("tmxedtior.bodyMenuConfiguration.copy"), null, null,
CommandContributionItem.STYLE_PUSH, null, false)));
menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
ActionFactory.PASTE.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages
.getString("tmxedtior.bodyMenuConfiguration.paste"), null, null,
CommandContributionItem.STYLE_PUSH, null, false)));
menuMgr.add(new Separator());
menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
"net.heartsome.cat.te.tmxeditor.command.addtu", Collections.EMPTY_MAP, null, null, null, null, null,
null, CommandContributionItem.STYLE_PUSH, null, false)));
menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
"net.heartsome.cat.te.tmxeditor.command.deletetu", Collections.EMPTY_MAP, null, null, null, null, null,
null, CommandContributionItem.STYLE_PUSH, null, false)));
menuMgr.add(new Separator());
menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
"net.heartsome.cat.te.ui.command.cleanSelectInnerTag", Collections.EMPTY_MAP, null, null, null, null, null,
null, CommandContributionItem.STYLE_PUSH, null, false)));
}
@Override
public void setActivePage(IEditorPart part) {
IActionBars actionBars = getActionBars();
if (actionBars != null) {
ITextEditor textEditor = (part instanceof XMLEditor) ? (ITextEditor) part : null;
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction1(textEditor,
ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction1(textEditor,
ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction1(textEditor,
ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction1(textEditor,
ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction1(textEditor,
ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction1(textEditor,
ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction1(textEditor,
ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), getAction1(textEditor,
ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction1(textEditor,
IDEActionFactory.BOOKMARK.getId()));
actionBars.updateActionBars();
}
}