KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > WorkbenchConfigurer


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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 JavaDoc;
14 import java.util.Map JavaDoc;
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.IMemento;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchWindow;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.WorkbenchException;
24 import org.eclipse.ui.application.IWorkbenchConfigurer;
25 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
26 import org.eclipse.ui.application.WorkbenchAdvisor;
27
28 /**
29  * Internal class providing special access for configuring the workbench.
30  * <p>
31  * Note that these objects are only available to the main application
32  * (the plug-in that creates and owns the workbench).
33  * </p>
34  * <p>
35  * This class is not intended to be instantiated or subclassed by clients.
36  * </p>
37  *
38  * @since 3.0
39  */

40 public final class WorkbenchConfigurer implements IWorkbenchConfigurer {
41
42     /**
43      * Table to hold arbitrary key-data settings (key type: <code>String</code>,
44      * value type: <code>Object</code>).
45      * @see #setData
46      */

47     private Map JavaDoc extraData = new HashMap JavaDoc();
48
49     /**
50      * Indicates whether workbench state should be saved on close and
51      * restored on subsequent open.
52      */

53     private boolean saveAndRestore = false;
54
55     /**
56      * Indicates whether the workbench is being force to close. During
57      * an emergency close, no interaction with the user should be done.
58      */

59     private boolean isEmergencyClosing = false;
60
61     /**
62      * Indicates the behaviour when the last window is closed.
63      * If <code>true</code>, the workbench will exit (saving the last window's state,
64      * if configured to do so).
65      * If <code>false</code> the window will be closed, leaving the workbench running.
66      *
67      * @since 3.1
68      */

69     private boolean exitOnLastWindowClose = true;
70
71     /**
72      * Creates a new workbench configurer.
73      * <p>
74      * This method is declared package-private. Clients are passed an instance
75      * only via {@link WorkbenchAdvisor#initialize WorkbenchAdvisor.initialize}
76      * </p>
77      */

78     /* package */WorkbenchConfigurer() {
79         super();
80     }
81
82     /* (non-javadoc)
83      * @see org.eclipse.ui.application.IWorkbenchConfigurer#getWorkbench
84      */

85     public IWorkbench getWorkbench() {
86         return PlatformUI.getWorkbench();
87     }
88
89     /* (non-javadoc)
90      * @see org.eclipse.ui.application.IWorkbenchConfigurer#getWorkbenchWindowManager
91      */

92     public WindowManager getWorkbenchWindowManager() {
93         // return the global workbench window manager
94
return ((Workbench) getWorkbench()).getWindowManager();
95     }
96
97     /* (non-javadoc)
98      * @see org.eclipse.ui.application.IWorkbenchConfigurer#declareImage
99      */

100     public void declareImage(String JavaDoc symbolicName, ImageDescriptor descriptor,
101             boolean shared) {
102         if (symbolicName == null || descriptor == null) {
103             throw new IllegalArgumentException JavaDoc();
104         }
105         WorkbenchImages.declareImage(symbolicName, descriptor, shared);
106     }
107
108     /* (non-javadoc)
109      * @see org.eclipse.ui.application.IWorkbenchConfigurer#getWindowConfigurer
110      */

111     public IWorkbenchWindowConfigurer getWindowConfigurer(
112             IWorkbenchWindow window) {
113         if (window == null) {
114             throw new IllegalArgumentException JavaDoc();
115         }
116         return ((WorkbenchWindow) window).getWindowConfigurer();
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.ui.application.IWorkbenchConfigurer#getSaveAndRestore()
121      */

122     public boolean getSaveAndRestore() {
123         return saveAndRestore;
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.ui.application.IWorkbenchConfigurer#setSaveAndRestore(boolean)
128      */

129     public void setSaveAndRestore(boolean enabled) {
130         saveAndRestore = enabled;
131     }
132
133     /* (non-Javadoc)
134      * @see org.eclipse.ui.application.IWorkbenchConfigurer#getData
135      */

136     public Object JavaDoc getData(String JavaDoc key) {
137         if (key == null) {
138             throw new IllegalArgumentException JavaDoc();
139         }
140         return extraData.get(key);
141     }
142
143     /* (non-Javadoc)
144      * @see org.eclipse.ui.application.IWorkbenchConfigurer#setData(String, Object)
145      */

146     public void setData(String JavaDoc key, Object JavaDoc data) {
147         if (key == null) {
148             throw new IllegalArgumentException JavaDoc();
149         }
150         if (data != null) {
151             extraData.put(key, data);
152         } else {
153             extraData.remove(key);
154         }
155     }
156
157     /* (non-Javadoc)
158      * @see org.eclipse.ui.application.IWorkbenchConfigurer#emergencyClose()
159      */

160     public void emergencyClose() {
161         if (!isEmergencyClosing) {
162             isEmergencyClosing = true;
163             if (Workbench.getInstance() != null
164                     && !Workbench.getInstance().isClosing()) {
165                 Workbench.getInstance().close(
166                         PlatformUI.RETURN_EMERGENCY_CLOSE, true);
167             }
168         }
169
170     }
171
172     /* (non-Javadoc)
173      * @see org.eclipse.ui.application.IWorkbenchConfigurer#emergencyClosing()
174      */

175     public boolean emergencyClosing() {
176         return isEmergencyClosing;
177     }
178
179     /* (non-Javadoc)
180      * @see org.eclipse.ui.application.IWorkbenchConfigurer#restoreState()
181      */

182     public IStatus restoreState() {
183         return ((Workbench) getWorkbench()).restoreState();
184     }
185
186     /* (non-Javadoc)
187      * @see org.eclipse.ui.application.IWorkbenchConfigurer#openFirstTimeWindow()
188      */

189     public void openFirstTimeWindow() {
190         ((Workbench) getWorkbench()).openFirstTimeWindow();
191     }
192
193     /* (non-Javadoc)
194      * @see org.eclipse.ui.application.IWorkbenchConfigurer#restoreWorkbenchWindow(org.eclipse.ui.IMemento)
195      */

196     public IWorkbenchWindowConfigurer restoreWorkbenchWindow(IMemento memento) throws WorkbenchException {
197         return getWindowConfigurer(((Workbench) getWorkbench()).restoreWorkbenchWindow(memento));
198     }
199
200     /* (non-Javadoc)
201      * @see org.eclipse.ui.application.IWorkbenchConfigurer#getExitOnLastWindowClose()
202      */

203     public boolean getExitOnLastWindowClose() {
204         return exitOnLastWindowClose;
205     }
206
207     /* (non-Javadoc)
208      * @see org.eclipse.ui.application.IWorkbenchConfigurer#setExitOnLastWindowClose(boolean)
209      */

210     public void setExitOnLastWindowClose(boolean enabled) {
211         exitOnLastWindowClose = enabled;
212     }
213 }
214
Popular Tags