01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.multipageeditor;
11:
12: import org.eclipse.jface.action.IAction;
13: import org.eclipse.ui.IActionBars;
14: import org.eclipse.ui.IEditorPart;
15: import org.eclipse.ui.actions.ActionFactory;
16: import org.eclipse.ui.ide.IDEActionFactory;
17: import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
18: import org.eclipse.ui.texteditor.ITextEditor;
19:
20: /**
21: * Manages the installation/deinstallation of global actions for multi-page editors.
22: * Responsible for the redirection of global actions to the active editor.
23: * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
24: */
25: public class MultiPageContributor extends
26: MultiPageEditorActionBarContributor {
27: private IEditorPart activeEditorPart;
28:
29: /**
30: * Creates a multi-page contributor.
31: */
32: public MultiPageContributor() {
33: super ();
34: }
35:
36: /**
37: * Returns the action registed with the given text editor.
38: * @return IAction or null if editor is null.
39: */
40: protected IAction getAction(ITextEditor editor, String actionID) {
41: return (editor == null ? null : editor.getAction(actionID));
42: }
43:
44: /* (non-JavaDoc)
45: * Method declared in MultiPageEditorActionBarContributor.
46: */
47: public void setActivePage(IEditorPart part) {
48: if (activeEditorPart == part)
49: return;
50:
51: activeEditorPart = part;
52:
53: IActionBars actionBars = getActionBars();
54: if (actionBars != null) {
55:
56: ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
57: : null;
58:
59: actionBars.setGlobalActionHandler(ActionFactory.DELETE
60: .getId(), getAction(editor, ActionFactory.DELETE
61: .getId()));
62: actionBars.setGlobalActionHandler(ActionFactory.UNDO
63: .getId(), getAction(editor, ActionFactory.UNDO
64: .getId()));
65: actionBars.setGlobalActionHandler(ActionFactory.REDO
66: .getId(), getAction(editor, ActionFactory.REDO
67: .getId()));
68: actionBars.setGlobalActionHandler(
69: ActionFactory.CUT.getId(), getAction(editor,
70: ActionFactory.CUT.getId()));
71: actionBars.setGlobalActionHandler(ActionFactory.COPY
72: .getId(), getAction(editor, ActionFactory.COPY
73: .getId()));
74: actionBars.setGlobalActionHandler(ActionFactory.PASTE
75: .getId(), getAction(editor, ActionFactory.PASTE
76: .getId()));
77: actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL
78: .getId(), getAction(editor,
79: ActionFactory.SELECT_ALL.getId()));
80: actionBars.setGlobalActionHandler(ActionFactory.FIND
81: .getId(), getAction(editor, ActionFactory.FIND
82: .getId()));
83: actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK
84: .getId(), getAction(editor,
85: IDEActionFactory.BOOKMARK.getId()));
86: actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK
87: .getId(), getAction(editor,
88: IDEActionFactory.ADD_TASK.getId()));
89: actionBars.updateActionBars();
90: }
91: }
92: }
|