Skip to main content
summaryrefslogtreecommitdiffstats
blob: d5bbe2de3d9fb0297cf65b43ff341238c148ebe8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.editors.actions;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jst.pagedesigner.IJMTConstants;
import org.eclipse.jst.pagedesigner.editors.HTMLEditor;
import org.eclipse.jst.pagedesigner.editors.SimpleGraphicalEditor;
import org.eclipse.jst.pagedesigner.ui.common.sash.NestedEditorActionBarContributor;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.sse.ui.internal.ExtendedEditorActionBuilder;
import org.eclipse.wst.sse.ui.internal.IExtendedContributor;
import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor;

/**
 * This is the actionbar contributor for HTML Editor. As HTMLEditor is
 * multipaged, so this contributor will also handle on which page currently is
 * activated.
 * 
 * @author mengbo
 */
public class PageDesignerActionBarContributor2 extends
		NestedEditorActionBarContributor implements IExtendedContributor {

	protected DesignPageActionContributor _designViewerActionBarContributor = null;

	protected ISourceViewerActionBarContributor _sourceViewerActionContributor = null;

	protected HTMLEditor _htmlEditor = null;

	// EditorExtension
	private static final String EDITOR_ID = IJMTConstants.EDITORID_HTML;

	private IExtendedContributor _extendedContributor;

	DesignerStyleActionGroup _group = new DesignerStyleActionGroup();

//	private IHTMLGraphicalViewer _viewer = null;
//
//	private IStructuredModel _model = null;

//	private final static Action action = new Action() {
//        
//	};

	public PageDesignerActionBarContributor2() {
		super();

		_sourceViewerActionContributor = new SourcePageActionContributor();
		_designViewerActionBarContributor = new DesignPageActionContributor();

		// Read action extensions.
		ExtendedEditorActionBuilder builder = new ExtendedEditorActionBuilder();
		_extendedContributor = builder.readActionExtensions(EDITOR_ID);
	}

	public void init(IActionBars actionBars) {
		super.init(actionBars);

		if (actionBars != null) {
			initCommonActionBarContributor(actionBars);
			initDesignViewerActionBarContributor(actionBars);
			initSourceViewerActionContributor(actionBars);
		}
	}

	/**
	 * @param actionBars
	 */
	private void initCommonActionBarContributor(IActionBars actionBars) {
		_group.fillActionBars(actionBars);
	}

	protected void initDesignViewerActionBarContributor(IActionBars actionBars) {
		if (_designViewerActionBarContributor != null)
			_designViewerActionBarContributor.init(actionBars, getPage());
	}

	protected void initSourceViewerActionContributor(IActionBars actionBars) {
		if (_sourceViewerActionContributor != null)
			_sourceViewerActionContributor.init(actionBars, getPage());
	}

	public void dispose() {
		super.dispose();
		if (_designViewerActionBarContributor != null) {
			_designViewerActionBarContributor.dispose();
		}
		if (_sourceViewerActionContributor != null) {
			_sourceViewerActionContributor.dispose();
		}
		if (_extendedContributor != null) {
			_extendedContributor.dispose();
		}
		if (_group != null) {
			_group.dispose();
		}
	}

	/**
	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager)
	 */
	public final void contributeToMenu(IMenuManager menu) {
		super.contributeToMenu(menu);
		addToMenu(menu);
		if (_extendedContributor != null)
			_extendedContributor.contributeToMenu(menu);
	}

	protected void addToMenu(IMenuManager menu) {
		// IMenuManager menuMgr = new MenuManager(PD_EDITOR_MENU_LABEL,
		// IJMTConstants.PD_EDITOR_MENU_ID);
		// menu.insertBefore(IWorkbenchActionConstants.M_NAVIGATE, menuMgr);
		//
		// menuMgr.add(action);
		// menuMgr.setRemoveAllWhenShown(true);
		//
		// menuMgr.addMenuListener(new IMenuListener()
		// {
		// public void menuAboutToShow(IMenuManager menuMgr)
		// {
		// PageDesignerActionConstants.addStandardActionGroups(menuMgr);
		// RelatedViewActionGroup viewMenu = new RelatedViewActionGroup();
		// viewMenu.fillContextMenu(menuMgr);
		// updateEditorMenu(menuMgr);
		// }
		// });
	}

	/**
	 * @see IExtendedContributor#contributeToPopupMenu(IMenuManager)
	 */
	public final void contributeToPopupMenu(IMenuManager menu) {
		// TODO: this method is empty addToPopupMenu(menu);
		if (_extendedContributor != null)
			_extendedContributor.contributeToPopupMenu(menu);
	}

//	protected void addToPopupMenu(IMenuManager menu) {
//        // do nothing
//	}

	/**
	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager)
	 */
	public final void contributeToToolBar(IToolBarManager toolBarManager) {
		super.contributeToToolBar(toolBarManager);
		// TODO: this method is empty addToToolBar(toolBarManager);
		if (_extendedContributor != null)
			_extendedContributor.contributeToToolBar(toolBarManager);
	}

//	protected void addToToolBar(IToolBarManager toolBarManager) {
//	}

	/**
	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToStatusLine(IStatusLineManager)
	 */
	public final void contributeToStatusLine(IStatusLineManager manager) {
		super.contributeToStatusLine(manager);
		// TODO: this method does nothing addToStatusLine(manager);
		if (_extendedContributor != null)
			_extendedContributor.contributeToStatusLine(manager);
	}

//	protected void addToStatusLine(IStatusLineManager manager) {
//	}

	/**
	 * @see IExtendedContributor#updateToolbarActions()
	 */
	public void updateToolbarActions() {
		if (_extendedContributor != null) {
			_extendedContributor.updateToolbarActions();
		}
		_group.setHTMLEditor(_htmlEditor);
	}

	public void setActiveEditor(IEditorPart targetEditor) {
		if (targetEditor instanceof HTMLEditor) {
			_htmlEditor = (HTMLEditor) targetEditor;
			//StructuredTextEditor textEditor = _htmlEditor.getTextEditor();
			// TODO: never read this._model = textEditor.getModel();
		}
		super.setActiveEditor(targetEditor);
		updateToolbarActions();
		if (_extendedContributor != null)
			_extendedContributor.setActiveEditor(targetEditor);
	}

	public void setInnerActivePage(IEditorPart activeEditor) {
		// This contributor is designed for StructuredTextMultiPageEditorPart.
		// To safe-guard this from problems caused by unexpected usage by
		// other editors, the following
		// check is added.
		if (_htmlEditor != null) {
			if (activeEditor instanceof StructuredTextEditor) {
				activateSourcePage((StructuredTextEditor) activeEditor);
			} else if (activeEditor instanceof SimpleGraphicalEditor) {
				//SimpleGraphicalEditor graphEditor = (SimpleGraphicalEditor) activeEditor;
				activateDesignPage((SimpleGraphicalEditor) activeEditor);
				// TODO: never read this._viewer = graphEditor.getGraphicViewer();
			} else {
				// currently we don't have special action for preview.
				deactivateSourceAndDesignPage(activeEditor);
				// TODO: never read this._viewer = null;
			}
		}

		updateToolbarActions();

		IActionBars actionBars = getActionBars();
		if (actionBars != null) {
			// update menu bar and tool bar
			actionBars.updateActionBars();
		}
	}

	/**
	 * 
	 */
	protected void deactivateSourceAndDesignPage(IEditorPart activeEditor) {
		if (_designViewerActionBarContributor != null) {
			_designViewerActionBarContributor.setActiveEditor(_htmlEditor);
			_designViewerActionBarContributor
					.setViewerSpecificContributionsEnabled(false);
		}
		if (_sourceViewerActionContributor != null) {
			_sourceViewerActionContributor.setActiveEditor(_htmlEditor);
			_sourceViewerActionContributor
					.setViewerSpecificContributionsEnabled(false);
		}
	}

	protected void activateDesignPage(SimpleGraphicalEditor activeEditor) {

		if (_sourceViewerActionContributor != null /*
													 * &&
													 * _sourceViewerActionContributor
													 * instanceof
													 * ISourceViewerActionBarContributor
													 */) {
			// previously I was trying setActiveEditor(null) here. But as in the
			// super class will
			// compare the editor with original one, if same then directly
			// return. So will not disable
			// those actions. (lium)
			_sourceViewerActionContributor.setActiveEditor(_htmlEditor);
			_sourceViewerActionContributor
					.setViewerSpecificContributionsEnabled(false);
		}

		if (_designViewerActionBarContributor != null) {
			_designViewerActionBarContributor.setActiveEditor(activeEditor);
			_designViewerActionBarContributor
					.setViewerSpecificContributionsEnabled(true);
		}
	}

	protected void activateSourcePage(StructuredTextEditor activeEditor) {
		if (_designViewerActionBarContributor != null /*
														 * &&
														 * _designViewerActionBarContributor
														 * instanceof
														 * IDesignViewerActionBarContributor
														 */) {
			// _designViewerActionBarContributor only recogonize HTMLEditor and
			// its own GraphicEditor. so not setting source editor to it.
			_designViewerActionBarContributor.setActiveEditor(_htmlEditor);
			_designViewerActionBarContributor
					.setViewerSpecificContributionsEnabled(false);
		}

		if (_sourceViewerActionContributor != null /*
													 * &&
													 * _sourceViewerActionContributor
													 * instanceof
													 * ISourceViewerActionBarContributor
													 */) {
			_sourceViewerActionContributor.setActiveEditor(activeEditor);
			_sourceViewerActionContributor.setViewerSpecificContributionsEnabled(true);
		}
	}

    // TODO: dead?
//	private void updateEditorMenu(IMenuManager menuMgr) {
//		if (this._viewer == null) {
//			return;
//		} else {
//			if (menuMgr != null) {
//				ContainerActionGroup containerActionGroup = new ContainerActionGroup();
//				ActionContext context = new ActionContext(this._viewer
//						.getSelection());
//				context.setInput(this._viewer);
//				containerActionGroup.setContext(context);
//				containerActionGroup.fillContextMenu(menuMgr);
//				containerActionGroup.setContext(null);
//
//				RangeActionGroup rangeActionGroup = new RangeActionGroup();
//				context = new ActionContext(this._viewer.getSelection());
//				context.setInput(this._viewer);
//				rangeActionGroup.setContext(context);
//				rangeActionGroup.fillContextMenu(menuMgr);
//				rangeActionGroup.setContext(null);
//
//				SingleElementActionGroup singleActionGroup = new SingleElementActionGroup();
//				singleActionGroup.setContext(new ActionContext(this._viewer
//						.getSelection()));
//				singleActionGroup.fillContextMenu(menuMgr);
//				singleActionGroup.setContext(null);
//
//				if (this._model != null) {
//					CustomedContextMenuActionGroup customedMenu = new CustomedContextMenuActionGroup();
//					customedMenu.setContext(new ActionContext(_viewer
//							.getSelection()));
//					customedMenu.setModel(_model);
//					customedMenu.setParentControl(_viewer.getControl());
//					customedMenu.fillContextMenu(menuMgr);
//					customedMenu.setContext(null);
//					customedMenu.setParentControl(null);
//					customedMenu.setModel(null);
//				}
//			}
//		}
//	}
}

Back to the top