Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / net / sourceforge / phpeclipse / 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 net.sourceforge.phpeclipse.webbrowser.internal;
12
13 import org.eclipse.ui.IActionBars;
14 import org.eclipse.ui.IEditorActionBarContributor;
15 import org.eclipse.ui.IEditorPart;
16 import org.eclipse.ui.IWorkbenchPage;
17 import org.eclipse.ui.actions.ActionFactory;
18 /**
19  * ActionBarContributor for the Web browser.
20  * Just adds cut, copy, paste actions.
21  */
22 public class WebBrowserEditorActionBarContributor implements IEditorActionBarContributor {
23         protected IActionBars actionBars;
24
25         /**
26          * WebBrowserEditorActionBarContributor constructor comment.
27          */
28         public WebBrowserEditorActionBarContributor() {
29                 super();
30         }
31
32         /**
33          * Initializes this contributor, which is expected to add contributions as
34          * required to the given action bars and global action handlers.
35          *
36          * @param bars the action bars
37          */
38         public void init(IActionBars bars, IWorkbenchPage page) {
39                 this.actionBars = bars;
40         }
41
42         /**
43          * Sets the active editor for the contributor.  
44          * Implementors should disconnect from the old editor, connect to the 
45          * new editor, and update the actions to reflect the new editor.
46          *
47          * @param targetEditor the new editor target
48          */
49         public void setActiveEditor(IEditorPart targetEditor) {
50                 if (targetEditor instanceof WebBrowserEditor) {
51                         WebBrowserEditor editor = (WebBrowserEditor) targetEditor;
52
53                         actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), editor.getCopyAction());
54                         actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), editor.getCutAction());
55                         actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), editor.getPasteAction());
56
57                         editor.updateActions();
58                 }
59         }
60
61         /**
62          * Disposes this contributor. 
63          */
64         public void dispose() { }
65 }