Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1a1220b5a752a65251518e96c30479d46d6edae7 (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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*******************************************************************************
 * Copyright (c) 2003, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Lars Vogel <Lars.Vogel@vogella.com> - Bug 441184, 440136
 *     Denis Zygann <d.zygann@web.de> - Bug 457390
 *******************************************************************************/
package org.eclipse.ui.internal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
import org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2;
import org.eclipse.jface.internal.provisional.action.ToolBarManager2;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;

/**
 * Internal class providing special access for configuring workbench windows.
 * <p>
 * Note that these objects are only available to the main application (the
 * plug-in that creates and owns the workbench).
 * </p>
 * <p>
 * This class is not intended to be instantiated or subclassed by clients.
 * </p>
 *
 * @since 3.0
 */
public final class WorkbenchWindowConfigurer implements IWorkbenchWindowConfigurer {

	/**
	 * The workbench window associated with this configurer.
	 */
	private WorkbenchWindow window;

	/**
	 * The shell style bits to use when the window's shell is being created.
	 */
	private int shellStyle = SWT.SHELL_TRIM | Window.getDefaultOrientation();

	/**
	 * The window title to set when the window's shell has been created.
	 */
	private String windowTitle;

	/**
	 * Whether the workbench window should show the perspective bar
	 */
	private boolean showPerspectiveBar = false;

	/**
	 * Whether the workbench window should show the status line.
	 */
	private boolean showStatusLine = true;

	/**
	 * Whether the workbench window should show the main tool bar.
	 */
	private boolean showToolBar = true;

	/**
	 * Whether the workbench window should show the main menu bar.
	 */
	private boolean showMenuBar = true;

	/**
	 * Whether the workbench window should have a progress indicator.
	 */
	private boolean showProgressIndicator = false;

	/**
	 * Table to hold arbitrary key-data settings (key type: <code>String</code>,
	 * value type: <code>Object</code>).
	 * 
	 * @see #setData
	 */
	private Map extraData = new HashMap(1);

	/**
	 * Holds the list drag and drop <code>Transfer</code> for the editor area
	 */
	private ArrayList transferTypes = new ArrayList(3);

	/**
	 * The <code>DropTargetListener</code> implementation for handling a drop into
	 * the editor area.
	 */
	private DropTargetListener dropTargetListener = null;

	/**
	 * Object for configuring this workbench window's action bars. Lazily
	 * initialized to an instance unique to this window.
	 */
	private WindowActionBarConfigurer actionBarConfigurer = null;

	/**
	 * The initial size to use for the shell.
	 */
	private Point initialSize = new Point(1024, 768);

	/**
	 * Action bar configurer that changes this workbench window. This implementation
	 * keeps track of of cool bar items
	 */
	class WindowActionBarConfigurer implements IActionBarConfigurer2 {

		private IActionBarConfigurer2 proxy;

		/**
		 * Sets the proxy to use, or <code>null</code> for none.
		 *
		 * @param proxy the proxy
		 */
		public void setProxy(IActionBarConfigurer2 proxy) {
			this.proxy = proxy;
		}

		@Override
		public IWorkbenchWindowConfigurer getWindowConfigurer() {
			return window.getWindowConfigurer();
		}

		/**
		 * Returns whether the given id is for a cool item.
		 *
		 * @param the item id
		 * @return <code>true</code> if it is a cool item, and <code>false</code>
		 *         otherwise
		 */
		/* package */boolean containsCoolItem(String id) {
			ICoolBarManager cbManager = getCoolBarManager();
			if (cbManager == null) {
				return false;
			}
			IContributionItem cbItem = cbManager.find(id);
			if (cbItem == null) {
				return false;
			}
			// @ issue: maybe we should check if cbItem is visible?
			return true;
		}

		@Override
		public IStatusLineManager getStatusLineManager() {
			if (proxy != null) {
				return proxy.getStatusLineManager();
			}
			return window.getStatusLineManager();
		}

		@Override
		public IMenuManager getMenuManager() {
			if (proxy != null) {
				return proxy.getMenuManager();
			}
			return window.getMenuManager();
		}

		@Override
		public ICoolBarManager getCoolBarManager() {
			if (proxy != null) {
				return proxy.getCoolBarManager();
			}
			return window.getCoolBarManager2();
		}

		@Override
		public void registerGlobalAction(IAction action) {
			if (proxy != null) {
				proxy.registerGlobalAction(action);
			}
			window.registerGlobalAction(action);
		}

		@Override
		public IToolBarManager createToolBarManager() {
			if (proxy != null) {
				return proxy.createToolBarManager();
			}
			return new ToolBarManager2(SWT.WRAP | SWT.FLAT | SWT.RIGHT);
		}

		@Override
		public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
			if (proxy != null) {
				return proxy.createToolBarContributionItem(toolBarManager, id);
			}
			return new ToolBarContributionItem2(toolBarManager, id);
		}
	}

	/**
	 * Creates a new workbench window configurer.
	 * <p>
	 * This method is declared package-private. Clients obtain instances via
	 * {@link WorkbenchAdvisor#getWindowConfigurer
	 * WorkbenchAdvisor.getWindowConfigurer}
	 * </p>
	 *
	 * @param window the workbench window that this object configures
	 * @see WorkbenchAdvisor#getWindowConfigurer
	 */
	WorkbenchWindowConfigurer(WorkbenchWindow window) {
		if (window == null) {
			throw new IllegalArgumentException();
		}
		this.window = window;
		windowTitle = WorkbenchPlugin.getDefault().getProductName();
		if (windowTitle == null) {
			windowTitle = ""; //$NON-NLS-1$
		}
	}

	@Override
	public IWorkbenchWindow getWindow() {
		return window;
	}

	@Override
	public IWorkbenchConfigurer getWorkbenchConfigurer() {
		return Workbench.getInstance().getWorkbenchConfigurer();
	}

	/**
	 * Returns the title as set by <code>setTitle</code>, without consulting the
	 * shell.
	 *
	 * @return the window title as set, or <code>null</code> if not set
	 */
	/* package */String basicGetTitle() {
		return windowTitle;
	}

	@Override
	public String getTitle() {
		Shell shell = window.getShell();
		if (shell != null && !shell.isDisposed()) {
			// update the cached title
			windowTitle = shell.getText();
		}
		return windowTitle;
	}

	@Override
	public void setTitle(String title) {
		if (title == null) {
			throw new IllegalArgumentException();
		}
		windowTitle = title;
		Shell shell = window.getShell();
		if (shell != null && !shell.isDisposed()) {
			shell.setText(TextProcessor.process(title, WorkbenchWindow.TEXT_DELIMITERS));
		}
	}

	@Override
	public boolean getShowMenuBar() {
		return showMenuBar;
	}

	@Override
	public void setShowMenuBar(boolean show) {
		showMenuBar = show;
		WorkbenchWindow win = (WorkbenchWindow) getWindow();
		Shell shell = win.getShell();
		if (shell != null) {
			boolean showing = shell.getMenuBar() != null;
			if (show != showing) {
				if (show) {
					shell.setMenuBar(null);
				} else {
					shell.setMenuBar(null);
				}
			}
		}
	}

	@Override
	public boolean getShowCoolBar() {
		return showToolBar;
	}

	@Override
	public void setShowCoolBar(boolean show) {
		showToolBar = show;
		// @issue need to be able to reconfigure after window's controls created
	}

	@Override
	public boolean getShowFastViewBars() {
		// not supported anymore
		return false;
	}

	@Override
	public void setShowFastViewBars(boolean show) {
		// not supported anymore
	}

	@Override
	public boolean getShowPerspectiveBar() {
		return showPerspectiveBar;
	}

	@Override
	public void setShowPerspectiveBar(boolean show) {
		showPerspectiveBar = show;
		// @issue need to be able to reconfigure after window's controls created
	}

	@Override
	public boolean getShowStatusLine() {
		return showStatusLine;
	}

	@Override
	public void setShowStatusLine(boolean show) {
		showStatusLine = show;
		window.setStatusLineVisible(show);
		// @issue need to be able to reconfigure after window's controls created
	}

	@Override
	public boolean getShowProgressIndicator() {
		return showProgressIndicator;
	}

	@Override
	public void setShowProgressIndicator(boolean show) {
		showProgressIndicator = show;
		// @issue need to be able to reconfigure after window's controls created
	}

	@Override
	public Object getData(String key) {
		if (key == null) {
			throw new IllegalArgumentException();
		}
		return extraData.get(key);
	}

	@Override
	public void setData(String key, Object data) {
		if (key == null) {
			throw new IllegalArgumentException();
		}
		if (data != null) {
			extraData.put(key, data);
		} else {
			extraData.remove(key);
		}
	}

	@Override
	public void addEditorAreaTransfer(Transfer tranfer) {
		if (tranfer != null && !transferTypes.contains(tranfer)) {
			transferTypes.add(tranfer);
		}
	}

	@Override
	public void configureEditorAreaDropListener(DropTargetListener dropTargetListener) {
		this.dropTargetListener = dropTargetListener;
	}

	/**
	 * Returns the array of <code>Transfer</code> added by the application
	 */
	/* package */Transfer[] getTransfers() {
		Transfer[] transfers = new Transfer[transferTypes.size()];
		transferTypes.toArray(transfers);
		return transfers;
	}

	/**
	 * Returns the drop listener provided by the application.
	 */
	/* package */DropTargetListener getDropTargetListener() {
		return dropTargetListener;
	}

	@Override
	public IActionBarConfigurer getActionBarConfigurer() {
		if (actionBarConfigurer == null) {
			// lazily initialize
			actionBarConfigurer = new WindowActionBarConfigurer();
		}
		return actionBarConfigurer;
	}

	/**
	 * Returns whether the given id is for a cool item.
	 *
	 * @param the item id
	 * @return <code>true</code> if it is a cool item, and <code>false</code>
	 *         otherwise
	 */
	/* package */boolean containsCoolItem(String id) {
		// trigger lazy initialization
		getActionBarConfigurer();
		return actionBarConfigurer.containsCoolItem(id);
	}

	@Override
	public int getShellStyle() {
		return shellStyle;
	}

	@Override
	public void setShellStyle(int shellStyle) {
		this.shellStyle = shellStyle;
	}

	@Override
	public Point getInitialSize() {
		return initialSize;
	}

	@Override
	public void setInitialSize(Point size) {
		initialSize = size;
	}

	/**
	 * Creates the default window contents.
	 *
	 * @param shell the shell
	 */
	public void createDefaultContents(Shell shell) {

	}

	@Override
	public Menu createMenuBar() {
		return null;
	}

	@Override
	public Control createCoolBarControl(Composite parent) {

		return null;
	}

	@Override
	public Control createStatusLineControl(Composite parent) {
		return null;
	}

	@Override
	public Control createPageComposite(Composite parent) {
		return null;
	}

	@Override
	public IStatus saveState(IMemento memento) {
		return null;
	}

}

Back to the top