View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.slc.client.rap;
17  
18  import org.argeo.cms.ui.workbench.rap.RapWindowAdvisor;
19  import org.argeo.cms.ui.workbench.rap.RapWorkbenchAdvisor;
20  import org.argeo.cms.ui.workbench.rap.RapWorkbenchLogin;
21  import org.eclipse.swt.SWT;
22  import org.eclipse.swt.graphics.Point;
23  import org.eclipse.swt.graphics.Rectangle;
24  import org.eclipse.swt.widgets.Display;
25  import org.eclipse.swt.widgets.Shell;
26  import org.eclipse.ui.IWorkbenchWindow;
27  import org.eclipse.ui.actions.ActionFactory;
28  import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
29  import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
30  import org.eclipse.ui.application.WorkbenchWindowAdvisor;
31  
32  /**
33   * This class controls all aspects of the application's execution and is
34   * contributed through the plugin.xml.
35   */
36  public class SlcSecureRap extends RapWorkbenchLogin {
37  
38  	@Override
39  	protected RapWorkbenchAdvisor createRapWorkbenchAdvisor(
40  			final String username) {
41  		return new RapWorkbenchAdvisor(username) {
42  			@Override
43  			public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
44  					IWorkbenchWindowConfigurer configurer) {
45  				return new SlcRapWorkbenchWindowAdvisor(configurer, username);
46  			}
47  
48  		};
49  	}
50  
51  	/** Workaround for resize issue */
52  	class SlcRapWorkbenchWindowAdvisor extends RapWindowAdvisor {
53  
54  		public SlcRapWorkbenchWindowAdvisor(
55  				IWorkbenchWindowConfigurer configurer, String username) {
56  			super(configurer, username);
57  		}
58  
59  		public void preWindowOpen() {
60  			IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
61  			configurer.setShowCoolBar(true);
62  			configurer.setShowMenuBar(false);
63  			configurer.setShowStatusLine(false);
64  			configurer.setShowPerspectiveBar(true);
65  			configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$
66  			// Full screen, see
67  			// http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg02697.html
68  			configurer.setShellStyle(SWT.NO_TRIM);
69  			Rectangle bounds = Display.getCurrent().getBounds();
70  			configurer.setInitialSize(new Point(bounds.width, bounds.height));
71  		}
72  
73  		@Override
74  		public void postWindowCreate() {
75  			Shell shell = getWindowConfigurer().getWindow().getShell();
76  			shell.setMaximized(true);
77  		}
78  
79  		@Override
80  		public void postWindowOpen() {
81  			String defaultPerspective = getWindowConfigurer()
82  					.getWorkbenchConfigurer().getWorkbench()
83  					.getPerspectiveRegistry().getDefaultPerspective();
84  			if (defaultPerspective == null) {
85  				IWorkbenchWindow window = getWindowConfigurer().getWindow();
86  				if (window == null)
87  					return;
88  
89  				IWorkbenchAction openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
90  						.create(window);
91  				openPerspectiveDialogAction.run();
92  			}
93  		}
94  
95  	}
96  }