1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 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 31 public class EditorSite extends PartSite implements IEditorSite { 32 34 private EditorDescriptor desc; 35 36 38 private SubActionBars ab = null; 39 40 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 setId(desc.getId()); 54 setRegisteredName(desc.getLabel()); 55 } 56 57 initializeDefaultServices(); 59 } 60 61 64 private void initializeDefaultServices() { 65 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 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 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 130 public IEditorPart getEditorPart() { 131 return (IEditorPart) getPart(); 132 } 133 134 public EditorDescriptor getEditorDescriptor() { 135 return desc; 136 } 137 138 protected String getInitialScopeId() { 139 return "org.eclipse.ui.textEditorScope"; } 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 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, selectionProvider, 166 includeEditorInput, getPart(), menuExtenders); 167 } 168 } 169 | Popular Tags |