001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.designstudio.editors.actionsequence;
014:
015: import org.eclipse.jface.action.Action;
016: import org.eclipse.jface.action.IAction;
017: import org.eclipse.jface.action.IMenuManager;
018: import org.eclipse.jface.action.IToolBarManager;
019: import org.eclipse.jface.action.MenuManager;
020: import org.eclipse.jface.action.Separator;
021: import org.eclipse.jface.wizard.WizardDialog;
022: import org.eclipse.ui.IActionBars;
023: import org.eclipse.ui.IEditorPart;
024: import org.eclipse.ui.IWorkbenchActionConstants;
025: import org.eclipse.ui.actions.ActionFactory;
026: import org.eclipse.ui.ide.IDEActionFactory;
027: import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
028: import org.eclipse.ui.texteditor.ITextEditor;
029: import org.eclipse.ui.texteditor.ITextEditorActionConstants;
030: import org.pentaho.designstudio.editors.actionsequence.wizards.ActionSequenceNewWizard;
031: import org.pentaho.designstudio.messages.Messages;
032:
033: /**
034: * Manages the installation/deinstallation of global actions for multi-page editors.
035: * Responsible for the redirection of global actions to the active editor.
036: * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
037: */
038: public class ActionSequenceEditorContributor extends
039: MultiPageEditorActionBarContributor {
040: private IEditorPart activeEditorPart;
041: private Action sampleAction;
042:
043: /**
044: * Creates a multi-page contributor.
045: */
046: public ActionSequenceEditorContributor() {
047: super ();
048: createActions();
049: }
050:
051: /**
052: * Returns the action registed with the given text editor.
053: * @return IAction or null if editor is null.
054: */
055: protected IAction getAction(ITextEditor editor, String actionID) {
056: return (editor == null ? null : editor.getAction(actionID));
057: }
058:
059: /* (non-JavaDoc)
060: * Method declared in AbstractMultiPageEditorActionBarContributor.
061: */
062:
063: public void setActivePage(IEditorPart part) {
064: if (activeEditorPart == part)
065: return;
066:
067: activeEditorPart = part;
068:
069: IActionBars actionBars = getActionBars();
070: if (actionBars != null) {
071:
072: ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
073: : null;
074:
075: actionBars.setGlobalActionHandler(ActionFactory.DELETE
076: .getId(), getAction(editor,
077: ITextEditorActionConstants.DELETE));
078: actionBars.setGlobalActionHandler(ActionFactory.UNDO
079: .getId(), getAction(editor,
080: ITextEditorActionConstants.UNDO));
081: actionBars.setGlobalActionHandler(ActionFactory.REDO
082: .getId(), getAction(editor,
083: ITextEditorActionConstants.REDO));
084: actionBars.setGlobalActionHandler(
085: ActionFactory.CUT.getId(), getAction(editor,
086: ITextEditorActionConstants.CUT));
087: actionBars.setGlobalActionHandler(ActionFactory.COPY
088: .getId(), getAction(editor,
089: ITextEditorActionConstants.COPY));
090: actionBars.setGlobalActionHandler(ActionFactory.PASTE
091: .getId(), getAction(editor,
092: ITextEditorActionConstants.PASTE));
093: actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL
094: .getId(), getAction(editor,
095: ITextEditorActionConstants.SELECT_ALL));
096: actionBars.setGlobalActionHandler(ActionFactory.FIND
097: .getId(), getAction(editor,
098: ITextEditorActionConstants.FIND));
099: actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK
100: .getId(), getAction(editor,
101: IDEActionFactory.BOOKMARK.getId()));
102: actionBars.updateActionBars();
103: }
104: }
105:
106: private void createActions() {
107: sampleAction = new Action() {
108: public void run() {
109: // create wizard
110: // create wizard dialog & launch wizard dialog
111: WizardDialog dialog = new WizardDialog(null,
112: new ActionSequenceNewWizard());
113:
114: dialog.open();
115: }
116: };
117: sampleAction
118: .setText(Messages
119: .getString("ASMultiPageEditorContributor.UI_NEW_ACTION_SEQUENCE_ACTION_TEXT")); //$NON-NLS-1$
120: sampleAction
121: .setToolTipText(Messages
122: .getString("ASMultiPageEditorContributor.UI_NEW_ACTION_SEQUENCE_ACTION_TOOLTIP")); //$NON-NLS-1$
123: sampleAction
124: .setImageDescriptor(ActionSequenceEditorPlugin
125: .getImageDescriptor(Messages
126: .getString("ASMultiPageEditorContributor.ICON_NEW_ACTION_SEQUENCE_ACTION"))); //$NON-NLS-1$
127:
128: }
129:
130: public void contributeToMenu(IMenuManager manager) {
131: IMenuManager menu = new MenuManager(
132: Messages
133: .getString("ASMultiPageEditorContributor.UI_NEW_ACTION_SEQUENCE_EDITOR_MENU")); //$NON-NLS-1$
134: manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS,
135: menu);
136: menu.add(sampleAction);
137: }
138:
139: public void contributeToToolBar(IToolBarManager manager) {
140: manager.add(new Separator());
141: manager.add(sampleAction);
142: }
143: }
|