001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.project.ui.internal;
016:
017: import org.eclipse.jface.action.IAction;
018: import org.eclipse.jface.action.ICoolBarManager;
019: import org.eclipse.jface.action.IMenuManager;
020: import org.eclipse.jface.action.IStatusLineManager;
021: import org.eclipse.jface.action.IToolBarManager;
022: import org.eclipse.jface.action.MenuManager;
023: import org.eclipse.jface.viewers.ISelectionProvider;
024: import org.eclipse.swt.widgets.Shell;
025: import org.eclipse.ui.IActionBars;
026: import org.eclipse.ui.IActionBars2;
027: import org.eclipse.ui.IEditorActionBarContributor;
028: import org.eclipse.ui.IEditorSite;
029: import org.eclipse.ui.IKeyBindingService;
030: import org.eclipse.ui.IViewSite;
031: import org.eclipse.ui.IWorkbenchPage;
032: import org.eclipse.ui.IWorkbenchPart;
033: import org.eclipse.ui.IWorkbenchPartSite;
034: import org.eclipse.ui.IWorkbenchWindow;
035: import org.eclipse.ui.services.IServiceLocator;
036:
037: /**
038: * Primarily used so the action bars returned by this is
039: * a MapEditorActionBars
040: *
041: * @author Jesse
042: * @since 1.1.0
043: */
044: public class MapEditorSite implements IEditorSite, IViewSite {
045:
046: IWorkbenchPartSite delegate;
047: private MapEditor editor;
048:
049: public MapEditorSite(IWorkbenchPartSite original, MapEditor editor) {
050: delegate = original;
051: this .editor = editor;
052: }
053:
054: public IEditorActionBarContributor getActionBarContributor() {
055: if (delegate instanceof IEditorSite) {
056: return ((IEditorSite) delegate).getActionBarContributor();
057: }
058: throw new IllegalStateException(
059: "delegate is not a IEditorSite!!!"); //$NON-NLS-1$
060: }
061:
062: public IActionBars getActionBars() {
063: if (delegate instanceof IEditorSite) {
064: return new MapEditorActionBars(
065: (IActionBars2) ((IEditorSite) delegate)
066: .getActionBars(), editor);
067: }
068: if (delegate instanceof IViewSite) {
069: return new MapEditorActionBars(
070: (IActionBars2) ((IViewSite) delegate)
071: .getActionBars(), editor);
072: }
073: throw new IllegalStateException(
074: "delegate is not a IEditorSite!!!!"); //$NON-NLS-1$
075: }
076:
077: public void registerContextMenu(MenuManager menuManager,
078: ISelectionProvider selectionProvider,
079: boolean includeEditorInput) {
080: if (delegate instanceof IEditorSite) {
081: ((IEditorSite) delegate).registerContextMenu(menuManager,
082: selectionProvider, includeEditorInput);
083: return;
084: }
085: throw new IllegalStateException(
086: "delegate is not a IEditorSite!!!!"); //$NON-NLS-1$
087: }
088:
089: public void registerContextMenu(String menuId,
090: MenuManager menuManager,
091: ISelectionProvider selectionProvider,
092: boolean includeEditorInput) {
093: if (delegate instanceof IEditorSite) {
094: ((IEditorSite) delegate).registerContextMenu(menuId,
095: menuManager, selectionProvider, includeEditorInput);
096: return;
097: }
098: throw new IllegalStateException(
099: "delegate is not a IEditorSite!!!!"); //$NON-NLS-1$
100: }
101:
102: public Object getAdapter(Class adapter) {
103: return delegate.getAdapter(adapter);
104: }
105:
106: public String getId() {
107: return delegate.getId();
108: }
109:
110: public IKeyBindingService getKeyBindingService() {
111: return delegate.getKeyBindingService();
112: }
113:
114: public IWorkbenchPage getPage() {
115: return delegate.getPage();
116: }
117:
118: public IWorkbenchPart getPart() {
119: return delegate.getPart();
120: }
121:
122: public String getPluginId() {
123: return delegate.getPluginId();
124: }
125:
126: public String getRegisteredName() {
127: return delegate.getRegisteredName();
128: }
129:
130: public ISelectionProvider getSelectionProvider() {
131: return delegate.getSelectionProvider();
132: }
133:
134: // public Object getService( Class api ) {
135: // return delegate.getService(api);
136: // }
137:
138: public Shell getShell() {
139: return delegate.getShell();
140: }
141:
142: public IWorkbenchWindow getWorkbenchWindow() {
143: return delegate.getWorkbenchWindow();
144: }
145:
146: // public boolean hasService( Class api ) {
147: // return delegate.hasService(api);
148: // }
149:
150: public void registerContextMenu(MenuManager menuManager,
151: ISelectionProvider selectionProvider) {
152: delegate.registerContextMenu(menuManager, selectionProvider);
153: }
154:
155: public void registerContextMenu(String menuId,
156: MenuManager menuManager,
157: ISelectionProvider selectionProvider) {
158: delegate.registerContextMenu(menuId, menuManager,
159: selectionProvider);
160: }
161:
162: public void setSelectionProvider(ISelectionProvider provider) {
163: delegate.setSelectionProvider(provider);
164: }
165:
166: public String getSecondaryId() {
167: if (delegate instanceof IViewSite) {
168: return ((IViewSite) delegate).getSecondaryId();
169: }
170: throw new IllegalStateException(
171: "delegate is not a IViewSite!!!!"); //$NON-NLS-1$
172: }
173:
174: private static class MapEditorActionBars implements IActionBars2 {
175: MapEditor editor;
176: private IActionBars2 actionBars;
177:
178: public MapEditorActionBars(IActionBars2 actionBars,
179: MapEditor editor) {
180: this .editor = editor;
181: this .actionBars = actionBars;
182: }
183:
184: public void clearGlobalActionHandlers() {
185: actionBars.clearGlobalActionHandlers();
186: }
187:
188: public IAction getGlobalActionHandler(String actionId) {
189: return actionBars.getGlobalActionHandler(actionId);
190: }
191:
192: public IMenuManager getMenuManager() {
193: return actionBars.getMenuManager();
194: }
195:
196: public IServiceLocator getServiceLocator() {
197: return actionBars.getServiceLocator();
198: }
199:
200: public IStatusLineManager getStatusLineManager() {
201: return editor.statusLineManager;
202: }
203:
204: public IToolBarManager getToolBarManager() {
205: return actionBars.getToolBarManager();
206: }
207:
208: public void setGlobalActionHandler(String actionId,
209: IAction handler) {
210: actionBars.setGlobalActionHandler(actionId, handler);
211: }
212:
213: public void updateActionBars() {
214: actionBars.updateActionBars();
215: }
216:
217: public ICoolBarManager getCoolBarManager() {
218: return actionBars.getCoolBarManager();
219: }
220: }
221:
222: public Object getService(Class api) {
223: return delegate.getService(api);
224: }
225:
226: public boolean hasService(Class api) {
227: return delegate.hasService(api);
228: }
229: }
|