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.cms.ui.workbench.rap;
17  
18  import org.eclipse.swt.SWT;
19  import org.eclipse.swt.graphics.Point;
20  import org.eclipse.swt.graphics.Rectangle;
21  import org.eclipse.swt.widgets.Display;
22  import org.eclipse.swt.widgets.Event;
23  import org.eclipse.swt.widgets.Listener;
24  import org.eclipse.swt.widgets.Shell;
25  import org.eclipse.ui.IWorkbenchWindow;
26  import org.eclipse.ui.actions.ActionFactory;
27  import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
28  import org.eclipse.ui.application.ActionBarAdvisor;
29  import org.eclipse.ui.application.IActionBarConfigurer;
30  import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
31  import org.eclipse.ui.application.WorkbenchWindowAdvisor;
32  
33  /** Eclipse RAP specific window advisor */
34  public class RapWindowAdvisor extends WorkbenchWindowAdvisor {
35  
36  	private String username;
37  
38  	public RapWindowAdvisor(IWorkbenchWindowConfigurer configurer,
39  			String username) {
40  		super(configurer);
41  		this.username = username;
42  	}
43  
44  	@Override
45  	public ActionBarAdvisor createActionBarAdvisor(
46  			IActionBarConfigurer configurer) {
47  		return new RapActionBarAdvisor(configurer, username);
48  	}
49  
50  	public void preWindowOpen() {
51  		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
52  		configurer.setShowCoolBar(true);
53  		configurer.setShowMenuBar(false);
54  		configurer.setShowStatusLine(false);
55  		configurer.setShowPerspectiveBar(true);
56  		configurer.setTitle("Argeo Web UI"); //$NON-NLS-1$
57  		// Full screen, see
58  		// http://wiki.eclipse.org/RAP/FAQ#How_to_create_a_fullscreen_application
59  		configurer.setShellStyle(SWT.NO_TRIM);
60  		Rectangle bounds = Display.getCurrent().getBounds();
61  		configurer.setInitialSize(new Point(bounds.width, bounds.height));
62  
63  		// Handle window resize in Rap 2.1+ see
64  		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417254
65  		Display.getCurrent().addListener(SWT.Resize, new Listener() {
66  			private static final long serialVersionUID = 2970912561866704526L;
67  
68  			@Override
69  			public void handleEvent(Event event) {
70  				Rectangle bounds = event.display.getBounds();
71  				IWorkbenchWindow iww = getWindowConfigurer().getWindow()
72  						.getWorkbench().getActiveWorkbenchWindow();
73  				iww.getShell().setBounds(bounds);
74  			}
75  		});
76  	}
77  
78  	@Override
79  	public void postWindowCreate() {
80  		Shell shell = getWindowConfigurer().getWindow().getShell();
81  		shell.setMaximized(true);
82  	}
83  
84  	@Override
85  	public void postWindowOpen() {
86  		String defaultPerspective = getWindowConfigurer()
87  				.getWorkbenchConfigurer().getWorkbench()
88  				.getPerspectiveRegistry().getDefaultPerspective();
89  		if (defaultPerspective == null) {
90  			IWorkbenchWindow window = getWindowConfigurer().getWindow();
91  			if (window == null)
92  				return;
93  
94  			IWorkbenchAction openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
95  					.create(window);
96  			openPerspectiveDialogAction.run();
97  		}
98  	}
99  
100 }