001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package org.terracotta.dso.editors;
005:
006: import org.eclipse.jface.action.Action;
007: import org.eclipse.jface.action.IAction;
008: import org.eclipse.jface.action.IMenuManager;
009: import org.eclipse.jface.action.IToolBarManager;
010: import org.eclipse.jface.action.MenuManager;
011: import org.eclipse.jface.action.Separator;
012: import org.eclipse.jface.dialogs.MessageDialog;
013: import org.eclipse.ui.IActionBars;
014: import org.eclipse.ui.IEditorPart;
015: import org.eclipse.ui.IWorkbenchActionConstants;
016: import org.eclipse.ui.PlatformUI;
017: import org.eclipse.ui.actions.ActionFactory;
018: import org.eclipse.ui.ide.IDE;
019: import org.eclipse.ui.ide.IDEActionFactory;
020: import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
021: import org.eclipse.ui.texteditor.ITextEditor;
022: import org.eclipse.ui.texteditor.ITextEditorActionConstants;
023:
024: public class ConfigurationEditorContributor extends
025: MultiPageEditorActionBarContributor {
026: private IEditorPart activeEditorPart;
027: private Action sampleAction;
028:
029: public ConfigurationEditorContributor() {
030: super ();
031: createActions();
032: }
033:
034: protected IAction getAction(ITextEditor editor, String actionID) {
035: return (editor == null ? null : editor.getAction(actionID));
036: }
037:
038: public void setActivePage(IEditorPart part) {
039: if (activeEditorPart == part) {
040: return;
041: }
042:
043: activeEditorPart = part;
044:
045: IActionBars actionBars = getActionBars();
046:
047: if (actionBars != null) {
048: ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
049: : null;
050:
051: actionBars.setGlobalActionHandler(ActionFactory.DELETE
052: .getId(), getAction(editor,
053: ITextEditorActionConstants.DELETE));
054: actionBars.setGlobalActionHandler(ActionFactory.UNDO
055: .getId(), getAction(editor,
056: ITextEditorActionConstants.UNDO));
057: actionBars.setGlobalActionHandler(ActionFactory.REDO
058: .getId(), getAction(editor,
059: ITextEditorActionConstants.REDO));
060: actionBars.setGlobalActionHandler(
061: ActionFactory.CUT.getId(), getAction(editor,
062: ITextEditorActionConstants.CUT));
063: actionBars.setGlobalActionHandler(ActionFactory.COPY
064: .getId(), getAction(editor,
065: ITextEditorActionConstants.COPY));
066: actionBars.setGlobalActionHandler(ActionFactory.PASTE
067: .getId(), getAction(editor,
068: ITextEditorActionConstants.PASTE));
069: actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL
070: .getId(), getAction(editor,
071: ITextEditorActionConstants.SELECT_ALL));
072: actionBars.setGlobalActionHandler(ActionFactory.FIND
073: .getId(), getAction(editor,
074: ITextEditorActionConstants.FIND));
075: actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK
076: .getId(), getAction(editor,
077: IDEActionFactory.BOOKMARK.getId()));
078: actionBars.updateActionBars();
079: }
080: }
081:
082: private void createActions() {
083: sampleAction = new Action() {
084: public void run() {
085: MessageDialog.openInformation(null, "Tc Plug-in",
086: "Sample Action Executed");
087: }
088: };
089: sampleAction.setText("Sample Action");
090: sampleAction.setToolTipText("Sample Action tool tip");
091: sampleAction.setImageDescriptor(PlatformUI.getWorkbench()
092: .getSharedImages().getImageDescriptor(
093: IDE.SharedImages.IMG_OBJS_TASK_TSK));
094: }
095:
096: public void contributeToMenu(IMenuManager manager) {
097: IMenuManager menu = new MenuManager("Editor &Menu");
098:
099: manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS,
100: menu);
101: menu.add(sampleAction);
102: }
103:
104: public void contributeToToolBar(IToolBarManager manager) {
105: manager.add(new Separator());
106: manager.add(sampleAction);
107: }
108: }
|