1 11 package org.eclipse.ui.internal.part; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.action.MenuManager; 16 import org.eclipse.jface.viewers.ISelectionChangedListener; 17 import org.eclipse.jface.viewers.ISelectionProvider; 18 import org.eclipse.jface.viewers.SelectionChangedEvent; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.ui.IActionBars; 21 import org.eclipse.ui.IEditorActionBarContributor; 22 import org.eclipse.ui.IEditorSite; 23 import org.eclipse.ui.IKeyBindingService; 24 import org.eclipse.ui.IViewSite; 25 import org.eclipse.ui.IWorkbenchPage; 26 import org.eclipse.ui.IWorkbenchPart; 27 import org.eclipse.ui.IWorkbenchPartSite; 28 import org.eclipse.ui.IWorkbenchWindow; 29 import org.eclipse.ui.internal.PartSite; 30 31 34 public class CompatibilityPartSite implements IWorkbenchPartSite, IViewSite, IEditorSite { 35 private ArrayList menuExtenders; 36 private IWorkbenchPart part; 37 private ISelectionProvider selectionProvider; 38 private IActionBars actionBars; 39 private IEditorActionBarContributor actionBarContributor; 40 private StandardWorkbenchServices services; 41 42 private ISelectionChangedListener selectionChangeListener = new ISelectionChangedListener() { 43 46 public void selectionChanged(SelectionChangedEvent event) { 47 services.getSelectionHandler().setSelection(event.getSelection()); 48 } 49 }; 50 51 59 public CompatibilityPartSite(StandardWorkbenchServices services, IWorkbenchPart part, 60 IEditorActionBarContributor actionBarContributor, IActionBars actionBars) { 61 super(); 62 this.services = services; 63 this.part = part; 64 this.actionBarContributor = actionBarContributor; 65 this.actionBars = actionBars; 66 } 67 70 public String getId() { 71 return services.getDescriptor().getId(); 72 } 73 74 77 public String getPluginId() { 78 return services.getPluginBundle().getSymbolicName(); 79 } 80 81 84 public String getRegisteredName() { 85 return services.getDescriptor().getLabel(); 86 } 87 88 91 public void registerContextMenu(MenuManager menuManager, 92 ISelectionProvider selProvider) { 93 registerContextMenu(getId(), menuManager, selProvider); 94 } 95 96 99 public void registerContextMenu(String menuID, MenuManager menuMgr, 100 ISelectionProvider selProvider) { 101 if (menuExtenders == null) { 102 menuExtenders = new ArrayList (1); 103 } 104 105 PartSite.registerContextMenu(menuID, menuMgr, selProvider, true, part, 106 menuExtenders); 107 } 108 109 112 public IKeyBindingService getKeyBindingService() { 113 return services.getKeyBindingService(); 114 } 115 116 119 public IWorkbenchPage getPage() { 120 return services.getPage(); 121 } 122 123 126 public ISelectionProvider getSelectionProvider() { 127 return selectionProvider; 128 } 129 130 133 public Shell getShell() { 134 return getWorkbenchWindow().getShell(); 135 } 136 137 140 public IWorkbenchWindow getWorkbenchWindow() { 141 return getPage().getWorkbenchWindow(); 142 } 143 144 147 public void setSelectionProvider(ISelectionProvider provider) { 148 if (selectionProvider != null) { 149 selectionProvider.removeSelectionChangedListener(selectionChangeListener); 150 } 151 152 selectionProvider = provider; 153 154 if (selectionProvider != null) { 155 selectionProvider.addSelectionChangedListener(selectionChangeListener); 156 services.getSelectionHandler().setSelection(provider.getSelection()); 157 } else { 158 provider.setSelection(null); 159 } 160 161 } 162 163 166 public Object getAdapter(Class adapter) { 167 return services.getAdapter(adapter); 168 } 169 170 173 public IWorkbenchPart getPart() { 174 return part; 175 } 176 177 180 public IEditorActionBarContributor getActionBarContributor() { 181 return actionBarContributor; 182 } 183 184 187 public IActionBars getActionBars() { 188 return actionBars; 189 } 190 191 194 public String getSecondaryId() { 195 return services.getSecondaryId().getSecondaryId(); 196 } 197 198 public final void registerContextMenu(final String menuId, 199 final MenuManager menuManager, 200 final ISelectionProvider selectionProvider, 201 final boolean includeEditorInput) { 202 if (menuExtenders == null) { 203 menuExtenders = new ArrayList (1); 204 } 205 206 PartSite.registerContextMenu(menuId, menuManager, selectionProvider, 207 includeEditorInput, part, menuExtenders); 208 } 209 210 public final void registerContextMenu(final MenuManager menuManager, 211 final ISelectionProvider selectionProvider, 212 final boolean includeEditorInput) { 213 registerContextMenu(getId(), menuManager, selectionProvider, 214 includeEditorInput); 215 } 216 } 217 | Popular Tags |