KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > base > app > IpanemaWorkbenchAdvisor


1 package com.nightlabs.ipanema.base.app;
2
3 import java.io.File JavaDoc;
4
5 import javax.security.auth.login.LoginException JavaDoc;
6
7 import org.apache.log4j.Logger;
8 import org.eclipse.jface.util.Assert;
9 import org.eclipse.swt.widgets.Display;
10 import org.eclipse.ui.IWorkbenchWindow;
11 import org.eclipse.ui.application.IActionBarConfigurer;
12 import org.eclipse.ui.application.IWorkbenchConfigurer;
13 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
14 import org.eclipse.ui.application.WorkbenchAdvisor;
15
16 import com.nightlabs.classsharing.ClasssharingPlugin;
17 import com.nightlabs.config.ConfigException;
18 import com.nightlabs.ipanema.base.login.IpanemaLoginHandler;
19 import com.nightlabs.ipanema.base.login.IpanemaSecurityConfiguration;
20 import com.nightlabs.ipanema.base.login.Login;
21 import com.nightlabs.ipanema.base.login.WorkOfflineException;
22 import com.nightlabs.ipanema.base.perspective.IpanemaWelcomePerspective;
23 import com.nightlabs.ipanema.boot.DelegatingClassLoader;
24 import com.nightlabs.ipanema.classloader.IpanemaCLDelegate;
25 import com.nightlabs.rcp.exceptionhandler.ExceptionHandlerRegistry;
26 import com.nightlabs.rcp.splash.SplashHandlingWorkbenchAdvisor;
27
28 /**
29  * By now only sets initial perspective
30  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
31  *
32  */

