KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > EditorSite


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.jface.action.MenuManager;
17 import org.eclipse.jface.viewers.ISelectionProvider;
18 import org.eclipse.ui.IActionBars2;
19 import org.eclipse.ui.IEditorActionBarContributor;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IEditorReference;
22 import org.eclipse.ui.IEditorSite;
23 import org.eclipse.ui.SubActionBars;
24 import org.eclipse.ui.SubActionBars2;
25 import org.eclipse.ui.dnd.IDragAndDropService;
26 import org.eclipse.ui.internal.registry.EditorDescriptor;
27
28 /**
29  * An editor container manages the services for an editor.
30  */

31 public class EditorSite extends PartSite implements IEditorSite {
32     /* package */ //static final int PROP_REUSE_EDITOR = -0x101;
33

34     private EditorDescriptor desc;
35
36     //private ListenerList propChangeListeners = new ListenerList(1);
37

38     private SubActionBars ab = null;
39     
40     /**
41      * Constructs an EditorSite for an editor.
42      */

43     public EditorSite(IEditorReference ref, IEditorPart editor,
44             WorkbenchPage page, EditorDescriptor desc) {
45         super(ref, editor, page);
46         Assert.isNotNull(desc);
47         this.desc = desc;
48         
49         if (desc.getConfigurationElement() != null) {
50             setConfigurationElement(desc.getConfigurationElement());
51         } else {
52             // system external and in-place editors do not have a corresponding configuration element
53
setId(desc.getId());
54             setRegisteredName(desc.getLabel());
55         }
56
57         // Initialize the services specific to this editor site.
58
initializeDefaultServices();
59     }
60
61     /**
62      * Initialize the local services.
63      */

64     private void initializeDefaultServices() {
65         // Register an implementation of the service appropriate for the
66
// EditorSite.
67
final IDragAndDropService editorDTService = new EditorSiteDragAndDropServiceImpl();
68         serviceLocator.registerService(IDragAndDropService.class, editorDTService);
69     }
70     
71     public void setActionBars(SubActionBars bars) {
72         super.setActionBars(bars);
73         
74         if (bars instanceof IActionBars2) {
75             ab = new SubActionBars2((IActionBars2)bars, this);
76         } else {
77             ab = new SubActionBars(bars, this);
78         }
79     }
80     
81     public void activateActionBars(boolean forceVisibility) {
82         if (ab != null) {
83             ab.activate(forceVisibility);
84         }
85         super.activateActionBars(forceVisibility);
86     }
87
88     public void deactivateActionBars(boolean forceHide) {
89         if (ab != null) {
90             ab.deactivate(forceHide);
91         }
92         super.deactivateActionBars(forceHide);
93     }
94     
95     /**
96      * Returns the editor action bar contributor for this editor.
97      * <p>
98      * An action contributor is responsable for the creation of actions.
99      * By design, this contributor is used for one or more editors of the same type.
100      * Thus, the contributor returned by this method is not owned completely
101      * by the editor. It is shared.
102      * </p>
103      *
104      * @return the editor action bar contributor
105      */

106     public IEditorActionBarContributor getActionBarContributor() {
107         EditorActionBars bars = (EditorActionBars) getActionBars();
108         if (bars != null) {
109             return bars.getEditorContributor();
110         }
111         
112         return null;
113     }
114
115     /**
116      * Returns the extension editor action bar contributor for this editor.
117      */

118     public IEditorActionBarContributor getExtensionActionBarContributor() {
119         EditorActionBars bars = (EditorActionBars) getActionBars();
120         if (bars != null) {
121             return bars.getExtensionContributor();
122         }
123         
124         return null;
125     }
126
127     /**
128      * Returns the editor
129      */

130     public IEditorPart getEditorPart() {
131         return (IEditorPart) getPart();
132     }
133
134     public EditorDescriptor getEditorDescriptor() {
135         return desc;
136     }
137
138     protected String JavaDoc getInitialScopeId() {
139         return "org.eclipse.ui.textEditorScope"; //$NON-NLS-1$
140
}
141     
142     public void dispose() {
143         super.dispose();
144         
145         if (ab != null) {
146             ab.dispose();
147         }
148     }
149     
150     public final void registerContextMenu(final MenuManager menuManager,
151             final ISelectionProvider selectionProvider,
152             final boolean includeEditorInput) {
153         registerContextMenu(getId(), menuManager, selectionProvider,
154                 includeEditorInput);
155     }
156     
157     public final void registerContextMenu(final String JavaDoc menuId,
158             final MenuManager menuManager,
159             final ISelectionProvider selectionProvider,
160             final boolean includeEditorInput) {
161         if (menuExtenders == null) {
162             menuExtenders = new ArrayList JavaDoc(1);
163         }
164         
165         PartSite.registerContextMenu(menuId, menuManager, selectionProvider,
166                 includeEditorInput, getPart(), menuExtenders);
167     }
168 }
169
Popular Tags