fd36893be4d51f679ea52a066f20ff826e8160ae
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / org / eclipse / webbrowser / internal / WebBrowserEditorActionBarContributor.java
1 /**
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved.   This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  */
11 package org.eclipse.webbrowser.internal;
12
13 import org.eclipse.ui.*;
14 import org.eclipse.ui.actions.ActionFactory;
15 /**
16  * ActionBarContributor for the Web browser.
17  * Just adds cut, copy, paste actions.
18  */
19 public class WebBrowserEditorActionBarContributor implements IEditorActionBarContributor {
20         protected IActionBars actionBars;
21
22         /**
23          * WebBrowserEditorActionBarContributor constructor comment.
24          */
25         public WebBrowserEditorActionBarContributor() {
26                 super();
27         }
28
29         /**
30          * Initializes this contributor, which is expected to add contributions as
31          * required to the given action bars and global action handlers.
32          *
33          * @param bars the action bars
34          */
35         public void init(IActionBars bars, IWorkbenchPage page) {
36                 this.actionBars = bars;
37         }
38
39         /**
40          * Sets the active editor for the contributor.  
41          * Implementors should disconnect from the old editor, connect to the 
42          * new editor, and update the actions to reflect the new editor.
43          *
44          * @param targetEditor the new editor target
45          */
46         public void setActiveEditor(IEditorPart targetEditor) {
47                 if (targetEditor instanceof WebBrowserEditor) {
48                         WebBrowserEditor editor = (WebBrowserEditor) targetEditor;
49
50                         actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), editor.getCopyAction());
51                         actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), editor.getCutAction());
52                         actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), editor.getPasteAction());
53
54                         editor.updateActions();
55                 }
56         }
57
58         /**
59          * Disposes this contributor. 
60          */
61         public void dispose() { }
62 }