Source code: org/eclipse/ui/internal/WorkbenchConfigurer.java
1 /*******************************************************************************
2 * Copyright (c) 2003, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.ui.internal;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.window.WindowManager;
19 import org.eclipse.ui.IWorkbench;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.application.IWorkbenchConfigurer;
23 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
24
25 /**
26 * Internal class providing special access for configuring the workbench.
27 * <p>
28 * Note that these objects are only available to the main application
29 * (the plug-in that creates and owns the workbench).
30 * </p>
31 * <p>
32 * This class is not intended to be instantiated or subclassed by clients.
33 * </p>
34 *
35 * @since 3.0
36 */
37 public final class WorkbenchConfigurer implements IWorkbenchConfigurer {
38
39 /**
40 * Table to hold arbitrary key-data settings (key type: <code>String</code>,
41 * value type: <code>Object</code>).
42 * @see #setData
43 */
44 private Map extraData = new HashMap();
45
46 /**
47 * Indicates whether workbench state should be saved on close and
48 * restored on subsequent open.
49 */
50 private boolean saveAndRestore = false;
51
52 /**
53 * Indicates whether the workbench is being force to close. During
54 * an emergency close, no interaction with the user should be done.
55 */
56 private boolean isEmergencyClosing = false;
57
58 /**
59 * Creates a new workbench configurer.
60 * <p>
61 * This method is declared package-private. Clients are passed an instance
62 * only via {@link WorkbenchAdvisor#initialize WorkbenchAdvisor.initialize}
63 * </p>
64 */
65 /* package */ WorkbenchConfigurer() {
66 super();
67 }
68
69 /* (non-javadoc)
70 * @see org.eclipse.ui.application.IWorkbenchConfigurer#getWorkbench
71 */
72 public IWorkbench getWorkbench() {
73 return PlatformUI.getWorkbench();
74 }
75
76 /* (non-javadoc)
77 * @see org.eclipse.ui.application.IWorkbenchConfigurer#getWorkbenchWindowManager
78 */
79 public WindowManager getWorkbenchWindowManager() {
80 // return the global workbench window manager
81 return ((Workbench)getWorkbench()).getWindowManager();
82 }
83
84 /* (non-javadoc)
85 * @see org.eclipse.ui.application.IWorkbenchConfigurer#declareImage
86 */
87 public void declareImage(String symbolicName, ImageDescriptor descriptor, boolean shared) {
88 if (symbolicName == null || descriptor == null) {
89 throw new IllegalArgumentException();
90 }
91 WorkbenchImages.declareImage(symbolicName, descriptor, shared);
92 }
93
94 /* (non-javadoc)
95 * @see org.eclipse.ui.application.IWorkbenchConfigurer#getWindowConfigurer
96 */
97 public IWorkbenchWindowConfigurer getWindowConfigurer(IWorkbenchWindow window) {
98 if (window == null) {
99 throw new IllegalArgumentException();
100 }
101 return ((WorkbenchWindow) window).getWindowConfigurer();
102 }
103
104
105 /* (non-Javadoc)
106 * @see org.eclipse.ui.application.IWorkbenchConfigurer#getSaveAndRestore()
107 */
108 public boolean getSaveAndRestore() {
109 return saveAndRestore;
110 }
111
112 /* (non-Javadoc)
113 * @see org.eclipse.ui.application.IWorkbenchConfigurer#setSaveAndRestore(boolean)
114 */
115 public void setSaveAndRestore(boolean enabled) {
116 saveAndRestore = enabled;
117 }
118
119 /* (non-Javadoc)
120 * @see org.eclipse.ui.application.IWorkbenchConfigurer#getData
121 */
122 public Object getData(String key) {
123 if (key == null) {
124 throw new IllegalArgumentException();
125 }
126 return extraData.get(key);
127 }
128
129 /* (non-Javadoc)
130 * @see org.eclipse.ui.application.IWorkbenchConfigurer#setData(String, Object)
131 */
132 public void setData(String key, Object data) {
133 if (key == null) {
134 throw new IllegalArgumentException();
135 }
136 if (data != null) {
137 extraData.put(key, data);
138 } else {
139 extraData.remove(key);
140 }
141 }
142
143 /* (non-Javadoc)
144 * @see org.eclipse.ui.application.IWorkbenchConfigurer#emergencyClose()
145 */
146 public void emergencyClose() {
147 if (!isEmergencyClosing) {
148 isEmergencyClosing = true;
149 if (Workbench.getInstance() != null && !Workbench.getInstance().isClosing()) {
150 Workbench.getInstance().close(PlatformUI.RETURN_EMERGENCY_CLOSE, true);
151 }
152 }
153
154 }
155
156 /* (non-Javadoc)
157 * @see org.eclipse.ui.application.IWorkbenchConfigurer#emergencyClosing()
158 */
159 public boolean emergencyClosing() {
160 return isEmergencyClosing;
161 }
162
163 /* (non-Javadoc)
164 * @see org.eclipse.ui.application.IWorkbenchConfigurer#restoreState()
165 */
166 public IStatus restoreState() {
167 return ((Workbench) getWorkbench()).restoreState();
168 }
169
170 /* (non-Javadoc)
171 * @see org.eclipse.ui.application.IWorkbenchConfigurer#openFirstTimeWindow()
172 */
173 public void openFirstTimeWindow() {
174 ((Workbench) getWorkbench()).openFirstTimeWindow();
175 }
176 }