KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > mapper > editors > ReverseEngineeringMultiPageEditorContributor


1 package org.hibernate.eclipse.mapper.editors;
2
3 import org.eclipse.jface.action.IMenuManager;
4 import org.eclipse.jface.action.IStatusLineManager;
5 import org.eclipse.jface.action.IToolBarManager;
6 import org.eclipse.ui.IActionBars;
7 import org.eclipse.ui.IEditorActionBarContributor;
8 import org.eclipse.ui.IEditorPart;
9 import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
10 import org.eclipse.wst.sse.ui.internal.ExtendedEditorActionBuilder;
11 import org.eclipse.wst.sse.ui.internal.IExtendedContributor;
12 import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor;
13 import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
14 import org.eclipse.wst.xml.ui.internal.tabletree.IDesignViewerActionBarContributor;
15 import org.eclipse.wst.xml.ui.internal.tabletree.SourcePageActionContributor;
16 import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
17
18 /**
19  * Manages the installation/deinstallation of global actions for multi-page editors.
20  * Responsible for the redirection of global actions to the active editor.
21  * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
22  */

23 public class ReverseEngineeringMultiPageEditorContributor extends MultiPageEditorActionBarContributor {
24     protected IEditorActionBarContributor designViewerActionBarContributor = null;
25     protected IEditorActionBarContributor sourceViewerActionContributor = null;
26     protected XMLMultiPageEditorPart multiPageEditor = null;
27
28     // EditorExtension
29
private static final String JavaDoc EDITOR_ID = "org.hibernate.eclipse.mapper.editors.ReverseEngineeringMultiPageEditor"; //$NON-NLS-1$
30
private IExtendedContributor extendedContributor;
31
32     public ReverseEngineeringMultiPageEditorContributor() {
33         super();
34
35         sourceViewerActionContributor = new SourcePageActionContributor();
36
37         // Read action extensions.
38
ExtendedEditorActionBuilder builder = new ExtendedEditorActionBuilder();
39         extendedContributor = builder.readActionExtensions(EDITOR_ID);
40     }
41
42     public void init(IActionBars actionBars) {
43         super.init(actionBars);
44
45         if (actionBars != null) {
46             initDesignViewerActionBarContributor(actionBars);
47             initSourceViewerActionContributor(actionBars);
48         }
49     }
50
51     protected void initDesignViewerActionBarContributor(IActionBars actionBars) {
52         if (designViewerActionBarContributor != null)
53             designViewerActionBarContributor.init(actionBars, getPage());
54     }
55
56     protected void initSourceViewerActionContributor(IActionBars actionBars) {
57         if (sourceViewerActionContributor != null)
58             sourceViewerActionContributor.init(actionBars, getPage());
59     }
60
61     public void dispose() {
62         super.dispose();
63
64         if (designViewerActionBarContributor != null)
65             designViewerActionBarContributor.dispose();
66
67         if (sourceViewerActionContributor != null)
68             sourceViewerActionContributor.dispose();
69
70         if (extendedContributor != null)
71             extendedContributor.dispose();
72     }
73
74     /**
75      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager)
76      */

77     public final void contributeToMenu(IMenuManager menu) {
78         super.contributeToMenu(menu);
79
80         addToMenu(menu);
81
82         if (extendedContributor != null)
83             extendedContributor.contributeToMenu(menu);
84     }
85
86     protected void addToMenu(IMenuManager menu) {
87     }
88
89     /**
90      * @see IExtendedContributor#contributeToPopupMenu(IMenuManager)
91      */

92     public final void contributeToPopupMenu(IMenuManager menu) {
93
94         addToPopupMenu(menu);
95
96         if (extendedContributor != null)
97             extendedContributor.contributeToPopupMenu(menu);
98     }
99
100     protected void addToPopupMenu(IMenuManager menu) {
101     }
102
103     /**
104      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager)
105      */

106     public final void contributeToToolBar(IToolBarManager toolBarManager) {
107         super.contributeToToolBar(toolBarManager);
108
109         addToToolBar(toolBarManager);
110
111         if (extendedContributor != null)
112             extendedContributor.contributeToToolBar(toolBarManager);
113     }
114
115     protected void addToToolBar(IToolBarManager toolBarManager) {
116     }
117
118     /**
119      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToStatusLine(IStatusLineManager)
120      */

121     public final void contributeToStatusLine(IStatusLineManager manager) {
122         super.contributeToStatusLine(manager);
123
124         addToStatusLine(manager);
125
126         if (extendedContributor != null)
127             extendedContributor.contributeToStatusLine(manager);
128     }
129
130     protected void addToStatusLine(IStatusLineManager manager) {
131     }
132
133     /**
134      * @see IExtendedContributor#updateToolbarActions()
135      */

136     public void updateToolbarActions() {
137         if (extendedContributor != null)
138             extendedContributor.updateToolbarActions();
139     }
140
141     public void setActiveEditor(IEditorPart targetEditor) {
142         // save multiPageEditor before calling
143
// super.setActiveEditor(targetEditor)
144
// super.setActiveEditor will call setActivePage(IEditorPart
145
// activeEditor)
146
// multiPageEditor is needed in setActivePage(IEditorPart
147
// activeEditor)
148
if (targetEditor instanceof XMLMultiPageEditorPart)
149             multiPageEditor = (XMLMultiPageEditorPart) targetEditor;
150
151         super.setActiveEditor(targetEditor);
152
153         updateToolbarActions();
154
155         if (extendedContributor != null)
156             extendedContributor.setActiveEditor(targetEditor);
157     }
158
159     public void setActivePage(IEditorPart activeEditor) {
160         // This contributor is designed for StructuredTextMultiPageEditorPart.
161
// To safe-guard this from problems caused by unexpected usage by
162
// other editors, the following
163
// check is added.
164
if (multiPageEditor != null) {
165             if (activeEditor != null && activeEditor instanceof StructuredTextEditor)
166                 activateSourcePage(activeEditor);
167             else
168                 activateDesignPage(activeEditor);
169         }
170
171         updateToolbarActions();
172
173         IActionBars actionBars = getActionBars();
174         if (actionBars != null) {
175             // update menu bar and tool bar
176
actionBars.updateActionBars();
177         }
178     }
179
180     protected void activateDesignPage(IEditorPart activeEditor) {
181         if (designViewerActionBarContributor != null && designViewerActionBarContributor instanceof IDesignViewerActionBarContributor) {
182             designViewerActionBarContributor.setActiveEditor(multiPageEditor);
183         }
184
185         if (sourceViewerActionContributor != null && sourceViewerActionContributor instanceof ISourceViewerActionBarContributor) {
186             // if design page is not really an IEditorPart, activeEditor ==
187
// null, so pass in multiPageEditor instead (d282414)
188
if (activeEditor == null) {
189                 sourceViewerActionContributor.setActiveEditor(multiPageEditor);
190             } else {
191                 sourceViewerActionContributor.setActiveEditor(activeEditor);
192             }
193             ((ISourceViewerActionBarContributor) sourceViewerActionContributor).setViewerSpecificContributionsEnabled(false);
194         }
195     }
196
197     protected void activateSourcePage(IEditorPart activeEditor) {
198         if (designViewerActionBarContributor != null && designViewerActionBarContributor instanceof IDesignViewerActionBarContributor) {
199             designViewerActionBarContributor.setActiveEditor(multiPageEditor);
200         }
201
202         if (sourceViewerActionContributor != null && sourceViewerActionContributor instanceof ISourceViewerActionBarContributor) {
203             sourceViewerActionContributor.setActiveEditor(activeEditor);
204             ((ISourceViewerActionBarContributor) sourceViewerActionContributor).setViewerSpecificContributionsEnabled(true);
205         }
206     }
207 }
208
Popular Tags