33 public class IpanemaWorkbenchAdvisor
34 extends SplashHandlingWorkbenchAdvisor
35 {
36     /**
37      * Key to look up the action builder on the window configurer.
38      */

39     private static final String JavaDoc BUILDER_KEY = "builder"; //$NON-NLS-1$
40
public static Logger LOGGER = null;
41     
42     /**
43      * Constructs a new <code>IpanemaWorkbenchAdvisor</code>.<br/>
44      * Registeres {@link EPClassLoaderDelegate} to the parent ClassLoader.<br/>
45      * Initializes logging, so all logging should be done after
46      * the WorkbenchAdvisor is created.<br/>
47      * At last initializes the config.
48      * @see ExceptionHandlingWorkbenchAdvisor
49      * @see com.nightlabs.rcp.splash.SplashHandlingWorkbenchAdvisor
50      */

51     public IpanemaWorkbenchAdvisor(Display display) {
52         super();
53     try {
54         if (isSystemClassLoaderDelegating()){
55                 System.out.println("Initializing classsharing ...");
56                 ClasssharingPlugin.initializeClassSharing();
57                 System.out.println("Initializing classsharing ... DONE");
58 // EPClassLoaderDelegate.sharedInstance().register();
59
}
60         
61             IpanemaApplication.initializeLogging();
62             
63             IpanemaWorkbenchAdvisor.LOGGER = Logger.getLogger(IpanemaWorkbenchAdvisor.class);
64     
65             initConfig();
66     } catch (Exception JavaDoc e) {
67         throw new RuntimeException JavaDoc(e);
68         }
69     }
70     
71     protected void initConfig() throws ConfigException, LoginException JavaDoc, WorkOfflineException
72     {
73 // initialize the Config
74
com.nightlabs.config.Config config = com.nightlabs.config.Config.createSharedInstance("config.xml", true, IpanemaApplication.getConfigDir());
75         
76         // create log directory if not existent
77
IpanemaApplication.getLogDir();
78         IpanemaCLDelegate.createSharedInstance(Login.getLogin(false), new File JavaDoc(IpanemaApplication.getRootDir(), "classloader.cache"));
79
80         initializeLoginModule();
81     }
82     
83
84    
85     public static boolean isSystemClassLoaderDelegating() {
86         return ClassLoader.getSystemClassLoader() instanceof DelegatingClassLoader;
87     }
88     
89     /**
90      * Intializes the workbench
91      */

92     public void initialize(IWorkbenchConfigurer configurer) {
93         super.initialize(configurer);
94         configurer.setSaveAndRestore(true);
95     }
96     
97 // Uncomment the code below for a custom window layout
98
//
99
// public void createWindowContents(IWorkbenchWindowConfigurer configurer, Shell shell) {
100
// Menu menuBar = configurer.createMenuBar();
101
// shell.setMenuBar(menuBar);
102
//
103
// GridLayout shellLayout = new GridLayout();
104
// shellLayout.marginWidth = 0;
105
// shellLayout.marginHeight = 0;
106
// shellLayout.verticalSpacing = 0;
107
// shell.setLayout(shellLayout);
108
//
109
// if (!"carbon".equals(SWT.getPlatform())) { //$NON-NLS-1$
110
// Label sep1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
111
// sep1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
112
// }
113
// Control coolBar = configurer.createCoolBarControl(shell);
114
// coolBar.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
115
//
116
// Label sep2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
117
// sep2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
118
//
119
// Control pageComposite = configurer.createPageComposite(shell);
120
// pageComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
121
//
122
// Label sep3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
123
// sep3.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
124
// Control statusLine = configurer.createStatusLineControl(shell);
125
// statusLine.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
126
// shell.layout(true);
127
// }
128

129     /**
130      * By now IpanemaWelcomePerspective is initial perspective
131      * @see org.eclipse.ui.application.WorkbenchAdvisor
132      */

133     public String JavaDoc getInitialWindowPerspectiveId()
134     {
135         return IpanemaWelcomePerspective.ID_PERSPECTIVE;
136     }
137         
138     
139     private boolean firstWindowToShow = true;
140     /* (non-Javadoc)
141      * @see org.eclipse.ui.application.WorkbenchAdvisor
142      */

143     public void preWindowOpen(IWorkbenchWindowConfigurer configurer)
144     {
145         super.preWindowOpen(configurer);
146         
147         configurer.setShowPerspectiveBar(true);
148         configurer.setShowMenuBar(true);
149         configurer.setShowCoolBar(true);
150         
151     }
152     
153     
154     
155     public void postWindowOpen(IWorkbenchWindowConfigurer configurer) {
156         super.postWindowOpen(configurer);
157 // Login.triggerLoginStateNotification();
158
// try {
159
// Login.doLogin();
160
// } catch (LoginException e) {
161
// // TODO LoginException ererben, um zu wissen, ob der User aborted hat.
162
// LOGGER.warn("Login aborted by user or failed.", e);
163
// }
164
}
165     
166     
167     /**
168      * Action bars are filled by {@link IpanemaActionBuilder}.
169      * @see org.eclipse.ui.application.WorkbenchAdvisor
170      */

171     public void fillActionBars(IWorkbenchWindow window, IActionBarConfigurer configurer, int flags) {
172         // FILL_PROXY is not currently handled
173
super.fillActionBars(window,configurer,flags);
174         Assert.isTrue((flags & WorkbenchAdvisor.FILL_PROXY) == 0);
175         IpanemaActionBuilder builder = new IpanemaActionBuilder(window);
176         getWorkbenchConfigurer().getWindowConfigurer(window).setData(BUILDER_KEY, builder);
177         builder.fillActionBars(configurer, flags);
178     }
179     
180     /* (non-Javadoc)
181      * @see org.eclipse.ui.application.WorkbenchAdvisor#postWindowClose(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
182      */

183     public void postWindowClose(IWorkbenchWindowConfigurer configurer) {
184         super.postWindowClose(configurer);
185         IpanemaActionBuilder builder = (IpanemaActionBuilder) configurer.getData(BUILDER_KEY);
186         if (builder != null) {
187             builder.dispose();
188         }
189     }
190     
191     
192     
193     public boolean preShutdown() {
194         try {
195             com.nightlabs.config.Config.sharedInstance().saveConfFile();
196         } catch (ConfigException e) {
197             LOGGER.error("Saving config failed!", e);
198         }
199         return super.preShutdown();
200     }
201
202     public void preStartup() {
203         super.preStartup();
204 // WorkbenchAdapterBuilder.registerAdapters();
205
}
206     
207     protected void initializeLoginModule(){
208         LOGGER.debug("#initializeLoginModule: Declaring Configuration");
209         IpanemaSecurityConfiguration.declareConfiguration();
210         
211         LOGGER.debug("#initializeLoginModule: Setting LoginHandler");
212         try {
213             Login.getLogin(false).setLoginHandler(new IpanemaLoginHandler());
214         } catch (LoginException JavaDoc e) {
215             throw new RuntimeException JavaDoc("How the hell could this happen?!", e);
216         }
217     }
218     
219     public void eventLoopException(Throwable JavaDoc exception) {
220         if (!ExceptionHandlerRegistry.syncHandleException(exception))
221             super.eventLoopException(exception);
222     }
223
224 // public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
225
// // TODO When completely moved to 3.1 change to WorkbenchWindowAdvisor and its ActionAdvisor
226
// return super.createWorkbenchWindowAdvisor(configurer);
227
// }
228

229     
230     
231 }
232
Popular Tags