001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.core.runtime.Assert;
015: import org.eclipse.jface.action.MenuManager;
016: import org.eclipse.jface.viewers.ISelectionProvider;
017: import org.eclipse.ui.IActionBars2;
018: import org.eclipse.ui.IEditorActionBarContributor;
019: import org.eclipse.ui.IEditorPart;
020: import org.eclipse.ui.IEditorReference;
021: import org.eclipse.ui.IEditorSite;
022: import org.eclipse.ui.SubActionBars;
023: import org.eclipse.ui.SubActionBars2;
024: import org.eclipse.ui.dnd.IDragAndDropService;
025: import org.eclipse.ui.internal.registry.EditorDescriptor;
026:
027: /**
028: * An editor container manages the services for an editor.
029: */
030: public class EditorSite extends PartSite implements IEditorSite {
031: /* package *///static final int PROP_REUSE_EDITOR = -0x101;
032: private EditorDescriptor desc;
033:
034: //private ListenerList propChangeListeners = new ListenerList(1);
035:
036: private SubActionBars ab = null;
037:
038: /**
039: * Constructs an EditorSite for an editor.
040: */
041: public EditorSite(IEditorReference ref, IEditorPart editor,
042: WorkbenchPage page, EditorDescriptor desc) {
043: super (ref, editor, page);
044: Assert.isNotNull(desc);
045: this .desc = desc;
046:
047: if (desc.getConfigurationElement() != null) {
048: setConfigurationElement(desc.getConfigurationElement());
049: } else {
050: // system external and in-place editors do not have a corresponding configuration element
051: setId(desc.getId());
052: setRegisteredName(desc.getLabel());
053: }
054:
055: // Initialize the services specific to this editor site.
056: initializeDefaultServices();
057: }
058:
059: /**
060: * Initialize the local services.
061: */
062: private void initializeDefaultServices() {
063: // Register an implementation of the service appropriate for the
064: // EditorSite.
065: final IDragAndDropService editorDTService = new EditorSiteDragAndDropServiceImpl();
066: serviceLocator.registerService(IDragAndDropService.class,
067: editorDTService);
068: }
069:
070: public void setActionBars(SubActionBars bars) {
071: super .setActionBars(bars);
072:
073: if (bars instanceof IActionBars2) {
074: ab = new SubActionBars2((IActionBars2) bars, this );
075: } else {
076: ab = new SubActionBars(bars, this );
077: }
078: }
079:
080: public void activateActionBars(boolean forceVisibility) {
081: if (ab != null) {
082: ab.activate(forceVisibility);
083: }
084: super .activateActionBars(forceVisibility);
085: }
086:
087: public void deactivateActionBars(boolean forceHide) {
088: if (ab != null) {
089: ab.deactivate(forceHide);
090: }
091: super .deactivateActionBars(forceHide);
092: }
093:
094: /**
095: * Returns the editor action bar contributor for this editor.
096: * <p>
097: * An action contributor is responsable for the creation of actions.
098: * By design, this contributor is used for one or more editors of the same type.
099: * Thus, the contributor returned by this method is not owned completely
100: * by the editor. It is shared.
101: * </p>
102: *
103: * @return the editor action bar contributor
104: */
105: public IEditorActionBarContributor getActionBarContributor() {
106: EditorActionBars bars = (EditorActionBars) getActionBars();
107: if (bars != null) {
108: return bars.getEditorContributor();
109: }
110:
111: return null;
112: }
113:
114: /**
115: * Returns the extension editor action bar contributor for this editor.
116: */
117: public IEditorActionBarContributor getExtensionActionBarContributor() {
118: EditorActionBars bars = (EditorActionBars) getActionBars();
119: if (bars != null) {
120: return bars.getExtensionContributor();
121: }
122:
123: return null;
124: }
125:
126: /**
127: * Returns the editor
128: */
129: public IEditorPart getEditorPart() {
130: return (IEditorPart) getPart();
131: }
132:
133: public EditorDescriptor getEditorDescriptor() {
134: return desc;
135: }
136:
137: protected String getInitialScopeId() {
138: return "org.eclipse.ui.textEditorScope"; //$NON-NLS-1$
139: }
140:
141: public void dispose() {
142: super .dispose();
143:
144: if (ab != null) {
145: ab.dispose();
146: }
147: }
148:
149: public final void registerContextMenu(
150: 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 menuId,
158: final MenuManager menuManager,
159: final ISelectionProvider selectionProvider,
160: final boolean includeEditorInput) {
161: if (menuExtenders == null) {
162: menuExtenders = new ArrayList(1);
163: }
164:
165: PartSite.registerContextMenu(menuId, menuManager,
166: selectionProvider, includeEditorInput, getPart(),
167: menuExtenders);
168: }
169: }
|