1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.workbench;
14 import java.util.List;
16 import org.eclipse.swt.widgets.Menu;
17 import org.eclipse.ui.IPerspectiveDescriptor;
18 import org.eclipse.ui.IPerspectiveListener4;
19 import org.eclipse.ui.IWindowListener;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.IWorkbenchPartReference;
23 import org.eclipse.ui.IWorkbenchWindow;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.ui.internal.WorkbenchWindow;
26 import org.eclipse.ui.internal.progress.ProgressRegion;
29 * Handler for perspectiveBars ExtensionPoint
31 * FIXME : statusLine widgets are not restored into original positions.
33 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
36 @SuppressWarnings("restriction")
37 public class PerspectiveBarsActivator implements IPerspectiveListener4, IWindowListener {
39 private IWorkbenchWindow activeWindow;
42 public PerspectiveBarsActivator() {
43 PlatformUI.getWorkbench().addWindowListener(this);
46 public void dispose() {
47 PlatformUI.getWorkbench().removeWindowListener(this);
50 //------------------------------------------------------------------------
51 // IPerspectiveListener4
52 //------------------------------------------------------------------------
55 public void perspectivePreDeactivate(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
59 public void perspectiveClosed(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
63 public void perspectiveDeactivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
67 public void perspectiveOpened(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
71 public void perspectiveSavedAs(IWorkbenchPage page, IPerspectiveDescriptor oldPerspective,
72 IPerspectiveDescriptor newPerspective) {
76 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective,
77 IWorkbenchPartReference partRef, String changeId) {
78 // See IWorkbenchPage.CHANGED_* constants for change id's.
82 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
83 activatePerspective(perspective.getId());
87 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
88 // See IWorkbenchPage.CHANGED_* constants for change id's.
91 //------------------------------------------------------------------------
93 //------------------------------------------------------------------------
96 public void windowActivated(IWorkbenchWindow window) {
97 // System.out.println("attaching to window: " + window);
98 attachToWindow(window);
102 public void windowClosed(IWorkbenchWindow window) {
106 public void windowDeactivated(IWorkbenchWindow window) {
107 // System.out.println("detaching from window: " + window);
108 detachFromWindow(window);
112 public void windowOpened(IWorkbenchWindow window) {
115 //------------------------------------------------------------------------
117 //------------------------------------------------------------------------
119 private void attachToWindow(IWorkbenchWindow window) {
120 activeWindow = window;
121 window.addPerspectiveListener(this);
122 IPerspectiveDescriptor perspective = window.getActivePage().getPerspective();
123 if (perspective != null) {
124 activatePerspective(perspective.getId());
128 private void detachFromWindow(IWorkbenchWindow window) {
129 window.removePerspectiveListener(this);
137 private void activatePerspective(String perspectiveId) {
138 // System.out.println("activating perspective: " + perspectiveId);
141 List<IPerspectiveBarsExtension> exts = PerspectiveBarsManager.getInstance().getExtensions(perspectiveId);
142 Boolean menuBar = null;
143 Boolean coolBar = null;
144 Boolean statusLine = null;
145 Boolean perspectiveBar = null;
146 Boolean fastViewBar = null;
147 Boolean progressIndicator = null;
148 for (IPerspectiveBarsExtension ext : exts) {
150 menuBar = ext.getMenuBar();
152 coolBar = ext.getCoolBar();
153 if (statusLine == null)
154 statusLine = ext.getStatusLine();
155 if (perspectiveBar == null)
156 perspectiveBar = ext.getPerspectiveBar();
157 if (fastViewBar == null)
158 fastViewBar = ext.getFastViewBar();
159 if (progressIndicator == null)
160 progressIndicator = ext.getProgressIndicator();
163 if (activeWindow instanceof WorkbenchWindow) {
164 WorkbenchWindow window = (WorkbenchWindow)activeWindow;
166 if (menuBar == null || menuBar == true) {
167 Menu m = window.getShell().getMenuBar();
168 if (m == null && menu != null) {
169 window.getShell().setMenuBar(menu);
172 Menu m = window.getShell().getMenuBar();
175 window.getShell().setMenuBar(null);
180 if (coolBar == null || coolBar == true) {
181 window.setCoolBarVisible(true);
183 window.setCoolBarVisible(false);
186 if (statusLine == null || statusLine == true) {
187 window.setStatusLineVisible(true);
188 //window.showHeapStatus(true);
190 window.setStatusLineVisible(false);
191 //window.showHeapStatus(false);
194 if (perspectiveBar == null || perspectiveBar == true) {
195 window.setPerspectiveBarVisible(true);
197 window.setPerspectiveBarVisible(false);
200 // Bug 479522 - Remove unused fastView methods in WorkbenchWindow
201 //if (fastViewBar == null || fastViewBar == true) {
202 // window.setFastViewBarVisible(true);
204 // window.setFastViewBarVisible(false);
207 if (progressIndicator == null || progressIndicator == true) {
208 ProgressRegion r = window.getProgressRegion();
210 r.getControl().setVisible(true);
213 ProgressRegion r = window.getProgressRegion();
215 r.getControl().setVisible(false);
217 // Bug 486768 - Delete unused internal ITrimManager
218 //window.getTrimManager().forceLayout();