Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 261795
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java (-20 / +68 lines)
Lines 13-19 Link Here
13
import java.util.HashMap;
13
import java.util.HashMap;
14
import java.util.Map;
14
import java.util.Map;
15
15
16
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.core.runtime.IExtensionPoint;
18
import org.eclipse.core.runtime.IExtensionRegistry;
16
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.jface.action.CoolBarManager;
21
import org.eclipse.jface.action.CoolBarManager;
18
import org.eclipse.jface.action.IAction;
22
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.action.IContributionItem;
23
import org.eclipse.jface.action.IContributionItem;
Lines 25-30 Link Here
25
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
29
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
26
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.window.Window;
27
import org.eclipse.osgi.util.TextProcessor;
31
import org.eclipse.osgi.util.TextProcessor;
32
import org.eclipse.rwt.branding.AbstractBranding;
33
import org.eclipse.rwt.internal.branding.BrandingUtil;
28
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.graphics.Point;
35
import org.eclipse.swt.graphics.Point;
30
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Composite;
Lines 578-605 Link Here
578
     * factory default presentation factory is used.
584
     * factory default presentation factory is used.
579
     */
585
     */
580
    private AbstractPresentationFactory createDefaultPresentationFactory() {
586
    private AbstractPresentationFactory createDefaultPresentationFactory() {
581
        final String factoryId = ((Workbench) window.getWorkbench())
587
      // RAP [hs] patched for interactiondesign API
582
                .getPresentationId();
588
      String tempId = getBrandingPresentationFactoryId();
583
589
      if( tempId == null ) {
584
        if (factoryId != null && factoryId.length() > 0) {
590
        tempId = ( ( Workbench ) window.getWorkbench() ).getPresentationId();
585
            final AbstractPresentationFactory [] factory = new AbstractPresentationFactory[1];
591
      }
586
            StartupThreading.runWithoutExceptions(new StartupRunnable() {
592
      final String factoryId = tempId;
587
593
588
				public void runWithException() throws Throwable {
594
      if (factoryId != null && factoryId.length() > 0) {
589
					factory[0] = WorkbenchPlugin.getDefault()
595
        final AbstractPresentationFactory [] factory = new AbstractPresentationFactory[1];
590
							.getPresentationFactory(factoryId);
596
        StartupThreading.runWithoutExceptions(new StartupRunnable() {
591
				}
597
      
592
			});
598
            public void runWithException() throws Throwable {
593
            
599
                factory[0] = WorkbenchPlugin.getDefault()
594
            if (factory[0] != null) {
600
                        .getPresentationFactory(factoryId);
595
                return factory[0];
601
            }
602
        });
603
        
604
        if (factory[0] != null) {
605
            return factory[0];
606
        }
607
      }
608
      // presentation ID must be a bogus value, reset it to the default
609
      PrefUtil.getAPIPreferenceStore().setValue(
610
            IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID,
611
            IWorkbenchConstants.DEFAULT_PRESENTATION_ID);
612
      return new WorkbenchPresentationFactory();
613
    }
614
    
615
    // RAP [hs] method introduced for interactiondesign API
616
    private String getBrandingPresentationFactoryId() {
617
      String result = null;
618
      AbstractBranding branding = BrandingUtil.findBranding();
619
      if( branding != null ) {
620
        String brandingId = branding.getId();
621
        IExtensionRegistry registry = Platform.getExtensionRegistry();
622
        final String id = "org.eclipse.rap.ui.branding";
623
        IExtensionPoint brandingPoint = registry.getExtensionPoint( id );
624
        if( brandingPoint != null ) {
625
          IConfigurationElement[] elements 
626
            = brandingPoint.getConfigurationElements();
627
          boolean found = false;
628
          for( int i = 0; i < elements.length && !found; i++ ) {
629
            String tempId = elements[ i ].getAttribute( "id" );
630
            if( tempId.equals( brandingId ) ) {
631
              found = true;
632
              result = loadBrandingPresentationFactoryId( elements[ i ] );
596
            }
633
            }
634
          }
597
        }
635
        }
598
        // presentation ID must be a bogus value, reset it to the default
636
      }
599
        PrefUtil.getAPIPreferenceStore().setValue(
637
      return result;
600
				IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID,
638
    }
601
				IWorkbenchConstants.DEFAULT_PRESENTATION_ID);
639
602
        return new WorkbenchPresentationFactory();
640
    // RAP [hs] method introduced for interactiondesign API
641
    private String loadBrandingPresentationFactoryId( 
642
      final IConfigurationElement element )
643
    {
644
      String result = null;
645
      IConfigurationElement[] factory 
646
        = element.getChildren( "presentationFactory" );
647
      if( factory.length > 0 ) {
648
        result = factory[ 0 ].getAttribute( "id" );
649
      }
650
      return result;
603
    }
651
    }
604
652
605
    /* (non-Javadoc)
653
    /* (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/internal/ViewPane.java (-4 / +10 lines)
Lines 317-326 Link Here
317
     * @see ViewActionBars
317
     * @see ViewActionBars
318
     */
318
     */
319
    public MenuManager getMenuManager() {
319
    public MenuManager getMenuManager() {
320
        if (isvMenuMgr == null) {
320
      if( isvMenuMgr == null ) {
321
			isvMenuMgr = new PaneMenuManager();
321
        WorkbenchWindow window = page.window;
322
		}
322
        // RAP [hs] patched for interactiondesign API
323
        return isvMenuMgr;
323
        if( window.getConfigurablePresentationFactory() != null ) {
324
          isvMenuMgr = window.createPartMenuManager();
325
        } else {        
326
          isvMenuMgr = new PaneMenuManager();
327
        }
328
      }
329
      return isvMenuMgr;
324
    }
330
    }
325
331
326
    /**
332
    /**
(-)Eclipse UI/org/eclipse/ui/internal/PartStack.java (-10 / +8 lines)
Lines 29-55 Link Here
29
import org.eclipse.jface.preference.IPreferenceStore;
29
import org.eclipse.jface.preference.IPreferenceStore;
30
import org.eclipse.jface.util.Geometry;
30
import org.eclipse.jface.util.Geometry;
31
import org.eclipse.osgi.util.NLS;
31
import org.eclipse.osgi.util.NLS;
32
//import org.eclipse.swt.graphics.Cursor;
33
import org.eclipse.swt.graphics.Point;
32
import org.eclipse.swt.graphics.Point;
34
import org.eclipse.swt.graphics.Rectangle;
33
import org.eclipse.swt.graphics.Rectangle;
35
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
35
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Display;
36
import org.eclipse.swt.widgets.Display;
38
//import org.eclipse.ui.IEditorInput;
39
import org.eclipse.ui.IMemento;
37
import org.eclipse.ui.IMemento;
40
import org.eclipse.ui.IPersistable;
38
import org.eclipse.ui.IPersistable;
41
import org.eclipse.ui.IPropertyListener;
39
import org.eclipse.ui.IPropertyListener;
42
import org.eclipse.ui.IWorkbenchPartReference;
40
import org.eclipse.ui.IWorkbenchPartReference;
43
import org.eclipse.ui.IWorkbenchPreferenceConstants;
41
import org.eclipse.ui.IWorkbenchPreferenceConstants;
44
//import org.eclipse.ui.PartInitException;
45
import org.eclipse.ui.PlatformUI;
42
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.XMLMemento;
43
import org.eclipse.ui.XMLMemento;
47
import org.eclipse.ui.internal.StartupThreading.StartupRunnable;
44
import org.eclipse.ui.internal.StartupThreading.StartupRunnable;
48
//import org.eclipse.ui.internal.dnd.AbstractDropTarget;
49
//import org.eclipse.ui.internal.dnd.DragUtil;
50
//import org.eclipse.ui.internal.dnd.IDropTarget;
51
import org.eclipse.ui.internal.dnd.SwtUtil;
45
import org.eclipse.ui.internal.dnd.SwtUtil;
52
//import org.eclipse.ui.internal.intro.IIntroConstants;
53
import org.eclipse.ui.internal.layout.ITrimManager;
46
import org.eclipse.ui.internal.layout.ITrimManager;
54
import org.eclipse.ui.internal.layout.IWindowTrim;
47
import org.eclipse.ui.internal.layout.IWindowTrim;
55
import org.eclipse.ui.internal.presentations.PresentablePart;
48
import org.eclipse.ui.internal.presentations.PresentablePart;
Lines 60-66 Link Here
60
import org.eclipse.ui.presentations.AbstractPresentationFactory;
53
import org.eclipse.ui.presentations.AbstractPresentationFactory;
61
import org.eclipse.ui.presentations.IPresentablePart;
54
import org.eclipse.ui.presentations.IPresentablePart;
62
import org.eclipse.ui.presentations.IStackPresentationSite;
55
import org.eclipse.ui.presentations.IStackPresentationSite;
63
//import org.eclipse.ui.presentations.StackDropResult;
64
import org.eclipse.ui.presentations.StackPresentation;
56
import org.eclipse.ui.presentations.StackPresentation;
65
57
66
/**
58
/**
Lines 168-176 Link Here
168
            return (IPresentablePart[]) parts.toArray(new IPresentablePart[parts.size()]);
160
            return (IPresentablePart[]) parts.toArray(new IPresentablePart[parts.size()]);
169
        }
161
        }
170
162
171
        public String getProperty(String id) {            
163
        public String getProperty(String id) { 
172
            return PartStack.this.getProperty(id);
164
          // RAP [hs] patched for interactiondesign API
165
          String result = PartStack.this.getProperty(id);
166
          if( id.equals( "id" ))
167
            result = PartStack.this.getID();
168
          return result;
173
        }
169
        }
170
        
171
174
    };
172
    };
175
173
176
// RAP [rh] PartStackDropResult disabled since DnD support is missing    
174
// RAP [rh] PartStackDropResult disabled since DnD support is missing    
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java (-3675 / +3761 lines)
Lines 1-16 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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
12
package org.eclipse.ui.internal;
1
package org.eclipse.ui.internal;
13
2
3
14
import java.lang.reflect.InvocationTargetException;
4
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
5
import java.util.ArrayList;
16
import java.util.HashMap;
6
import java.util.HashMap;
Lines 54-59 Link Here
54
import org.eclipse.jface.window.Window;
44
import org.eclipse.jface.window.Window;
55
import org.eclipse.osgi.util.NLS;
45
import org.eclipse.osgi.util.NLS;
56
import org.eclipse.osgi.util.TextProcessor;
46
import org.eclipse.osgi.util.TextProcessor;
47
import org.eclipse.rap.ui.interactiondesign.IWindowComposer;
48
import org.eclipse.rap.ui.interactiondesign.PresentationFactory;
57
import org.eclipse.swt.SWT;
49
import org.eclipse.swt.SWT;
58
import org.eclipse.swt.custom.BusyIndicator;
50
import org.eclipse.swt.custom.BusyIndicator;
59
import org.eclipse.swt.custom.CBanner;
51
import org.eclipse.swt.custom.CBanner;
Lines 88-94 Link Here
88
import org.eclipse.ui.IWorkbenchPage;
80
import org.eclipse.ui.IWorkbenchPage;
89
import org.eclipse.ui.IWorkbenchPart;
81
import org.eclipse.ui.IWorkbenchPart;
90
import org.eclipse.ui.IWorkbenchPartReference;
82
import org.eclipse.ui.IWorkbenchPartReference;
91
//import org.eclipse.ui.IWorkbenchPreferenceConstants;
92
import org.eclipse.ui.IWorkbenchWindow;
83
import org.eclipse.ui.IWorkbenchWindow;
93
import org.eclipse.ui.PlatformUI;
84
import org.eclipse.ui.PlatformUI;
94
import org.eclipse.ui.WorkbenchException;
85
import org.eclipse.ui.WorkbenchException;
Lines 105-111 Link Here
105
import org.eclipse.ui.internal.dnd.SwtUtil;
96
import org.eclipse.ui.internal.dnd.SwtUtil;
106
import org.eclipse.ui.internal.handlers.ActionCommandMappingService;
97
import org.eclipse.ui.internal.handlers.ActionCommandMappingService;
107
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
98
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
108
//import org.eclipse.ui.internal.intro.IIntroConstants;
109
import org.eclipse.ui.internal.layout.CacheWrapper;
99
import org.eclipse.ui.internal.layout.CacheWrapper;
110
import org.eclipse.ui.internal.layout.ITrimManager;
100
import org.eclipse.ui.internal.layout.ITrimManager;
111
import org.eclipse.ui.internal.layout.IWindowTrim;
101
import org.eclipse.ui.internal.layout.IWindowTrim;
Lines 130-136 Link Here
130
import org.eclipse.ui.internal.services.ServiceLocator;
120
import org.eclipse.ui.internal.services.ServiceLocator;
131
import org.eclipse.ui.internal.tweaklets.Tweaklets;
121
import org.eclipse.ui.internal.tweaklets.Tweaklets;
132
import org.eclipse.ui.internal.tweaklets.WorkbenchImplementation;
122
import org.eclipse.ui.internal.tweaklets.WorkbenchImplementation;
133
//import org.eclipse.ui.internal.util.PrefUtil;
134
import org.eclipse.ui.internal.util.Util;
123
import org.eclipse.ui.internal.util.Util;
135
import org.eclipse.ui.menus.IMenuService;
124
import org.eclipse.ui.menus.IMenuService;
136
import org.eclipse.ui.menus.MenuUtil;
125
import org.eclipse.ui.menus.MenuUtil;
Lines 140-3861 Link Here
140
 * A window within the workbench.
129
 * A window within the workbench.
141
 */
130
 */
142
public class WorkbenchWindow extends ApplicationWindow implements
131
public class WorkbenchWindow extends ApplicationWindow implements
143
		IWorkbenchWindow {
132
        IWorkbenchWindow {
144
133
145
	private WorkbenchWindowAdvisor windowAdvisor;
134
    private WorkbenchWindowAdvisor windowAdvisor;
146
135
147
	private ActionBarAdvisor actionBarAdvisor;
136
    private ActionBarAdvisor actionBarAdvisor;
148
137
149
	private int number;
138
    private int number;
150
139
151
	private PageList pageList = new PageList();
140
    private PageList pageList = new PageList();
152
141
153
	private PageListenerList pageListeners = new PageListenerList();
142
    private PageListenerList pageListeners = new PageListenerList();
154
143
155
	private PerspectiveListenerList perspectiveListeners = new PerspectiveListenerList();
144
    private PerspectiveListenerList perspectiveListeners = new PerspectiveListenerList();
156
145
157
	private WWinPartService partService = new WWinPartService(this);
146
    private WWinPartService partService = new WWinPartService(this);
158
147
159
	private ActionPresentation actionPresentation;
148
    private ActionPresentation actionPresentation;
160
149
161
	private WWinActionBars actionBars;
150
    private WWinActionBars actionBars;
162
151
163
	private boolean updateDisabled = true;
152
    private boolean updateDisabled = true;
164
153
165
	private boolean closing = false;
154
    private boolean closing = false;
166
155
167
	private boolean shellActivated = false;
156
    private boolean shellActivated = false;
168
157
169
	private FastViewBar fastViewBar;
158
    private FastViewBar fastViewBar;
170
159
171
	private PerspectiveSwitcher perspectiveSwitcher = null;
160
    private PerspectiveSwitcher perspectiveSwitcher = null;
172
161
173
	private TrimLayout defaultLayout;
162
    private TrimLayout defaultLayout;
174
163
175
	ProgressRegion progressRegion = null;
164
    ProgressRegion progressRegion = null;
176
165
177
	// Legacy (3.2) contribution handling
166
    // Legacy (3.2) contribution handling
178
	private TrimBarManager2 trimMgr2 = null;
167
    private TrimBarManager2 trimMgr2 = null;
179
	
168
    
180
	// 3.3 Trim Contribution handling
169
    // 3.3 Trim Contribution handling
181
	private TrimContributionManager trimContributionMgr = null;
170
    private TrimContributionManager trimContributionMgr = null;
182
	
171
    
183
	/**
172
    /**
184
	 * The map of services maintained by the workbench window. These services
173
     * The map of services maintained by the workbench window. These services
185
	 * are initialized during workbench window during the
174
     * are initialized during workbench window during the
186
	 * {@link #configureShell(Shell)}.
175
     * {@link #configureShell(Shell)}.
187
	 */
176
     */
188
	private final ServiceLocator serviceLocator;
177
    private final ServiceLocator serviceLocator;
189
178
190
// RAP [rh] HeapStatus not supported  
179
// RAP [rh] HeapStatus not supported  
191
//	private HeapStatus heapStatus;
180
//  private HeapStatus heapStatus;
192
181
193
//	private WindowTrimProxy heapStatusTrim = null;
182
//  private WindowTrimProxy heapStatusTrim = null;
194
183
195
	private boolean emptyWindowContentsCreated = false;
184
    private boolean emptyWindowContentsCreated = false;
196
185
197
	private Control emptyWindowContents;
186
    private Control emptyWindowContents;
198
187
199
	private Rectangle normalBounds;
188
    private Rectangle normalBounds;
200
201
	private boolean asMaximizedState = false;
202
203
	private CBanner topBar;
204
205
	private IWindowTrim topBarTrim;
206
207
	// Previous shell size. Used to prevent the CBanner from triggering
208
	// redundant layouts
209
	private Point lastShellSize = new Point(0, 0);
210
211
	/**
212
	 * The composite under which workbench pages create their controls.
213
	 */
214
	private Composite pageComposite;
215
216
	/**
217
	 * Bit flags indication which submenus (New, Show Views, ...) this window
218
	 * contains. Initially none.
219
	 */
220
	private int submenus = 0x00;
221
222
	/**
223
	 * Object for configuring this workbench window. Lazily initialized to an
224
	 * instance unique to this window.
225
	 */
226
	private WorkbenchWindowConfigurer windowConfigurer = null;
227
	
228
	/**
229
	 * List of generic property listeners.
230
	 */
231
	private ListenerList genericPropertyListeners = new ListenerList();
232
233
	// RAP [bm]: detached windows
234
//	private ShellPool detachedWindowShells;
235
	// RAPEND: [bm] 
236
	
237
	static final String TEXT_DELIMITERS = TextProcessor.getDefaultDelimiters() + "-"; //$NON-NLS-1$
238
239
	// constants for shortcut bar group ids
240
	static final String GRP_PAGES = "pages"; //$NON-NLS-1$
241
242
	static final String GRP_PERSPECTIVES = "perspectives"; //$NON-NLS-1$
243
244
	static final String GRP_FAST_VIEWS = "fastViews"; //$NON-NLS-1$
245
246
	// static fields for inner classes.
247
	static final int VGAP = 0;
248
249
	static final int CLIENT_INSET = 3;
250
251
	static final int BAR_SIZE = 23;
252
253
	/**
254
	 * Coolbar visibility change property.
255
	 */
256
	public static final String PROP_COOLBAR_VISIBLE = "coolbarVisible"; //$NON-NLS-1$
257
	
258
	/**
259
	 * Perspective bar visibility change property.
260
	 */
261
	public static final String PROP_PERSPECTIVEBAR_VISIBLE = "perspectiveBarVisible"; //$NON-NLS-1$
262
	
263
	/**
264
	 * Constant (bit mask) indicating which the Show View submenu is probably
265
	 * present somewhere in this window.
266
	 * 
267
	 * @see #addSubmenu
268
	 */
269
	public static final int SHOW_VIEW_SUBMENU = 0x01;
270
271
	/**
272
	 * Constant (bit mask) indicating which the Open Perspective submenu is
273
	 * probably present somewhere in this window.
274
	 * 
275
	 * @see #addSubmenu
276
	 */
277
	public static final int OPEN_PERSPECTIVE_SUBMENU = 0x02;
278
279
	/**
280
	 * Constant (bit mask) indicating which the New Wizard submenu is probably
281
	 * present somewhere in this window.
282
	 * 
283
	 * @see #addSubmenu
284
	 */
285
	public static final int NEW_WIZARD_SUBMENU = 0x04;
286
287
	/**
288
	 * Remembers that this window contains the given submenu.
289
	 * 
290
	 * @param type
291
	 *            the type of submenu, one of:
292
	 *            {@link #NEW_WIZARD_SUBMENU NEW_WIZARD_SUBMENU},
293
	 *            {@link #OPEN_PERSPECTIVE_SUBMENU OPEN_PERSPECTIVE_SUBMENU},
294
	 *            {@link #SHOW_VIEW_SUBMENU SHOW_VIEW_SUBMENU}
295
	 * @see #containsSubmenu
296
	 */
297
	public void addSubmenu(int type) {
298
		submenus |= type;
299
	}
300
301
	/**
302
	 * Checks to see if this window contains the given type of submenu.
303
	 * 
304
	 * @param type
305
	 *            the type of submenu, one of:
306
	 *            {@link #NEW_WIZARD_SUBMENU NEW_WIZARD_SUBMENU},
307
	 *            {@link #OPEN_PERSPECTIVE_SUBMENU OPEN_PERSPECTIVE_SUBMENU},
308
	 *            {@link #SHOW_VIEW_SUBMENU SHOW_VIEW_SUBMENU}
309
	 * @return <code>true</code> if window contains submenu,
310
	 *         <code>false</code> otherwise
311
	 * @see #addSubmenu
312
	 */
313
	public boolean containsSubmenu(int type) {
314
		return ((submenus & type) != 0);
315
	}
316
317
	/**
318
	 * Constant indicating that all the actions bars should be filled.
319
	 */
320
	private static final int FILL_ALL_ACTION_BARS = ActionBarAdvisor.FILL_MENU_BAR
321
			| ActionBarAdvisor.FILL_COOL_BAR
322
			| ActionBarAdvisor.FILL_STATUS_LINE;
323
324
	/**
325
	 * Creates and initializes a new workbench window.
326
	 * 
327
	 * @param number
328
	 *            the number for the window
329
	 */
330
	public WorkbenchWindow(int number) {
331
		super(null);
332
		this.number = number;
333
334
		// Make sure there is a workbench. This call will throw
335
		// an exception if workbench not created yet.
336
		final IWorkbench workbench = PlatformUI.getWorkbench();
337
		IServiceLocatorCreator slc = (IServiceLocatorCreator) workbench
338
				.getService(IServiceLocatorCreator.class);
339
		this.serviceLocator = (ServiceLocator) slc
340
				.createServiceLocator(workbench, null);
341
		initializeDefaultServices();
342
343
		// Add contribution managers that are exposed to other plugins.
344
		addMenuBar();
345
		addCoolBar(SWT.NONE);  // style is unused
346
		addStatusLine();
347
348
		// register with the tracker
349
		getExtensionTracker()
350
				.registerHandler(
351
						actionSetHandler,
352
						ExtensionTracker
353
								.createExtensionPointFilter(getActionSetExtensionPoint()));
354
355
		fireWindowOpening();
356
357
		// set the shell style
358
		setShellStyle(getWindowConfigurer().getShellStyle());
359
360
		// Fill the action bars
361
		fillActionBars(FILL_ALL_ACTION_BARS);
362
	}
363
364
	/**
365
	 * Return the action set extension point.
366
	 * 
367
	 * @return the action set extension point
368
	 */
369
	private IExtensionPoint getActionSetExtensionPoint() {
370
		// RAP [bm]: 
371
//		return Platform.getExtensionRegistry().getExtensionPoint(
372
//				PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_ACTION_SETS);
373
		return Platform.getExtensionRegistry().getExtensionPoint(
374
				PlatformUI.PLUGIN_EXTENSION_NAME_SPACE, IWorkbenchRegistryConstants.PL_ACTION_SETS);
375
376
	}
377
378
	/**
379
	 * Return the style bits for the shortcut bar.
380
	 * 
381
	 * @return int
382
	 */
383
	protected int perspectiveBarStyle() {
384
		return SWT.FLAT | SWT.WRAP | SWT.RIGHT | SWT.HORIZONTAL;
385
	}
386
387
	// RAP [bm]: not used
388
//	private TrimDropTarget trimDropTarget;
389
	// RAPEND: [bm] 
390
391
	private boolean coolBarVisible = true;
392
393
	private boolean perspectiveBarVisible = true;
394
	
395
	private boolean fastViewBarVisible = true;
396
397
	private boolean statusLineVisible = true;
398
399
	private IWindowTrim statusLineTrim = null;
400
401
	/**
402
	 * The handlers for global actions that were last submitted to the workbench
403
	 * command support. This is a map of command identifiers to
404
	 * <code>ActionHandler</code>. This map is never <code>null</code>,
405
	 * and is never empty as long as at least one global action has been
406
	 * registered.
407
	 */
408
	private Map globalActionHandlersByCommandId = new HashMap();
409
410
	/**
411
	 * The list of handler submissions submitted to the workbench command
412
	 * support. This list may be empty, but it is never <code>null</code>.
413
	 */
414
	private List handlerActivations = new ArrayList();
415
416
	/**
417
	 * The number of large updates that are currently going on. If this is
418
	 * number is greater than zero, then UI updateActionBars is a no-op.
419
	 */
420
	private int largeUpdates = 0;
421
422
	private IExtensionTracker tracker;
423
424
	private IExtensionChangeHandler actionSetHandler = new IExtensionChangeHandler() {
425
426
		/*
427
		 * (non-Javadoc)
428
		 * 
429
		 * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamichelpers.IExtensionTracker,
430
		 *      org.eclipse.core.runtime.IExtension)
431
		 */
432
		public void addExtension(IExtensionTracker tracker, IExtension extension) {
433
			// this assumes that the workbench-level tracker will have already
434
			// updated the registry
435
436
			ArrayList setsToActivate = new ArrayList();
437
			// look for all new sets that are on by default. Examine the tracker
438
			// at the workbench level to see what descriptors are registered
439
			// against this extension
440
			Object[] registeredObjects = getWorkbench().getExtensionTracker()
441
					.getObjects(extension);
442
			for (int i = 0; i < registeredObjects.length; i++) {
443
				if (registeredObjects[i] instanceof IActionSetDescriptor) {
444
					IActionSetDescriptor desc = (IActionSetDescriptor) registeredObjects[i];
445
					if (desc.isInitiallyVisible()) {
446
						setsToActivate.add(desc);
447
					}
448
				}
449
			}
450
451
			// if none of the new sets are marked as initially visible, abort.
452
			if (setsToActivate.isEmpty()) {
453
				return;
454
			}
455
456
			IActionSetDescriptor[] descriptors = (IActionSetDescriptor[]) setsToActivate
457
					.toArray(new IActionSetDescriptor[setsToActivate.size()]);
458
459
			WorkbenchPage page = getActiveWorkbenchPage();
460
			if (page != null) {
461
				Perspective[] perspectives = page.getOpenInternalPerspectives();
462
463
				for (int i = 0; i < perspectives.length; i++) {
464
					perspectives[i].turnOnActionSets(descriptors);
465
				}
466
			}
467
468
			updateActionSets();
469
		}
470
471
		/*
472
		 * (non-Javadoc)
473
		 * 
474
		 * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension,
475
		 *      java.lang.Object[])
476
		 */
477
		public void removeExtension(IExtension extension, Object[] objects) {
478
			// remove the contributions from the window bars and dispose of the
479
			// actions
480
			for (int i = 0; i < objects.length; i++) {
481
				if (objects[i] instanceof PluginActionSetBuilder.Binding) {
482
					PluginActionSetBuilder.Binding binding = (PluginActionSetBuilder.Binding) objects[i];
483
					binding.builder.removeActionExtensions(binding.set,
484
							binding.window);
485
					binding.set.dispose();
486
				}
487
			}
488
489
			// update all opened perspectives
490
			Perspective[] perspectives = getActiveWorkbenchPage()
491
					.getOpenInternalPerspectives();
492
			boolean updateNeeded = true;
493
			IContextService contextService = (IContextService) getService(IContextService.class);
494
			try {
495
				contextService.activateContext(ContextAuthority.DEFER_EVENTS);
496
				
497
				for (int i = 0; i < perspectives.length; i++) {
498
					for (int j = 0; j < objects.length; j++) {
499
						if (objects[j] instanceof IActionSetDescriptor) {
500
							perspectives[i]
501
									.removeActionSet((IActionSetDescriptor) objects[j]);
502
							getActionPresentation().removeActionSet(
503
									(IActionSetDescriptor) objects[j]);
504
						}
505
					}
506
				}
507
			} finally {
508
				contextService.activateContext(ContextAuthority.SEND_EVENTS);
509
			}
510
511
			if (updateNeeded) {
512
				// refresh the window
513
				updateActionSets();
514
			}
515
		}
516
	};
517
518
	void registerGlobalAction(IAction globalAction) {
519
		String commandId = globalAction.getActionDefinitionId();
520
521
		if (commandId != null) {
522
			final Object value = globalActionHandlersByCommandId.get(commandId);
523
			if (value instanceof ActionHandler) {
524
				// This handler is about to get clobbered, so dispose it.
525
				final ActionHandler handler = (ActionHandler) value;
526
				handler.dispose();
527
			}
528
529
			if (globalAction instanceof CommandAction) {
530
				final String actionId = globalAction.getId();
531
				if (actionId != null) {
532
					final IActionCommandMappingService mappingService = (IActionCommandMappingService) serviceLocator
533
							.getService(IActionCommandMappingService.class);
534
					mappingService.map(actionId, commandId);
535
				}
536
			} else {
537
				globalActionHandlersByCommandId.put(commandId,
538
						new ActionHandler(globalAction));
539
			}
540
		}
541
542
		submitGlobalActions();
543
	}
544
545
	/**
546
	 * <p>
547
	 * Submits the action handlers for action set actions and global actions.
548
	 * Global actions are given priority, so that if a global action and an
549
	 * action set action both handle the same command, the global action is
550
	 * given priority.
551
	 * </p>
552
	 * <p>
553
	 * These submissions are submitted as <code>Priority.LEGACY</code>, which
554
	 * means that they are the lowest priority. This means that if a higher
555
	 * priority submission handles the same command under the same conditions,
556
	 * that that submission will become the handler.
557
	 * </p>
558
	 */
559
	void submitGlobalActions() {
560
		final IHandlerService handlerService = (IHandlerService) getWorkbench().getService(IHandlerService.class);
561
562
		/*
563
		 * Mash the action sets and global actions together, with global actions
564
		 * taking priority.
565
		 */
566
		Map handlersByCommandId = new HashMap();
567
		handlersByCommandId.putAll(globalActionHandlersByCommandId);
568
569
		List newHandlers = new ArrayList(handlersByCommandId.size());
570
571
		Iterator existingIter = handlerActivations.iterator();
572
		while (existingIter.hasNext()) {
573
			IHandlerActivation next = (IHandlerActivation) existingIter.next();
574
575
			String cmdId = next.getCommandId();
576
577
			Object handler = handlersByCommandId.get(cmdId);
578
			if (handler == next.getHandler()) {
579
				handlersByCommandId.remove(cmdId);
580
				newHandlers.add(next);
581
			} else {
582
				handlerService.deactivateHandler(next);
583
			}
584
		}
585
586
		final Shell shell = getShell();
587
		if (shell != null) {
588
			final Expression expression = new ActiveShellExpression(shell);
589
			for (Iterator iterator = handlersByCommandId.entrySet().iterator(); iterator
590
					.hasNext();) {
591
				Map.Entry entry = (Map.Entry) iterator.next();
592
				String commandId = (String) entry.getKey();
593
				IHandler handler = (IHandler) entry.getValue();
594
				newHandlers.add(handlerService.activateHandler(commandId,
595
						handler, expression));
596
			}
597
		}
598
599
		handlerActivations = newHandlers;
600
	}
601
	
602
	/**
603
	 * Add a generic property listener.
604
	 * 
605
	 * @param listener the listener to add
606
	 */
607
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
608
		genericPropertyListeners.add(listener);
609
	}
610
	
611
	/**
612
	 * Removes a generic property listener.
613
	 * 
614
	 * @param listener the listener to remove 
615
	 */
616
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
617
		genericPropertyListeners.remove(listener);
618
	}
619
	
620
	private void firePropertyChanged(final String property, final Object oldValue, final Object newValue) {
621
		PropertyChangeEvent event = new PropertyChangeEvent(this, property, oldValue, newValue);
622
		Object[] listeners = genericPropertyListeners.getListeners();
623
		for (int i = 0; i < listeners.length; i++) {
624
			IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i];
625
			listener.propertyChange(event);
626
		}
627
	}
628
629
	/*
630
	 * Adds an listener to the part service.
631
	 */
632
	public void addPageListener(IPageListener l) {
633
		pageListeners.addPageListener(l);
634
	}
635
636
	/**
637
	 * @see org.eclipse.ui.IPageService
638
	 */
639
	public void addPerspectiveListener(org.eclipse.ui.IPerspectiveListener l) {
640
		perspectiveListeners.addPerspectiveListener(l);
641
	}
642
643
	/**
644
	 * Configures this window to have a perspecive bar. Does nothing if it
645
	 * already has one.
646
	 */
647
	protected void addPerspectiveBar(int style) {
648
		Assert.isTrue(perspectiveSwitcher == null);
649
		perspectiveSwitcher = new PerspectiveSwitcher(this, topBar, style);
650
	}
651
652
	/**
653
	 * Close the window.
654
	 * 
655
	 * Assumes that busy cursor is active.
656
	 */
657
	private boolean busyClose() {
658
		// Whether the window was actually closed or not
659
		boolean windowClosed = false;
660
661
		// Setup internal flags to indicate window is in
662
		// progress of closing and no update should be done.
663
		closing = true;
664
		updateDisabled = true;
665
666
		try {
667
			// Only do the check if it is OK to close if we are not closing
668
			// via the workbench as the workbench will check this itself.
669
			Workbench workbench = getWorkbenchImpl();
670
			int count = workbench.getWorkbenchWindowCount();
671
			// also check for starting - if the first window dies on startup
672
			// then we'll need to open a default window.
673
			if (!workbench.isStarting()
674
					&& !workbench.isClosing()
675
					&& count <= 1
676
					&& workbench.getWorkbenchConfigurer()
677
							.getExitOnLastWindowClose()) {
678
				windowClosed = workbench.close();
679
			} else {
680
				if (okToClose()) {
681
					windowClosed = hardClose();
682
				}
683
			}
684
		} finally {
685
			if (!windowClosed) {
686
				// Reset the internal flags if window was not closed.
687
				closing = false;
688
				updateDisabled = false;
689
			}
690
		}
691
692
		if (windowClosed && tracker != null) {
693
			tracker.close();
694
		}
695
696
		return windowClosed;
697
	}
698
699
	/**
700
	 * Opens a new page. Assumes that busy cursor is active.
701
	 * <p>
702
	 * <b>Note:</b> Since release 2.0, a window is limited to contain at most
703
	 * one page. If a page exist in the window when this method is used, then
704
	 * another window is created for the new page. Callers are strongly
705
	 * recommended to use the <code>IWorkbench.openPerspective</code> APIs to
706
	 * programmatically show a perspective.
707
	 * </p>
708
	 */
709
	protected IWorkbenchPage busyOpenPage(String perspID, IAdaptable input)
710
			throws WorkbenchException {
711
		IWorkbenchPage newPage = null;
712
713
		if (pageList.isEmpty()) {
714
			newPage = ((WorkbenchImplementation) Tweaklets
715
					.get(WorkbenchImplementation.KEY)).createWorkbenchPage(this, perspID, input);
716
			pageList.add(newPage);
717
			firePageOpened(newPage);
718
			setActivePage(newPage);
719
		} else {
720
			IWorkbenchWindow window = getWorkbench().openWorkbenchWindow(
721
					perspID, input);
722
			newPage = window.getActivePage();
723
		}
724
725
		return newPage;
726
	}
727
728
	/**
729
	 * @see Window
730
	 */
731
	public int open() {
732
		if (getPages().length == 0) {
733
			showEmptyWindowContents();
734
		}
735
		fireWindowCreated();
736
// RAP [rh] Intro mechanism not supported
737
//		getWindowAdvisor().openIntro();
738
		int result = super.open();
739
189
740
		// It's time for a layout ... to insure that if TrimLayout
190
    private boolean asMaximizedState = false;
741
		// is in play, it updates all of the trim it's responsible
742
		// for. We have to do this before updating in order to get
743
		// the PerspectiveBar management correct...see defect 137334
744
		getShell().layout();
745
		
746
		fireWindowOpened();
747
		if (perspectiveSwitcher != null) {
748
			perspectiveSwitcher.updatePerspectiveBar();
749
			perspectiveSwitcher.updateBarParent();
750
		}
751
		
752
		return result;
753
	}
754
755
	/*
756
	 * (non-Javadoc) Method declared on Window.
757
	 */
758
	protected boolean canHandleShellCloseEvent() {
759
		if (!super.canHandleShellCloseEvent()) {
760
			return false;
761
		}
762
		// let the advisor or other interested parties
763
		// veto the user's explicit request to close the window
764
		return fireWindowShellClosing();
765
	}
766
767
	/**
768
	 * @see IWorkbenchWindow
769
	 */
770
	public boolean close() {
771
		final boolean[] ret = new boolean[1];
772
		BusyIndicator.showWhile(null, new Runnable() {
773
			public void run() {
774
				ret[0] = busyClose();
775
			}
776
		});
777
		return ret[0];
778
	}
779
780
	protected boolean isClosing() {
781
		return closing || getWorkbenchImpl().isClosing();
782
	}
783
784
	/**
785
	 * Return whether or not the coolbar layout is locked.
786
	 */
787
	protected boolean isCoolBarLocked() {
788
        ICoolBarManager cbm = getCoolBarManager2(); 
789
		return cbm != null && cbm.getLockLayout();
790
	}
791
191
792
	/**
192
    private CBanner topBar;
793
	 * Close all of the pages.
794
	 */
795
	private void closeAllPages() {
796
		// Deactivate active page.
797
		setActivePage(null);
798
799
		// Clone and deref all so that calls to getPages() returns
800
		// empty list (if call by pageClosed event handlers)
801
		PageList oldList = pageList;
802
		pageList = new PageList();
803
804
		// Close all.
805
		Iterator itr = oldList.iterator();
806
		while (itr.hasNext()) {
807
			WorkbenchPage page = (WorkbenchPage) itr.next();
808
			firePageClosed(page);
809
			page.dispose();
810
		}
811
		if (!closing) {
812
			showEmptyWindowContents();
813
		}
814
	}
815
816
	/**
817
	 * Save and close all of the pages.
818
	 */
819
	public void closeAllPages(boolean save) {
820
		if (save) {
821
			boolean ret = saveAllPages(true);
822
			if (!ret) {
823
				return;
824
			}
825
		}
826
		closeAllPages();
827
	}
828
829
	/**
830
	 * closePerspective method comment.
831
	 */
832
	protected boolean closePage(IWorkbenchPage in, boolean save) {
833
		// Validate the input.
834
		if (!pageList.contains(in)) {
835
			return false;
836
		}
837
		WorkbenchPage oldPage = (WorkbenchPage) in;
838
839
		// Save old perspective.
840
		if (save && oldPage.isSaveNeeded()) {
841
			if (!oldPage.saveAllEditors(true)) {
842
				return false;
843
			}
844
		}
845
846
		// If old page is activate deactivate.
847
		boolean oldIsActive = (oldPage == getActiveWorkbenchPage());
848
		if (oldIsActive) {
849
			setActivePage(null);
850
		}
851
852
		// Close old page.
853
		pageList.remove(oldPage);
854
		firePageClosed(oldPage);
855
		oldPage.dispose();
856
857
		// Activate new page.
858
		if (oldIsActive) {
859
			IWorkbenchPage newPage = pageList.getNextActive();
860
			if (newPage != null) {
861
				setActivePage(newPage);
862
			}
863
		}
864
		if (!closing && pageList.isEmpty()) {
865
			showEmptyWindowContents();
866
		}
867
		return true;
868
	}
869
870
	private void showEmptyWindowContents() {
871
		if (!emptyWindowContentsCreated) {
872
			Composite parent = getPageComposite();
873
			emptyWindowContents = getWindowAdvisor().createEmptyWindowContents(
874
					parent);
875
			emptyWindowContentsCreated = true;
876
			// force the empty window composite to be layed out
877
			((StackLayout) parent.getLayout()).topControl = emptyWindowContents;
878
			parent.layout();
879
		}
880
	}
881
882
	private void hideEmptyWindowContents() {
883
		if (emptyWindowContentsCreated) {
884
			if (emptyWindowContents != null) {
885
				emptyWindowContents.dispose();
886
				emptyWindowContents = null;
887
				getPageComposite().layout();
888
			}
889
			emptyWindowContentsCreated = false;
890
		}
891
	}
892
893
	/*
894
	 * (non-Javadoc)
895
	 * 
896
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
897
	 */
898
	protected void configureShell(Shell shell) {
899
		super.configureShell(shell);
900
901
		// RAP [bm]: detached windows
902
//		detachedWindowShells = new ShellPool(shell, SWT.TOOL | SWT.TITLE
903
//				| SWT.MAX | SWT.RESIZE | getDefaultOrientation());
904
		// RAPEND: [bm] 
905
906
		String title = getWindowConfigurer().basicGetTitle();
907
		if (title != null) {
908
			shell.setText(TextProcessor.process(title, TEXT_DELIMITERS)); 
909
		}
910
193
911
// RAP [rh] IWorkbench#getHelpSystem() not implemented 
194
    private IWindowTrim topBarTrim;
912
//		final IWorkbench workbench = getWorkbench();
913
//		workbench.getHelpSystem().setHelp(shell,
914
//				IWorkbenchHelpContextIds.WORKBENCH_WINDOW);
915
916
//		initializeDefaultServices();
917
		final IContextService contextService = (IContextService) getWorkbench().getService(IContextService.class);
918
		contextService.registerShell(shell, IContextService.TYPE_WINDOW);
919
920
		trackShellActivation(shell);
921
		trackShellResize(shell);
922
	}
923
924
	// RAP [bm]: detached windows
925
//	/* package */ShellPool getDetachedWindowPool() {
926
//		return detachedWindowShells;
927
//	}
928
	// RAPEND: [bm] 
929
930
	/*
931
	 * (non-Javadoc)
932
	 * 
933
	 * @see org.eclipse.jface.window.ApplicationWindow#createTrimWidgets(org.eclipse.swt.widgets.Shell)
934
	 */
935
	protected void createTrimWidgets(Shell shell) {
936
		// do nothing -- trim widgets are created in createDefaultContents
937
	}
938
939
	/**
940
	 * Creates and remembers the client composite, under which workbench pages
941
	 * create their controls.
942
	 */
943
	protected Composite createPageComposite(Composite parent) {
944
		pageComposite = new Composite(parent, SWT.NONE);
945
		// use a StackLayout instead of a FillLayout (see bug 81460 [Workbench]
946
		// (regression) Close all perspectives, open Java perspective, layout
947
		// wrong)
948
		pageComposite.setLayout(new StackLayout());
949
		return pageComposite;
950
	}
951
952
	/**
953
	 * Creates the contents of the workbench window, including trim controls and
954
	 * the client composite. This MUST create the client composite via a call to
955
	 * <code>createClientComposite</code>.
956
	 */
957
	protected Control createContents(Composite parent) {
958
		// we know from Window.create that the parent is a Shell.
959
		getWindowAdvisor().createWindowContents((Shell) parent);
960
		// the page composite must be set by createWindowContents
961
		Assert
962
				.isNotNull(pageComposite,
963
						"createWindowContents must call configurer.createPageComposite"); //$NON-NLS-1$
964
		return pageComposite;
965
	}
966
967
	/**
968
	 * If the perspective bar is drawn on the top right corner of the window,
969
	 * then this method changes its appearance from curved to square. This
970
	 * should have its own preference, but for now it piggy-backs on the
971
	 * SHOW_TRADITIONAL_STYLE_TABS preference.
972
	 * 
973
	 * @param square
974
	 *            true for a square banner and false otherwise
975
	 */
976
	public void setBannerCurve(boolean square) {
977
		if (topBar != null) {
978
			topBar.setSimple(square);
979
		}
980
	}
981
982
	/**
983
	 * Creates the default contents and layout of the shell.
984
	 * 
985
	 * @param shell
986
	 *            the shell
987
	 */
988
	protected void createDefaultContents(final Shell shell) {
989
		defaultLayout = new TrimLayout();
990
		shell.setLayout(defaultLayout);
991
992
		Menu menuBar = getMenuBarManager().createMenuBar(shell);
993
		if (getWindowConfigurer().getShowMenuBar()) {
994
			shell.setMenuBar(menuBar);
995
		}
996
997
		// Create the CBanner widget which parents both the Coolbar
998
		// and the perspective switcher, and supports some configurations
999
		// on the left right and bottom
1000
		topBar = new CBanner(shell, SWT.NONE);
1001
		topBarTrim = new WindowTrimProxy(topBar,
1002
				"org.eclipse.ui.internal.WorkbenchWindow.topBar", //$NON-NLS-1$  
1003
				WorkbenchMessages.get().TrimCommon_Main_TrimName, SWT.NONE, true);
1004
1005
		// the banner gets a curve along with the new tab style
1006
		// TODO create a dedicated preference for this
1007
		// RAP [bm]: not needed
1008
//		setBannerCurve(PrefUtil.getAPIPreferenceStore().getBoolean(
1009
//				IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
1010
		setBannerCurve(false);
1011
		// RAPEND: [bm] 
1012
1013
		CacheWrapper coolbarCacheWrapper = new CacheWrapper(topBar);
1014
1015
		final Control coolBar = createCoolBarControl(coolbarCacheWrapper
1016
				.getControl());
1017
		// need to resize the shell, not just the coolbar's immediate
1018
		// parent, if the coolbar wants to grow or shrink
1019
1020
		coolBar.addListener(SWT.Resize, new Listener() {
1021
			public void handleEvent(Event event) {
1022
				// If the user is dragging the sash then we will need to force
1023
				// a resize. However, if the coolbar was resized programatically
1024
				// then everything is already layed out correctly. There is no
1025
				// direct way to tell the difference between these cases,
1026
				// however
1027
				// we take advantage of the fact that dragging the sash does not
1028
				// change the size of the shell, and only force another layout
1029
				// if the shell size is unchanged.
1030
				Rectangle clientArea = shell.getClientArea();
1031
1032
				if (lastShellSize.x == clientArea.width
1033
						&& lastShellSize.y == clientArea.height) {
1034
					LayoutUtil.resize(coolBar);
1035
				}
1036
1037
				lastShellSize.x = clientArea.width;
1038
				lastShellSize.y = clientArea.height;
1039
			}
1040
		});
1041
1042
		if (getWindowConfigurer().getShowCoolBar()) {
1043
			topBar.setLeft(coolbarCacheWrapper.getControl());
1044
		}
1045
1046
		createStatusLine(shell);
1047
1048
		fastViewBar = new FastViewBar(this);
1049
		fastViewBar.createControl(shell);
1050
1051
		if (getWindowConfigurer().getShowPerspectiveBar()) {
1052
			addPerspectiveBar(perspectiveBarStyle());
1053
			perspectiveSwitcher.createControl(shell);
1054
		}
1055
195
1056
		createProgressIndicator(shell);
196
    // Previous shell size. Used to prevent the CBanner from triggering
197
    // redundant layouts
198
    private Point lastShellSize = new Point(0, 0);
1057
199
1058
// RAP [rh] HeapStatus not supported  
200
    /**
1059
//		if (getShowHeapStatus()) {
201
     * The composite under which workbench pages create their controls.
1060
//			createHeapStatus(shell);
202
     */
1061
//		}
203
    private Composite pageComposite;
1062
		
1063
		// Insert any contributed trim into the layout
1064
		// Legacy (3.2) trim
1065
		trimMgr2 = new TrimBarManager2(this);
1066
		
1067
		// 3.3 Trim contributions
1068
		trimContributionMgr = new TrimContributionManager(this);
1069
		
1070
		// RAP [bm]: DnD
1071
//		trimDropTarget = new TrimDropTarget(shell, this);
1072
//		DragUtil.addDragTarget(shell, trimDropTarget);
1073
//		DragUtil.addDragTarget(null, trimDropTarget);
1074
		// RAPEND: [bm] 
1075
1076
		// Create the client composite area (where page content goes).
1077
		createPageComposite(shell);
1078
1079
		setLayoutDataForContents();
1080
		// System.err.println(defaultLayout.displayTrim());
1081
	}
1082
204
1083
// RAP [rh] HeapStatus not supported 
205
    /**
1084
//	/**
206
     * Bit flags indication which submenus (New, Show Views, ...) this window
1085
//	 * Returns whether the heap status indicator should be shown.
207
     * contains. Initially none.
1086
//	 * 
208
     */
1087
//	 * @return <code>true</code> to show the heap status indicator,
209
    private int submenus = 0x00;
1088
//	 *         <code>false</code> otherwise
1089
//	 */
1090
//	private boolean getShowHeapStatus() {
1091
//		return // Show if the preference is set or debug option is on
1092
//		PrefUtil.getAPIPreferenceStore().getBoolean(
1093
//				IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR)
1094
//				|| Boolean.valueOf(
1095
//						Platform.getDebugOption(PlatformUI.PLUGIN_ID
1096
//								+ "/perf/showHeapStatus")).booleanValue(); //$NON-NLS-1$
1097
//	}
1098
//
1099
//	/**
1100
//	 * Creates the controls for the heap status indicator.
1101
//	 * 
1102
//	 * @param parent
1103
//	 *            the parent composite
1104
//	 */
1105
//	private void createHeapStatus(Composite parent) {
1106
//		heapStatus = new HeapStatus(parent, PrefUtil
1107
//				.getInternalPreferenceStore());
1108
//
1109
//		// Subclass the trim to allow closing...
1110
//		heapStatusTrim = new WindowTrimProxy(heapStatus,
1111
//				"org.eclipse.ui.internal.HeapStatus", //$NON-NLS-1$
1112
//				WorkbenchMessages.get().TrimCommon_HeapStatus_TrimName, SWT.BOTTOM
1113
//						| SWT.TOP) {
1114
//
1115
//			public void handleClose() {
1116
//				getControl().dispose();
1117
//			}
1118
//
1119
//			public boolean isCloseable() {
1120
//				return true;
1121
//			}
1122
//		};
1123
//	}
1124
1125
    /**
1126
	 * <p>
1127
	 * Returns a new menu manager for this workbench window. This menu manager
1128
	 * will just be a proxy to the new command-based menu service.
1129
	 * </p>
1130
	 * <p>
1131
	 * Subclasses may override this method to customize the menu manager.
1132
	 * </p>
1133
	 * 
1134
	 * @return a menu manager for this workbench window; never <code>null</code>.
1135
	 */
1136
	protected MenuManager createMenuManager() {
1137
		return super.createMenuManager();
1138
	}
1139
1140
	/**
1141
	 * Set the perspective bar location
1142
	 * 
1143
	 * @param location
1144
	 *            the location to place the bar
1145
	 */
1146
	public void setPerspectiveBarLocation(String location) {
1147
		if (perspectiveSwitcher != null) {
1148
			perspectiveSwitcher.setPerspectiveBarLocation(location);
1149
		}
1150
	}
1151
1152
	/**
1153
	 * Notifies interested parties (namely the advisor) that the window is about
1154
	 * to be opened.
1155
	 */
1156
	private void fireWindowOpening() {
1157
		// let the application do further configuration
1158
		getWindowAdvisor().preWindowOpen();
1159
	}
1160
1161
	/**
1162
	 * Notifies interested parties (namely the advisor) that the window has been
1163
	 * restored from a previously saved state.
1164
	 * 
1165
	 * @throws WorkbenchException
1166
	 *             passed through from the advisor
1167
	 */
1168
	void fireWindowRestored() throws WorkbenchException {
1169
		StartupThreading.runWithWorkbenchExceptions(new StartupRunnable() {
1170
			public void runWithException() throws Throwable {
1171
				getWindowAdvisor().postWindowRestore();
1172
			}
1173
		});
1174
	}
1175
1176
	/**
1177
	 * Notifies interested parties (namely the advisor) that the window has been
1178
	 * created.
1179
	 */
1180
	private void fireWindowCreated() {
1181
		getWindowAdvisor().postWindowCreate();
1182
	}
1183
1184
	/**
1185
	 * Notifies interested parties (namely the advisor and the window listeners)
1186
	 * that the window has been opened.
1187
	 */
1188
	private void fireWindowOpened() {
1189
		getWorkbenchImpl().fireWindowOpened(this);
1190
		getWindowAdvisor().postWindowOpen();
1191
	}
1192
1193
	/**
1194
	 * Notifies interested parties (namely the advisor) that the window's shell
1195
	 * is closing. Allows the close to be vetoed.
1196
	 * 
1197
	 * @return <code>true</code> if the close should proceed,
1198
	 *         <code>false</code> if it should be canceled
1199
	 */
1200
	private boolean fireWindowShellClosing() {
1201
		return getWindowAdvisor().preWindowShellClose();
1202
	}
1203
1204
	/**
1205
	 * Notifies interested parties (namely the advisor and the window listeners)
1206
	 * that the window has been closed.
1207
	 */
1208
	private void fireWindowClosed() {
1209
		// let the application do further deconfiguration
1210
		getWindowAdvisor().postWindowClose();
1211
		getWorkbenchImpl().fireWindowClosed(this);
1212
	}
1213
1214
	/**
1215
	 * Fires page activated
1216
	 */
1217
	private void firePageActivated(IWorkbenchPage page) {
1218
		String label = null; // debugging only
1219
		if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
1220
			label = "activated " + page.getLabel(); //$NON-NLS-1$
1221
		}
1222
		try {
1223
			UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
1224
			UIListenerLogging.logPageEvent(this, page,
1225
					UIListenerLogging.WPE_PAGE_ACTIVATED);
1226
			pageListeners.firePageActivated(page);
1227
			partService.pageActivated(page);
1228
		} finally {
1229
			UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
1230
		}
1231
	}
1232
1233
	/**
1234
	 * Fires page closed
1235
	 */
1236
	private void firePageClosed(IWorkbenchPage page) {
1237
		String label = null; // debugging only
1238
		if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
1239
			label = "closed " + page.getLabel(); //$NON-NLS-1$
1240
		}
1241
		try {
1242
			UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
1243
			UIListenerLogging.logPageEvent(this, page,
1244
					UIListenerLogging.WPE_PAGE_CLOSED);
1245
			pageListeners.firePageClosed(page);
1246
			partService.pageClosed(page);
1247
		} finally {
1248
			UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
1249
		}
1250
1251
	}
1252
1253
	/**
1254
	 * Fires page opened
1255
	 */
1256
	private void firePageOpened(IWorkbenchPage page) {
1257
		String label = null; // debugging only
1258
		if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
1259
			label = "opened " + page.getLabel(); //$NON-NLS-1$
1260
		}
1261
		try {
1262
			UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
1263
			UIListenerLogging.logPageEvent(this, page,
1264
					UIListenerLogging.WPE_PAGE_OPENED);
1265
			pageListeners.firePageOpened(page);
1266
			partService.pageOpened(page);
1267
		} finally {
1268
			UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
1269
		}
1270
	}
1271
1272
	/**
1273
	 * Fires perspective activated
1274
	 */
1275
	void firePerspectiveActivated(IWorkbenchPage page,
1276
			IPerspectiveDescriptor perspective) {
1277
		UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1278
				UIListenerLogging.PLE_PERSP_ACTIVATED);
1279
		perspectiveListeners.firePerspectiveActivated(page, perspective);
1280
	}
1281
1282
	/**
1283
	 * Fires perspective deactivated.
1284
	 */
1285
	void firePerspectivePreDeactivate(IWorkbenchPage page,
1286
			IPerspectiveDescriptor perspective) {
1287
		UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1288
				UIListenerLogging.PLE_PERSP_PRE_DEACTIVATE);
1289
		perspectiveListeners.firePerspectivePreDeactivate(page, perspective);
1290
	}
1291
	
1292
	/**
1293
	 * Fires perspective deactivated.
1294
	 */
1295
	void firePerspectiveDeactivated(IWorkbenchPage page,
1296
			IPerspectiveDescriptor perspective) {
1297
		UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1298
				UIListenerLogging.PLE_PERSP_DEACTIVATED);
1299
		perspectiveListeners.firePerspectiveDeactivated(page, perspective);
1300
	}
1301
1302
	/**
1303
	 * Fires perspective changed
1304
	 */
1305
	public void firePerspectiveChanged(IWorkbenchPage page,
1306
			IPerspectiveDescriptor perspective, String changeId) {
1307
		// Some callers call this even when there is no active perspective.
1308
		// Just ignore this case.
1309
		if (perspective != null) {
1310
			UIListenerLogging.logPerspectiveChangedEvent(this, page,
1311
					perspective, null, changeId);
1312
			perspectiveListeners.firePerspectiveChanged(page, perspective,
1313
					changeId);
1314
		}
1315
	}
1316
1317
	/**
1318
	 * Fires perspective changed for an affected part
1319
	 */
1320
	public void firePerspectiveChanged(IWorkbenchPage page,
1321
			IPerspectiveDescriptor perspective,
1322
			IWorkbenchPartReference partRef, String changeId) {
1323
		// Some callers call this even when there is no active perspective.
1324
		// Just ignore this case.
1325
		if (perspective != null) {
1326
			UIListenerLogging.logPerspectiveChangedEvent(this, page,
1327
					perspective, partRef, changeId);
1328
			perspectiveListeners.firePerspectiveChanged(page, perspective,
1329
					partRef, changeId);
1330
		}
1331
	}
1332
1333
	/**
1334
	 * Fires perspective closed
1335
	 */
1336
	void firePerspectiveClosed(IWorkbenchPage page,
1337
			IPerspectiveDescriptor perspective) {
1338
		UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1339
				UIListenerLogging.PLE_PERSP_CLOSED);
1340
		perspectiveListeners.firePerspectiveClosed(page, perspective);
1341
	}
1342
1343
	/**
1344
	 * Fires perspective opened
1345
	 */
1346
	void firePerspectiveOpened(IWorkbenchPage page,
1347
			IPerspectiveDescriptor perspective) {
1348
		UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1349
				UIListenerLogging.PLE_PERSP_OPENED);
1350
		perspectiveListeners.firePerspectiveOpened(page, perspective);
1351
	}
1352
1353
	/**
1354
	 * Fires perspective saved as.
1355
	 */
1356
	void firePerspectiveSavedAs(IWorkbenchPage page,
1357
			IPerspectiveDescriptor oldPerspective,
1358
			IPerspectiveDescriptor newPerspective) {
1359
		UIListenerLogging.logPerspectiveSavedAs(this, page, oldPerspective,
1360
				newPerspective);
1361
		perspectiveListeners.firePerspectiveSavedAs(page, oldPerspective,
1362
				newPerspective);
1363
	}
1364
1365
	/**
1366
	 * Returns the action bars for this window.
1367
	 */
1368
	public WWinActionBars getActionBars() {
1369
		if (actionBars == null) {
1370
			actionBars = new WWinActionBars(this);
1371
		}
1372
		return actionBars;
1373
	}
1374
1375
	/**
1376
	 * Returns the active page.
1377
	 * 
1378
	 * @return the active page
1379
	 */
1380
	public IWorkbenchPage getActivePage() {
1381
		return pageList.getActive();
1382
	}
1383
1384
	/**
1385
	 * Returns the active workbench page.
1386
	 * 
1387
	 * @return the active workbench page
1388
	 */
1389
	/* package */
1390
	WorkbenchPage getActiveWorkbenchPage() {
1391
		return pageList.getActive();
1392
	}
1393
1394
	/**
1395
	 * Returns the page composite, under which the window's pages create their
1396
	 * controls.
1397
	 */
1398
	protected Composite getPageComposite() {
1399
		return pageComposite;
1400
	}
1401
1402
	/**
1403
	 * Answer the menu manager for this window.
1404
	 */
1405
	public MenuManager getMenuManager() {
1406
		return getMenuBarManager();
1407
	}
1408
1409
	/**
1410
	 * Returns the number. This corresponds to a page number in a window or a
1411
	 * window number in the workbench.
1412
	 */
1413
	public int getNumber() {
1414
		return number;
1415
	}
1416
1417
	/**
1418
	 * Returns an array of the pages in the workbench window.
1419
	 * 
1420
	 * @return an array of pages
1421
	 */
1422
	public IWorkbenchPage[] getPages() {
1423
		return pageList.getPages();
1424
	}
1425
1426
	/**
1427
	 * @see IWorkbenchWindow
1428
	 */
1429
	public IPartService getPartService() {
1430
		return partService;
1431
	}
1432
1433
	/**
1434
	 * Returns the layout for the shell.
1435
	 * 
1436
	 * @return the layout for the shell
1437
	 */
1438
	protected Layout getLayout() {
1439
		return null;
1440
	}
1441
1442
	/**
1443
	 * @see IWorkbenchWindow
1444
	 */
1445
	public ISelectionService getSelectionService() {
1446
		return partService.getSelectionService();
1447
	}
1448
1449
	/**
1450
	 * Returns <code>true</code> when the window's shell is activated,
1451
	 * <code>false</code> when it's shell is deactivated
1452
	 * 
1453
	 * @return boolean <code>true</code> when shell activated,
1454
	 *         <code>false</code> when shell deactivated
1455
	 */
1456
	public boolean getShellActivated() {
1457
		return shellActivated;
1458
	}
1459
1460
	/**
1461
	 * Returns the status line manager for this window (if it has one).
1462
	 * 
1463
	 * @return the status line manager, or <code>null</code> if this window
1464
	 *         does not have a status line
1465
	 * @see ApplicationWindow#addStatusLine
1466
	 */
1467
	public StatusLineManager getStatusLineManager() {
1468
		return super.getStatusLineManager();
1469
	}
1470
1471
	private IWindowTrim getStatusLineTrim() {
1472
		if (statusLineTrim == null) {
1473
			statusLineTrim = new WindowTrimProxy(
1474
					getStatusLineManager().getControl(),
1475
					"org.eclipse.jface.action.StatusLineManager", //$NON-NLS-1$
1476
					WorkbenchMessages.get().TrimCommon_StatusLine_TrimName, SWT.NONE,
1477
					true);
1478
		}
1479
		return statusLineTrim;
1480
	}
1481
1482
	/**
1483
	 * @see IWorkbenchWindow
1484
	 */
1485
	public IWorkbench getWorkbench() {
1486
		return PlatformUI.getWorkbench();
1487
	}
1488
1489
	public String getToolbarLabel(String actionSetId) {
1490
		ActionSetRegistry registry = WorkbenchPlugin.getDefault()
1491
				.getActionSetRegistry();
1492
		IActionSetDescriptor actionSet = registry.findActionSet(actionSetId);
1493
		if (actionSet != null) {
1494
			return actionSet.getLabel();
1495
		}
1496
1497
		if (IWorkbenchActionConstants.TOOLBAR_FILE
1498
				.equalsIgnoreCase(actionSetId)) {
1499
			return WorkbenchMessages.get().WorkbenchWindow_FileToolbar;
1500
		}
1501
1502
		if (IWorkbenchActionConstants.TOOLBAR_NAVIGATE
1503
				.equalsIgnoreCase(actionSetId)) {
1504
			return WorkbenchMessages.get().WorkbenchWindow_NavigateToolbar;
1505
		}
1506
1507
		return null;
1508
	}
1509
1510
	/**
1511
	 * Unconditionally close this window. Assumes the proper flags have been set
1512
	 * correctly (e.i. closing and updateDisabled)
1513
	 */
1514
	private boolean hardClose() {
1515
		boolean result;
1516
		try {
1517
			// Clear the action sets, fix for bug 27416.
1518
            getActionPresentation().clearActionSets();
1519
210
1520
			// Remove the handler submissions. Bug 64024.
211
    /**
1521
			final IWorkbench workbench = getWorkbench();
212
     * Object for configuring this workbench window. Lazily initialized to an
1522
			final IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
213
     * instance unique to this window.
1523
			handlerService.deactivateHandlers(handlerActivations);
214
     */
1524
			final Iterator activationItr = handlerActivations.iterator();
215
    private WorkbenchWindowConfigurer windowConfigurer = null;
1525
			while (activationItr.hasNext()) {
216
    
1526
				final IHandlerActivation activation = (IHandlerActivation) activationItr
217
    /**
1527
						.next();
218
     * List of generic property listeners.
1528
				activation.getHandler().dispose();
219
     */
1529
			}
220
    private ListenerList genericPropertyListeners = new ListenerList();
1530
			handlerActivations.clear();
1531
			globalActionHandlersByCommandId.clear();
1532
1533
			// Remove the enabled submissions. Bug 64024.
1534
			final IContextService contextService = (IContextService) workbench.getService(IContextService.class);
1535
			contextService.unregisterShell(getShell());
1536
1537
			closeAllPages();
1538
1539
			fireWindowClosed();
1540
			
1541
			// time to wipe our our populate
1542
			IMenuService menuService = (IMenuService) workbench
1543
					.getService(IMenuService.class);
1544
			menuService
1545
					.releaseContributions(((ContributionManager) getActionBars()
1546
							.getMenuManager()));
1547
			ICoolBarManager coolbar = getActionBars().getCoolBarManager();
1548
			if (coolbar != null) {
1549
				menuService
1550
						.releaseContributions(((ContributionManager) coolbar));
1551
			}
1552
1553
			getActionBarAdvisor().dispose();
1554
			getWindowAdvisor().dispose();
1555
			
1556
			// RAP [bm]: detached windows
1557
//			detachedWindowShells.dispose();
1558
			// RAPEND: [bm] 
1559
1560
			// Bring down all of the services.
1561
			serviceLocator.dispose();
1562
1563
			// Null out the progress region. Bug 64024.
1564
			progressRegion = null;
1565
			
1566
			// RAP [bm]: 
1567
//			// Remove drop targets
1568
//			DragUtil.removeDragTarget(null, trimDropTarget);
1569
//			DragUtil.removeDragTarget(getShell(), trimDropTarget);
1570
//			trimDropTarget = null;
1571
			// RAPEND: [bm] 
1572
1573
			if (trimMgr2 != null) {
1574
				trimMgr2.dispose();
1575
				trimMgr2 = null;
1576
			}
1577
			
1578
			if (trimContributionMgr != null) {
1579
				trimContributionMgr.dispose();
1580
				trimContributionMgr = null;
1581
			}
1582
		} finally {
1583
			result = super.close();
1584
		}
1585
		return result;
1586
	}
1587
1588
	/**
1589
	 * @see IWorkbenchWindow
1590
	 */
1591
	public boolean isApplicationMenu(String menuID) {
1592
		// delegate this question to the action bar advisor
1593
		return getActionBarAdvisor().isApplicationMenu(menuID);
1594
	}
1595
1596
	/**
1597
	 * Return whether or not the given id matches the id of the coolitems that
1598
	 * the application creates.
1599
	 */
1600
	/* package */
1601
	boolean isWorkbenchCoolItemId(String id) {
1602
		return windowConfigurer.containsCoolItem(id);
1603
	}
1604
1605
	/**
1606
	 * Locks/unlocks the CoolBar for the workbench.
1607
	 * 
1608
	 * @param lock
1609
	 *            whether the CoolBar should be locked or unlocked
1610
	 */
1611
	/* package */
1612
	void lockCoolBar(boolean lock) {
1613
        getCoolBarManager2().setLockLayout(lock);
1614
	}
1615
221
1616
	/**
222
    // RAP [bm]: detached windows
1617
	 * Makes the window visible and frontmost.
223
//  private ShellPool detachedWindowShells;
1618
	 */
224
    // RAPEND: [bm] 
1619
	void makeVisible() {
225
    
1620
		Shell shell = getShell();
226
    static final String TEXT_DELIMITERS = TextProcessor.getDefaultDelimiters() + "-"; //$NON-NLS-1$
1621
		if (shell != null && !shell.isDisposed()) {
1622
			// see bug 96700 and bug 4414 for a discussion on the use of open()
1623
			// here
1624
			shell.open();
1625
		}
1626
	}
1627
1628
	/**
1629
	 * Called when this window is about to be closed.
1630
	 * 
1631
	 * Subclasses may overide to add code that returns <code>false</code> to
1632
	 * prevent closing under certain conditions.
1633
	 */
1634
	public boolean okToClose() {
1635
		// Save all of the editors.
1636
		if (!getWorkbenchImpl().isClosing()) {
1637
			if (!saveAllPages(true)) {
1638
				return false;
1639
			}
1640
		}
1641
		return true;
1642
	}
1643
1644
	/**
1645
	 * Opens a new page.
1646
	 * <p>
1647
	 * <b>Note:</b> Since release 2.0, a window is limited to contain at most
1648
	 * one page. If a page exist in the window when this method is used, then
1649
	 * another window is created for the new page. Callers are strongly
1650
	 * recommended to use the <code>IWorkbench.openPerspective</code> APIs to
1651
	 * programmatically show a perspective.
1652
	 * </p>
1653
	 */
1654
	public IWorkbenchPage openPage(final String perspId, final IAdaptable input)
1655
			throws WorkbenchException {
1656
		Assert.isNotNull(perspId);
1657
1658
		// Run op in busy cursor.
1659
		final Object[] result = new Object[1];
1660
		BusyIndicator.showWhile(null, new Runnable() {
1661
			public void run() {
1662
				try {
1663
					result[0] = busyOpenPage(perspId, input);
1664
				} catch (WorkbenchException e) {
1665
					result[0] = e;
1666
				}
1667
			}
1668
		});
1669
1670
		if (result[0] instanceof IWorkbenchPage) {
1671
			return (IWorkbenchPage) result[0];
1672
		} else if (result[0] instanceof WorkbenchException) {
1673
			throw (WorkbenchException) result[0];
1674
		} else {
1675
			throw new WorkbenchException(
1676
					WorkbenchMessages.get().WorkbenchWindow_exceptionMessage);
1677
		}
1678
	}
1679
1680
	/**
1681
	 * Opens a new page.
1682
	 * <p>
1683
	 * <b>Note:</b> Since release 2.0, a window is limited to contain at most
1684
	 * one page. If a page exist in the window when this method is used, then
1685
	 * another window is created for the new page. Callers are strongly
1686
	 * recommended to use the <code>IWorkbench.openPerspective</code> APIs to
1687
	 * programmatically show a perspective.
1688
	 * </p>
1689
	 */
1690
	public IWorkbenchPage openPage(IAdaptable input) throws WorkbenchException {
1691
		String perspId = getWorkbenchImpl().getPerspectiveRegistry()
1692
				.getDefaultPerspective();
1693
		return openPage(perspId, input);
1694
	}
1695
1696
	/*
1697
	 * Removes an listener from the part service.
1698
	 */
1699
	public void removePageListener(IPageListener l) {
1700
		pageListeners.removePageListener(l);
1701
	}
1702
1703
	/**
1704
	 * @see org.eclipse.ui.IPageService
1705
	 */
1706
	public void removePerspectiveListener(org.eclipse.ui.IPerspectiveListener l) {
1707
		perspectiveListeners.removePerspectiveListener(l);
1708
	}
1709
1710
	private IStatus unableToRestorePage(IMemento pageMem) {
1711
		String pageName = pageMem.getString(IWorkbenchConstants.TAG_LABEL);
1712
		if (pageName == null) {
1713
			pageName = ""; //$NON-NLS-1$
1714
		}
1715
		return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind(
1716
				WorkbenchMessages.get().WorkbenchWindow_unableToRestorePerspective,
1717
				pageName), null);
1718
	}
1719
1720
	public IStatus restoreState(IMemento memento,
1721
			IPerspectiveDescriptor activeDescriptor) {
1722
		Assert.isNotNull(getShell());
1723
1724
		final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
1725
				WorkbenchMessages.get().WorkbenchWindow_problemsRestoringWindow, null);
1726
1727
		// Restore the window advisor state.
1728
		IMemento windowAdvisorState = memento
1729
				.getChild(IWorkbenchConstants.TAG_WORKBENCH_WINDOW_ADVISOR);
1730
		if (windowAdvisorState != null) {
1731
			result.add(getWindowAdvisor().restoreState(windowAdvisorState));
1732
		}
1733
1734
		// Restore actionbar advisor state.
1735
		IMemento actionBarAdvisorState = memento
1736
				.getChild(IWorkbenchConstants.TAG_ACTION_BAR_ADVISOR);
1737
		if (actionBarAdvisorState != null) {
1738
			result.add(getActionBarAdvisor()
1739
					.restoreState(actionBarAdvisorState));
1740
		}
1741
1742
		// Read window's bounds and state.
1743
		final Rectangle [] displayBounds = new Rectangle[1];
1744
		StartupThreading.runWithoutExceptions(new StartupRunnable() {
1745
1746
			public void runWithException() {
1747
				displayBounds[0] = getShell().getDisplay().getBounds();
1748
				
1749
			}});
1750
		final Rectangle shellBounds = new Rectangle(0, 0, 0, 0);
1751
1752
		final IMemento fastViewMem = memento
1753
				.getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
1754
		if (fastViewMem != null) {
1755
			if (fastViewBar != null) {
1756
				StartupThreading.runWithoutExceptions(new StartupRunnable() {
1757
1758
					public void runWithException() {
1759
						fastViewBar.restoreState(fastViewMem);
1760
					}});
1761
				
1762
			}
1763
		}
1764
		Integer bigInt = memento.getInteger(IWorkbenchConstants.TAG_X);
1765
		shellBounds.x = bigInt == null ? 0 : bigInt.intValue();
1766
		bigInt = memento.getInteger(IWorkbenchConstants.TAG_Y);
1767
		shellBounds.y = bigInt == null ? 0 : bigInt.intValue();
1768
		bigInt = memento.getInteger(IWorkbenchConstants.TAG_WIDTH);
1769
		shellBounds.width = bigInt == null ? 0 : bigInt.intValue();
1770
		bigInt = memento.getInteger(IWorkbenchConstants.TAG_HEIGHT);
1771
		shellBounds.height = bigInt == null ? 0 : bigInt.intValue();
1772
		if (!shellBounds.isEmpty()) {
1773
			StartupThreading.runWithoutExceptions(new StartupRunnable() {
1774
1775
				public void runWithException() {
1776
					if (!shellBounds.intersects(displayBounds[0])) {
1777
						// RAP [bm]: Display#getClientArea
1778
//						Rectangle clientArea = getShell().getDisplay().getClientArea();
1779
						Rectangle clientArea = getShell().getDisplay().getBounds();
1780
						// RAPEND: [bm] 
1781
1782
						shellBounds.x = clientArea.x;
1783
						shellBounds.y = clientArea.y;
1784
					}
1785
					getShell().setBounds(shellBounds);
1786
				}});
1787
		}
1788
		if ("true".equals(memento.getString(IWorkbenchConstants.TAG_MAXIMIZED))) { //$NON-NLS-1$
1789
			StartupThreading.runWithoutExceptions(new StartupRunnable() {
1790
1791
				public void runWithException() {
1792
					getShell().setMaximized(true);
1793
				}});
1794
			
1795
		}
1796
		if ("true".equals(memento.getString(IWorkbenchConstants.TAG_MINIMIZED))) { //$NON-NLS-1$
1797
			// getShell().setMinimized(true);
1798
		}
1799
1800
		// restore the width of the perspective bar
1801
		if (perspectiveSwitcher != null) {
1802
			perspectiveSwitcher.restoreState(memento);
1803
		}
1804
1805
		// Restore the cool bar order by creating all the tool bar contribution
1806
		// items
1807
		// This needs to be done before pages are created to ensure proper
1808
		// canonical creation
1809
		// of cool items
1810
		final ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
1811
        if (coolBarMgr != null) {
1812
			IMemento coolBarMem = memento
1813
					.getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
1814
			if (coolBarMem != null) {
1815
				// Check if the layout is locked
1816
				final Integer lockedInt = coolBarMem
1817
						.getInteger(IWorkbenchConstants.TAG_LOCKED);
1818
				StartupThreading.runWithoutExceptions(new StartupRunnable(){
1819
1820
					public void runWithException() {
1821
						if ((lockedInt != null) && (lockedInt.intValue() == 1)) {
1822
							coolBarMgr.setLockLayout(true);
1823
						} else {
1824
							coolBarMgr.setLockLayout(false);
1825
						}
1826
					}});
1827
				
1828
				// The new layout of the cool bar manager
1829
				ArrayList coolBarLayout = new ArrayList();
1830
				// Traverse through all the cool item in the memento
1831
				IMemento contributionMems[] = coolBarMem
1832
						.getChildren(IWorkbenchConstants.TAG_COOLITEM);
1833
				for (int i = 0; i < contributionMems.length; i++) {
1834
					IMemento contributionMem = contributionMems[i];
1835
					String type = contributionMem
1836
							.getString(IWorkbenchConstants.TAG_ITEM_TYPE);
1837
					if (type == null) {
1838
						// Do not recognize that type
1839
						continue;
1840
					}
1841
					String id = contributionMem
1842
							.getString(IWorkbenchConstants.TAG_ID);
1843
1844
					// Prevent duplicate items from being read back in.
1845
					IContributionItem existingItem = coolBarMgr.find(id);
1846
					if ((id != null) && (existingItem != null)) {
1847
						if (Policy.DEBUG_TOOLBAR_DISPOSAL) {
1848
							System.out
1849
									.println("Not loading duplicate cool bar item: " + id); //$NON-NLS-1$
1850
						}
1851
						coolBarLayout.add(existingItem);
1852
						continue;
1853
					}
1854
					IContributionItem newItem = null;
1855
					if (type.equals(IWorkbenchConstants.TAG_TYPE_SEPARATOR)) {
1856
						if (id != null) {
1857
							newItem = new Separator(id);
1858
						} else {
1859
							newItem = new Separator();
1860
						}
1861
					} else if (id != null) {
1862
						if (type
1863
								.equals(IWorkbenchConstants.TAG_TYPE_GROUPMARKER)) {
1864
							newItem = new GroupMarker(id);
1865
1866
						} else if (type
1867
								.equals(IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION)
1868
								|| type
1869
										.equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
1870
1871
							// Get Width and height
1872
							Integer width = contributionMem
1873
									.getInteger(IWorkbenchConstants.TAG_ITEM_X);
1874
							Integer height = contributionMem
1875
									.getInteger(IWorkbenchConstants.TAG_ITEM_Y);
1876
							// Look for the object in the current cool bar
1877
							// manager
1878
							IContributionItem oldItem = coolBarMgr.find(id);
1879
							// If a tool bar contribution item already exists
1880
							// for this id then use the old object
1881
							if (oldItem != null) {
1882
								newItem = oldItem;
1883
							} else {
1884
								IActionBarPresentationFactory actionBarPresentation = getActionBarPresentationFactory();
1885
								newItem = actionBarPresentation.createToolBarContributionItem(
1886
										actionBarPresentation.createToolBarManager(), id);
1887
								if (type
1888
										.equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
1889
									IToolBarContributionItem newToolBarItem = (IToolBarContributionItem) newItem;
1890
									if (height != null) {
1891
										newToolBarItem.setCurrentHeight(height
1892
												.intValue());
1893
									}
1894
									if (width != null) {
1895
										newToolBarItem.setCurrentWidth(width
1896
												.intValue());
1897
									}
1898
									newItem = new PlaceholderContributionItem(
1899
											newToolBarItem);
1900
								}
1901
								// make it invisible by default
1902
								newItem.setVisible(false);
1903
								// Need to add the item to the cool bar manager
1904
								// so that its canonical order can be preserved
1905
								IContributionItem refItem = findAlphabeticalOrder(
1906
										IWorkbenchActionConstants.MB_ADDITIONS,
1907
										id, coolBarMgr);
1908
								if (refItem != null) {
1909
									coolBarMgr.insertAfter(refItem.getId(),
1910
											newItem);
1911
								} else {
1912
									coolBarMgr.add(newItem);
1913
								}
1914
							}
1915
							// Set the current height and width
1916
							if ((width != null)
1917
									&& (newItem instanceof IToolBarContributionItem)) {
1918
								((IToolBarContributionItem) newItem)
1919
										.setCurrentWidth(width.intValue());
1920
							}
1921
							if ((height != null)
1922
									&& (newItem instanceof IToolBarContributionItem)) {
1923
								((IToolBarContributionItem) newItem)
1924
										.setCurrentHeight(height.intValue());
1925
							}
1926
						}
1927
					}
1928
					// Add new item into cool bar manager
1929
					if (newItem != null) {
1930
						coolBarLayout.add(newItem);
1931
						newItem.setParent(coolBarMgr);
1932
						coolBarMgr.markDirty();
1933
					}
1934
				}
1935
1936
				// We need to check if we have everything we need in the layout.
1937
				final ArrayList finalLayout = new ArrayList();
1938
				IContributionItem[] existingItems = coolBarMgr.getItems();
1939
				for (int i = 0; i < existingItems.length; i++) {
1940
					IContributionItem existingItem = existingItems[i];
1941
1942
					/*
1943
					 * This line shouldn't be necessary, but is here for
1944
					 * robustness.
1945
					 */
1946
					if (existingItem == null) {
1947
						continue;
1948
					}
1949
1950
					boolean found = false;
1951
					Iterator layoutItemItr = coolBarLayout.iterator();
1952
					while (layoutItemItr.hasNext()) {
1953
						IContributionItem layoutItem = (IContributionItem) layoutItemItr
1954
								.next();
1955
						if ((layoutItem != null)
1956
								&& (layoutItem.equals(existingItem))) {
1957
							found = true;
1958
							break;
1959
						}
1960
					}
1961
1962
					if (!found) {
1963
						if (existingItem != null) {
1964
							finalLayout.add(existingItem);
1965
						}
1966
					}
1967
				}
1968
1969
				// Set the cool bar layout to the given layout.
1970
				finalLayout.addAll(coolBarLayout);
1971
				final IContributionItem[] itemsToSet = new IContributionItem[finalLayout
1972
						.size()];
1973
				finalLayout.toArray(itemsToSet);
1974
				StartupThreading.runWithoutExceptions(new StartupRunnable() {
1975
1976
					public void runWithException() {
1977
						coolBarMgr.setItems(itemsToSet);
1978
					}});
1979
				
1980
			} else {
1981
				// For older workbenchs
1982
				coolBarMem = memento
1983
						.getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
1984
				if (coolBarMem != null) {
1985
					// Restore an older layout
1986
					restoreOldCoolBar(coolBarMem);
1987
				}
1988
			}
1989
		}
1990
1991
		// Recreate each page in the window.
1992
		IWorkbenchPage newActivePage = null;
1993
		IMemento[] pageArray = memento
1994
				.getChildren(IWorkbenchConstants.TAG_PAGE);
1995
		for (int i = 0; i < pageArray.length; i++) {
1996
			final IMemento pageMem = pageArray[i];
1997
			String strFocus = pageMem.getString(IWorkbenchConstants.TAG_FOCUS);
1998
			if (strFocus == null || strFocus.length() == 0) {
1999
				continue;
2000
			}
2001
2002
			// Get the input factory.
2003
			final IAdaptable [] input = new IAdaptable[1];
2004
			final IMemento inputMem = pageMem.getChild(IWorkbenchConstants.TAG_INPUT);
2005
			if (inputMem != null) {
2006
				final String factoryID = inputMem
2007
						.getString(IWorkbenchConstants.TAG_FACTORY_ID);
2008
				if (factoryID == null) {
2009
					WorkbenchPlugin
2010
							.log("Unable to restore page - no input factory ID."); //$NON-NLS-1$
2011
					result.add(unableToRestorePage(pageMem));
2012
					continue;
2013
				}
2014
				try {
2015
					UIStats.start(UIStats.RESTORE_WORKBENCH,
2016
							"WorkbenchPageFactory"); //$NON-NLS-1$
2017
					StartupThreading
2018
							.runWithoutExceptions(new StartupRunnable() {
2019
2020
								public void runWithException() throws Throwable {
2021
									IElementFactory factory = PlatformUI
2022
											.getWorkbench().getElementFactory(
2023
													factoryID);
2024
									if (factory == null) {
2025
										WorkbenchPlugin
2026
												.log("Unable to restore page - cannot instantiate input factory: " + factoryID); //$NON-NLS-1$
2027
										result
2028
												.add(unableToRestorePage(pageMem));
2029
										return;
2030
									}
2031
2032
									// Get the input element.
2033
									input[0] = factory.createElement(inputMem);
2034
								}
2035
							});
2036
					
2037
					if (input[0] == null) {
2038
						WorkbenchPlugin
2039
								.log("Unable to restore page - cannot instantiate input element: " + factoryID); //$NON-NLS-1$
2040
						result.add(unableToRestorePage(pageMem));
2041
						continue;
2042
					}
2043
				} finally {
2044
					UIStats.end(UIStats.RESTORE_WORKBENCH, factoryID,
2045
							"WorkbenchPageFactory"); //$NON-NLS-1$
2046
				}
2047
			}
2048
			// Open the perspective.
2049
			final IAdaptable finalInput = input[0];
2050
			final WorkbenchPage [] newPage = new WorkbenchPage[1];
2051
			try {
2052
				StartupThreading.runWithWorkbenchExceptions(new StartupRunnable(){
2053
2054
					public void runWithException() throws WorkbenchException {
2055
						newPage[0] = ((WorkbenchImplementation) Tweaklets
2056
								.get(WorkbenchImplementation.KEY)).createWorkbenchPage(WorkbenchWindow.this, finalInput);
2057
					}});
2058
				
2059
				result.add(newPage[0].restoreState(pageMem, activeDescriptor));
2060
				pageList.add(newPage[0]);
2061
				StartupThreading.runWithoutExceptions(new StartupRunnable() {
2062
2063
					public void runWithException() throws Throwable {
2064
						firePageOpened(newPage[0]);
2065
					}});
2066
				
2067
			} catch (WorkbenchException e) {
2068
				WorkbenchPlugin
2069
						.log(
2070
								"Unable to restore perspective - constructor failed.", e); //$NON-NLS-1$
2071
				result.add(e.getStatus());
2072
				continue;
2073
			}
2074
2075
			if (strFocus != null && strFocus.length() > 0) {
2076
				newActivePage = newPage[0];
2077
			}
2078
		}
2079
2080
		// If there are no pages create a default.
2081
		if (pageList.isEmpty()) {
2082
			try {
2083
				final String defPerspID = getWorkbenchImpl().getPerspectiveRegistry()
2084
						.getDefaultPerspective();
2085
				if (defPerspID != null) {
2086
					final WorkbenchPage [] newPage = new WorkbenchPage[1];
2087
					StartupThreading.runWithWorkbenchExceptions(new StartupRunnable() {
2088
						
2089
						public void runWithException() throws Throwable {
2090
							newPage[0] = ((WorkbenchImplementation) Tweaklets
2091
									.get(WorkbenchImplementation.KEY)).createWorkbenchPage(WorkbenchWindow.this, defPerspID,
2092
											getDefaultPageInput());
2093
						}});
2094
					
2095
					pageList.add(newPage[0]);
2096
					StartupThreading.runWithoutExceptions(new StartupRunnable() {
2097
2098
						public void runWithException() throws Throwable {
2099
							firePageOpened(newPage[0]);
2100
						}});
2101
				}
2102
			} catch (WorkbenchException e) {
2103
				WorkbenchPlugin
2104
						.log(
2105
								"Unable to create default perspective - constructor failed.", e); //$NON-NLS-1$
2106
				result.add(e.getStatus());
2107
				String productName = WorkbenchPlugin.getDefault()
2108
						.getProductName();
2109
				if (productName == null) {
2110
					productName = ""; //$NON-NLS-1$
2111
				}
2112
				getShell().setText(productName);
2113
			}
2114
		}
2115
2116
		// Set active page.
2117
		if (newActivePage == null) {
2118
			newActivePage = pageList.getNextActive();
2119
		}
2120
		final IWorkbenchPage myPage = newActivePage;
2121
		StartupThreading.runWithoutExceptions(new StartupRunnable() {
2122
2123
			public void runWithException() throws Throwable {
2124
				setActivePage(myPage);
2125
			}});
2126
		
2127
227
2128
// RAP [rh] Intro mechanism not supported
228
    // constants for shortcut bar group ids
2129
//		final IMemento introMem = memento.getChild(IWorkbenchConstants.TAG_INTRO);
229
    static final String GRP_PAGES = "pages"; //$NON-NLS-1$
2130
//		if (introMem != null) {
2131
//			StartupThreading.runWithoutExceptions(new StartupRunnable() {
2132
//
2133
//				public void runWithException() throws Throwable {
2134
//					getWorkbench()
2135
//							.getIntroManager()
2136
//							.showIntro(
2137
//									WorkbenchWindow.this,
2138
//									Boolean
2139
//											.valueOf(
2140
//													introMem
2141
//															.getString(IWorkbenchConstants.TAG_STANDBY))
2142
//											.booleanValue());
2143
//				}
2144
//			});
2145
//
2146
//		}
2147
		
2148
		// Only restore the trim state if we're using the default layout
2149
		if (defaultLayout != null) {
2150
			// Restore the trim state. We pass in the 'root'
2151
			// memento since we have to check for pre-3.2
2152
			// state.
2153
			result.add(restoreTrimState(memento));
2154
		}
2155
		
2156
		return result;
2157
	}
2158
2159
	/**
2160
	 * Restores cool item order from an old workbench.
2161
	 */
2162
	private boolean restoreOldCoolBar(IMemento coolbarMem) {
2163
		// Make sure the tag exist
2164
		if (coolbarMem == null) {
2165
			return false;
2166
		}
2167
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
2168
		// Check to see if layout is locked
2169
		Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
2170
		boolean state = (locked != null) && (locked.intValue() == 1);
2171
		coolBarMgr.setLockLayout(state);
2172
2173
		// Get the visual layout
2174
		IMemento visibleLayout = coolbarMem
2175
				.getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
2176
		ArrayList visibleWrapIndicies = new ArrayList();
2177
		ArrayList visibleItems = new ArrayList();
2178
		if (visibleLayout != null) {
2179
			if (readLayout(visibleLayout, visibleItems, visibleWrapIndicies) == false) {
2180
				return false;
2181
			}
2182
		}
2183
		// Get the remembered layout
2184
		IMemento rememberedLayout = coolbarMem
2185
				.getChild(IWorkbenchConstants.TAG_LAYOUT);
2186
		ArrayList rememberedWrapIndicies = new ArrayList();
2187
		ArrayList rememberedItems = new ArrayList();
2188
		if (rememberedLayout != null) {
2189
			if (readLayout(rememberedLayout, rememberedItems,
2190
					rememberedWrapIndicies) == false) {
2191
				return false;
2192
			}
2193
		}
2194
2195
		// Create the objects
2196
		if (visibleItems != null) {
2197
			// Merge remembered layout into visible layout
2198
			if (rememberedItems != null) {
2199
				// Traverse through all the remembered items
2200
				int currentIndex = 0;
2201
				for (Iterator i = rememberedItems.iterator(); i.hasNext(); currentIndex++) {
2202
					String id = (String) i.next();
2203
					int index = -1;
2204
					for (Iterator iter = visibleItems.iterator(); iter
2205
							.hasNext();) {
2206
						String visibleId = (String) iter.next();
2207
						if (visibleId.equals(id)) {
2208
							index = visibleItems.indexOf(visibleId);
2209
							break;
2210
						}
2211
					}
2212
					// The item is not in the visible list
2213
					if (index == -1) {
2214
						int insertAt = Math.max(0, Math.min(currentIndex,
2215
								visibleItems.size()));
2216
						boolean separateLine = false;
2217
						// Check whether this item is on a separate line
2218
						for (Iterator iter = rememberedWrapIndicies.iterator(); iter
2219
								.hasNext();) {
2220
							Integer wrapIndex = (Integer) iter.next();
2221
							if (wrapIndex.intValue() <= insertAt) {
2222
								insertAt = visibleItems.size();
2223
								// Add new wrap index for this Item
2224
								visibleWrapIndicies.add(new Integer(insertAt));
2225
								separateLine = true;
2226
							}
2227
						}
2228
						// Add item to array list
2229
						visibleItems.add(insertAt, id);
2230
						// If the item was not on a separate line then adjust
2231
						// the visible wrap indicies
2232
						if (!separateLine) {
2233
							// Adjust visible wrap indicies
2234
							for (int j = 0; j < visibleWrapIndicies.size(); j++) {
2235
								Integer index2 = (Integer) visibleWrapIndicies
2236
										.get(j);
2237
								if (index2.intValue() >= insertAt) {
2238
									visibleWrapIndicies.set(j, new Integer(
2239
											index2.intValue() + 1));
2240
								}
2241
							}
2242
						}
2243
					}
2244
				}
2245
			}
2246
			// The new layout of the cool bar manager
2247
			ArrayList coolBarLayout = new ArrayList(visibleItems.size());
2248
			// Add all visible items to the layout object
2249
			for (Iterator i = visibleItems.iterator(); i.hasNext();) {
2250
				String id = (String) i.next();
2251
				// Look for the object in the current cool bar manager
2252
				IContributionItem oldItem = null;
2253
				IContributionItem newItem = null;
2254
				if (id != null) {
2255
					oldItem = coolBarMgr.find(id);
2256
				}
2257
				// If a tool bar contribution item already exists for this id
2258
				// then use the old object
2259
				if (oldItem instanceof IToolBarContributionItem) {
2260
					newItem = oldItem;
2261
				} else {
2262
					IActionBarPresentationFactory actionBarPresentaiton = getActionBarPresentationFactory();
2263
					newItem = actionBarPresentaiton.createToolBarContributionItem(
2264
									actionBarPresentaiton.createToolBarManager(), id);
2265
					// make it invisible by default
2266
					newItem.setVisible(false);
2267
					// Need to add the item to the cool bar manager so that its
2268
					// canonical order can be preserved
2269
					IContributionItem refItem = findAlphabeticalOrder(
2270
							IWorkbenchActionConstants.MB_ADDITIONS, id,
2271
							coolBarMgr);
2272
					if (refItem != null) {
2273
						coolBarMgr.insertAfter(refItem.getId(), newItem);
2274
					} else {
2275
						coolBarMgr.add(newItem);
2276
					}
2277
				}
2278
				// Add new item into cool bar manager
2279
				if (newItem != null) {
2280
					coolBarLayout.add(newItem);
2281
					newItem.setParent(coolBarMgr);
2282
					coolBarMgr.markDirty();
2283
				}
2284
			}
2285
2286
			// Add separators to the displayed Items data structure
2287
			int offset = 0;
2288
			for (int i = 1; i < visibleWrapIndicies.size(); i++) {
2289
				int insertAt = ((Integer) visibleWrapIndicies.get(i))
2290
						.intValue()
2291
						+ offset;
2292
				coolBarLayout.add(insertAt, new Separator(
2293
						CoolBarManager.USER_SEPARATOR));
2294
				offset++;
2295
			}
2296
2297
			// Add any group markers in their appropriate places
2298
			IContributionItem[] items = coolBarMgr.getItems();
2299
			for (int i = 0; i < items.length; i++) {
2300
				IContributionItem item = items[i];
2301
				if (item.isGroupMarker()) {
2302
					coolBarLayout.add(Math.max(Math
2303
							.min(i, coolBarLayout.size()), 0), item);
2304
				}
2305
			}
2306
			IContributionItem[] itemsToSet = new IContributionItem[coolBarLayout
2307
					.size()];
2308
			coolBarLayout.toArray(itemsToSet);
2309
			coolBarMgr.setItems(itemsToSet);
2310
		}
2311
		return true;
2312
	}
2313
2314
	/**
2315
	 * Helper method used for restoring an old cool bar layout. This method
2316
	 * reads the memento and populatates the item id's and wrap indicies.
2317
	 */
2318
	private boolean readLayout(IMemento memento, ArrayList itemIds,
2319
			ArrayList wrapIndicies) {
2320
		// Get the Wrap indicies
2321
		IMemento[] wraps = memento
2322
				.getChildren(IWorkbenchConstants.TAG_ITEM_WRAP_INDEX);
2323
		if (wraps == null) {
2324
			return false;
2325
		}
2326
		for (int i = 0; i < wraps.length; i++) {
2327
			IMemento wrapMem = wraps[i];
2328
			Integer index = wrapMem.getInteger(IWorkbenchConstants.TAG_INDEX);
2329
			if (index == null) {
2330
				return false;
2331
			}
2332
			wrapIndicies.add(index);
2333
		}
2334
		// Get the Item ids
2335
		IMemento[] savedItems = memento
2336
				.getChildren(IWorkbenchConstants.TAG_ITEM);
2337
		if (savedItems == null) {
2338
			return false;
2339
		}
2340
		for (int i = 0; i < savedItems.length; i++) {
2341
			IMemento savedMem = savedItems[i];
2342
			String id = savedMem.getString(IWorkbenchConstants.TAG_ID);
2343
			if (id == null) {
2344
				return false;
2345
			}
2346
			itemIds.add(id);
2347
		}
2348
		return true;
2349
	}
2350
2351
	/**
2352
	 * Returns the contribution item that the given contribution item should be
2353
	 * inserted after.
2354
	 * 
2355
	 * @param startId
2356
	 *            the location to start looking alphabetically.
2357
	 * @param itemId
2358
	 *            the target item id.
2359
	 * @param mgr
2360
	 *            the contribution manager.
2361
	 * @return the contribution item that the given items should be returned
2362
	 *         after.
2363
	 */
2364
	private IContributionItem findAlphabeticalOrder(String startId,
2365
			String itemId, IContributionManager mgr) {
2366
		IContributionItem[] items = mgr.getItems();
2367
		int insertIndex = 0;
2368
2369
		// look for starting point
2370
		while (insertIndex < items.length) {
2371
			IContributionItem item = items[insertIndex];
2372
			if (item.getId() != null && item.getId().equals(startId)) {
2373
				break;
2374
			}
2375
			++insertIndex;
2376
		}
2377
2378
		// Find the index that this item should be inserted in
2379
		for (int i = insertIndex + 1; i < items.length; i++) {
2380
			IContributionItem item = items[i];
2381
			String testId = item.getId();
2382
2383
			if (item.isGroupMarker()) {
2384
				break;
2385
			}
2386
2387
			if (itemId != null && testId != null) {
2388
				if (itemId.compareTo(testId) < 1) {
2389
					break;
2390
				}
2391
			}
2392
			insertIndex = i;
2393
		}
2394
		if (insertIndex >= items.length) {
2395
			return null;
2396
		}
2397
		return items[insertIndex];
2398
	}
2399
2400
	/*
2401
	 * (non-Javadoc) Method declared on IRunnableContext.
2402
	 */
2403
	public void run(boolean fork, boolean cancelable,
2404
			IRunnableWithProgress runnable) throws InvocationTargetException,
2405
			InterruptedException {
2406
2407
		// RAP [bm]: 
2408
//		IWorkbenchContextSupport contextSupport = getWorkbench()
2409
//				.getContextSupport();
2410
//		final boolean keyFilterEnabled = contextSupport.isKeyFilterEnabled();
2411
2412
		Control fastViewBarControl = getFastViewBar() == null ? null
2413
				: getFastViewBar().getControl();
2414
		boolean fastViewBarWasEnabled = fastViewBarControl == null ? false
2415
				: fastViewBarControl.getEnabled();
2416
2417
		Control perspectiveBarControl = getPerspectiveBar() == null ? null
2418
				: getPerspectiveBar().getControl();
2419
		boolean perspectiveBarWasEnabled = perspectiveBarControl == null ? false
2420
				: perspectiveBarControl.getEnabled();
2421
2422
		// Cache for any diabled trim controls
2423
		List disabledControls = null;
2424
		
2425
		try {
2426
			if (fastViewBarControl != null && !fastViewBarControl.isDisposed()) {
2427
				fastViewBarControl.setEnabled(false);
2428
			}
2429
2430
			if (perspectiveBarControl != null
2431
					&& !perspectiveBarControl.isDisposed()) {
2432
				perspectiveBarControl.setEnabled(false);
2433
			}
2434
			
2435
			// RAP [bm]: 
2436
//			if (keyFilterEnabled) {
2437
//				contextSupport.setKeyFilterEnabled(false);
2438
//			}
2439
			// RAPEND: [bm] 
2440
2441
			// Disable all trim -except- the StatusLine
2442
			if (defaultLayout != null)
2443
				disabledControls = defaultLayout.disableTrim(getStatusLineTrim());
2444
2445
			super.run(fork, cancelable, runnable);
2446
		} finally {
2447
			if (fastViewBarControl != null && !fastViewBarControl.isDisposed()) {
2448
				fastViewBarControl.setEnabled(fastViewBarWasEnabled);
2449
			}
2450
2451
			if (perspectiveBarControl != null
2452
					&& !perspectiveBarControl.isDisposed()) {
2453
				perspectiveBarControl.setEnabled(perspectiveBarWasEnabled);
2454
			}
2455
2456
			// RAP [bm]: 
2457
//			if (keyFilterEnabled) {
2458
//				contextSupport.setKeyFilterEnabled(true);
2459
//			}
2460
			// RAPEND: [bm] 
2461
2462
			// Re-enable any disabled trim
2463
			if (defaultLayout != null && disabledControls != null)
2464
				defaultLayout.enableTrim(disabledControls);
2465
		}
2466
	}
2467
2468
	/**
2469
	 * Save all of the pages. Returns true if the operation succeeded.
2470
	 */
2471
	private boolean saveAllPages(boolean bConfirm) {
2472
		boolean bRet = true;
2473
		Iterator itr = pageList.iterator();
2474
		while (bRet && itr.hasNext()) {
2475
			WorkbenchPage page = (WorkbenchPage) itr.next();
2476
			bRet = page.saveAllEditors(bConfirm);
2477
		}
2478
		return bRet;
2479
	}
2480
2481
	/**
2482
	 * @see IPersistable
2483
	 */
2484
	public IStatus saveState(IMemento memento) {
2485
2486
		MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
2487
				WorkbenchMessages.get().WorkbenchWindow_problemsSavingWindow, null);
2488
2489
		// Save the window's state and bounds.
2490
		if (getShell().getMaximized() || asMaximizedState) {
2491
			memento.putString(IWorkbenchConstants.TAG_MAXIMIZED, "true"); //$NON-NLS-1$
2492
		}
2493
		if (getShell().getMinimized()) {
2494
			memento.putString(IWorkbenchConstants.TAG_MINIMIZED, "true"); //$NON-NLS-1$
2495
		}
2496
		if (normalBounds == null) {
2497
			normalBounds = getShell().getBounds();
2498
		}
2499
		IMemento fastViewBarMem = memento
2500
				.createChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
2501
		if (fastViewBar != null) {
2502
			fastViewBar.saveState(fastViewBarMem);
2503
		}
2504
2505
		memento.putInteger(IWorkbenchConstants.TAG_X, normalBounds.x);
2506
		memento.putInteger(IWorkbenchConstants.TAG_Y, normalBounds.y);
2507
		memento.putInteger(IWorkbenchConstants.TAG_WIDTH, normalBounds.width);
2508
		memento.putInteger(IWorkbenchConstants.TAG_HEIGHT, normalBounds.height);
2509
230
2510
// RAP [rh] Intro mechanism not supported
231
    static final String GRP_PERSPECTIVES = "perspectives"; //$NON-NLS-1$
2511
//		IWorkbenchPage activePage = getActivePage();
2512
//		if (activePage != null
2513
//				&& activePage.findView(IIntroConstants.INTRO_VIEW_ID) != null) {
2514
//			IMemento introMem = memento
2515
//					.createChild(IWorkbenchConstants.TAG_INTRO);
2516
//			boolean isStandby = getWorkbench()
2517
//					.getIntroManager()
2518
//					.isIntroStandby(getWorkbench().getIntroManager().getIntro());
2519
//			introMem.putString(IWorkbenchConstants.TAG_STANDBY, String
2520
//					.valueOf(isStandby));
2521
//		}
2522
2523
		// save the width of the perspective bar
2524
		IMemento persBarMem = memento
2525
				.createChild(IWorkbenchConstants.TAG_PERSPECTIVE_BAR);
2526
		if (perspectiveSwitcher != null) {
2527
			perspectiveSwitcher.saveState(persBarMem);
2528
		}
2529
232
2530
		// / Save the order of the cool bar contribution items
233
    static final String GRP_FAST_VIEWS = "fastViews"; //$NON-NLS-1$
2531
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
2532
        if (coolBarMgr != null) {
2533
        	coolBarMgr.refresh();
2534
			IMemento coolBarMem = memento
2535
					.createChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
2536
            if (coolBarMgr.getLockLayout() == true) {
2537
				coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 1);
2538
			} else {
2539
				coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 0);
2540
			}
2541
            IContributionItem[] items = coolBarMgr.getItems();
2542
			for (int i = 0; i < items.length; i++) {
2543
				IMemento coolItemMem = coolBarMem
2544
						.createChild(IWorkbenchConstants.TAG_COOLITEM);
2545
				IContributionItem item = items[i];
2546
				// The id of the contribution item
2547
				if (item.getId() != null) {
2548
					coolItemMem.putString(IWorkbenchConstants.TAG_ID, item
2549
							.getId());
2550
				}
2551
				// Write out type and size if applicable
2552
				if (item.isSeparator()) {
2553
					coolItemMem.putString(IWorkbenchConstants.TAG_ITEM_TYPE,
2554
							IWorkbenchConstants.TAG_TYPE_SEPARATOR);
2555
				} else if (item.isGroupMarker() && !item.isSeparator()) {
2556
					coolItemMem.putString(IWorkbenchConstants.TAG_ITEM_TYPE,
2557
							IWorkbenchConstants.TAG_TYPE_GROUPMARKER);
2558
				} else {
2559
					if (item instanceof PlaceholderContributionItem) {
2560
						coolItemMem.putString(
2561
								IWorkbenchConstants.TAG_ITEM_TYPE,
2562
								IWorkbenchConstants.TAG_TYPE_PLACEHOLDER);
2563
					} else {
2564
						// Store the identifier.
2565
						coolItemMem
2566
								.putString(
2567
										IWorkbenchConstants.TAG_ITEM_TYPE,
2568
										IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION);
2569
					}
2570
2571
					/*
2572
					 * Retrieve a reasonable approximation of the height and
2573
					 * width, if possible.
2574
					 */
2575
					final int height;
2576
					final int width;
2577
					if (item instanceof IToolBarContributionItem) {
2578
						IToolBarContributionItem toolBarItem = (IToolBarContributionItem) item;
2579
						toolBarItem.saveWidgetState();
2580
						height = toolBarItem.getCurrentHeight();
2581
						width = toolBarItem.getCurrentWidth();
2582
					} else if (item instanceof PlaceholderContributionItem) {
2583
						PlaceholderContributionItem placeholder = (PlaceholderContributionItem) item;
2584
						height = placeholder.getHeight();
2585
						width = placeholder.getWidth();
2586
					} else {
2587
						height = -1;
2588
						width = -1;
2589
					}
2590
2591
					// Store the height and width.
2592
					coolItemMem.putInteger(IWorkbenchConstants.TAG_ITEM_X,
2593
							width);
2594
					coolItemMem.putInteger(IWorkbenchConstants.TAG_ITEM_Y,
2595
							height);
2596
				}
2597
			}
2598
		}
2599
2600
		// Save each page.
2601
		Iterator itr = pageList.iterator();
2602
		while (itr.hasNext()) {
2603
			WorkbenchPage page = (WorkbenchPage) itr.next();
2604
2605
			// Save perspective.
2606
			IMemento pageMem = memento
2607
					.createChild(IWorkbenchConstants.TAG_PAGE);
2608
			pageMem.putString(IWorkbenchConstants.TAG_LABEL, page.getLabel());
2609
			result.add(page.saveState(pageMem));
2610
2611
			if (page == getActiveWorkbenchPage()) {
2612
				pageMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$
2613
			}
2614
2615
			// Get the input.
2616
			IAdaptable input = page.getInput();
2617
			if (input != null) {
2618
				IPersistableElement persistable = (IPersistableElement) Util.getAdapter(input,
2619
						IPersistableElement.class);
2620
				if (persistable == null) {
2621
					WorkbenchPlugin
2622
							.log("Unable to save page input: " //$NON-NLS-1$
2623
									+ input
2624
									+ ", because it does not adapt to IPersistableElement"); //$NON-NLS-1$
2625
				} else {
2626
					// Save input.
2627
					IMemento inputMem = pageMem
2628
							.createChild(IWorkbenchConstants.TAG_INPUT);
2629
					inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID,
2630
							persistable.getFactoryId());
2631
					persistable.saveState(inputMem);
2632
				}
2633
			}
2634
		}
2635
2636
		// Save window advisor state.
2637
		IMemento windowAdvisorState = memento
2638
				.createChild(IWorkbenchConstants.TAG_WORKBENCH_WINDOW_ADVISOR);
2639
		result.add(getWindowAdvisor().saveState(windowAdvisorState));
2640
2641
		// Save actionbar advisor state.
2642
		IMemento actionBarAdvisorState = memento
2643
				.createChild(IWorkbenchConstants.TAG_ACTION_BAR_ADVISOR);
2644
		result.add(getActionBarAdvisor().saveState(actionBarAdvisorState));
2645
2646
		// Only save the trim state if we're using the default layout
2647
		if (defaultLayout != null) {
2648
			IMemento trimState = memento.createChild(IWorkbenchConstants.TAG_TRIM);
2649
			result.add(saveTrimState(trimState));
2650
		}
2651
2652
		return result;
2653
	}
2654
2655
	/**
2656
	 * Save the trim layout trim area and trim ordering.
2657
	 * 
2658
	 * @param memento
2659
	 *            the memento to update
2660
	 * @return the status, OK or not..
2661
	 */
2662
	private IStatus saveTrimState(IMemento memento) {
2663
		int[] ids = defaultLayout.getAreaIds();
2664
		for (int i = 0; i < ids.length; i++) {
2665
			int id = ids[i];
2666
			List trim = defaultLayout.getAreaTrim(id);
2667
			if (!trim.isEmpty()) {
2668
				IMemento area = memento
2669
						.createChild(IWorkbenchConstants.TAG_TRIM_AREA, Integer
2670
								.toString(id));
2671
				Iterator d = trim.iterator();
2672
				while (d.hasNext()) {
2673
					IWindowTrim item = (IWindowTrim) d.next();
2674
					area.createChild(IWorkbenchConstants.TAG_TRIM_ITEM, item
2675
							.getId());
2676
				}
2677
			}
2678
		}
2679
		return Status.OK_STATUS;
2680
	}
2681
2682
	/**
2683
	 * Restore the trim layout state from the memento.
2684
	 * 
2685
	 * @param memento
2686
	 *            the 'root' Workbench memento to restore
2687
	 * @return the status, OK or not
2688
	 */
2689
	private IStatus restoreTrimState(IMemento memento) {
2690
		// Determine if we have saved state. If we don't have any 3.2
2691
		// type state we're not done because the FastViewBar maintained
2692
		// its own 'side' state in 3.1 so we'll honor its value
2693
		IMemento trimState = memento.getChild(IWorkbenchConstants.TAG_TRIM);
2694
		if (trimState != null) {
2695
			// first pass sets up ordering for all trim areas
2696
			IMemento[] areas = trimState
2697
					.getChildren(IWorkbenchConstants.TAG_TRIM_AREA);
2698
			
2699
			// We need to remember all the trim that was repositioned
2700
			// here so we can re-site -newly contributed- trim after
2701
			// we're done
2702
			final List knownIds = new ArrayList();
2703
			
2704
			List[] trimOrder = new List[areas.length];
2705
			for (int i = 0; i < areas.length; i++) {
2706
				trimOrder[i] = new ArrayList();
2707
				List preferredLocations = new ArrayList();
2708
				IMemento area = areas[i];
2709
				IMemento[] items = area
2710
						.getChildren(IWorkbenchConstants.TAG_TRIM_ITEM);
2711
				for (int j = 0; j < items.length; j++) {
2712
					IMemento item = items[j];
2713
					String id = item.getID();
2714
					knownIds.add(id);
2715
					preferredLocations.add(id);
2716
					
2717
					IWindowTrim t = defaultLayout.getTrim(id);
2718
					if (t != null) {
2719
						trimOrder[i].add(t);
2720
					}
2721
				}
2722
				
2723
				// Inform the TrimLayout of the preferred location for this area
2724
				String areaIdString = areas[i].getID();
2725
				int areaId = Integer.parseInt(areaIdString);
2726
				defaultLayout.setPreferredLocations(areaId, preferredLocations);
2727
			}
2728
	
2729
			// second pass applies all of the window trim
2730
			for (int i = 0; i < areas.length; i++) {
2731
				IMemento area = areas[i];
2732
				final int id = Integer.parseInt(area.getID());
2733
				final List myTrimOrderList = trimOrder[i];
2734
				StartupThreading.runWithoutExceptions(new StartupRunnable() {
2735
2736
					public void runWithException() throws Throwable {
2737
						defaultLayout.updateAreaTrim(id, myTrimOrderList, false);
2738
					}});
2739
				
2740
			}
2741
2742
			// get the trim manager to re-locate any -newly contributed-
2743
			// trim widgets
2744
			// Legacy (3.2) trim
2745
			if (trimMgr2 != null) {
2746
				StartupThreading.runWithoutExceptions(new StartupRunnable() {
2747
2748
					public void runWithException() throws Throwable {
2749
						trimMgr2.updateLocations(knownIds);
2750
					}});
2751
				
2752
			}
2753
			
2754
			// 3.3 Trim Contributions
2755
			if (trimContributionMgr != null) {
2756
				StartupThreading.runWithoutExceptions(new StartupRunnable() {
2757
					public void runWithException() throws Throwable {
2758
						trimContributionMgr.updateLocations(knownIds);
2759
2760
						// Update the GUI with the new locations
2761
						WorkbenchPage page = getActiveWorkbenchPage();
2762
						if (page != null) {
2763
							Perspective perspective = page.getActivePerspective();
2764
							if (perspective != null) {
2765
								// Ensure that only the upper/right editor stack has
2766
								// min/max buttons
2767
								page.getEditorPresentation().updateStackButtons();
2768
								
2769
								// The perspective's onActivate manipulates the trim under the
2770
								// new min/max story so cause it to refresh...
2771
								perspective.onActivate();
2772
							}
2773
						}
2774
					}});
2775
			}
2776
		}
2777
		else {
2778
			// No 3.2 state...check if the FVB has state
2779
			IMemento fastViewMem = memento
2780
					.getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
2781
			if (fastViewMem != null) {
2782
				if (fastViewBar != null) {
2783
			        final Integer bigInt = fastViewMem.getInteger(IWorkbenchConstants.TAG_FAST_VIEW_SIDE);
2784
			        if (bigInt != null) {
2785
			        	StartupThreading.runWithoutExceptions(new StartupRunnable() {
2786
2787
							public void runWithException() throws Throwable {
2788
								fastViewBar.dock(bigInt.intValue());
2789
					        	getTrimManager().addTrim(bigInt.intValue(), fastViewBar);
2790
							}});
2791
			        	
2792
			        }
2793
				}
2794
			}
2795
		}
2796
		
2797
		return Status.OK_STATUS;
2798
	}
2799
2800
	/**
2801
	 * Sets the active page within the window.
2802
	 * 
2803
	 * @param in
2804
	 *            identifies the new active page, or <code>null</code> for no
2805
	 *            active page
2806
	 */
2807
	public void setActivePage(final IWorkbenchPage in) {
2808
		if (getActiveWorkbenchPage() == in) {
2809
			return;
2810
		}
2811
2812
		// 1FVGTNR: ITPUI:WINNT - busy cursor for switching perspectives
2813
		BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
2814
			public void run() {
2815
				// Deactivate old persp.
2816
				WorkbenchPage currentPage = getActiveWorkbenchPage();
2817
				if (currentPage != null) {
2818
					currentPage.onDeactivate();
2819
				}
2820
2821
				// Activate new persp.
2822
				if (in == null || pageList.contains(in)) {
2823
					pageList.setActive(in);
2824
				}
2825
				WorkbenchPage newPage = pageList.getActive();
2826
				Composite parent = getPageComposite();
2827
				StackLayout layout = (StackLayout) parent.getLayout();
2828
				if (newPage != null) {
2829
					layout.topControl = newPage.getClientComposite();
2830
					parent.layout();
2831
					hideEmptyWindowContents();
2832
					newPage.onActivate();
2833
					firePageActivated(newPage);
2834
					if (newPage.getPerspective() != null) {
2835
						firePerspectiveActivated(newPage, newPage
2836
								.getPerspective());
2837
					}
2838
				} else {
2839
					layout.topControl = null;
2840
					parent.layout();
2841
				}
2842
2843
				updateFastViewBar();
2844
2845
				if (isClosing()) {
2846
					return;
2847
				}
2848
2849
				updateDisabled = false;
2850
2851
				// Update action bars ( implicitly calls updateActionBars() )
2852
				updateActionSets();
2853
				submitGlobalActions();
2854
2855
				if (perspectiveSwitcher != null) {
2856
					perspectiveSwitcher.update(false);
2857
				}
2858
2859
				getMenuManager().update(IAction.TEXT);
2860
			}
2861
		});
2862
	}
2863
2864
	/**
2865
	 * Returns whether or not children exist for the Window's toolbar control.
2866
	 * Overridden for coolbar support.
2867
	 * <p>
2868
	 * 
2869
	 * @return boolean true if children exist, false otherwise
2870
	 */
2871
	protected boolean toolBarChildrenExist() {
2872
		CoolBar coolBarControl = (CoolBar) getCoolBarControl();
2873
		return coolBarControl.getItemCount() > 0;
2874
	}
2875
2876
	/**
2877
	 * Hooks a listener to track the activation and deactivation of the window's
2878
	 * shell. Notifies the active part and editor of the change
2879
	 */
2880
	private void trackShellActivation(Shell shell) {
2881
		shell.addShellListener(new ShellAdapter() {
2882
			public void shellActivated(ShellEvent event) {
2883
				shellActivated = true;
2884
				serviceLocator.activate();
2885
				getWorkbenchImpl().setActivatedWindow(WorkbenchWindow.this);
2886
				WorkbenchPage currentPage = getActiveWorkbenchPage();
2887
				if (currentPage != null) {
2888
					IWorkbenchPart part = currentPage.getActivePart();
2889
					if (part != null) {
2890
						PartSite site = (PartSite) part.getSite();
2891
						site.getPane().shellActivated();
2892
					}
2893
					IEditorPart editor = currentPage.getActiveEditor();
2894
					if (editor != null) {
2895
						PartSite site = (PartSite) editor.getSite();
2896
						site.getPane().shellActivated();
2897
					}
2898
					getWorkbenchImpl()
2899
							.fireWindowActivated(WorkbenchWindow.this);
2900
				}
2901
			}
2902
2903
			public void shellDeactivated(ShellEvent event) {
2904
				shellActivated = false;
2905
				serviceLocator.deactivate();
2906
				WorkbenchPage currentPage = getActiveWorkbenchPage();
2907
				if (currentPage != null) {
2908
					IWorkbenchPart part = currentPage.getActivePart();
2909
					if (part != null) {
2910
						PartSite site = (PartSite) part.getSite();
2911
						site.getPane().shellDeactivated();
2912
					}
2913
					IEditorPart editor = currentPage.getActiveEditor();
2914
					if (editor != null) {
2915
						PartSite site = (PartSite) editor.getSite();
2916
						site.getPane().shellDeactivated();
2917
					}
2918
					getWorkbenchImpl().fireWindowDeactivated(
2919
							WorkbenchWindow.this);
2920
				}
2921
			}
2922
		});
2923
	}
2924
2925
	/**
2926
	 * Hooks a listener to track the resize of the window's shell. Stores the
2927
	 * new bounds if in normal state - that is, not in minimized or maximized
2928
	 * state)
2929
	 */
2930
	private void trackShellResize(Shell newShell) {
2931
		newShell.addControlListener(new ControlAdapter() {
2932
			public void controlMoved(ControlEvent e) {
2933
				saveBounds();
2934
			}
2935
2936
			public void controlResized(ControlEvent e) {
2937
				saveBounds();
2938
			}
2939
2940
			private void saveBounds() {
2941
				Shell shell = getShell();
2942
				if (shell == null) {
2943
					return;
2944
				}
2945
				if (shell.isDisposed()) {
2946
					return;
2947
				}
2948
				if (shell.getMinimized()) {
2949
					return;
2950
				}
2951
				if (shell.getMaximized()) {
2952
					asMaximizedState = true;
2953
					return;
2954
				}
2955
				asMaximizedState = false;
2956
				normalBounds = shell.getBounds();
2957
			}
2958
		});
2959
	}
2960
2961
	/**
2962
	 * update the action bars.
2963
	 */
2964
	public void updateActionBars() {
2965
		if (updateDisabled || updatesDeferred()) {
2966
			return;
2967
		}
2968
		// updateAll required in order to enable accelerators on pull-down menus
2969
		getMenuBarManager().update(false);
2970
2971
		// RAP [bm]: Composite#setLayoutDeferred
2972
//		try {
2973
//			getShell().setLayoutDeferred(true);
2974
//			getCoolBarManager2().update(false);
2975
//		} finally {
2976
//			getShell().setLayoutDeferred(false);
2977
//		}
2978
		getCoolBarManager2().update(false);
2979
		// RAPEND: [bm] 
2980
2981
		getStatusLineManager().update(false);
2982
	}
2983
2984
	/**
2985
	 * Returns true iff we are currently deferring UI processing due to a large
2986
	 * update
2987
	 * 
2988
	 * @return true iff we are deferring UI updates.
2989
	 */
2990
	private boolean updatesDeferred() {
2991
		return largeUpdates > 0;
2992
	}
2993
2994
	/**
2995
	 * <p>
2996
	 * Indicates the start of a large update within this window. This is used to
2997
	 * disable CPU-intensive, change-sensitive services that were temporarily
2998
	 * disabled in the midst of large changes. This method should always be
2999
	 * called in tandem with <code>largeUpdateEnd</code>, and the event loop
3000
	 * should not be allowed to spin before that method is called.
3001
	 * </p>
3002
	 * <p>
3003
	 * Important: always use with <code>largeUpdateEnd</code>!
3004
	 * </p>
3005
	 */
3006
	public final void largeUpdateStart() {
3007
		largeUpdates++;
3008
	}
3009
3010
	/**
3011
	 * <p>
3012
	 * Indicates the end of a large update within this window. This is used to
3013
	 * re-enable services that were temporarily disabled in the midst of large
3014
	 * changes. This method should always be called in tandem with
3015
	 * <code>largeUpdateStart</code>, and the event loop should not be
3016
	 * allowed to spin before this method is called.
3017
	 * </p>
3018
	 * <p>
3019
	 * Important: always protect this call by using <code>finally</code>!
3020
	 * </p>
3021
	 */
3022
	public final void largeUpdateEnd() {
3023
		if (--largeUpdates == 0) {
3024
			updateActionBars();
3025
		}
3026
	}
3027
3028
	/**
3029
	 * Update the visible action sets. This method is typically called from a
3030
	 * page when the user changes the visible action sets within the
3031
	 * prespective.
3032
	 */
3033
	public void updateActionSets() {
3034
		if (updateDisabled) {
3035
			return;
3036
		}
3037
3038
		WorkbenchPage currentPage = getActiveWorkbenchPage();
3039
		if (currentPage == null) {
3040
			getActionPresentation().clearActionSets();
3041
		} else {
3042
			ICoolBarManager2 coolBarManager = (ICoolBarManager2) getCoolBarManager2();
3043
			if (coolBarManager != null) {
3044
				coolBarManager.refresh();
3045
			}
3046
			getActionPresentation().setActionSets(
3047
					currentPage.getActionSets());
3048
		}
3049
		fireActionSetsChanged();
3050
		updateActionBars();
3051
3052
		// hide the launch menu if it is empty
3053
		String path = IWorkbenchActionConstants.M_WINDOW
3054
				+ IWorkbenchActionConstants.SEP
3055
				+ IWorkbenchActionConstants.M_LAUNCH;
3056
		IMenuManager manager = getMenuBarManager().findMenuUsingPath(path);
3057
		IContributionItem item = getMenuBarManager().findUsingPath(path);
3058
3059
		if (manager == null || item == null) {
3060
			return;
3061
		}
3062
		item.setVisible(manager.getItems().length >= 2);
3063
		// there is a separator for the additions group thus >= 2
3064
	}
3065
3066
	private ListenerList actionSetListeners = null;
3067
3068
	private ListenerList backgroundSaveListeners = new ListenerList(ListenerList.IDENTITY);
3069
3070
	private final void fireActionSetsChanged() {
3071
		if (actionSetListeners != null) {
3072
			final Object[] listeners = actionSetListeners.getListeners();
3073
			for (int i = 0; i < listeners.length; i++) {
3074
				final IActionSetsListener listener = (IActionSetsListener) listeners[i];
3075
				final WorkbenchPage currentPage = getActiveWorkbenchPage();
3076
				final IActionSetDescriptor[] newActionSets;
3077
				if (currentPage == null) {
3078
					newActionSets = null;
3079
				} else {
3080
					newActionSets = currentPage.getActionSets();
3081
				}
3082
				final ActionSetsEvent event = new ActionSetsEvent(newActionSets);
3083
				listener.actionSetsChanged(event);
3084
			}
3085
		}
3086
	}
3087
3088
	final void addActionSetsListener(final IActionSetsListener listener) {
3089
		if (actionSetListeners == null) {
3090
			actionSetListeners = new ListenerList();
3091
		}
3092
3093
		actionSetListeners.add(listener);
3094
	}
3095
3096
	final void removeActionSetsListener(final IActionSetsListener listener) {
3097
		if (actionSetListeners != null) {
3098
			actionSetListeners.remove(listener);
3099
			if (actionSetListeners.isEmpty()) {
3100
				actionSetListeners = null;
3101
			}
3102
		}
3103
	}
3104
3105
	/**
3106
	 * Create the progress indicator for the receiver.
3107
	 * 
3108
	 * @param shell
3109
	 *            the parent shell
3110
	 */
3111
	private void createProgressIndicator(Shell shell) {
3112
		if (getWindowConfigurer().getShowProgressIndicator()) {
3113
			progressRegion = new ProgressRegion();
3114
			progressRegion.createContents(shell, this);
3115
		}
3116
	}
3117
3118
	class PageList {
3119
		// List of pages in the order they were created;
3120
		private List pagesInCreationOrder;
3121
3122
		// List of pages where the top is the last activated.
3123
		private List pageInActivationOrder;
3124
3125
		// The page explicitly activated
3126
		private Object active;
3127
3128
		public PageList() {
3129
			pagesInCreationOrder = new ArrayList(4);
3130
			pageInActivationOrder = new ArrayList(4);
3131
		}
3132
3133
		public boolean add(Object object) {
3134
			pagesInCreationOrder.add(object);
3135
			pageInActivationOrder.add(0, object);
3136
			// It will be moved to top only when activated.
3137
			return true;
3138
		}
3139
3140
		public Iterator iterator() {
3141
			return pagesInCreationOrder.iterator();
3142
		}
3143
3144
		public boolean contains(Object object) {
3145
			return pagesInCreationOrder.contains(object);
3146
		}
3147
3148
		public boolean remove(Object object) {
3149
			if (active == object) {
3150
				active = null;
3151
			}
3152
			pageInActivationOrder.remove(object);
3153
			return pagesInCreationOrder.remove(object);
3154
		}
3155
3156
		public boolean isEmpty() {
3157
			return pagesInCreationOrder.isEmpty();
3158
		}
3159
3160
		public IWorkbenchPage[] getPages() {
3161
			int nSize = pagesInCreationOrder.size();
3162
			IWorkbenchPage[] retArray = new IWorkbenchPage[nSize];
3163
			pagesInCreationOrder.toArray(retArray);
3164
			return retArray;
3165
		}
3166
3167
		public void setActive(Object page) {
3168
			if (active == page) {
3169
				return;
3170
			}
3171
3172
			active = page;
3173
3174
			if (page != null) {
3175
				pageInActivationOrder.remove(page);
3176
				pageInActivationOrder.add(page);
3177
			}
3178
		}
3179
3180
		public WorkbenchPage getActive() {
3181
			return (WorkbenchPage) active;
3182
		}
3183
3184
		public WorkbenchPage getNextActive() {
3185
			if (active == null) {
3186
				if (pageInActivationOrder.isEmpty()) {
3187
					return null;
3188
				}
3189
3190
				return (WorkbenchPage) pageInActivationOrder
3191
						.get(pageInActivationOrder.size() - 1);
3192
			}
3193
3194
			if (pageInActivationOrder.size() < 2) {
3195
				return null;
3196
			}
3197
3198
			return (WorkbenchPage) pageInActivationOrder
3199
					.get(pageInActivationOrder.size() - 2);
3200
		}
3201
	}
3202
3203
	/**
3204
	 * Returns the unique object that applications use to configure this window.
3205
	 * <p>
3206
	 * IMPORTANT This method is declared package-private to prevent regular
3207
	 * plug-ins from downcasting IWorkbenchWindow to WorkbenchWindow and getting
3208
	 * hold of the workbench window configurer that would allow them to tamper
3209
	 * with the workbench window. The workbench window configurer is available
3210
	 * only to the application.
3211
	 * </p>
3212
	 */
3213
	/* package - DO NOT CHANGE */
3214
	WorkbenchWindowConfigurer getWindowConfigurer() {
3215
		if (windowConfigurer == null) {
3216
			// lazy initialize
3217
			windowConfigurer = new WorkbenchWindowConfigurer(this);
3218
		}
3219
		return windowConfigurer;
3220
	}
3221
3222
	/**
3223
	 * Returns the workbench advisor. Assumes the workbench has been created
3224
	 * already.
3225
	 * <p>
3226
	 * IMPORTANT This method is declared private to prevent regular plug-ins
3227
	 * from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
3228
	 * the workbench advisor that would allow them to tamper with the workbench.
3229
	 * The workbench advisor is internal to the application.
3230
	 * </p>
3231
	 */
3232
	private/* private - DO NOT CHANGE */
3233
	WorkbenchAdvisor getAdvisor() {
3234
		return getWorkbenchImpl().getAdvisor();
3235
	}
3236
3237
	/**
3238
	 * Returns the window advisor, creating a new one for this window if needed.
3239
	 * <p>
3240
	 * IMPORTANT This method is declared private to prevent regular plug-ins
3241
	 * from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
3242
	 * the window advisor that would allow them to tamper with the window. The
3243
	 * window advisor is internal to the application.
3244
	 * </p>
3245
	 */
3246
	private/* private - DO NOT CHANGE */
3247
	WorkbenchWindowAdvisor getWindowAdvisor() {
3248
		if (windowAdvisor == null) {
3249
			windowAdvisor = getAdvisor().createWorkbenchWindowAdvisor(
3250
					getWindowConfigurer());
3251
			Assert.isNotNull(windowAdvisor);
3252
		}
3253
		return windowAdvisor;
3254
	}
3255
3256
	/**
3257
	 * Returns the action bar advisor, creating a new one for this window if
3258
	 * needed.
3259
	 * <p>
3260
	 * IMPORTANT This method is declared private to prevent regular plug-ins
3261
	 * from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
3262
	 * the action bar advisor that would allow them to tamper with the window's
3263
	 * action bars. The action bar advisor is internal to the application.
3264
	 * </p>
3265
	 */
3266
	private/* private - DO NOT CHANGE */
3267
	ActionBarAdvisor getActionBarAdvisor() {
3268
		if (actionBarAdvisor == null) {
3269
			actionBarAdvisor = getWindowAdvisor().createActionBarAdvisor(
3270
					getWindowConfigurer().getActionBarConfigurer());
3271
			Assert.isNotNull(actionBarAdvisor);
3272
		}
3273
		return actionBarAdvisor;
3274
	}
3275
3276
	/*
3277
	 * Returns the IWorkbench implementation.
3278
	 */
3279
	private Workbench getWorkbenchImpl() {
3280
		return Workbench.getInstance();
3281
	}
3282
3283
	/**
3284
	 * Fills the window's real action bars.
3285
	 * 
3286
	 * @param flags
3287
	 *            indicate which bars to fill
3288
	 */
3289
	public void fillActionBars(int flags) {
3290
		Workbench workbench = getWorkbenchImpl();
3291
		workbench.largeUpdateStart();
3292
		try {
3293
			getActionBarAdvisor().fillActionBars(flags);
3294
			//
3295
			// 3.3 start
3296
			final IMenuService menuService = (IMenuService) serviceLocator
3297
					.getService(IMenuService.class);
3298
			menuService.populateContributionManager(
3299
					(ContributionManager) getActionBars().getMenuManager(),
3300
					MenuUtil.MAIN_MENU);
3301
			ICoolBarManager coolbar = getActionBars().getCoolBarManager();
3302
			if (coolbar != null) {
3303
				menuService.populateContributionManager(
3304
						(ContributionManager) coolbar,
3305
						MenuUtil.MAIN_TOOLBAR);
3306
			}
3307
			// 3.3 end
3308
		} finally {
3309
			workbench.largeUpdateEnd();
3310
		}
3311
	}
3312
3313
	/**
3314
	 * Fills the window's proxy action bars.
3315
	 * 
3316
	 * @param proxyBars
3317
	 *            the proxy configurer
3318
	 * @param flags
3319
	 *            indicate which bars to fill
3320
	 */
3321
	public void fillActionBars(IActionBarConfigurer2 proxyBars, int flags) {
3322
		Assert.isNotNull(proxyBars);
3323
		WorkbenchWindowConfigurer.WindowActionBarConfigurer wab = (WorkbenchWindowConfigurer.WindowActionBarConfigurer) getWindowConfigurer()
3324
				.getActionBarConfigurer();
3325
		wab.setProxy(proxyBars);
3326
		try {
3327
			getActionBarAdvisor().fillActionBars(
3328
					flags | ActionBarAdvisor.FILL_PROXY);
3329
		} finally {
3330
			wab.setProxy(null);
3331
		}
3332
	}
3333
3334
	/**
3335
	 * The <code>WorkbenchWindow</code> implementation of this method has the
3336
	 * same logic as <code>Window</code>'s implementation, but without the
3337
	 * resize check. We don't want to skip setting the bounds if the shell has
3338
	 * been resized since a free resize event occurs on Windows when the menubar
3339
	 * is set in configureShell.
3340
	 */
3341
	protected void initializeBounds() {
3342
		Point size = getInitialSize();
3343
		Point location = getInitialLocation(size);
3344
		getShell().setBounds(
3345
				getConstrainedShellBounds(new Rectangle(location.x, location.y,
3346
						size.x, size.y)));
3347
	}
3348
3349
	/*
3350
	 * Unlike dialogs, the position of the workbench window is set by the user
3351
	 * and persisted across sessions. If the user wants to put the window
3352
	 * offscreen or spanning multiple monitors, let them (bug 74762)
3353
	 */
3354
	protected void constrainShellSize() {
3355
		// As long as the shell is visible on some monitor, don't change it.
3356
		Rectangle bounds = getShell().getBounds();
3357
		if (!SwtUtil.intersectsAnyMonitor(Display.getCurrent(), bounds)) {
3358
			super.constrainShellSize();
3359
		}
3360
	}
3361
3362
	/*
3363
	 * Unlike dialogs, the position of the workbench window is set by the user
3364
	 * and persisted across sessions. If the user wants to put the window
3365
	 * offscreen or spanning multiple monitors, let them (bug 74762)
3366
	 */
3367
	protected Point getInitialLocation(Point size) {
3368
		Shell shell = getShell();
3369
		if (shell != null) {
3370
			return shell.getLocation();
3371
		}
3372
3373
		return super.getInitialLocation(size);
3374
	}
3375
3376
	/**
3377
	 * The <code>WorkbenchWindow</code> implementation of this method
3378
	 * delegates to the window configurer.
3379
	 */
3380
	protected Point getInitialSize() {
3381
		return getWindowConfigurer().getInitialSize();
3382
	}
3383
3384
	/**
3385
	 * @param visible
3386
	 *            whether the cool bar should be shown. This is only applicable
3387
	 *            if the window configurer also wishes either the cool bar to be
3388
	 *            visible.
3389
	 */
3390
	public void setCoolBarVisible(boolean visible) {
3391
		boolean oldValue = coolBarVisible;
3392
		coolBarVisible = visible;
3393
		if (oldValue != coolBarVisible) {
3394
			updateLayoutDataForContents();
3395
		}
3396
	}
3397
3398
	/**
3399
	 * @return whether the cool bar should be shown. This is only applicable if
3400
	 *         the window configurer also wishes either the cool bar to be
3401
	 *         visible.
3402
	 */
3403
	public boolean getCoolBarVisible() {
3404
		return coolBarVisible;
3405
	}
3406
3407
	/**
3408
	 * @param visible
3409
	 *            whether the perspective bar should be shown. This is only
3410
	 *            applicable if the window configurer also wishes either the
3411
	 *            perspective bar to be visible.
3412
	 */
3413
	public void setPerspectiveBarVisible(boolean visible) {
3414
		boolean oldValue = perspectiveBarVisible;
3415
		perspectiveBarVisible = visible;
3416
		if (oldValue != perspectiveBarVisible) {
3417
			updateLayoutDataForContents();
3418
		}
3419
	}
3420
3421
	/**
3422
	 * @return whether the perspective bar should be shown. This is only
3423
	 *         applicable if the window configurer also wishes either the
3424
	 *         perspective bar to be visible.
3425
	 */
3426
	public boolean getPerspectiveBarVisible() {
3427
		return perspectiveBarVisible;
3428
	}
3429
	
3430
	/**
3431
	 * Tell the workbench window a visible state for the fastview bar. This is
3432
	 * only applicable if the window configurer also wishes the fast view bar to
3433
	 * be visible.
3434
	 * 
3435
	 * @param visible
3436
	 *            <code>true</code> or <code>false</code>
3437
	 */
3438
	public void setFastViewBarVisible(boolean visible) {
3439
		boolean oldValue = fastViewBarVisible;
3440
		fastViewBarVisible = visible;
3441
		if (oldValue != fastViewBarVisible) {
3442
			updateLayoutDataForContents();
3443
		}
3444
	}
3445
	
3446
	/**
3447
	 * The workbench window take on the fastview bar. This is only applicable if
3448
	 * the window configurer also wishes the fast view bar to be visible.
3449
	 * 
3450
	 * @return <code>true</code> if the workbench window thinks the fastview
3451
	 *         bar should be visible.
3452
	 */
3453
	public boolean getFastViewBarVisible() {
3454
		return fastViewBarVisible;
3455
	}
3456
3457
	/**
3458
	 * @param visible
3459
	 *            whether the perspective bar should be shown. This is only
3460
	 *            applicable if the window configurer also wishes either the
3461
	 *            perspective bar to be visible.
3462
	 */
3463
	public void setStatusLineVisible(boolean visible) {
3464
		boolean oldValue = statusLineVisible;
3465
		statusLineVisible = visible;
3466
		if (oldValue != statusLineVisible) {
3467
			updateLayoutDataForContents();
3468
		}
3469
	}
3470
3471
	/**
3472
	 * @return whether the perspective bar should be shown. This is only
3473
	 *         applicable if the window configurer also wishes either the
3474
	 *         perspective bar to be visible.
3475
	 */
3476
	public boolean getStatusLineVisible() {
3477
		return statusLineVisible;
3478
	}
3479
3480
	/**
3481
	 * Note that this will only have an effect if the default implementation of
3482
	 * WorkbenchAdvisor.createWindowContents() has been invoked.
3483
	 * 
3484
	 * called IWorkbench
3485
	 */
3486
	private void updateLayoutDataForContents() {
3487
		if (defaultLayout == null) {
3488
			return;
3489
		}
3490
3491
		// @issue this is not ideal; coolbar and perspective shortcuts should be
3492
		// separately configurable
3493
		if ((getCoolBarVisible() && getWindowConfigurer().getShowCoolBar())
3494
				|| (getPerspectiveBarVisible() && getWindowConfigurer()
3495
						.getShowPerspectiveBar())) {
3496
			if (defaultLayout.getTrim(topBarTrim.getId()) == null) {
3497
				defaultLayout.addTrim(SWT.TOP, topBarTrim);
3498
			}
3499
			topBar.setVisible(true);
3500
		} else {
3501
			defaultLayout.removeTrim(topBarTrim);
3502
			topBar.setVisible(false);
3503
		}
3504
3505
		if (fastViewBar != null) {
3506
			if (getFastViewBarVisible()
3507
					&& getWindowConfigurer().getShowFastViewBars()) {
3508
				int side = fastViewBar.getSide();
3509
3510
				if (defaultLayout.getTrim(fastViewBar.getId()) == null) {
3511
					defaultLayout.addTrim(side, fastViewBar);
3512
				}
3513
				fastViewBar.getControl().setVisible(true);
3514
			} else {
3515
				defaultLayout.removeTrim(fastViewBar);
3516
				fastViewBar.getControl().setVisible(false);
3517
			}
3518
		}
3519
3520
		if (getStatusLineVisible() && getWindowConfigurer().getShowStatusLine()) {
3521
			if (defaultLayout.getTrim(getStatusLineTrim().getId()) == null) {
3522
				defaultLayout.addTrim(SWT.BOTTOM, getStatusLineTrim());
3523
			}
3524
			getStatusLineManager().getControl().setVisible(true);
3525
		} else {
3526
			defaultLayout.removeTrim(getStatusLineTrim());
3527
			getStatusLineManager().getControl().setVisible(false);
3528
		}
3529
234
3530
// RAP [rh] HeapStatus not supported  
235
    // static fields for inner classes.
3531
//		if (heapStatus != null) {
236
    static final int VGAP = 0;
3532
//			if (getShowHeapStatus()) {
237
3533
//				if (heapStatus.getLayoutData() == null) {
238
    static final int CLIENT_INSET = 3;
3534
//					heapStatusTrim.setWidthHint(heapStatus.computeSize(
239
3535
//							SWT.DEFAULT, SWT.DEFAULT).x);
240
    static final int BAR_SIZE = 23;
3536
//					heapStatusTrim
3537
//							.setHeightHint(getStatusLineManager().getControl()
3538
//									.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
3539
//				}
3540
//
3541
//				if (defaultLayout.getTrim(heapStatusTrim.getId()) == null) {
3542
//					defaultLayout.addTrim(SWT.BOTTOM, heapStatusTrim);
3543
//				}
3544
//				heapStatus.setVisible(true);
3545
//			} else {
3546
//
3547
//				defaultLayout.removeTrim(heapStatusTrim);
3548
//				heapStatus.setVisible(false);
3549
//			}
3550
//		}
3551
3552
		if (progressRegion != null) {
3553
			if (getWindowConfigurer().getShowProgressIndicator()) {
3554
				if (defaultLayout.getTrim(progressRegion.getId()) == null) {
3555
					defaultLayout.addTrim(SWT.BOTTOM, progressRegion);
3556
				}
3557
				progressRegion.getControl().setVisible(true);
3558
			} else {
3559
				defaultLayout.removeTrim(progressRegion);
3560
				progressRegion.getControl().setVisible(false);
3561
			}
3562
		}
3563
		
3564
		defaultLayout.setCenterControl(getPageComposite());
3565
3566
		// Re-populate the trim elements
3567
		if (trimMgr2 != null)
3568
			trimMgr2.update(true, false, !topBar.getVisible());
3569
		if (trimContributionMgr != null)
3570
			trimContributionMgr.update(true,  !topBar.getVisible());
3571
	}
3572
3573
	public boolean getShowFastViewBars() {
3574
		return getWindowConfigurer().getShowFastViewBars();
3575
	}
3576
3577
	/**
3578
	 * Set the layout data for the contents of the window.
3579
	 */
3580
	private void setLayoutDataForContents() {
3581
		updateLayoutDataForContents();
3582
	}
3583
3584
	/**
3585
	 * Returns the fast view bar.
3586
	 */
3587
	public FastViewBar getFastViewBar() {
3588
		return fastViewBar;
3589
	}
3590
3591
	/**
3592
	 * Returns the perspective bar.
3593
	 * 
3594
	 * @return Returns the perspective bar, or <code>null</code> if it has not
3595
	 *         been initialized.
3596
	 */
3597
	public PerspectiveBarManager getPerspectiveBar() {
3598
		return perspectiveSwitcher == null ? null : perspectiveSwitcher
3599
				.getPerspectiveBar();
3600
	}
3601
241
3602
    /**
242
    /**
3603
     * Returns the action presentation for dynamic UI
243
     * Coolbar visibility change property.
3604
     * @return action presentation
3605
     */
244
     */
3606
    public ActionPresentation getActionPresentation() {
245
    public static final String PROP_COOLBAR_VISIBLE = "coolbarVisible"; //$NON-NLS-1$
3607
        if (actionPresentation == null) {
246
    
3608
        	actionPresentation = new ActionPresentation(this);
247
    /**
3609
        }
248
     * Perspective bar visibility change property.
3610
        return actionPresentation;
249
     */
250
    public static final String PROP_PERSPECTIVEBAR_VISIBLE = "perspectiveBarVisible"; //$NON-NLS-1$
251
    
252
    /**
253
     * Constant (bit mask) indicating which the Show View submenu is probably
254
     * present somewhere in this window.
255
     * 
256
     * @see #addSubmenu
257
     */
258
    public static final int SHOW_VIEW_SUBMENU = 0x01;
259
260
    /**
261
     * Constant (bit mask) indicating which the Open Perspective submenu is
262
     * probably present somewhere in this window.
263
     * 
264
     * @see #addSubmenu
265
     */
266
    public static final int OPEN_PERSPECTIVE_SUBMENU = 0x02;
267
268
    /**
269
     * Constant (bit mask) indicating which the New Wizard submenu is probably
270
     * present somewhere in this window.
271
     * 
272
     * @see #addSubmenu
273
     */
274
    public static final int NEW_WIZARD_SUBMENU = 0x04;
275
276
    /**
277
     * Remembers that this window contains the given submenu.
278
     * 
279
     * @param type
280
     *            the type of submenu, one of:
281
     *            {@link #NEW_WIZARD_SUBMENU NEW_WIZARD_SUBMENU},
282
     *            {@link #OPEN_PERSPECTIVE_SUBMENU OPEN_PERSPECTIVE_SUBMENU},
283
     *            {@link #SHOW_VIEW_SUBMENU SHOW_VIEW_SUBMENU}
284
     * @see #containsSubmenu
285
     */
286
    public void addSubmenu(int type) {
287
        submenus |= type;
288
    }
289
290
    /**
291
     * Checks to see if this window contains the given type of submenu.
292
     * 
293
     * @param type
294
     *            the type of submenu, one of:
295
     *            {@link #NEW_WIZARD_SUBMENU NEW_WIZARD_SUBMENU},
296
     *            {@link #OPEN_PERSPECTIVE_SUBMENU OPEN_PERSPECTIVE_SUBMENU},
297
     *            {@link #SHOW_VIEW_SUBMENU SHOW_VIEW_SUBMENU}
298
     * @return <code>true</code> if window contains submenu,
299
     *         <code>false</code> otherwise
300
     * @see #addSubmenu
301
     */
302
    public boolean containsSubmenu(int type) {
303
        return ((submenus & type) != 0);
3611
    }
304
    }
305
306
    /**
307
     * Constant indicating that all the actions bars should be filled.
308
     */
309
    private static final int FILL_ALL_ACTION_BARS = ActionBarAdvisor.FILL_MENU_BAR
310
            | ActionBarAdvisor.FILL_COOL_BAR
311
            | ActionBarAdvisor.FILL_STATUS_LINE;
3612
    
312
    
313
3613
    /**
314
    /**
3614
     * Return the action bar presentation used for creating toolbars.  This
315
     * Creates and initializes a new workbench window.
3615
     * is for internal use only, used for consistency with the window.
3616
     * 
316
     * 
3617
     * @return the presentation used.
317
     * @param number
318
     *            the number for the window
3618
     */
319
     */
3619
    public IActionBarPresentationFactory getActionBarPresentationFactory() {
320
    public WorkbenchWindow(int number) {
3620
    	// allow replacement of the actionbar presentation
321
        super(null);
3621
    	IActionBarPresentationFactory actionBarPresentation;        	
322
        this.number = number;
3622
    	AbstractPresentationFactory presentationFactory = 
323
3623
    		getWindowConfigurer().getPresentationFactory();
324
        
3624
    	if (presentationFactory instanceof IActionBarPresentationFactory) {
325
        // Make sure there is a workbench. This call will throw
3625
        	actionBarPresentation = ((IActionBarPresentationFactory) presentationFactory);
326
        // an exception if workbench not created yet.
3626
    	} else {
327
        final IWorkbench workbench = PlatformUI.getWorkbench();
3627
			actionBarPresentation = new DefaultActionBarPresentationFactory();
328
        IServiceLocatorCreator slc = (IServiceLocatorCreator) workbench
3628
		}      
329
                .getService(IServiceLocatorCreator.class);
3629
    	
330
        this.serviceLocator = (ServiceLocator) slc
3630
    	return actionBarPresentation;        	
331
                .createServiceLocator(workbench, null);
3631
    }
332
        initializeDefaultServices();
3632
    
333
3633
	/*
334
        // Add contribution managers that are exposed to other plugins.
3634
	 * (non-Javadoc)
335
        addMenuBar();
3635
	 * 
336
        addCoolBar(SWT.NONE);  // style is unused
3636
	 * @see org.eclipse.jface.window.ApplicationWindow#showTopSeperator()
337
        addStatusLine();
3637
	 */
338
3638
	protected boolean showTopSeperator() {
339
        // register with the tracker
3639
		return false;
340
        getExtensionTracker()
3640
	}
341
                .registerHandler(
342
                        actionSetHandler,
343
                        ExtensionTracker
344
                                .createExtensionPointFilter(getActionSetExtensionPoint()));
3641
345
3642
	/**
346
        fireWindowOpening();
3643
     * Returns a new cool bar manager for the window.
347
348
        // set the shell style
349
        setShellStyle(getWindowConfigurer().getShellStyle());
350
351
        // Fill the action bars
352
        fillActionBars(FILL_ALL_ACTION_BARS);
353
    }
354
355
    /**
356
     * Return the action set extension point.
357
     * 
358
     * @return the action set extension point
359
     */
360
    private IExtensionPoint getActionSetExtensionPoint() {
361
        // RAP [bm]: 
362
//      return Platform.getExtensionRegistry().getExtensionPoint(
363
//              PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_ACTION_SETS);
364
        return Platform.getExtensionRegistry().getExtensionPoint(
365
                PlatformUI.PLUGIN_EXTENSION_NAME_SPACE, IWorkbenchRegistryConstants.PL_ACTION_SETS);
366
367
    }
368
369
    /**
370
     * Return the style bits for the shortcut bar.
371
     * 
372
     * @return int
373
     */
374
    protected int perspectiveBarStyle() {
375
        return SWT.FLAT | SWT.WRAP | SWT.RIGHT | SWT.HORIZONTAL;
376
    }
377
378
    // RAP [bm]: not used
379
//  private TrimDropTarget trimDropTarget;
380
    // RAPEND: [bm] 
381
382
    private boolean coolBarVisible = true;
383
384
    private boolean perspectiveBarVisible = true;
385
    
386
    private boolean fastViewBarVisible = true;
387
388
    private boolean statusLineVisible = true;
389
390
    private IWindowTrim statusLineTrim = null;
391
392
    /**
393
     * The handlers for global actions that were last submitted to the workbench
394
     * command support. This is a map of command identifiers to
395
     * <code>ActionHandler</code>. This map is never <code>null</code>,
396
     * and is never empty as long as at least one global action has been
397
     * registered.
398
     */
399
    private Map globalActionHandlersByCommandId = new HashMap();
400
401
    /**
402
     * The list of handler submissions submitted to the workbench command
403
     * support. This list may be empty, but it is never <code>null</code>.
404
     */
405
    private List handlerActivations = new ArrayList();
406
407
    /**
408
     * The number of large updates that are currently going on. If this is
409
     * number is greater than zero, then UI updateActionBars is a no-op.
410
     */
411
    private int largeUpdates = 0;
412
413
    private IExtensionTracker tracker;
414
415
    private IExtensionChangeHandler actionSetHandler = new IExtensionChangeHandler() {
416
417
        /*
418
         * (non-Javadoc)
419
         * 
420
         * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamichelpers.IExtensionTracker,
421
         *      org.eclipse.core.runtime.IExtension)
422
         */
423
        public void addExtension(IExtensionTracker tracker, IExtension extension) {
424
            // this assumes that the workbench-level tracker will have already
425
            // updated the registry
426
427
            ArrayList setsToActivate = new ArrayList();
428
            // look for all new sets that are on by default. Examine the tracker
429
            // at the workbench level to see what descriptors are registered
430
            // against this extension
431
            Object[] registeredObjects = getWorkbench().getExtensionTracker()
432
                    .getObjects(extension);
433
            for (int i = 0; i < registeredObjects.length; i++) {
434
                if (registeredObjects[i] instanceof IActionSetDescriptor) {
435
                    IActionSetDescriptor desc = (IActionSetDescriptor) registeredObjects[i];
436
                    if (desc.isInitiallyVisible()) {
437
                        setsToActivate.add(desc);
438
                    }
439
                }
440
            }
441
442
            // if none of the new sets are marked as initially visible, abort.
443
            if (setsToActivate.isEmpty()) {
444
                return;
445
            }
446
447
            IActionSetDescriptor[] descriptors = (IActionSetDescriptor[]) setsToActivate
448
                    .toArray(new IActionSetDescriptor[setsToActivate.size()]);
449
450
            WorkbenchPage page = getActiveWorkbenchPage();
451
            if (page != null) {
452
                Perspective[] perspectives = page.getOpenInternalPerspectives();
453
454
                for (int i = 0; i < perspectives.length; i++) {
455
                    perspectives[i].turnOnActionSets(descriptors);
456
                }
457
            }
458
459
            updateActionSets();
460
        }
461
462
        /*
463
         * (non-Javadoc)
464
         * 
465
         * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension,
466
         *      java.lang.Object[])
467
         */
468
        public void removeExtension(IExtension extension, Object[] objects) {
469
            // remove the contributions from the window bars and dispose of the
470
            // actions
471
            for (int i = 0; i < objects.length; i++) {
472
                if (objects[i] instanceof PluginActionSetBuilder.Binding) {
473
                    PluginActionSetBuilder.Binding binding = (PluginActionSetBuilder.Binding) objects[i];
474
                    binding.builder.removeActionExtensions(binding.set,
475
                            binding.window);
476
                    binding.set.dispose();
477
                }
478
            }
479
480
            // update all opened perspectives
481
            Perspective[] perspectives = getActiveWorkbenchPage()
482
                    .getOpenInternalPerspectives();
483
            boolean updateNeeded = true;
484
            IContextService contextService = (IContextService) getService(IContextService.class);
485
            try {
486
                contextService.activateContext(ContextAuthority.DEFER_EVENTS);
487
                
488
                for (int i = 0; i < perspectives.length; i++) {
489
                    for (int j = 0; j < objects.length; j++) {
490
                        if (objects[j] instanceof IActionSetDescriptor) {
491
                            perspectives[i]
492
                                    .removeActionSet((IActionSetDescriptor) objects[j]);
493
                            getActionPresentation().removeActionSet(
494
                                    (IActionSetDescriptor) objects[j]);
495
                        }
496
                    }
497
                }
498
            } finally {
499
                contextService.activateContext(ContextAuthority.SEND_EVENTS);
500
            }
501
502
            if (updateNeeded) {
503
                // refresh the window
504
                updateActionSets();
505
            }
506
        }
507
    };
508
509
    void registerGlobalAction(IAction globalAction) {
510
        String commandId = globalAction.getActionDefinitionId();
511
512
        if (commandId != null) {
513
            final Object value = globalActionHandlersByCommandId.get(commandId);
514
            if (value instanceof ActionHandler) {
515
                // This handler is about to get clobbered, so dispose it.
516
                final ActionHandler handler = (ActionHandler) value;
517
                handler.dispose();
518
            }
519
520
            if (globalAction instanceof CommandAction) {
521
                final String actionId = globalAction.getId();
522
                if (actionId != null) {
523
                    final IActionCommandMappingService mappingService = (IActionCommandMappingService) serviceLocator
524
                            .getService(IActionCommandMappingService.class);
525
                    mappingService.map(actionId, commandId);
526
                }
527
            } else {
528
                globalActionHandlersByCommandId.put(commandId,
529
                        new ActionHandler(globalAction));
530
            }
531
        }
532
533
        submitGlobalActions();
534
    }
535
536
    /**
3644
     * <p>
537
     * <p>
3645
     * Subclasses may override this method to customize the cool bar manager.
538
     * Submits the action handlers for action set actions and global actions.
539
     * Global actions are given priority, so that if a global action and an
540
     * action set action both handle the same command, the global action is
541
     * given priority.
542
     * </p>
543
     * <p>
544
     * These submissions are submitted as <code>Priority.LEGACY</code>, which
545
     * means that they are the lowest priority. This means that if a higher
546
     * priority submission handles the same command under the same conditions,
547
     * that that submission will become the handler.
3646
     * </p>
548
     * </p>
549
     */
550
    void submitGlobalActions() {
551
        final IHandlerService handlerService = (IHandlerService) getWorkbench().getService(IHandlerService.class);
552
553
        /*
554
         * Mash the action sets and global actions together, with global actions
555
         * taking priority.
556
         */
557
        Map handlersByCommandId = new HashMap();
558
        handlersByCommandId.putAll(globalActionHandlersByCommandId);
559
560
        List newHandlers = new ArrayList(handlersByCommandId.size());
561
562
        Iterator existingIter = handlerActivations.iterator();
563
        while (existingIter.hasNext()) {
564
            IHandlerActivation next = (IHandlerActivation) existingIter.next();
565
566
            String cmdId = next.getCommandId();
567
568
            Object handler = handlersByCommandId.get(cmdId);
569
            if (handler == next.getHandler()) {
570
                handlersByCommandId.remove(cmdId);
571
                newHandlers.add(next);
572
            } else {
573
                handlerService.deactivateHandler(next);
574
            }
575
        }
576
577
        final Shell shell = getShell();
578
        if (shell != null) {
579
            final Expression expression = new ActiveShellExpression(shell);
580
            for (Iterator iterator = handlersByCommandId.entrySet().iterator(); iterator
581
                    .hasNext();) {
582
                Map.Entry entry = (Map.Entry) iterator.next();
583
                String commandId = (String) entry.getKey();
584
                IHandler handler = (IHandler) entry.getValue();
585
                newHandlers.add(handlerService.activateHandler(commandId,
586
                        handler, expression));
587
            }
588
        }
589
590
        handlerActivations = newHandlers;
591
    }
592
    
593
    /**
594
     * Add a generic property listener.
3647
     * 
595
     * 
3648
     * @return a cool bar manager
596
     * @param listener the listener to add
3649
     */
597
     */
3650
    protected ICoolBarManager createCoolBarManager2(int style) {
598
    public void addPropertyChangeListener(IPropertyChangeListener listener) {
3651
        return getActionBarPresentationFactory().createCoolBarManager();
599
        genericPropertyListeners.add(listener);
600
    }
601
    
602
    /**
603
     * Removes a generic property listener.
604
     * 
605
     * @param listener the listener to remove 
606
     */
607
    public void removePropertyChangeListener(IPropertyChangeListener listener) {
608
        genericPropertyListeners.remove(listener);
609
    }
610
    
611
    private void firePropertyChanged(final String property, final Object oldValue, final Object newValue) {
612
        PropertyChangeEvent event = new PropertyChangeEvent(this, property, oldValue, newValue);
613
        Object[] listeners = genericPropertyListeners.getListeners();
614
        for (int i = 0; i < listeners.length; i++) {
615
            IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i];
616
            listener.propertyChange(event);
617
        }
618
    }
619
620
    /*
621
     * Adds an listener to the part service.
622
     */
623
    public void addPageListener(IPageListener l) {
624
        pageListeners.addPageListener(l);
3652
    }
625
    }
3653
626
3654
    /**
627
    /**
3655
     * Returns a new tool bar manager for the window.
628
     * @see org.eclipse.ui.IPageService
629
     */
630
    public void addPerspectiveListener(org.eclipse.ui.IPerspectiveListener l) {
631
        perspectiveListeners.addPerspectiveListener(l);
632
    }
633
634
    /**
635
     * Configures this window to have a perspecive bar. Does nothing if it
636
     * already has one.
637
     */
638
    protected void addPerspectiveBar(int style) {
639
        Assert.isTrue(perspectiveSwitcher == null);
640
        perspectiveSwitcher = new PerspectiveSwitcher(this, topBar, style);
641
    }
642
643
    /**
644
     * Close the window.
645
     * 
646
     * Assumes that busy cursor is active.
647
     */
648
    private boolean busyClose() {
649
        // Whether the window was actually closed or not
650
        boolean windowClosed = false;
651
652
        // Setup internal flags to indicate window is in
653
        // progress of closing and no update should be done.
654
        closing = true;
655
        updateDisabled = true;
656
657
        try {
658
            // Only do the check if it is OK to close if we are not closing
659
            // via the workbench as the workbench will check this itself.
660
            Workbench workbench = getWorkbenchImpl();
661
            int count = workbench.getWorkbenchWindowCount();
662
            // also check for starting - if the first window dies on startup
663
            // then we'll need to open a default window.
664
            if (!workbench.isStarting()
665
                    && !workbench.isClosing()
666
                    && count <= 1
667
                    && workbench.getWorkbenchConfigurer()
668
                            .getExitOnLastWindowClose()) {
669
                windowClosed = workbench.close();
670
            } else {
671
                if (okToClose()) {
672
                    windowClosed = hardClose();
673
                }
674
            }
675
        } finally {
676
            if (!windowClosed) {
677
                // Reset the internal flags if window was not closed.
678
                closing = false;
679
                updateDisabled = false;
680
            }
681
        }
682
683
        if (windowClosed && tracker != null) {
684
            tracker.close();
685
        }
686
687
        return windowClosed;
688
    }
689
690
    /**
691
     * Opens a new page. Assumes that busy cursor is active.
3656
     * <p>
692
     * <p>
3657
     * Subclasses may override this method to customize the tool bar manager.
693
     * <b>Note:</b> Since release 2.0, a window is limited to contain at most
694
     * one page. If a page exist in the window when this method is used, then
695
     * another window is created for the new page. Callers are strongly
696
     * recommended to use the <code>IWorkbench.openPerspective</code> APIs to
697
     * programmatically show a perspective.
3658
     * </p>
698
     * </p>
3659
     * @return a tool bar manager
3660
     */
699
     */
3661
    protected IToolBarManager createToolBarManager2(int style) {
700
    protected IWorkbenchPage busyOpenPage(String perspID, IAdaptable input)
3662
        return getActionBarPresentationFactory().createToolBarManager();
701
            throws WorkbenchException {
702
        IWorkbenchPage newPage = null;
703
704
        if (pageList.isEmpty()) {
705
            newPage = ((WorkbenchImplementation) Tweaklets
706
                    .get(WorkbenchImplementation.KEY)).createWorkbenchPage(this, perspID, input);
707
            pageList.add(newPage);
708
            firePageOpened(newPage);
709
            setActivePage(newPage);
710
        } else {
711
            IWorkbenchWindow window = getWorkbench().openWorkbenchWindow(
712
                    perspID, input);
713
            newPage = window.getActivePage();
714
        }
715
716
        return newPage;
3663
    }
717
    }
3664
    
718
3665
    /**
719
    /**
3666
	 * Delegate to the presentation factory.
720
     * @see Window
3667
	 * 
721
     */
3668
	 * @see org.eclipse.jface.window.ApplicationWindow#createStatusLineManager
722
    public int open() {
3669
	 */
723
        if (getPages().length == 0) {
3670
	protected StatusLineManager createStatusLineManager() {
724
            showEmptyWindowContents();
3671
		// @issue ApplicationWindow and WorkbenchWindow should allow full
725
        }
3672
		// IStatusLineManager
726
        fireWindowCreated();
3673
		return (StatusLineManager) getWindowConfigurer()
727
// RAP [rh] Intro mechanism not supported
3674
				.getPresentationFactory().createStatusLineManager();
728
//      getWindowAdvisor().openIntro();
3675
	}
729
        int result = super.open();
3676
730
3677
	/**
731
        // It's time for a layout ... to insure that if TrimLayout
3678
	 * Delegate to the presentation factory.
732
        // is in play, it updates all of the trim it's responsible
3679
	 * 
733
        // for. We have to do this before updating in order to get
3680
	 * @see org.eclipse.jface.window.ApplicationWindow#createStatusLine
734
        // the PerspectiveBar management correct...see defect 137334
3681
	 */
735
        getShell().layout();
3682
	protected void createStatusLine(Shell shell) {
736
        
3683
		getWindowConfigurer().getPresentationFactory().createStatusLineControl(
737
        fireWindowOpened();
3684
				getStatusLineManager(), shell);
738
        if (perspectiveSwitcher != null) {
3685
	}
739
            perspectiveSwitcher.updatePerspectiveBar();
3686
740
            perspectiveSwitcher.updateBarParent();
3687
	/**
741
        }
3688
	 * Updates the fast view bar, if present. TODO: The fast view bar should
742
        
3689
	 * update itself as necessary. All calls to this should be cleaned up.
743
        return result;
3690
	 */
744
    }
3691
	public void updateFastViewBar() {
745
3692
		if (getFastViewBar() != null) {
746
    /*
3693
			getFastViewBar().update(true);
747
     * (non-Javadoc) Method declared on Window.
3694
		}
748
     */
3695
	}
749
    protected boolean canHandleShellCloseEvent() {
3696
750
        if (!super.canHandleShellCloseEvent()) {
3697
	/**
751
            return false;
3698
	 * @return Returns the progressRegion.
752
        }
3699
	 */
753
        // let the advisor or other interested parties
3700
	public ProgressRegion getProgressRegion() {
754
        // veto the user's explicit request to close the window
3701
		return progressRegion;
755
        return fireWindowShellClosing();
3702
	}
756
    }
3703
757
3704
	/**
758
    /**
3705
	 * Adds the given control to the specified side of this window's trim.
759
     * @see IWorkbenchWindow
3706
	 * 
760
     */
3707
	 * @param trim
761
    public boolean close() {
3708
	 *            the bar's IWindowTrim
762
        final boolean[] ret = new boolean[1];
3709
	 * @param side
763
        BusyIndicator.showWhile(null, new Runnable() {
3710
	 *            one of <code>SWT.LEFT</code>,<code>SWT.BOTTOM</code>,
764
            public void run() {
3711
	 *            or <code>SWT.RIGHT</code> (only LEFT has been tested)
765
                ret[0] = busyClose();
3712
	 */
766
            }
3713
	public void addToTrim(IWindowTrim trim, int side) {
767
        });
3714
		IWindowTrim reference = null;
768
        return ret[0];
3715
		defaultLayout.addTrim(side, trim, reference);
769
    }
3716
	}
770
3717
771
    protected boolean isClosing() {
3718
	/*
772
        return closing || getWorkbenchImpl().isClosing();
3719
	 * (non-Javadoc)
773
    }
3720
	 * 
774
3721
	 * @see org.eclipse.ui.IWorkbenchWindow#getExtensionTracker()
775
    /**
3722
	 */
776
     * Return whether or not the coolbar layout is locked.
3723
	public IExtensionTracker getExtensionTracker() {
777
     */
3724
		if (tracker == null) {
778
    protected boolean isCoolBarLocked() {
3725
			tracker = new UIExtensionTracker(getWorkbench().getDisplay());
779
        ICoolBarManager cbm = getCoolBarManager2(); 
3726
		}
780
        return cbm != null && cbm.getLockLayout();
3727
		return tracker;
781
    }
3728
	}
782
3729
783
    /**
3730
	/**
784
     * Close all of the pages.
3731
	 * Creates the perspective customization dialog.
785
     */
3732
	 * 
786
    private void closeAllPages() {
3733
	 * @param persp
787
        // Deactivate active page.
3734
	 *            perspective to customize
788
        setActivePage(null);
3735
	 * 
789
3736
	 * @return a new perspective customization dialog
790
        // Clone and deref all so that calls to getPages() returns
3737
	 */
791
        // empty list (if call by pageClosed event handlers)
3738
	public CustomizePerspectiveDialog createCustomizePerspectiveDialog(
792
        PageList oldList = pageList;
3739
			Perspective persp) {
793
        pageList = new PageList();
3740
		return new CustomizePerspectiveDialog(getWindowConfigurer(), persp);
794
3741
	}
795
        // Close all.
3742
796
        Iterator itr = oldList.iterator();
3743
	/**
797
        while (itr.hasNext()) {
3744
	 * Returns the default page input for workbench pages opened in this window.
798
            WorkbenchPage page = (WorkbenchPage) itr.next();
3745
	 * 
799
            firePageClosed(page);
3746
	 * @return the default page input or <code>null</code> if none
800
            page.dispose();
3747
	 */
801
        }
3748
	IAdaptable getDefaultPageInput() {
802
        if (!closing) {
3749
		return getWorkbenchImpl().getDefaultPageInput();
803
            showEmptyWindowContents();
3750
	}
804
        }
3751
805
    }
3752
	/**
806
3753
	 * Add a listener for perspective reordering.
807
    /**
3754
	 * 
808
     * Save and close all of the pages.
3755
	 * @param listener
809
     */
3756
	 */
810
    public void closeAllPages(boolean save) {
3757
	public void addPerspectiveReorderListener(IReorderListener listener) {
811
        if (save) {
3758
		if (perspectiveSwitcher != null) {
812
            boolean ret = saveAllPages(true);
3759
			perspectiveSwitcher.addReorderListener(listener);
813
            if (!ret) {
3760
		}
814
                return;
3761
	}
815
            }
3762
816
        }
3763
// RAP [rh] HeapStatus not supported	
817
        closeAllPages();
3764
//	/**
818
    }
3765
//	 * Show the heap status
819
3766
//	 * 
820
    /**
3767
//	 * @param selection
821
     * closePerspective method comment.
3768
//	 */
822
     */
3769
//	public void showHeapStatus(boolean selection) {
823
    protected boolean closePage(IWorkbenchPage in, boolean save) {
3770
//		if (selection) {
824
        // Validate the input.
3771
//			if (heapStatus == null) {
825
        if (!pageList.contains(in)) {
3772
//				createHeapStatus(getShell());
826
            return false;
3773
//				updateLayoutDataForContents();
827
        }
3774
//				getShell().layout();
828
        WorkbenchPage oldPage = (WorkbenchPage) in;
3775
//			}
829
3776
//		} else {
830
        // Save old perspective.
3777
//			if (heapStatus != null) {
831
        if (save && oldPage.isSaveNeeded()) {
3778
//				heapStatus.dispose();
832
            if (!oldPage.saveAllEditors(true)) {
3779
//				heapStatus = null;
833
                return false;
3780
//			}
834
            }
3781
//		}
835
        }
3782
//
836
3783
//	}
837
        // If old page is activate deactivate.
838
        boolean oldIsActive = (oldPage == getActiveWorkbenchPage());
839
        if (oldIsActive) {
840
            setActivePage(null);
841
        }
842
843
        // Close old page.
844
        pageList.remove(oldPage);
845
        firePageClosed(oldPage);
846
        oldPage.dispose();
847
848
        // Activate new page.
849
        if (oldIsActive) {
850
            IWorkbenchPage newPage = pageList.getNextActive();
851
            if (newPage != null) {
852
                setActivePage(newPage);
853
            }
854
        }
855
        if (!closing && pageList.isEmpty()) {
856
            showEmptyWindowContents();
857
        }
858
        return true;
859
    }
860
861
    private void showEmptyWindowContents() {
862
        if (!emptyWindowContentsCreated) {
863
            Composite parent = getPageComposite();
864
            emptyWindowContents = getWindowAdvisor().createEmptyWindowContents(
865
                    parent);
866
            emptyWindowContentsCreated = true;
867
            // force the empty window composite to be layed out
868
            ((StackLayout) parent.getLayout()).topControl = emptyWindowContents;
869
            parent.layout();
870
        }
871
    }
3784
872
3785
	/*
873
    private void hideEmptyWindowContents() {
3786
	 * (non-Javadoc)
874
        if (emptyWindowContentsCreated) {
3787
	 * 
875
            if (emptyWindowContents != null) {
3788
	 * @see org.eclipse.ui.IWorkbenchWindow#getTrimManager()
876
                emptyWindowContents.dispose();
3789
	 */
877
                emptyWindowContents = null;
3790
	public ITrimManager getTrimManager() {
878
                getPageComposite().layout();
3791
		return defaultLayout;
879
            }
3792
	}
880
            emptyWindowContentsCreated = false;
3793
881
        }
3794
	/**
882
    }
3795
	 * Initializes all of the default command-based services for the workbench
883
3796
	 * window.
884
    /*
3797
	 */
885
     * (non-Javadoc)
3798
	private final void initializeDefaultServices() {
886
     * 
3799
		serviceLocator.registerService(IWorkbenchWindow.class, this);
887
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
3800
		
888
     */
3801
		final ActionCommandMappingService mappingService = new ActionCommandMappingService();
889
    protected void configureShell(Shell shell) {
3802
		serviceLocator.registerService(IActionCommandMappingService.class,
890
        super.configureShell(shell);
3803
				mappingService);
891
3804
892
        // RAP [bm]: detached windows
3805
		final LegacyActionPersistence actionPersistence = new LegacyActionPersistence(
893
//      detachedWindowShells = new ShellPool(shell, SWT.TOOL | SWT.TITLE
3806
				this);
894
//              | SWT.MAX | SWT.RESIZE | getDefaultOrientation());
3807
		serviceLocator.registerService(LegacyActionPersistence.class,
895
        // RAPEND: [bm] 
3808
				actionPersistence);
896
3809
		actionPersistence.read();
897
        String title = getWindowConfigurer().basicGetTitle();
3810
898
        if (title != null) {
3811
	}
899
            shell.setText(TextProcessor.process(title, TEXT_DELIMITERS)); 
3812
900
        }
3813
	public final Object getService(final Class key) {
901
3814
		return serviceLocator.getService(key);
902
// RAP [rh] IWorkbench#getHelpSystem() not implemented 
3815
	}
903
//      final IWorkbench workbench = getWorkbench();
3816
904
//      workbench.getHelpSystem().setHelp(shell,
3817
	public final boolean hasService(final Class key) {
905
//              IWorkbenchHelpContextIds.WORKBENCH_WINDOW);
3818
		return serviceLocator.hasService(key);
906
3819
	}
907
//      initializeDefaultServices();
3820
	
908
        final IContextService contextService = (IContextService) getWorkbench().getService(IContextService.class);
3821
	/**
909
        contextService.registerShell(shell, IContextService.TYPE_WINDOW);
3822
	 * Toggle the visibility of the coolbar/perspective bar. This method
910
3823
	 * respects the window configurer and will only toggle visibility if the
911
        trackShellActivation(shell);
3824
	 * item in question was originally declared visible by the window advisor.
912
        trackShellResize(shell);
3825
	 */
913
    }
3826
	public void toggleToolbarVisibility() {
914
3827
		boolean coolbarVisible = getCoolBarVisible();
915
    // RAP [bm]: detached windows
3828
		boolean perspectivebarVisible = getPerspectiveBarVisible();
916
//  /* package */ShellPool getDetachedWindowPool() {
3829
		// only toggle the visibility of the components that
917
//      return detachedWindowShells;
3830
		// were on initially
918
//  }
3831
		if (getWindowConfigurer().getShowCoolBar()) {
919
    // RAPEND: [bm] 
3832
			setCoolBarVisible(!coolbarVisible);
920
3833
			firePropertyChanged(PROP_COOLBAR_VISIBLE,
921
    /*
3834
					coolbarVisible ? Boolean.TRUE : Boolean.FALSE,
922
     * (non-Javadoc)
3835
					!coolbarVisible ? Boolean.TRUE : Boolean.FALSE);
923
     * 
3836
		}
924
     * @see org.eclipse.jface.window.ApplicationWindow#createTrimWidgets(org.eclipse.swt.widgets.Shell)
3837
		if (getWindowConfigurer().getShowPerspectiveBar()) {
925
     */
3838
			setPerspectiveBarVisible(!perspectivebarVisible);
926
    protected void createTrimWidgets(Shell shell) {
3839
			firePropertyChanged(PROP_PERSPECTIVEBAR_VISIBLE,
927
        // do nothing -- trim widgets are created in createDefaultContents
3840
					coolbarVisible ? Boolean.TRUE : Boolean.FALSE,
928
    }
3841
					!coolbarVisible ? Boolean.TRUE : Boolean.FALSE);
929
3842
		}
930
    /**
3843
		getShell().layout();
931
     * Creates and remembers the client composite, under which workbench pages
3844
	}
932
     * create their controls.
3845
933
     */
3846
	/*package*/ void addBackgroundSaveListener(IBackgroundSaveListener listener) {
934
    protected Composite createPageComposite(Composite parent) {
3847
		backgroundSaveListeners.add(listener);
935
        pageComposite = new Composite(parent, SWT.NONE);
3848
	}
936
        // use a StackLayout instead of a FillLayout (see bug 81460 [Workbench]
3849
	
937
        // (regression) Close all perspectives, open Java perspective, layout
3850
	/*package*/ void fireBackgroundSaveStarted() {
938
        // wrong)
3851
		Object[] listeners = backgroundSaveListeners.getListeners();
939
        pageComposite.setLayout(new StackLayout());
3852
		for (int i = 0; i < listeners.length; i++) {
940
        return pageComposite;
3853
			IBackgroundSaveListener listener = (IBackgroundSaveListener) listeners[i];
941
    }
3854
			listener.handleBackgroundSaveStarted();
942
3855
		}
943
    /**
3856
	}
944
     * Creates the contents of the workbench window, including trim controls and
3857
945
     * the client composite. This MUST create the client composite via a call to
3858
	/*package*/ void removeBackgroundSaveListener(IBackgroundSaveListener listener) {
946
     * <code>createClientComposite</code>.
3859
		backgroundSaveListeners.remove(listener);
947
     */    
3860
	}
948
    protected Control createContents(Composite parent) {
949
      // RAP [hs] patched for interactiondesign API
950
      if( getConfigurablePresentationFactory() != null ) {
951
        defaultLayout = new TrimLayout();
952
        
953
        Composite pageComp = createConfigurableDefaultContents( ( Shell ) parent );
954
        createPageComposite( pageComp );
955
956
      } else {
957
        // we know from Window.create that the parent is a Shell.
958
        getWindowAdvisor().createWindowContents((Shell) parent);
959
        // the page composite must be set by createWindowContents
960
      }
961
        Assert
962
                .isNotNull(pageComposite,
963
                        "createWindowContents must call configurer.createPageComposite"); //$NON-NLS-1$
964
        return pageComposite;
965
    }
966
    
967
    // RAP [hs] method introduced for interactiondesign API
968
    public PresentationFactory getConfigurablePresentationFactory() {
969
      PresentationFactory result = null;
970
      WorkbenchWindowConfigurer configurer = getWindowConfigurer();
971
      AbstractPresentationFactory presentationFactory 
972
        = configurer.getPresentationFactory();
973
      if( presentationFactory instanceof PresentationFactory ) {
974
        result = ( PresentationFactory ) presentationFactory;
975
      }
976
      return result;
977
    }
978
    
979
    // RAP [hs] method introduced for interactiondesign API
980
    private Composite createConfigurableDefaultContents( Shell shell ) {      
981
      PresentationFactory presentationFactory 
982
        = getConfigurablePresentationFactory();
983
      IWindowComposer windowComposer 
984
        = presentationFactory.createWindowComposer();
985
      Composite result 
986
        = windowComposer.createWindowContents( shell, getWindowConfigurer() );
987
      return result;
988
    }    
989
    
990
    // RAP [hs] method introduced for interactiondesign API
991
    private void callConfigurablePreWindowOpen() {
992
      PresentationFactory presentationFactory 
993
        = getConfigurablePresentationFactory();
994
      IWindowComposer windowComposer 
995
        = presentationFactory.createWindowComposer();
996
      windowComposer.preWindowOpen( getWindowConfigurer() );
997
    }
998
    
999
    // RAP [hs] method introduced for interactiondesign API
1000
    private void callConfigurablePostWindowCreate() {
1001
      PresentationFactory presentationFactory 
1002
        = getConfigurablePresentationFactory();
1003
      IWindowComposer windowComposer 
1004
        = presentationFactory.createWindowComposer();
1005
      windowComposer.postWindowCreate( getWindowConfigurer() );
1006
    }
1007
    
1008
    // RAP [hs] method introduced for interactiondesign API
1009
    private MenuManager createConfigurableMenuManager() {
1010
      PresentationFactory presentationFactory 
1011
        = getConfigurablePresentationFactory();
1012
      return presentationFactory.createMenuBarManager();
1013
    }
1014
    
1015
    // RAP [hs] method introduced for interactiondesign API
1016
    MenuManager createPartMenuManager() {
1017
      PresentationFactory presentationFactory 
1018
        = getConfigurablePresentationFactory();
1019
      return presentationFactory.createPartMenuManager();
1020
    }
1021
1022
    // RAP [hs] method introduced for interactiondesign API
1023
    public Composite changeWindowLayoutSet() {
1024
      Shell shell = getShell();
1025
      Composite result = createConfigurableDefaultContents( shell );
1026
1027
      getMenuBarManager().update( false );
1028
      getCoolBarManager2().update( false );
1029
      getStatusLineManager().update( true );
1030
      
1031
      return result;
1032
    }    
1033
    
1034
1035
    /**
1036
     * If the perspective bar is drawn on the top right corner of the window,
1037
     * then this method changes its appearance from curved to square. This
1038
     * should have its own preference, but for now it piggy-backs on the
1039
     * SHOW_TRADITIONAL_STYLE_TABS preference.
1040
     * 
1041
     * @param square
1042
     *            true for a square banner and false otherwise
1043
     */
1044
    public void setBannerCurve(boolean square) {
1045
        if (topBar != null) {
1046
            topBar.setSimple(square);
1047
        }
1048
    }
1049
1050
    /**
1051
     * Creates the default contents and layout of the shell.
1052
     * 
1053
     * @param shell
1054
     *            the shell
1055
     */
1056
    protected void createDefaultContents(final Shell shell) {
1057
        defaultLayout = new TrimLayout();
1058
        shell.setLayout(defaultLayout);
1059
1060
        Menu menuBar = getMenuBarManager().createMenuBar(shell);
1061
        if (getWindowConfigurer().getShowMenuBar()) {
1062
            shell.setMenuBar(menuBar);
1063
        }
1064
1065
        // Create the CBanner widget which parents both the Coolbar
1066
        // and the perspective switcher, and supports some configurations
1067
        // on the left right and bottom
1068
        topBar = new CBanner(shell, SWT.NONE);
1069
        topBarTrim = new WindowTrimProxy(topBar,
1070
                "org.eclipse.ui.internal.WorkbenchWindow.topBar", //$NON-NLS-1$  
1071
                WorkbenchMessages.get().TrimCommon_Main_TrimName, SWT.NONE, true);
1072
1073
        // the banner gets a curve along with the new tab style
1074
        // TODO create a dedicated preference for this
1075
        // RAP [bm]: not needed
1076
//      setBannerCurve(PrefUtil.getAPIPreferenceStore().getBoolean(
1077
//              IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
1078
        setBannerCurve(false);
1079
        // RAPEND: [bm] 
1080
1081
        CacheWrapper coolbarCacheWrapper = new CacheWrapper(topBar);
1082
1083
        final Control coolBar = createCoolBarControl(coolbarCacheWrapper
1084
                .getControl());
1085
        // need to resize the shell, not just the coolbar's immediate
1086
        // parent, if the coolbar wants to grow or shrink
1087
1088
        coolBar.addListener(SWT.Resize, new Listener() {
1089
            public void handleEvent(Event event) {
1090
                // If the user is dragging the sash then we will need to force
1091
                // a resize. However, if the coolbar was resized programatically
1092
                // then everything is already layed out correctly. There is no
1093
                // direct way to tell the difference between these cases,
1094
                // however
1095
                // we take advantage of the fact that dragging the sash does not
1096
                // change the size of the shell, and only force another layout
1097
                // if the shell size is unchanged.
1098
                Rectangle clientArea = shell.getClientArea();
1099
1100
                if (lastShellSize.x == clientArea.width
1101
                        && lastShellSize.y == clientArea.height) {
1102
                    LayoutUtil.resize(coolBar);
1103
                }
1104
1105
                lastShellSize.x = clientArea.width;
1106
                lastShellSize.y = clientArea.height;
1107
            }
1108
        });
1109
1110
        if (getWindowConfigurer().getShowCoolBar()) {
1111
            topBar.setLeft(coolbarCacheWrapper.getControl());
1112
        }
1113
1114
        createStatusLine(shell);
1115
1116
        fastViewBar = new FastViewBar(this);
1117
        fastViewBar.createControl(shell);
1118
1119
        if (getWindowConfigurer().getShowPerspectiveBar()) {
1120
            addPerspectiveBar(perspectiveBarStyle());
1121
            perspectiveSwitcher.createControl(shell);
1122
        }
1123
1124
        createProgressIndicator(shell);
1125
1126
// RAP [rh] HeapStatus not supported  
1127
//      if (getShowHeapStatus()) {
1128
//          createHeapStatus(shell);
1129
//      }
1130
        
1131
        // Insert any contributed trim into the layout
1132
        // Legacy (3.2) trim
1133
        trimMgr2 = new TrimBarManager2(this);
1134
        
1135
        // 3.3 Trim contributions
1136
        trimContributionMgr = new TrimContributionManager(this);
1137
        
1138
        // RAP [bm]: DnD
1139
//      trimDropTarget = new TrimDropTarget(shell, this);
1140
//      DragUtil.addDragTarget(shell, trimDropTarget);
1141
//      DragUtil.addDragTarget(null, trimDropTarget);
1142
        // RAPEND: [bm] 
1143
1144
        // Create the client composite area (where page content goes).
1145
        createPageComposite(shell);
1146
1147
        setLayoutDataForContents();
1148
        // System.err.println(defaultLayout.displayTrim());
1149
    }
1150
1151
// RAP [rh] HeapStatus not supported 
1152
//  /**
1153
//   * Returns whether the heap status indicator should be shown.
1154
//   * 
1155
//   * @return <code>true</code> to show the heap status indicator,
1156
//   *         <code>false</code> otherwise
1157
//   */
1158
//  private boolean getShowHeapStatus() {
1159
//      return // Show if the preference is set or debug option is on
1160
//      PrefUtil.getAPIPreferenceStore().getBoolean(
1161
//              IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR)
1162
//              || Boolean.valueOf(
1163
//                      Platform.getDebugOption(PlatformUI.PLUGIN_ID
1164
//                              + "/perf/showHeapStatus")).booleanValue(); //$NON-NLS-1$
1165
//  }
1166
//
1167
//  /**
1168
//   * Creates the controls for the heap status indicator.
1169
//   * 
1170
//   * @param parent
1171
//   *            the parent composite
1172
//   */
1173
//  private void createHeapStatus(Composite parent) {
1174
//      heapStatus = new HeapStatus(parent, PrefUtil
1175
//              .getInternalPreferenceStore());
1176
//
1177
//      // Subclass the trim to allow closing...
1178
//      heapStatusTrim = new WindowTrimProxy(heapStatus,
1179
//              "org.eclipse.ui.internal.HeapStatus", //$NON-NLS-1$
1180
//              WorkbenchMessages.get().TrimCommon_HeapStatus_TrimName, SWT.BOTTOM
1181
//                      | SWT.TOP) {
1182
//
1183
//          public void handleClose() {
1184
//              getControl().dispose();
1185
//          }
1186
//
1187
//          public boolean isCloseable() {
1188
//              return true;
1189
//          }
1190
//      };
1191
//  }
1192
1193
    /**
1194
     * <p>
1195
     * Returns a new menu manager for this workbench window. This menu manager
1196
     * will just be a proxy to the new command-based menu service.
1197
     * </p>
1198
     * <p>
1199
     * Subclasses may override this method to customize the menu manager.
1200
     * </p>
1201
     * 
1202
     * @return a menu manager for this workbench window; never <code>null</code>.
1203
     */
1204
    protected MenuManager createMenuManager() {
1205
      MenuManager result = null;
1206
      // RAP [hs] patched for interactiondesign API
1207
      if( getConfigurablePresentationFactory() != null ) {
1208
        result = createConfigurableMenuManager();
1209
      } 
1210
      if( result == null ) {
1211
        result = super.createMenuManager();
1212
      }
1213
      return result;
1214
    }
1215
1216
    /**
1217
     * Set the perspective bar location
1218
     * 
1219
     * @param location
1220
     *            the location to place the bar
1221
     */
1222
    public void setPerspectiveBarLocation(String location) {
1223
        if (perspectiveSwitcher != null) {
1224
            perspectiveSwitcher.setPerspectiveBarLocation(location);
1225
        }
1226
    }
1227
1228
    /**
1229
     * Notifies interested parties (namely the advisor) that the window is about
1230
     * to be opened.
1231
     */
1232
    private void fireWindowOpening() {
1233
      // RAP [hs] patched for interactiondesign API
1234
      if( getConfigurablePresentationFactory() != null ) {
1235
        callConfigurablePreWindowOpen();
1236
      } else {
1237
        // let the application do further configuration
1238
        getWindowAdvisor().preWindowOpen();
1239
      }        
1240
    }
1241
1242
    /**
1243
     * Notifies interested parties (namely the advisor) that the window has been
1244
     * restored from a previously saved state.
1245
     * 
1246
     * @throws WorkbenchException
1247
     *             passed through from the advisor
1248
     */
1249
    void fireWindowRestored() throws WorkbenchException {
1250
        StartupThreading.runWithWorkbenchExceptions(new StartupRunnable() {
1251
            public void runWithException() throws Throwable {
1252
                getWindowAdvisor().postWindowRestore();
1253
            }
1254
        });
1255
    }
1256
1257
    /**
1258
     * Notifies interested parties (namely the advisor) that the window has been
1259
     * created.
1260
     */
1261
    private void fireWindowCreated() {
1262
      // RAP [hs] patched for interactiondesign API  
1263
      if( getConfigurablePresentationFactory() != null ) {
1264
        callConfigurablePostWindowCreate();
1265
      } else {
1266
        getWindowAdvisor().postWindowCreate();
1267
      }
1268
    }
1269
1270
    /**
1271
     * Notifies interested parties (namely the advisor and the window listeners)
1272
     * that the window has been opened.
1273
     */
1274
    private void fireWindowOpened() {
1275
        getWorkbenchImpl().fireWindowOpened(this);
1276
        getWindowAdvisor().postWindowOpen();
1277
    }
1278
1279
    /**
1280
     * Notifies interested parties (namely the advisor) that the window's shell
1281
     * is closing. Allows the close to be vetoed.
1282
     * 
1283
     * @return <code>true</code> if the close should proceed,
1284
     *         <code>false</code> if it should be canceled
1285
     */
1286
    private boolean fireWindowShellClosing() {
1287
        return getWindowAdvisor().preWindowShellClose();
1288
    }
1289
1290
    /**
1291
     * Notifies interested parties (namely the advisor and the window listeners)
1292
     * that the window has been closed.
1293
     */
1294
    private void fireWindowClosed() {
1295
        // let the application do further deconfiguration
1296
        getWindowAdvisor().postWindowClose();
1297
        getWorkbenchImpl().fireWindowClosed(this);
1298
    }
1299
1300
    /**
1301
     * Fires page activated
1302
     */
1303
    private void firePageActivated(IWorkbenchPage page) {
1304
        String label = null; // debugging only
1305
        if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
1306
            label = "activated " + page.getLabel(); //$NON-NLS-1$
1307
        }
1308
        try {
1309
            UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
1310
            UIListenerLogging.logPageEvent(this, page,
1311
                    UIListenerLogging.WPE_PAGE_ACTIVATED);
1312
            pageListeners.firePageActivated(page);
1313
            partService.pageActivated(page);
1314
        } finally {
1315
            UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
1316
        }
1317
    }
1318
1319
    /**
1320
     * Fires page closed
1321
     */
1322
    private void firePageClosed(IWorkbenchPage page) {
1323
        String label = null; // debugging only
1324
        if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
1325
            label = "closed " + page.getLabel(); //$NON-NLS-1$
1326
        }
1327
        try {
1328
            UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
1329
            UIListenerLogging.logPageEvent(this, page,
1330
                    UIListenerLogging.WPE_PAGE_CLOSED);
1331
            pageListeners.firePageClosed(page);
1332
            partService.pageClosed(page);
1333
        } finally {
1334
            UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
1335
        }
1336
1337
    }
1338
1339
    /**
1340
     * Fires page opened
1341
     */
1342
    private void firePageOpened(IWorkbenchPage page) {
1343
        String label = null; // debugging only
1344
        if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
1345
            label = "opened " + page.getLabel(); //$NON-NLS-1$
1346
        }
1347
        try {
1348
            UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
1349
            UIListenerLogging.logPageEvent(this, page,
1350
                    UIListenerLogging.WPE_PAGE_OPENED);
1351
            pageListeners.firePageOpened(page);
1352
            partService.pageOpened(page);
1353
        } finally {
1354
            UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
1355
        }
1356
    }
1357
1358
    /**
1359
     * Fires perspective activated
1360
     */
1361
    void firePerspectiveActivated(IWorkbenchPage page,
1362
            IPerspectiveDescriptor perspective) {
1363
        UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1364
                UIListenerLogging.PLE_PERSP_ACTIVATED);
1365
        perspectiveListeners.firePerspectiveActivated(page, perspective);
1366
    }
1367
1368
    /**
1369
     * Fires perspective deactivated.
1370
     */
1371
    void firePerspectivePreDeactivate(IWorkbenchPage page,
1372
            IPerspectiveDescriptor perspective) {
1373
        UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1374
                UIListenerLogging.PLE_PERSP_PRE_DEACTIVATE);
1375
        perspectiveListeners.firePerspectivePreDeactivate(page, perspective);
1376
    }
1377
    
1378
    /**
1379
     * Fires perspective deactivated.
1380
     */
1381
    void firePerspectiveDeactivated(IWorkbenchPage page,
1382
            IPerspectiveDescriptor perspective) {
1383
        UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1384
                UIListenerLogging.PLE_PERSP_DEACTIVATED);
1385
        perspectiveListeners.firePerspectiveDeactivated(page, perspective);
1386
    }
1387
1388
    /**
1389
     * Fires perspective changed
1390
     */
1391
    public void firePerspectiveChanged(IWorkbenchPage page,
1392
            IPerspectiveDescriptor perspective, String changeId) {
1393
        // Some callers call this even when there is no active perspective.
1394
        // Just ignore this case.
1395
        if (perspective != null) {
1396
            UIListenerLogging.logPerspectiveChangedEvent(this, page,
1397
                    perspective, null, changeId);
1398
            perspectiveListeners.firePerspectiveChanged(page, perspective,
1399
                    changeId);
1400
        }
1401
    }
1402
1403
    /**
1404
     * Fires perspective changed for an affected part
1405
     */
1406
    public void firePerspectiveChanged(IWorkbenchPage page,
1407
            IPerspectiveDescriptor perspective,
1408
            IWorkbenchPartReference partRef, String changeId) {
1409
        // Some callers call this even when there is no active perspective.
1410
        // Just ignore this case.
1411
        if (perspective != null) {
1412
            UIListenerLogging.logPerspectiveChangedEvent(this, page,
1413
                    perspective, partRef, changeId);
1414
            perspectiveListeners.firePerspectiveChanged(page, perspective,
1415
                    partRef, changeId);
1416
        }
1417
    }
1418
1419
    /**
1420
     * Fires perspective closed
1421
     */
1422
    void firePerspectiveClosed(IWorkbenchPage page,
1423
            IPerspectiveDescriptor perspective) {
1424
        UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1425
                UIListenerLogging.PLE_PERSP_CLOSED);
1426
        perspectiveListeners.firePerspectiveClosed(page, perspective);
1427
    }
1428
1429
    /**
1430
     * Fires perspective opened
1431
     */
1432
    void firePerspectiveOpened(IWorkbenchPage page,
1433
            IPerspectiveDescriptor perspective) {
1434
        UIListenerLogging.logPerspectiveEvent(this, page, perspective,
1435
                UIListenerLogging.PLE_PERSP_OPENED);
1436
        perspectiveListeners.firePerspectiveOpened(page, perspective);
1437
    }
1438
1439
    /**
1440
     * Fires perspective saved as.
1441
     */
1442
    void firePerspectiveSavedAs(IWorkbenchPage page,
1443
            IPerspectiveDescriptor oldPerspective,
1444
            IPerspectiveDescriptor newPerspective) {
1445
        UIListenerLogging.logPerspectiveSavedAs(this, page, oldPerspective,
1446
                newPerspective);
1447
        perspectiveListeners.firePerspectiveSavedAs(page, oldPerspective,
1448
                newPerspective);
1449
    }
1450
1451
    /**
1452
     * Returns the action bars for this window.
1453
     */
1454
    public WWinActionBars getActionBars() {
1455
        if (actionBars == null) {
1456
            actionBars = new WWinActionBars(this);
1457
        }
1458
        return actionBars;
1459
    }
1460
1461
    /**
1462
     * Returns the active page.
1463
     * 
1464
     * @return the active page
1465
     */
1466
    public IWorkbenchPage getActivePage() {
1467
        return pageList.getActive();
1468
    }
1469
1470
    /**
1471
     * Returns the active workbench page.
1472
     * 
1473
     * @return the active workbench page
1474
     */
1475
    /* package */
1476
    WorkbenchPage getActiveWorkbenchPage() {
1477
        return pageList.getActive();
1478
    }
1479
1480
    /**
1481
     * Returns the page composite, under which the window's pages create their
1482
     * controls.
1483
     */
1484
    protected Composite getPageComposite() {
1485
        return pageComposite;
1486
    }
1487
1488
    /**
1489
     * Answer the menu manager for this window.
1490
     */
1491
    public MenuManager getMenuManager() {
1492
        return getMenuBarManager();
1493
    }
1494
1495
    /**
1496
     * Returns the number. This corresponds to a page number in a window or a
1497
     * window number in the workbench.
1498
     */
1499
    public int getNumber() {
1500
        return number;
1501
    }
1502
1503
    /**
1504
     * Returns an array of the pages in the workbench window.
1505
     * 
1506
     * @return an array of pages
1507
     */
1508
    public IWorkbenchPage[] getPages() {
1509
        return pageList.getPages();
1510
    }
1511
1512
    /**
1513
     * @see IWorkbenchWindow
1514
     */
1515
    public IPartService getPartService() {
1516
        return partService;
1517
    }
1518
1519
    /**
1520
     * Returns the layout for the shell.
1521
     * 
1522
     * @return the layout for the shell
1523
     */
1524
    protected Layout getLayout() {
1525
        return null;
1526
    }
1527
1528
    /**
1529
     * @see IWorkbenchWindow
1530
     */
1531
    public ISelectionService getSelectionService() {
1532
        return partService.getSelectionService();
1533
    }
1534
1535
    /**
1536
     * Returns <code>true</code> when the window's shell is activated,
1537
     * <code>false</code> when it's shell is deactivated
1538
     * 
1539
     * @return boolean <code>true</code> when shell activated,
1540
     *         <code>false</code> when shell deactivated
1541
     */
1542
    public boolean getShellActivated() {
1543
        return shellActivated;
1544
    }
1545
1546
    /**
1547
     * Returns the status line manager for this window (if it has one).
1548
     * 
1549
     * @return the status line manager, or <code>null</code> if this window
1550
     *         does not have a status line
1551
     * @see ApplicationWindow#addStatusLine
1552
     */
1553
    public StatusLineManager getStatusLineManager() {
1554
        return super.getStatusLineManager();
1555
    }
1556
1557
    private IWindowTrim getStatusLineTrim() {
1558
        if (statusLineTrim == null) {
1559
            statusLineTrim = new WindowTrimProxy(
1560
                    getStatusLineManager().getControl(),
1561
                    "org.eclipse.jface.action.StatusLineManager", //$NON-NLS-1$
1562
                    WorkbenchMessages.get().TrimCommon_StatusLine_TrimName, SWT.NONE,
1563
                    true);
1564
        }
1565
        return statusLineTrim;
1566
    }
1567
1568
    /**
1569
     * @see IWorkbenchWindow
1570
     */
1571
    public IWorkbench getWorkbench() {
1572
        return PlatformUI.getWorkbench();
1573
    }
1574
1575
    public String getToolbarLabel(String actionSetId) {
1576
        ActionSetRegistry registry = WorkbenchPlugin.getDefault()
1577
                .getActionSetRegistry();
1578
        IActionSetDescriptor actionSet = registry.findActionSet(actionSetId);
1579
        if (actionSet != null) {
1580
            return actionSet.getLabel();
1581
        }
1582
1583
        if (IWorkbenchActionConstants.TOOLBAR_FILE
1584
                .equalsIgnoreCase(actionSetId)) {
1585
            return WorkbenchMessages.get().WorkbenchWindow_FileToolbar;
1586
        }
1587
1588
        if (IWorkbenchActionConstants.TOOLBAR_NAVIGATE
1589
                .equalsIgnoreCase(actionSetId)) {
1590
            return WorkbenchMessages.get().WorkbenchWindow_NavigateToolbar;
1591
        }
1592
1593
        return null;
1594
    }
1595
1596
    /**
1597
     * Unconditionally close this window. Assumes the proper flags have been set
1598
     * correctly (e.i. closing and updateDisabled)
1599
     */
1600
    private boolean hardClose() {
1601
        boolean result;
1602
        try {
1603
            // Clear the action sets, fix for bug 27416.
1604
            getActionPresentation().clearActionSets();
1605
1606
            // Remove the handler submissions. Bug 64024.
1607
            final IWorkbench workbench = getWorkbench();
1608
            final IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
1609
            handlerService.deactivateHandlers(handlerActivations);
1610
            final Iterator activationItr = handlerActivations.iterator();
1611
            while (activationItr.hasNext()) {
1612
                final IHandlerActivation activation = (IHandlerActivation) activationItr
1613
                        .next();
1614
                activation.getHandler().dispose();
1615
            }
1616
            handlerActivations.clear();
1617
            globalActionHandlersByCommandId.clear();
1618
1619
            // Remove the enabled submissions. Bug 64024.
1620
            final IContextService contextService = (IContextService) workbench.getService(IContextService.class);
1621
            contextService.unregisterShell(getShell());
1622
1623
            closeAllPages();
1624
1625
            fireWindowClosed();
1626
            
1627
            // time to wipe our our populate
1628
            IMenuService menuService = (IMenuService) workbench
1629
                    .getService(IMenuService.class);
1630
            menuService
1631
                    .releaseContributions(((ContributionManager) getActionBars()
1632
                            .getMenuManager()));
1633
            ICoolBarManager coolbar = getActionBars().getCoolBarManager();
1634
            if (coolbar != null) {
1635
                menuService
1636
                        .releaseContributions(((ContributionManager) coolbar));
1637
            }
1638
1639
            getActionBarAdvisor().dispose();
1640
            getWindowAdvisor().dispose();
1641
            
1642
            // RAP [bm]: detached windows
1643
//          detachedWindowShells.dispose();
1644
            // RAPEND: [bm] 
1645
1646
            // Bring down all of the services.
1647
            serviceLocator.dispose();
1648
1649
            // Null out the progress region. Bug 64024.
1650
            progressRegion = null;
1651
            
1652
            // RAP [bm]: 
1653
//          // Remove drop targets
1654
//          DragUtil.removeDragTarget(null, trimDropTarget);
1655
//          DragUtil.removeDragTarget(getShell(), trimDropTarget);
1656
//          trimDropTarget = null;
1657
            // RAPEND: [bm] 
1658
1659
            if (trimMgr2 != null) {
1660
                trimMgr2.dispose();
1661
                trimMgr2 = null;
1662
            }
1663
            
1664
            if (trimContributionMgr != null) {
1665
                trimContributionMgr.dispose();
1666
                trimContributionMgr = null;
1667
            }
1668
        } finally {
1669
            result = super.close();
1670
        }
1671
        return result;
1672
    }
1673
1674
    /**
1675
     * @see IWorkbenchWindow
1676
     */
1677
    public boolean isApplicationMenu(String menuID) {
1678
        // delegate this question to the action bar advisor
1679
        return getActionBarAdvisor().isApplicationMenu(menuID);
1680
    }
1681
1682
    /**
1683
     * Return whether or not the given id matches the id of the coolitems that
1684
     * the application creates.
1685
     */
1686
    /* package */
1687
    boolean isWorkbenchCoolItemId(String id) {
1688
        return windowConfigurer.containsCoolItem(id);
1689
    }
1690
1691
    /**
1692
     * Locks/unlocks the CoolBar for the workbench.
1693
     * 
1694
     * @param lock
1695
     *            whether the CoolBar should be locked or unlocked
1696
     */
1697
    /* package */
1698
    void lockCoolBar(boolean lock) {
1699
        getCoolBarManager2().setLockLayout(lock);
1700
    }
1701
1702
    /**
1703
     * Makes the window visible and frontmost.
1704
     */
1705
    void makeVisible() {
1706
        Shell shell = getShell();
1707
        if (shell != null && !shell.isDisposed()) {
1708
            // see bug 96700 and bug 4414 for a discussion on the use of open()
1709
            // here
1710
            shell.open();
1711
        }
1712
    }
1713
1714
    /**
1715
     * Called when this window is about to be closed.
1716
     * 
1717
     * Subclasses may overide to add code that returns <code>false</code> to
1718
     * prevent closing under certain conditions.
1719
     */
1720
    public boolean okToClose() {
1721
        // Save all of the editors.
1722
        if (!getWorkbenchImpl().isClosing()) {
1723
            if (!saveAllPages(true)) {
1724
                return false;
1725
            }
1726
        }
1727
        return true;
1728
    }
1729
1730
    /**
1731
     * Opens a new page.
1732
     * <p>
1733
     * <b>Note:</b> Since release 2.0, a window is limited to contain at most
1734
     * one page. If a page exist in the window when this method is used, then
1735
     * another window is created for the new page. Callers are strongly
1736
     * recommended to use the <code>IWorkbench.openPerspective</code> APIs to
1737
     * programmatically show a perspective.
1738
     * </p>
1739
     */
1740
    public IWorkbenchPage openPage(final String perspId, final IAdaptable input)
1741
            throws WorkbenchException {
1742
        Assert.isNotNull(perspId);
1743
1744
        // Run op in busy cursor.
1745
        final Object[] result = new Object[1];
1746
        BusyIndicator.showWhile(null, new Runnable() {
1747
            public void run() {
1748
                try {
1749
                    result[0] = busyOpenPage(perspId, input);
1750
                } catch (WorkbenchException e) {
1751
                    result[0] = e;
1752
                }
1753
            }
1754
        });
1755
1756
        if (result[0] instanceof IWorkbenchPage) {
1757
            return (IWorkbenchPage) result[0];
1758
        } else if (result[0] instanceof WorkbenchException) {
1759
            throw (WorkbenchException) result[0];
1760
        } else {
1761
            throw new WorkbenchException(
1762
                    WorkbenchMessages.get().WorkbenchWindow_exceptionMessage);
1763
        }
1764
    }
1765
1766
    /**
1767
     * Opens a new page.
1768
     * <p>
1769
     * <b>Note:</b> Since release 2.0, a window is limited to contain at most
1770
     * one page. If a page exist in the window when this method is used, then
1771
     * another window is created for the new page. Callers are strongly
1772
     * recommended to use the <code>IWorkbench.openPerspective</code> APIs to
1773
     * programmatically show a perspective.
1774
     * </p>
1775
     */
1776
    public IWorkbenchPage openPage(IAdaptable input) throws WorkbenchException {
1777
        String perspId = getWorkbenchImpl().getPerspectiveRegistry()
1778
                .getDefaultPerspective();
1779
        return openPage(perspId, input);
1780
    }
1781
1782
    /*
1783
     * Removes an listener from the part service.
1784
     */
1785
    public void removePageListener(IPageListener l) {
1786
        pageListeners.removePageListener(l);
1787
    }
1788
1789
    /**
1790
     * @see org.eclipse.ui.IPageService
1791
     */
1792
    public void removePerspectiveListener(org.eclipse.ui.IPerspectiveListener l) {
1793
        perspectiveListeners.removePerspectiveListener(l);
1794
    }
1795
1796
    private IStatus unableToRestorePage(IMemento pageMem) {
1797
        String pageName = pageMem.getString(IWorkbenchConstants.TAG_LABEL);
1798
        if (pageName == null) {
1799
            pageName = ""; //$NON-NLS-1$
1800
        }
1801
        return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind(
1802
                WorkbenchMessages.get().WorkbenchWindow_unableToRestorePerspective,
1803
                pageName), null);
1804
    }
1805
1806
    public IStatus restoreState(IMemento memento,
1807
            IPerspectiveDescriptor activeDescriptor) {
1808
        Assert.isNotNull(getShell());
1809
1810
        final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
1811
                WorkbenchMessages.get().WorkbenchWindow_problemsRestoringWindow, null);
1812
1813
        // Restore the window advisor state.
1814
        IMemento windowAdvisorState = memento
1815
                .getChild(IWorkbenchConstants.TAG_WORKBENCH_WINDOW_ADVISOR);
1816
        if (windowAdvisorState != null) {
1817
            result.add(getWindowAdvisor().restoreState(windowAdvisorState));
1818
        }
1819
1820
        // Restore actionbar advisor state.
1821
        IMemento actionBarAdvisorState = memento
1822
                .getChild(IWorkbenchConstants.TAG_ACTION_BAR_ADVISOR);
1823
        if (actionBarAdvisorState != null) {
1824
            result.add(getActionBarAdvisor()
1825
                    .restoreState(actionBarAdvisorState));
1826
        }
1827
1828
        // Read window's bounds and state.
1829
        final Rectangle [] displayBounds = new Rectangle[1];
1830
        StartupThreading.runWithoutExceptions(new StartupRunnable() {
1831
1832
            public void runWithException() {
1833
                displayBounds[0] = getShell().getDisplay().getBounds();
1834
                
1835
            }});
1836
        final Rectangle shellBounds = new Rectangle(0, 0, 0, 0);
1837
1838
        final IMemento fastViewMem = memento
1839
                .getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
1840
        if (fastViewMem != null) {
1841
            if (fastViewBar != null) {
1842
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
1843
1844
                    public void runWithException() {
1845
                        fastViewBar.restoreState(fastViewMem);
1846
                    }});
1847
                
1848
            }
1849
        }
1850
        Integer bigInt = memento.getInteger(IWorkbenchConstants.TAG_X);
1851
        shellBounds.x = bigInt == null ? 0 : bigInt.intValue();
1852
        bigInt = memento.getInteger(IWorkbenchConstants.TAG_Y);
1853
        shellBounds.y = bigInt == null ? 0 : bigInt.intValue();
1854
        bigInt = memento.getInteger(IWorkbenchConstants.TAG_WIDTH);
1855
        shellBounds.width = bigInt == null ? 0 : bigInt.intValue();
1856
        bigInt = memento.getInteger(IWorkbenchConstants.TAG_HEIGHT);
1857
        shellBounds.height = bigInt == null ? 0 : bigInt.intValue();
1858
        if (!shellBounds.isEmpty()) {
1859
            StartupThreading.runWithoutExceptions(new StartupRunnable() {
1860
1861
                public void runWithException() {
1862
                    if (!shellBounds.intersects(displayBounds[0])) {
1863
                        // RAP [bm]: Display#getClientArea
1864
//                      Rectangle clientArea = getShell().getDisplay().getClientArea();
1865
                        Rectangle clientArea = getShell().getDisplay().getBounds();
1866
                        // RAPEND: [bm] 
1867
1868
                        shellBounds.x = clientArea.x;
1869
                        shellBounds.y = clientArea.y;
1870
                    }
1871
                    getShell().setBounds(shellBounds);
1872
                }});
1873
        }
1874
        if ("true".equals(memento.getString(IWorkbenchConstants.TAG_MAXIMIZED))) { //$NON-NLS-1$
1875
            StartupThreading.runWithoutExceptions(new StartupRunnable() {
1876
1877
                public void runWithException() {
1878
                    getShell().setMaximized(true);
1879
                }});
1880
            
1881
        }
1882
        if ("true".equals(memento.getString(IWorkbenchConstants.TAG_MINIMIZED))) { //$NON-NLS-1$
1883
            // getShell().setMinimized(true);
1884
        }
1885
1886
        // restore the width of the perspective bar
1887
        if (perspectiveSwitcher != null) {
1888
            perspectiveSwitcher.restoreState(memento);
1889
        }
1890
1891
        // Restore the cool bar order by creating all the tool bar contribution
1892
        // items
1893
        // This needs to be done before pages are created to ensure proper
1894
        // canonical creation
1895
        // of cool items
1896
        final ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
1897
        if (coolBarMgr != null) {
1898
            IMemento coolBarMem = memento
1899
                    .getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
1900
            if (coolBarMem != null) {
1901
                // Check if the layout is locked
1902
                final Integer lockedInt = coolBarMem
1903
                        .getInteger(IWorkbenchConstants.TAG_LOCKED);
1904
                StartupThreading.runWithoutExceptions(new StartupRunnable(){
1905
1906
                    public void runWithException() {
1907
                        if ((lockedInt != null) && (lockedInt.intValue() == 1)) {
1908
                            coolBarMgr.setLockLayout(true);
1909
                        } else {
1910
                            coolBarMgr.setLockLayout(false);
1911
                        }
1912
                    }});
1913
                
1914
                // The new layout of the cool bar manager
1915
                ArrayList coolBarLayout = new ArrayList();
1916
                // Traverse through all the cool item in the memento
1917
                IMemento contributionMems[] = coolBarMem
1918
                        .getChildren(IWorkbenchConstants.TAG_COOLITEM);
1919
                for (int i = 0; i < contributionMems.length; i++) {
1920
                    IMemento contributionMem = contributionMems[i];
1921
                    String type = contributionMem
1922
                            .getString(IWorkbenchConstants.TAG_ITEM_TYPE);
1923
                    if (type == null) {
1924
                        // Do not recognize that type
1925
                        continue;
1926
                    }
1927
                    String id = contributionMem
1928
                            .getString(IWorkbenchConstants.TAG_ID);
1929
1930
                    // Prevent duplicate items from being read back in.
1931
                    IContributionItem existingItem = coolBarMgr.find(id);
1932
                    if ((id != null) && (existingItem != null)) {
1933
                        if (Policy.DEBUG_TOOLBAR_DISPOSAL) {
1934
                            System.out
1935
                                    .println("Not loading duplicate cool bar item: " + id); //$NON-NLS-1$
1936
                        }
1937
                        coolBarLayout.add(existingItem);
1938
                        continue;
1939
                    }
1940
                    IContributionItem newItem = null;
1941
                    if (type.equals(IWorkbenchConstants.TAG_TYPE_SEPARATOR)) {
1942
                        if (id != null) {
1943
                            newItem = new Separator(id);
1944
                        } else {
1945
                            newItem = new Separator();
1946
                        }
1947
                    } else if (id != null) {
1948
                        if (type
1949
                                .equals(IWorkbenchConstants.TAG_TYPE_GROUPMARKER)) {
1950
                            newItem = new GroupMarker(id);
1951
1952
                        } else if (type
1953
                                .equals(IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION)
1954
                                || type
1955
                                        .equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
1956
1957
                            // Get Width and height
1958
                            Integer width = contributionMem
1959
                                    .getInteger(IWorkbenchConstants.TAG_ITEM_X);
1960
                            Integer height = contributionMem
1961
                                    .getInteger(IWorkbenchConstants.TAG_ITEM_Y);
1962
                            // Look for the object in the current cool bar
1963
                            // manager
1964
                            IContributionItem oldItem = coolBarMgr.find(id);
1965
                            // If a tool bar contribution item already exists
1966
                            // for this id then use the old object
1967
                            if (oldItem != null) {
1968
                                newItem = oldItem;
1969
                            } else {
1970
                                IActionBarPresentationFactory actionBarPresentation = getActionBarPresentationFactory();
1971
                                newItem = actionBarPresentation.createToolBarContributionItem(
1972
                                        actionBarPresentation.createToolBarManager(), id);
1973
                                if (type
1974
                                        .equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
1975
                                    IToolBarContributionItem newToolBarItem = (IToolBarContributionItem) newItem;
1976
                                    if (height != null) {
1977
                                        newToolBarItem.setCurrentHeight(height
1978
                                                .intValue());
1979
                                    }
1980
                                    if (width != null) {
1981
                                        newToolBarItem.setCurrentWidth(width
1982
                                                .intValue());
1983
                                    }
1984
                                    newItem = new PlaceholderContributionItem(
1985
                                            newToolBarItem);
1986
                                }
1987
                                // make it invisible by default
1988
                                newItem.setVisible(false);
1989
                                // Need to add the item to the cool bar manager
1990
                                // so that its canonical order can be preserved
1991
                                IContributionItem refItem = findAlphabeticalOrder(
1992
                                        IWorkbenchActionConstants.MB_ADDITIONS,
1993
                                        id, coolBarMgr);
1994
                                if (refItem != null) {
1995
                                    coolBarMgr.insertAfter(refItem.getId(),
1996
                                            newItem);
1997
                                } else {
1998
                                    coolBarMgr.add(newItem);
1999
                                }
2000
                            }
2001
                            // Set the current height and width
2002
                            if ((width != null)
2003
                                    && (newItem instanceof IToolBarContributionItem)) {
2004
                                ((IToolBarContributionItem) newItem)
2005
                                        .setCurrentWidth(width.intValue());
2006
                            }
2007
                            if ((height != null)
2008
                                    && (newItem instanceof IToolBarContributionItem)) {
2009
                                ((IToolBarContributionItem) newItem)
2010
                                        .setCurrentHeight(height.intValue());
2011
                            }
2012
                        }
2013
                    }
2014
                    // Add new item into cool bar manager
2015
                    if (newItem != null) {
2016
                        coolBarLayout.add(newItem);
2017
                        newItem.setParent(coolBarMgr);
2018
                        coolBarMgr.markDirty();
2019
                    }
2020
                }
2021
2022
                // We need to check if we have everything we need in the layout.
2023
                final ArrayList finalLayout = new ArrayList();
2024
                IContributionItem[] existingItems = coolBarMgr.getItems();
2025
                for (int i = 0; i < existingItems.length; i++) {
2026
                    IContributionItem existingItem = existingItems[i];
2027
2028
                    /*
2029
                     * This line shouldn't be necessary, but is here for
2030
                     * robustness.
2031
                     */
2032
                    if (existingItem == null) {
2033
                        continue;
2034
                    }
2035
2036
                    boolean found = false;
2037
                    Iterator layoutItemItr = coolBarLayout.iterator();
2038
                    while (layoutItemItr.hasNext()) {
2039
                        IContributionItem layoutItem = (IContributionItem) layoutItemItr
2040
                                .next();
2041
                        if ((layoutItem != null)
2042
                                && (layoutItem.equals(existingItem))) {
2043
                            found = true;
2044
                            break;
2045
                        }
2046
                    }
2047
2048
                    if (!found) {
2049
                        if (existingItem != null) {
2050
                            finalLayout.add(existingItem);
2051
                        }
2052
                    }
2053
                }
2054
2055
                // Set the cool bar layout to the given layout.
2056
                finalLayout.addAll(coolBarLayout);
2057
                final IContributionItem[] itemsToSet = new IContributionItem[finalLayout
2058
                        .size()];
2059
                finalLayout.toArray(itemsToSet);
2060
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
2061
2062
                    public void runWithException() {
2063
                        coolBarMgr.setItems(itemsToSet);
2064
                    }});
2065
                
2066
            } else {
2067
                // For older workbenchs
2068
                coolBarMem = memento
2069
                        .getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
2070
                if (coolBarMem != null) {
2071
                    // Restore an older layout
2072
                    restoreOldCoolBar(coolBarMem);
2073
                }
2074
            }
2075
        }
2076
2077
        // Recreate each page in the window.
2078
        IWorkbenchPage newActivePage = null;
2079
        IMemento[] pageArray = memento
2080
                .getChildren(IWorkbenchConstants.TAG_PAGE);
2081
        for (int i = 0; i < pageArray.length; i++) {
2082
            final IMemento pageMem = pageArray[i];
2083
            String strFocus = pageMem.getString(IWorkbenchConstants.TAG_FOCUS);
2084
            if (strFocus == null || strFocus.length() == 0) {
2085
                continue;
2086
            }
2087
2088
            // Get the input factory.
2089
            final IAdaptable [] input = new IAdaptable[1];
2090
            final IMemento inputMem = pageMem.getChild(IWorkbenchConstants.TAG_INPUT);
2091
            if (inputMem != null) {
2092
                final String factoryID = inputMem
2093
                        .getString(IWorkbenchConstants.TAG_FACTORY_ID);
2094
                if (factoryID == null) {
2095
                    WorkbenchPlugin
2096
                            .log("Unable to restore page - no input factory ID."); //$NON-NLS-1$
2097
                    result.add(unableToRestorePage(pageMem));
2098
                    continue;
2099
                }
2100
                try {
2101
                    UIStats.start(UIStats.RESTORE_WORKBENCH,
2102
                            "WorkbenchPageFactory"); //$NON-NLS-1$
2103
                    StartupThreading
2104
                            .runWithoutExceptions(new StartupRunnable() {
2105
2106
                                public void runWithException() throws Throwable {
2107
                                    IElementFactory factory = PlatformUI
2108
                                            .getWorkbench().getElementFactory(
2109
                                                    factoryID);
2110
                                    if (factory == null) {
2111
                                        WorkbenchPlugin
2112
                                                .log("Unable to restore page - cannot instantiate input factory: " + factoryID); //$NON-NLS-1$
2113
                                        result
2114
                                                .add(unableToRestorePage(pageMem));
2115
                                        return;
2116
                                    }
2117
2118
                                    // Get the input element.
2119
                                    input[0] = factory.createElement(inputMem);
2120
                                }
2121
                            });
2122
                    
2123
                    if (input[0] == null) {
2124
                        WorkbenchPlugin
2125
                                .log("Unable to restore page - cannot instantiate input element: " + factoryID); //$NON-NLS-1$
2126
                        result.add(unableToRestorePage(pageMem));
2127
                        continue;
2128
                    }
2129
                } finally {
2130
                    UIStats.end(UIStats.RESTORE_WORKBENCH, factoryID,
2131
                            "WorkbenchPageFactory"); //$NON-NLS-1$
2132
                }
2133
            }
2134
            // Open the perspective.
2135
            final IAdaptable finalInput = input[0];
2136
            final WorkbenchPage [] newPage = new WorkbenchPage[1];
2137
            try {
2138
                StartupThreading.runWithWorkbenchExceptions(new StartupRunnable(){
2139
2140
                    public void runWithException() throws WorkbenchException {
2141
                        newPage[0] = ((WorkbenchImplementation) Tweaklets
2142
                                .get(WorkbenchImplementation.KEY)).createWorkbenchPage(WorkbenchWindow.this, finalInput);
2143
                    }});
2144
                
2145
                result.add(newPage[0].restoreState(pageMem, activeDescriptor));
2146
                pageList.add(newPage[0]);
2147
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
2148
2149
                    public void runWithException() throws Throwable {
2150
                        firePageOpened(newPage[0]);
2151
                    }});
2152
                
2153
            } catch (WorkbenchException e) {
2154
                WorkbenchPlugin
2155
                        .log(
2156
                                "Unable to restore perspective - constructor failed.", e); //$NON-NLS-1$
2157
                result.add(e.getStatus());
2158
                continue;
2159
            }
2160
2161
            if (strFocus != null && strFocus.length() > 0) {
2162
                newActivePage = newPage[0];
2163
            }
2164
        }
2165
2166
        // If there are no pages create a default.
2167
        if (pageList.isEmpty()) {
2168
            try {
2169
                final String defPerspID = getWorkbenchImpl().getPerspectiveRegistry()
2170
                        .getDefaultPerspective();
2171
                if (defPerspID != null) {
2172
                    final WorkbenchPage [] newPage = new WorkbenchPage[1];
2173
                    StartupThreading.runWithWorkbenchExceptions(new StartupRunnable() {
2174
                        
2175
                        public void runWithException() throws Throwable {
2176
                            newPage[0] = ((WorkbenchImplementation) Tweaklets
2177
                                    .get(WorkbenchImplementation.KEY)).createWorkbenchPage(WorkbenchWindow.this, defPerspID,
2178
                                            getDefaultPageInput());
2179
                        }});
2180
                    
2181
                    pageList.add(newPage[0]);
2182
                    StartupThreading.runWithoutExceptions(new StartupRunnable() {
2183
2184
                        public void runWithException() throws Throwable {
2185
                            firePageOpened(newPage[0]);
2186
                        }});
2187
                }
2188
            } catch (WorkbenchException e) {
2189
                WorkbenchPlugin
2190
                        .log(
2191
                                "Unable to create default perspective - constructor failed.", e); //$NON-NLS-1$
2192
                result.add(e.getStatus());
2193
                String productName = WorkbenchPlugin.getDefault()
2194
                        .getProductName();
2195
                if (productName == null) {
2196
                    productName = ""; //$NON-NLS-1$
2197
                }
2198
                getShell().setText(productName);
2199
            }
2200
        }
2201
2202
        // Set active page.
2203
        if (newActivePage == null) {
2204
            newActivePage = pageList.getNextActive();
2205
        }
2206
        final IWorkbenchPage myPage = newActivePage;
2207
        StartupThreading.runWithoutExceptions(new StartupRunnable() {
2208
2209
            public void runWithException() throws Throwable {
2210
                setActivePage(myPage);
2211
            }});
2212
        
2213
2214
// RAP [rh] Intro mechanism not supported
2215
//      final IMemento introMem = memento.getChild(IWorkbenchConstants.TAG_INTRO);
2216
//      if (introMem != null) {
2217
//          StartupThreading.runWithoutExceptions(new StartupRunnable() {
2218
//
2219
//              public void runWithException() throws Throwable {
2220
//                  getWorkbench()
2221
//                          .getIntroManager()
2222
//                          .showIntro(
2223
//                                  WorkbenchWindow.this,
2224
//                                  Boolean
2225
//                                          .valueOf(
2226
//                                                  introMem
2227
//                                                          .getString(IWorkbenchConstants.TAG_STANDBY))
2228
//                                          .booleanValue());
2229
//              }
2230
//          });
2231
//
2232
//      }
2233
        
2234
        // Only restore the trim state if we're using the default layout
2235
        if (defaultLayout != null) {
2236
            // Restore the trim state. We pass in the 'root'
2237
            // memento since we have to check for pre-3.2
2238
            // state.
2239
            result.add(restoreTrimState(memento));
2240
        }
2241
        
2242
        return result;
2243
    }
2244
2245
    /**
2246
     * Restores cool item order from an old workbench.
2247
     */
2248
    private boolean restoreOldCoolBar(IMemento coolbarMem) {
2249
        // Make sure the tag exist
2250
        if (coolbarMem == null) {
2251
            return false;
2252
        }
2253
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
2254
        // Check to see if layout is locked
2255
        Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
2256
        boolean state = (locked != null) && (locked.intValue() == 1);
2257
        coolBarMgr.setLockLayout(state);
2258
2259
        // Get the visual layout
2260
        IMemento visibleLayout = coolbarMem
2261
                .getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
2262
        ArrayList visibleWrapIndicies = new ArrayList();
2263
        ArrayList visibleItems = new ArrayList();
2264
        if (visibleLayout != null) {
2265
            if (readLayout(visibleLayout, visibleItems, visibleWrapIndicies) == false) {
2266
                return false;
2267
            }
2268
        }
2269
        // Get the remembered layout
2270
        IMemento rememberedLayout = coolbarMem
2271
                .getChild(IWorkbenchConstants.TAG_LAYOUT);
2272
        ArrayList rememberedWrapIndicies = new ArrayList();
2273
        ArrayList rememberedItems = new ArrayList();
2274
        if (rememberedLayout != null) {
2275
            if (readLayout(rememberedLayout, rememberedItems,
2276
                    rememberedWrapIndicies) == false) {
2277
                return false;
2278
            }
2279
        }
2280
2281
        // Create the objects
2282
        if (visibleItems != null) {
2283
            // Merge remembered layout into visible layout
2284
            if (rememberedItems != null) {
2285
                // Traverse through all the remembered items
2286
                int currentIndex = 0;
2287
                for (Iterator i = rememberedItems.iterator(); i.hasNext(); currentIndex++) {
2288
                    String id = (String) i.next();
2289
                    int index = -1;
2290
                    for (Iterator iter = visibleItems.iterator(); iter
2291
                            .hasNext();) {
2292
                        String visibleId = (String) iter.next();
2293
                        if (visibleId.equals(id)) {
2294
                            index = visibleItems.indexOf(visibleId);
2295
                            break;
2296
                        }
2297
                    }
2298
                    // The item is not in the visible list
2299
                    if (index == -1) {
2300
                        int insertAt = Math.max(0, Math.min(currentIndex,
2301
                                visibleItems.size()));
2302
                        boolean separateLine = false;
2303
                        // Check whether this item is on a separate line
2304
                        for (Iterator iter = rememberedWrapIndicies.iterator(); iter
2305
                                .hasNext();) {
2306
                            Integer wrapIndex = (Integer) iter.next();
2307
                            if (wrapIndex.intValue() <= insertAt) {
2308
                                insertAt = visibleItems.size();
2309
                                // Add new wrap index for this Item
2310
                                visibleWrapIndicies.add(new Integer(insertAt));
2311
                                separateLine = true;
2312
                            }
2313
                        }
2314
                        // Add item to array list
2315
                        visibleItems.add(insertAt, id);
2316
                        // If the item was not on a separate line then adjust
2317
                        // the visible wrap indicies
2318
                        if (!separateLine) {
2319
                            // Adjust visible wrap indicies
2320
                            for (int j = 0; j < visibleWrapIndicies.size(); j++) {
2321
                                Integer index2 = (Integer) visibleWrapIndicies
2322
                                        .get(j);
2323
                                if (index2.intValue() >= insertAt) {
2324
                                    visibleWrapIndicies.set(j, new Integer(
2325
                                            index2.intValue() + 1));
2326
                                }
2327
                            }
2328
                        }
2329
                    }
2330
                }
2331
            }
2332
            // The new layout of the cool bar manager
2333
            ArrayList coolBarLayout = new ArrayList(visibleItems.size());
2334
            // Add all visible items to the layout object
2335
            for (Iterator i = visibleItems.iterator(); i.hasNext();) {
2336
                String id = (String) i.next();
2337
                // Look for the object in the current cool bar manager
2338
                IContributionItem oldItem = null;
2339
                IContributionItem newItem = null;
2340
                if (id != null) {
2341
                    oldItem = coolBarMgr.find(id);
2342
                }
2343
                // If a tool bar contribution item already exists for this id
2344
                // then use the old object
2345
                if (oldItem instanceof IToolBarContributionItem) {
2346
                    newItem = oldItem;
2347
                } else {
2348
                    IActionBarPresentationFactory actionBarPresentaiton = getActionBarPresentationFactory();
2349
                    newItem = actionBarPresentaiton.createToolBarContributionItem(
2350
                                    actionBarPresentaiton.createToolBarManager(), id);
2351
                    // make it invisible by default
2352
                    newItem.setVisible(false);
2353
                    // Need to add the item to the cool bar manager so that its
2354
                    // canonical order can be preserved
2355
                    IContributionItem refItem = findAlphabeticalOrder(
2356
                            IWorkbenchActionConstants.MB_ADDITIONS, id,
2357
                            coolBarMgr);
2358
                    if (refItem != null) {
2359
                        coolBarMgr.insertAfter(refItem.getId(), newItem);
2360
                    } else {
2361
                        coolBarMgr.add(newItem);
2362
                    }
2363
                }
2364
                // Add new item into cool bar manager
2365
                if (newItem != null) {
2366
                    coolBarLayout.add(newItem);
2367
                    newItem.setParent(coolBarMgr);
2368
                    coolBarMgr.markDirty();
2369
                }
2370
            }
2371
2372
            // Add separators to the displayed Items data structure
2373
            int offset = 0;
2374
            for (int i = 1; i < visibleWrapIndicies.size(); i++) {
2375
                int insertAt = ((Integer) visibleWrapIndicies.get(i))
2376
                        .intValue()
2377
                        + offset;
2378
                coolBarLayout.add(insertAt, new Separator(
2379
                        CoolBarManager.USER_SEPARATOR));
2380
                offset++;
2381
            }
2382
2383
            // Add any group markers in their appropriate places
2384
            IContributionItem[] items = coolBarMgr.getItems();
2385
            for (int i = 0; i < items.length; i++) {
2386
                IContributionItem item = items[i];
2387
                if (item.isGroupMarker()) {
2388
                    coolBarLayout.add(Math.max(Math
2389
                            .min(i, coolBarLayout.size()), 0), item);
2390
                }
2391
            }
2392
            IContributionItem[] itemsToSet = new IContributionItem[coolBarLayout
2393
                    .size()];
2394
            coolBarLayout.toArray(itemsToSet);
2395
            coolBarMgr.setItems(itemsToSet);
2396
        }
2397
        return true;
2398
    }
2399
2400
    /**
2401
     * Helper method used for restoring an old cool bar layout. This method
2402
     * reads the memento and populatates the item id's and wrap indicies.
2403
     */
2404
    private boolean readLayout(IMemento memento, ArrayList itemIds,
2405
            ArrayList wrapIndicies) {
2406
        // Get the Wrap indicies
2407
        IMemento[] wraps = memento
2408
                .getChildren(IWorkbenchConstants.TAG_ITEM_WRAP_INDEX);
2409
        if (wraps == null) {
2410
            return false;
2411
        }
2412
        for (int i = 0; i < wraps.length; i++) {
2413
            IMemento wrapMem = wraps[i];
2414
            Integer index = wrapMem.getInteger(IWorkbenchConstants.TAG_INDEX);
2415
            if (index == null) {
2416
                return false;
2417
            }
2418
            wrapIndicies.add(index);
2419
        }
2420
        // Get the Item ids
2421
        IMemento[] savedItems = memento
2422
                .getChildren(IWorkbenchConstants.TAG_ITEM);
2423
        if (savedItems == null) {
2424
            return false;
2425
        }
2426
        for (int i = 0; i < savedItems.length; i++) {
2427
            IMemento savedMem = savedItems[i];
2428
            String id = savedMem.getString(IWorkbenchConstants.TAG_ID);
2429
            if (id == null) {
2430
                return false;
2431
            }
2432
            itemIds.add(id);
2433
        }
2434
        return true;
2435
    }
2436
2437
    /**
2438
     * Returns the contribution item that the given contribution item should be
2439
     * inserted after.
2440
     * 
2441
     * @param startId
2442
     *            the location to start looking alphabetically.
2443
     * @param itemId
2444
     *            the target item id.
2445
     * @param mgr
2446
     *            the contribution manager.
2447
     * @return the contribution item that the given items should be returned
2448
     *         after.
2449
     */
2450
    private IContributionItem findAlphabeticalOrder(String startId,
2451
            String itemId, IContributionManager mgr) {
2452
        IContributionItem[] items = mgr.getItems();
2453
        int insertIndex = 0;
2454
2455
        // look for starting point
2456
        while (insertIndex < items.length) {
2457
            IContributionItem item = items[insertIndex];
2458
            if (item.getId() != null && item.getId().equals(startId)) {
2459
                break;
2460
            }
2461
            ++insertIndex;
2462
        }
2463
2464
        // Find the index that this item should be inserted in
2465
        for (int i = insertIndex + 1; i < items.length; i++) {
2466
            IContributionItem item = items[i];
2467
            String testId = item.getId();
2468
2469
            if (item.isGroupMarker()) {
2470
                break;
2471
            }
2472
2473
            if (itemId != null && testId != null) {
2474
                if (itemId.compareTo(testId) < 1) {
2475
                    break;
2476
                }
2477
            }
2478
            insertIndex = i;
2479
        }
2480
        if (insertIndex >= items.length) {
2481
            return null;
2482
        }
2483
        return items[insertIndex];
2484
    }
2485
2486
    /*
2487
     * (non-Javadoc) Method declared on IRunnableContext.
2488
     */
2489
    public void run(boolean fork, boolean cancelable,
2490
            IRunnableWithProgress runnable) throws InvocationTargetException,
2491
            InterruptedException {
2492
2493
        // RAP [bm]: 
2494
//      IWorkbenchContextSupport contextSupport = getWorkbench()
2495
//              .getContextSupport();
2496
//      final boolean keyFilterEnabled = contextSupport.isKeyFilterEnabled();
2497
2498
        Control fastViewBarControl = getFastViewBar() == null ? null
2499
                : getFastViewBar().getControl();
2500
        boolean fastViewBarWasEnabled = fastViewBarControl == null ? false
2501
                : fastViewBarControl.getEnabled();
2502
2503
        Control perspectiveBarControl = getPerspectiveBar() == null ? null
2504
                : getPerspectiveBar().getControl();
2505
        boolean perspectiveBarWasEnabled = perspectiveBarControl == null ? false
2506
                : perspectiveBarControl.getEnabled();
2507
2508
        // Cache for any diabled trim controls
2509
        List disabledControls = null;
2510
        
2511
        try {
2512
            if (fastViewBarControl != null && !fastViewBarControl.isDisposed()) {
2513
                fastViewBarControl.setEnabled(false);
2514
            }
2515
2516
            if (perspectiveBarControl != null
2517
                    && !perspectiveBarControl.isDisposed()) {
2518
                perspectiveBarControl.setEnabled(false);
2519
            }
2520
            
2521
            // RAP [bm]: 
2522
//          if (keyFilterEnabled) {
2523
//              contextSupport.setKeyFilterEnabled(false);
2524
//          }
2525
            // RAPEND: [bm] 
2526
2527
            // Disable all trim -except- the StatusLine
2528
            if (defaultLayout != null)
2529
                disabledControls = defaultLayout.disableTrim(getStatusLineTrim());
2530
2531
            super.run(fork, cancelable, runnable);
2532
        } finally {
2533
            if (fastViewBarControl != null && !fastViewBarControl.isDisposed()) {
2534
                fastViewBarControl.setEnabled(fastViewBarWasEnabled);
2535
            }
2536
2537
            if (perspectiveBarControl != null
2538
                    && !perspectiveBarControl.isDisposed()) {
2539
                perspectiveBarControl.setEnabled(perspectiveBarWasEnabled);
2540
            }
2541
2542
            // RAP [bm]: 
2543
//          if (keyFilterEnabled) {
2544
//              contextSupport.setKeyFilterEnabled(true);
2545
//          }
2546
            // RAPEND: [bm] 
2547
2548
            // Re-enable any disabled trim
2549
            if (defaultLayout != null && disabledControls != null)
2550
                defaultLayout.enableTrim(disabledControls);
2551
        }
2552
    }
2553
2554
    /**
2555
     * Save all of the pages. Returns true if the operation succeeded.
2556
     */
2557
    private boolean saveAllPages(boolean bConfirm) {
2558
        boolean bRet = true;
2559
        Iterator itr = pageList.iterator();
2560
        while (bRet && itr.hasNext()) {
2561
            WorkbenchPage page = (WorkbenchPage) itr.next();
2562
            bRet = page.saveAllEditors(bConfirm);
2563
        }
2564
        return bRet;
2565
    }
2566
2567
    /**
2568
     * @see IPersistable
2569
     */
2570
    public IStatus saveState(IMemento memento) {
2571
2572
        MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
2573
                WorkbenchMessages.get().WorkbenchWindow_problemsSavingWindow, null);
2574
2575
        // Save the window's state and bounds.
2576
        if (getShell().getMaximized() || asMaximizedState) {
2577
            memento.putString(IWorkbenchConstants.TAG_MAXIMIZED, "true"); //$NON-NLS-1$
2578
        }
2579
        if (getShell().getMinimized()) {
2580
            memento.putString(IWorkbenchConstants.TAG_MINIMIZED, "true"); //$NON-NLS-1$
2581
        }
2582
        if (normalBounds == null) {
2583
            normalBounds = getShell().getBounds();
2584
        }
2585
        IMemento fastViewBarMem = memento
2586
                .createChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
2587
        if (fastViewBar != null) {
2588
            fastViewBar.saveState(fastViewBarMem);
2589
        }
2590
2591
        memento.putInteger(IWorkbenchConstants.TAG_X, normalBounds.x);
2592
        memento.putInteger(IWorkbenchConstants.TAG_Y, normalBounds.y);
2593
        memento.putInteger(IWorkbenchConstants.TAG_WIDTH, normalBounds.width);
2594
        memento.putInteger(IWorkbenchConstants.TAG_HEIGHT, normalBounds.height);
2595
2596
// RAP [rh] Intro mechanism not supported
2597
//      IWorkbenchPage activePage = getActivePage();
2598
//      if (activePage != null
2599
//              && activePage.findView(IIntroConstants.INTRO_VIEW_ID) != null) {
2600
//          IMemento introMem = memento
2601
//                  .createChild(IWorkbenchConstants.TAG_INTRO);
2602
//          boolean isStandby = getWorkbench()
2603
//                  .getIntroManager()
2604
//                  .isIntroStandby(getWorkbench().getIntroManager().getIntro());
2605
//          introMem.putString(IWorkbenchConstants.TAG_STANDBY, String
2606
//                  .valueOf(isStandby));
2607
//      }
2608
2609
        // save the width of the perspective bar
2610
        IMemento persBarMem = memento
2611
                .createChild(IWorkbenchConstants.TAG_PERSPECTIVE_BAR);
2612
        if (perspectiveSwitcher != null) {
2613
            perspectiveSwitcher.saveState(persBarMem);
2614
        }
2615
2616
        // / Save the order of the cool bar contribution items
2617
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
2618
        if (coolBarMgr != null) {
2619
            coolBarMgr.refresh();
2620
            IMemento coolBarMem = memento
2621
                    .createChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
2622
            if (coolBarMgr.getLockLayout() == true) {
2623
                coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 1);
2624
            } else {
2625
                coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 0);
2626
            }
2627
            IContributionItem[] items = coolBarMgr.getItems();
2628
            for (int i = 0; i < items.length; i++) {
2629
                IMemento coolItemMem = coolBarMem
2630
                        .createChild(IWorkbenchConstants.TAG_COOLITEM);
2631
                IContributionItem item = items[i];
2632
                // The id of the contribution item
2633
                if (item.getId() != null) {
2634
                    coolItemMem.putString(IWorkbenchConstants.TAG_ID, item
2635
                            .getId());
2636
                }
2637
                // Write out type and size if applicable
2638
                if (item.isSeparator()) {
2639
                    coolItemMem.putString(IWorkbenchConstants.TAG_ITEM_TYPE,
2640
                            IWorkbenchConstants.TAG_TYPE_SEPARATOR);
2641
                } else if (item.isGroupMarker() && !item.isSeparator()) {
2642
                    coolItemMem.putString(IWorkbenchConstants.TAG_ITEM_TYPE,
2643
                            IWorkbenchConstants.TAG_TYPE_GROUPMARKER);
2644
                } else {
2645
                    if (item instanceof PlaceholderContributionItem) {
2646
                        coolItemMem.putString(
2647
                                IWorkbenchConstants.TAG_ITEM_TYPE,
2648
                                IWorkbenchConstants.TAG_TYPE_PLACEHOLDER);
2649
                    } else {
2650
                        // Store the identifier.
2651
                        coolItemMem
2652
                                .putString(
2653
                                        IWorkbenchConstants.TAG_ITEM_TYPE,
2654
                                        IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION);
2655
                    }
2656
2657
                    /*
2658
                     * Retrieve a reasonable approximation of the height and
2659
                     * width, if possible.
2660
                     */
2661
                    final int height;
2662
                    final int width;
2663
                    if (item instanceof IToolBarContributionItem) {
2664
                        IToolBarContributionItem toolBarItem = (IToolBarContributionItem) item;
2665
                        toolBarItem.saveWidgetState();
2666
                        height = toolBarItem.getCurrentHeight();
2667
                        width = toolBarItem.getCurrentWidth();
2668
                    } else if (item instanceof PlaceholderContributionItem) {
2669
                        PlaceholderContributionItem placeholder = (PlaceholderContributionItem) item;
2670
                        height = placeholder.getHeight();
2671
                        width = placeholder.getWidth();
2672
                    } else {
2673
                        height = -1;
2674
                        width = -1;
2675
                    }
2676
2677
                    // Store the height and width.
2678
                    coolItemMem.putInteger(IWorkbenchConstants.TAG_ITEM_X,
2679
                            width);
2680
                    coolItemMem.putInteger(IWorkbenchConstants.TAG_ITEM_Y,
2681
                            height);
2682
                }
2683
            }
2684
        }
2685
2686
        // Save each page.
2687
        Iterator itr = pageList.iterator();
2688
        while (itr.hasNext()) {
2689
            WorkbenchPage page = (WorkbenchPage) itr.next();
2690
2691
            // Save perspective.
2692
            IMemento pageMem = memento
2693
                    .createChild(IWorkbenchConstants.TAG_PAGE);
2694
            pageMem.putString(IWorkbenchConstants.TAG_LABEL, page.getLabel());
2695
            result.add(page.saveState(pageMem));
2696
2697
            if (page == getActiveWorkbenchPage()) {
2698
                pageMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$
2699
            }
2700
2701
            // Get the input.
2702
            IAdaptable input = page.getInput();
2703
            if (input != null) {
2704
                IPersistableElement persistable = (IPersistableElement) Util.getAdapter(input,
2705
                        IPersistableElement.class);
2706
                if (persistable == null) {
2707
                    WorkbenchPlugin
2708
                            .log("Unable to save page input: " //$NON-NLS-1$
2709
                                    + input
2710
                                    + ", because it does not adapt to IPersistableElement"); //$NON-NLS-1$
2711
                } else {
2712
                    // Save input.
2713
                    IMemento inputMem = pageMem
2714
                            .createChild(IWorkbenchConstants.TAG_INPUT);
2715
                    inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID,
2716
                            persistable.getFactoryId());
2717
                    persistable.saveState(inputMem);
2718
                }
2719
            }
2720
        }
2721
2722
        // Save window advisor state.
2723
        IMemento windowAdvisorState = memento
2724
                .createChild(IWorkbenchConstants.TAG_WORKBENCH_WINDOW_ADVISOR);
2725
        result.add(getWindowAdvisor().saveState(windowAdvisorState));
2726
2727
        // Save actionbar advisor state.
2728
        IMemento actionBarAdvisorState = memento
2729
                .createChild(IWorkbenchConstants.TAG_ACTION_BAR_ADVISOR);
2730
        result.add(getActionBarAdvisor().saveState(actionBarAdvisorState));
2731
2732
        // Only save the trim state if we're using the default layout
2733
        if (defaultLayout != null) {
2734
            IMemento trimState = memento.createChild(IWorkbenchConstants.TAG_TRIM);
2735
            result.add(saveTrimState(trimState));
2736
        }
2737
2738
        return result;
2739
    }
2740
2741
    /**
2742
     * Save the trim layout trim area and trim ordering.
2743
     * 
2744
     * @param memento
2745
     *            the memento to update
2746
     * @return the status, OK or not..
2747
     */
2748
    private IStatus saveTrimState(IMemento memento) {
2749
        int[] ids = defaultLayout.getAreaIds();
2750
        for (int i = 0; i < ids.length; i++) {
2751
            int id = ids[i];
2752
            List trim = defaultLayout.getAreaTrim(id);
2753
            if (!trim.isEmpty()) {
2754
                IMemento area = memento
2755
                        .createChild(IWorkbenchConstants.TAG_TRIM_AREA, Integer
2756
                                .toString(id));
2757
                Iterator d = trim.iterator();
2758
                while (d.hasNext()) {
2759
                    IWindowTrim item = (IWindowTrim) d.next();
2760
                    area.createChild(IWorkbenchConstants.TAG_TRIM_ITEM, item
2761
                            .getId());
2762
                }
2763
            }
2764
        }
2765
        return Status.OK_STATUS;
2766
    }
2767
2768
    /**
2769
     * Restore the trim layout state from the memento.
2770
     * 
2771
     * @param memento
2772
     *            the 'root' Workbench memento to restore
2773
     * @return the status, OK or not
2774
     */
2775
    private IStatus restoreTrimState(IMemento memento) {
2776
        // Determine if we have saved state. If we don't have any 3.2
2777
        // type state we're not done because the FastViewBar maintained
2778
        // its own 'side' state in 3.1 so we'll honor its value
2779
        IMemento trimState = memento.getChild(IWorkbenchConstants.TAG_TRIM);
2780
        if (trimState != null) {
2781
            // first pass sets up ordering for all trim areas
2782
            IMemento[] areas = trimState
2783
                    .getChildren(IWorkbenchConstants.TAG_TRIM_AREA);
2784
            
2785
            // We need to remember all the trim that was repositioned
2786
            // here so we can re-site -newly contributed- trim after
2787
            // we're done
2788
            final List knownIds = new ArrayList();
2789
            
2790
            List[] trimOrder = new List[areas.length];
2791
            for (int i = 0; i < areas.length; i++) {
2792
                trimOrder[i] = new ArrayList();
2793
                List preferredLocations = new ArrayList();
2794
                IMemento area = areas[i];
2795
                IMemento[] items = area
2796
                        .getChildren(IWorkbenchConstants.TAG_TRIM_ITEM);
2797
                for (int j = 0; j < items.length; j++) {
2798
                    IMemento item = items[j];
2799
                    String id = item.getID();
2800
                    knownIds.add(id);
2801
                    preferredLocations.add(id);
2802
                    
2803
                    IWindowTrim t = defaultLayout.getTrim(id);
2804
                    if (t != null) {
2805
                        trimOrder[i].add(t);
2806
                    }
2807
                }
2808
                
2809
                // Inform the TrimLayout of the preferred location for this area
2810
                String areaIdString = areas[i].getID();
2811
                int areaId = Integer.parseInt(areaIdString);
2812
                defaultLayout.setPreferredLocations(areaId, preferredLocations);
2813
            }
2814
    
2815
            // second pass applies all of the window trim
2816
            for (int i = 0; i < areas.length; i++) {
2817
                IMemento area = areas[i];
2818
                final int id = Integer.parseInt(area.getID());
2819
                final List myTrimOrderList = trimOrder[i];
2820
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
2821
2822
                    public void runWithException() throws Throwable {
2823
                        defaultLayout.updateAreaTrim(id, myTrimOrderList, false);
2824
                    }});
2825
                
2826
            }
2827
2828
            // get the trim manager to re-locate any -newly contributed-
2829
            // trim widgets
2830
            // Legacy (3.2) trim
2831
            if (trimMgr2 != null) {
2832
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
2833
2834
                    public void runWithException() throws Throwable {
2835
                        trimMgr2.updateLocations(knownIds);
2836
                    }});
2837
                
2838
            }
2839
            
2840
            // 3.3 Trim Contributions
2841
            if (trimContributionMgr != null) {
2842
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
2843
                    public void runWithException() throws Throwable {
2844
                        trimContributionMgr.updateLocations(knownIds);
2845
2846
                        // Update the GUI with the new locations
2847
                        WorkbenchPage page = getActiveWorkbenchPage();
2848
                        if (page != null) {
2849
                            Perspective perspective = page.getActivePerspective();
2850
                            if (perspective != null) {
2851
                                // Ensure that only the upper/right editor stack has
2852
                                // min/max buttons
2853
                                page.getEditorPresentation().updateStackButtons();
2854
                                
2855
                                // The perspective's onActivate manipulates the trim under the
2856
                                // new min/max story so cause it to refresh...
2857
                                perspective.onActivate();
2858
                            }
2859
                        }
2860
                    }});
2861
            }
2862
        }
2863
        else {
2864
            // No 3.2 state...check if the FVB has state
2865
            IMemento fastViewMem = memento
2866
                    .getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
2867
            if (fastViewMem != null) {
2868
                if (fastViewBar != null) {
2869
                    final Integer bigInt = fastViewMem.getInteger(IWorkbenchConstants.TAG_FAST_VIEW_SIDE);
2870
                    if (bigInt != null) {
2871
                        StartupThreading.runWithoutExceptions(new StartupRunnable() {
2872
2873
                            public void runWithException() throws Throwable {
2874
                                fastViewBar.dock(bigInt.intValue());
2875
                                getTrimManager().addTrim(bigInt.intValue(), fastViewBar);
2876
                            }});
2877
                        
2878
                    }
2879
                }
2880
            }
2881
        }
2882
        
2883
        return Status.OK_STATUS;
2884
    }
2885
2886
    /**
2887
     * Sets the active page within the window.
2888
     * 
2889
     * @param in
2890
     *            identifies the new active page, or <code>null</code> for no
2891
     *            active page
2892
     */
2893
    public void setActivePage(final IWorkbenchPage in) {
2894
        if (getActiveWorkbenchPage() == in) {
2895
            return;
2896
        }
2897
2898
        // 1FVGTNR: ITPUI:WINNT - busy cursor for switching perspectives
2899
        BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
2900
            public void run() {
2901
                // Deactivate old persp.
2902
                WorkbenchPage currentPage = getActiveWorkbenchPage();
2903
                if (currentPage != null) {
2904
                    currentPage.onDeactivate();
2905
                }
2906
2907
                // Activate new persp.
2908
                if (in == null || pageList.contains(in)) {
2909
                    pageList.setActive(in);
2910
                }
2911
                WorkbenchPage newPage = pageList.getActive();
2912
                Composite parent = getPageComposite();
2913
                StackLayout layout = (StackLayout) parent.getLayout();
2914
                if (newPage != null) {
2915
                    layout.topControl = newPage.getClientComposite();
2916
                    parent.layout();
2917
                    hideEmptyWindowContents();
2918
                    newPage.onActivate();
2919
                    firePageActivated(newPage);
2920
                    if (newPage.getPerspective() != null) {
2921
                        firePerspectiveActivated(newPage, newPage
2922
                                .getPerspective());
2923
                    }
2924
                } else {
2925
                    layout.topControl = null;
2926
                    parent.layout();
2927
                }
2928
2929
                updateFastViewBar();
2930
2931
                if (isClosing()) {
2932
                    return;
2933
                }
2934
2935
                updateDisabled = false;
2936
2937
                // Update action bars ( implicitly calls updateActionBars() )
2938
                updateActionSets();
2939
                submitGlobalActions();
2940
2941
                if (perspectiveSwitcher != null) {
2942
                    perspectiveSwitcher.update(false);
2943
                }
2944
2945
                getMenuManager().update(IAction.TEXT);
2946
            }
2947
        });
2948
    }
2949
2950
    /**
2951
     * Returns whether or not children exist for the Window's toolbar control.
2952
     * Overridden for coolbar support.
2953
     * <p>
2954
     * 
2955
     * @return boolean true if children exist, false otherwise
2956
     */
2957
    protected boolean toolBarChildrenExist() {
2958
        CoolBar coolBarControl = (CoolBar) getCoolBarControl();
2959
        return coolBarControl.getItemCount() > 0;
2960
    }
2961
2962
    /**
2963
     * Hooks a listener to track the activation and deactivation of the window's
2964
     * shell. Notifies the active part and editor of the change
2965
     */
2966
    private void trackShellActivation(Shell shell) {
2967
        shell.addShellListener(new ShellAdapter() {
2968
            public void shellActivated(ShellEvent event) {
2969
                shellActivated = true;
2970
                serviceLocator.activate();
2971
                getWorkbenchImpl().setActivatedWindow(WorkbenchWindow.this);
2972
                WorkbenchPage currentPage = getActiveWorkbenchPage();
2973
                if (currentPage != null) {
2974
                    IWorkbenchPart part = currentPage.getActivePart();
2975
                    if (part != null) {
2976
                        PartSite site = (PartSite) part.getSite();
2977
                        site.getPane().shellActivated();
2978
                    }
2979
                    IEditorPart editor = currentPage.getActiveEditor();
2980
                    if (editor != null) {
2981
                        PartSite site = (PartSite) editor.getSite();
2982
                        site.getPane().shellActivated();
2983
                    }
2984
                    getWorkbenchImpl()
2985
                            .fireWindowActivated(WorkbenchWindow.this);
2986
                }
2987
            }
2988
2989
            public void shellDeactivated(ShellEvent event) {
2990
                shellActivated = false;
2991
                serviceLocator.deactivate();
2992
                WorkbenchPage currentPage = getActiveWorkbenchPage();
2993
                if (currentPage != null) {
2994
                    IWorkbenchPart part = currentPage.getActivePart();
2995
                    if (part != null) {
2996
                        PartSite site = (PartSite) part.getSite();
2997
                        site.getPane().shellDeactivated();
2998
                    }
2999
                    IEditorPart editor = currentPage.getActiveEditor();
3000
                    if (editor != null) {
3001
                        PartSite site = (PartSite) editor.getSite();
3002
                        site.getPane().shellDeactivated();
3003
                    }
3004
                    getWorkbenchImpl().fireWindowDeactivated(
3005
                            WorkbenchWindow.this);
3006
                }
3007
            }
3008
        });
3009
    }
3010
3011
    /**
3012
     * Hooks a listener to track the resize of the window's shell. Stores the
3013
     * new bounds if in normal state - that is, not in minimized or maximized
3014
     * state)
3015
     */
3016
    private void trackShellResize(Shell newShell) {
3017
        newShell.addControlListener(new ControlAdapter() {
3018
            public void controlMoved(ControlEvent e) {
3019
                saveBounds();
3020
            }
3021
3022
            public void controlResized(ControlEvent e) {
3023
                saveBounds();
3024
            }
3025
3026
            private void saveBounds() {
3027
                Shell shell = getShell();
3028
                if (shell == null) {
3029
                    return;
3030
                }
3031
                if (shell.isDisposed()) {
3032
                    return;
3033
                }
3034
                if (shell.getMinimized()) {
3035
                    return;
3036
                }
3037
                if (shell.getMaximized()) {
3038
                    asMaximizedState = true;
3039
                    return;
3040
                }
3041
                asMaximizedState = false;
3042
                normalBounds = shell.getBounds();
3043
            }
3044
        });
3045
    }
3046
3047
    /**
3048
     * update the action bars.
3049
     */
3050
    public void updateActionBars() {
3051
        if (updateDisabled || updatesDeferred()) {
3052
            return;
3053
        }
3054
        // updateAll required in order to enable accelerators on pull-down menus
3055
        getMenuBarManager().update(false);
3056
3057
        // RAP [bm]: Composite#setLayoutDeferred
3058
//      try {
3059
//          getShell().setLayoutDeferred(true);
3060
//          getCoolBarManager2().update(false);
3061
//      } finally {
3062
//          getShell().setLayoutDeferred(false);
3063
//      }
3064
        getCoolBarManager2().update(false);
3065
        // RAPEND: [bm] 
3066
3067
        getStatusLineManager().update(false);
3068
    }
3069
3070
    /**
3071
     * Returns true iff we are currently deferring UI processing due to a large
3072
     * update
3073
     * 
3074
     * @return true iff we are deferring UI updates.
3075
     */
3076
    private boolean updatesDeferred() {
3077
        return largeUpdates > 0;
3078
    }
3079
3080
    /**
3081
     * <p>
3082
     * Indicates the start of a large update within this window. This is used to
3083
     * disable CPU-intensive, change-sensitive services that were temporarily
3084
     * disabled in the midst of large changes. This method should always be
3085
     * called in tandem with <code>largeUpdateEnd</code>, and the event loop
3086
     * should not be allowed to spin before that method is called.
3087
     * </p>
3088
     * <p>
3089
     * Important: always use with <code>largeUpdateEnd</code>!
3090
     * </p>
3091
     */
3092
    public final void largeUpdateStart() {
3093
        largeUpdates++;
3094
    }
3095
3096
    /**
3097
     * <p>
3098
     * Indicates the end of a large update within this window. This is used to
3099
     * re-enable services that were temporarily disabled in the midst of large
3100
     * changes. This method should always be called in tandem with
3101
     * <code>largeUpdateStart</code>, and the event loop should not be
3102
     * allowed to spin before this method is called.
3103
     * </p>
3104
     * <p>
3105
     * Important: always protect this call by using <code>finally</code>!
3106
     * </p>
3107
     */
3108
    public final void largeUpdateEnd() {
3109
        if (--largeUpdates == 0) {
3110
            updateActionBars();
3111
        }
3112
    }
3113
3114
    /**
3115
     * Update the visible action sets. This method is typically called from a
3116
     * page when the user changes the visible action sets within the
3117
     * prespective.
3118
     */
3119
    public void updateActionSets() {
3120
        if (updateDisabled) {
3121
            return;
3122
        }
3123
3124
        WorkbenchPage currentPage = getActiveWorkbenchPage();
3125
        if (currentPage == null) {
3126
            getActionPresentation().clearActionSets();
3127
        } else {
3128
            ICoolBarManager2 coolBarManager = (ICoolBarManager2) getCoolBarManager2();
3129
            if (coolBarManager != null) {
3130
                coolBarManager.refresh();
3131
            }
3132
            getActionPresentation().setActionSets(
3133
                    currentPage.getActionSets());
3134
        }
3135
        fireActionSetsChanged();
3136
        updateActionBars();
3137
3138
        // hide the launch menu if it is empty
3139
        String path = IWorkbenchActionConstants.M_WINDOW
3140
                + IWorkbenchActionConstants.SEP
3141
                + IWorkbenchActionConstants.M_LAUNCH;
3142
        IMenuManager manager = getMenuBarManager().findMenuUsingPath(path);
3143
        IContributionItem item = getMenuBarManager().findUsingPath(path);
3144
3145
        if (manager == null || item == null) {
3146
            return;
3147
        }
3148
        item.setVisible(manager.getItems().length >= 2);
3149
        // there is a separator for the additions group thus >= 2
3150
    }
3151
3152
    private ListenerList actionSetListeners = null;
3153
3154
    private ListenerList backgroundSaveListeners = new ListenerList(ListenerList.IDENTITY);
3155
3156
    private final void fireActionSetsChanged() {
3157
        if (actionSetListeners != null) {
3158
            final Object[] listeners = actionSetListeners.getListeners();
3159
            for (int i = 0; i < listeners.length; i++) {
3160
                final IActionSetsListener listener = (IActionSetsListener) listeners[i];
3161
                final WorkbenchPage currentPage = getActiveWorkbenchPage();
3162
                final IActionSetDescriptor[] newActionSets;
3163
                if (currentPage == null) {
3164
                    newActionSets = null;
3165
                } else {
3166
                    newActionSets = currentPage.getActionSets();
3167
                }
3168
                final ActionSetsEvent event = new ActionSetsEvent(newActionSets);
3169
                listener.actionSetsChanged(event);
3170
            }
3171
        }
3172
    }
3173
3174
    final void addActionSetsListener(final IActionSetsListener listener) {
3175
        if (actionSetListeners == null) {
3176
            actionSetListeners = new ListenerList();
3177
        }
3178
3179
        actionSetListeners.add(listener);
3180
    }
3181
3182
    final void removeActionSetsListener(final IActionSetsListener listener) {
3183
        if (actionSetListeners != null) {
3184
            actionSetListeners.remove(listener);
3185
            if (actionSetListeners.isEmpty()) {
3186
                actionSetListeners = null;
3187
            }
3188
        }
3189
    }
3190
3191
    /**
3192
     * Create the progress indicator for the receiver.
3193
     * 
3194
     * @param shell
3195
     *            the parent shell
3196
     */
3197
    private void createProgressIndicator(Shell shell) {
3198
        if (getWindowConfigurer().getShowProgressIndicator()) {
3199
            progressRegion = new ProgressRegion();
3200
            progressRegion.createContents(shell, this);
3201
        }
3202
    }
3203
3204
    class PageList {
3205
        // List of pages in the order they were created;
3206
        private List pagesInCreationOrder;
3207
3208
        // List of pages where the top is the last activated.
3209
        private List pageInActivationOrder;
3210
3211
        // The page explicitly activated
3212
        private Object active;
3213
3214
        public PageList() {
3215
            pagesInCreationOrder = new ArrayList(4);
3216
            pageInActivationOrder = new ArrayList(4);
3217
        }
3218
3219
        public boolean add(Object object) {
3220
            pagesInCreationOrder.add(object);
3221
            pageInActivationOrder.add(0, object);
3222
            // It will be moved to top only when activated.
3223
            return true;
3224
        }
3225
3226
        public Iterator iterator() {
3227
            return pagesInCreationOrder.iterator();
3228
        }
3229
3230
        public boolean contains(Object object) {
3231
            return pagesInCreationOrder.contains(object);
3232
        }
3233
3234
        public boolean remove(Object object) {
3235
            if (active == object) {
3236
                active = null;
3237
            }
3238
            pageInActivationOrder.remove(object);
3239
            return pagesInCreationOrder.remove(object);
3240
        }
3241
3242
        public boolean isEmpty() {
3243
            return pagesInCreationOrder.isEmpty();
3244
        }
3245
3246
        public IWorkbenchPage[] getPages() {
3247
            int nSize = pagesInCreationOrder.size();
3248
            IWorkbenchPage[] retArray = new IWorkbenchPage[nSize];
3249
            pagesInCreationOrder.toArray(retArray);
3250
            return retArray;
3251
        }
3252
3253
        public void setActive(Object page) {
3254
            if (active == page) {
3255
                return;
3256
            }
3257
3258
            active = page;
3259
3260
            if (page != null) {
3261
                pageInActivationOrder.remove(page);
3262
                pageInActivationOrder.add(page);
3263
            }
3264
        }
3265
3266
        public WorkbenchPage getActive() {
3267
            return (WorkbenchPage) active;
3268
        }
3269
3270
        public WorkbenchPage getNextActive() {
3271
            if (active == null) {
3272
                if (pageInActivationOrder.isEmpty()) {
3273
                    return null;
3274
                }
3275
3276
                return (WorkbenchPage) pageInActivationOrder
3277
                        .get(pageInActivationOrder.size() - 1);
3278
            }
3279
3280
            if (pageInActivationOrder.size() < 2) {
3281
                return null;
3282
            }
3283
3284
            return (WorkbenchPage) pageInActivationOrder
3285
                    .get(pageInActivationOrder.size() - 2);
3286
        }
3287
    }
3288
3289
    /**
3290
     * Returns the unique object that applications use to configure this window.
3291
     * <p>
3292
     * IMPORTANT This method is declared package-private to prevent regular
3293
     * plug-ins from downcasting IWorkbenchWindow to WorkbenchWindow and getting
3294
     * hold of the workbench window configurer that would allow them to tamper
3295
     * with the workbench window. The workbench window configurer is available
3296
     * only to the application.
3297
     * </p>
3298
     */
3299
    /* package - DO NOT CHANGE */
3300
    WorkbenchWindowConfigurer getWindowConfigurer() {
3301
        if (windowConfigurer == null) {
3302
            // lazy initialize
3303
            windowConfigurer = new WorkbenchWindowConfigurer( this );
3304
        }
3305
        return windowConfigurer;
3306
    }
3307
3308
    /**
3309
     * Returns the workbench advisor. Assumes the workbench has been created
3310
     * already.
3311
     * <p>
3312
     * IMPORTANT This method is declared private to prevent regular plug-ins
3313
     * from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
3314
     * the workbench advisor that would allow them to tamper with the workbench.
3315
     * The workbench advisor is internal to the application.
3316
     * </p>
3317
     */
3318
    private/* private - DO NOT CHANGE */
3319
    WorkbenchAdvisor getAdvisor() {
3320
        return getWorkbenchImpl().getAdvisor();
3321
    }
3322
3323
    /**
3324
     * Returns the window advisor, creating a new one for this window if needed.
3325
     * <p>
3326
     * IMPORTANT This method is declared private to prevent regular plug-ins
3327
     * from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
3328
     * the window advisor that would allow them to tamper with the window. The
3329
     * window advisor is internal to the application.
3330
     * </p>
3331
     */
3332
    private/* private - DO NOT CHANGE */
3333
    WorkbenchWindowAdvisor getWindowAdvisor() {
3334
        if (windowAdvisor == null) {
3335
            windowAdvisor = getAdvisor().createWorkbenchWindowAdvisor(
3336
                    getWindowConfigurer());
3337
            Assert.isNotNull(windowAdvisor);
3338
        }
3339
        return windowAdvisor;
3340
    }
3341
3342
    /**
3343
     * Returns the action bar advisor, creating a new one for this window if
3344
     * needed.
3345
     * <p>
3346
     * IMPORTANT This method is declared private to prevent regular plug-ins
3347
     * from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
3348
     * the action bar advisor that would allow them to tamper with the window's
3349
     * action bars. The action bar advisor is internal to the application.
3350
     * </p>
3351
     */
3352
    private/* private - DO NOT CHANGE */
3353
    ActionBarAdvisor getActionBarAdvisor() {
3354
        if (actionBarAdvisor == null) {
3355
            actionBarAdvisor = getWindowAdvisor().createActionBarAdvisor(
3356
                    getWindowConfigurer().getActionBarConfigurer());
3357
            Assert.isNotNull(actionBarAdvisor);
3358
        }
3359
        return actionBarAdvisor;
3360
    }
3361
3362
    /*
3363
     * Returns the IWorkbench implementation.
3364
     */
3365
    private Workbench getWorkbenchImpl() {
3366
        return Workbench.getInstance();
3367
    }
3368
3369
    /**
3370
     * Fills the window's real action bars.
3371
     * 
3372
     * @param flags
3373
     *            indicate which bars to fill
3374
     */
3375
    public void fillActionBars(int flags) {
3376
        Workbench workbench = getWorkbenchImpl();
3377
        workbench.largeUpdateStart();
3378
        try {
3379
            getActionBarAdvisor().fillActionBars(flags);
3380
            //
3381
            // 3.3 start
3382
            final IMenuService menuService = (IMenuService) serviceLocator
3383
                    .getService(IMenuService.class);
3384
            menuService.populateContributionManager(
3385
                    (ContributionManager) getActionBars().getMenuManager(),
3386
                    MenuUtil.MAIN_MENU);
3387
            ICoolBarManager coolbar = getActionBars().getCoolBarManager();
3388
            if (coolbar != null) {
3389
                menuService.populateContributionManager(
3390
                        (ContributionManager) coolbar,
3391
                        MenuUtil.MAIN_TOOLBAR);
3392
            }
3393
            // 3.3 end
3394
        } finally {
3395
            workbench.largeUpdateEnd();
3396
        }
3397
    }
3398
3399
    /**
3400
     * Fills the window's proxy action bars.
3401
     * 
3402
     * @param proxyBars
3403
     *            the proxy configurer
3404
     * @param flags
3405
     *            indicate which bars to fill
3406
     */
3407
    public void fillActionBars(IActionBarConfigurer2 proxyBars, int flags) {
3408
        Assert.isNotNull(proxyBars);
3409
        WorkbenchWindowConfigurer.WindowActionBarConfigurer wab = (WorkbenchWindowConfigurer.WindowActionBarConfigurer) getWindowConfigurer()
3410
                .getActionBarConfigurer();
3411
        wab.setProxy(proxyBars);
3412
        try {
3413
            getActionBarAdvisor().fillActionBars(
3414
                    flags | ActionBarAdvisor.FILL_PROXY);
3415
        } finally {
3416
            wab.setProxy(null);
3417
        }
3418
    }
3419
3420
    /**
3421
     * The <code>WorkbenchWindow</code> implementation of this method has the
3422
     * same logic as <code>Window</code>'s implementation, but without the
3423
     * resize check. We don't want to skip setting the bounds if the shell has
3424
     * been resized since a free resize event occurs on Windows when the menubar
3425
     * is set in configureShell.
3426
     */
3427
    protected void initializeBounds() {
3428
        Point size = getInitialSize();
3429
        Point location = getInitialLocation(size);
3430
        getShell().setBounds(
3431
                getConstrainedShellBounds(new Rectangle(location.x, location.y,
3432
                        size.x, size.y)));
3433
    }
3434
3435
    /*
3436
     * Unlike dialogs, the position of the workbench window is set by the user
3437
     * and persisted across sessions. If the user wants to put the window
3438
     * offscreen or spanning multiple monitors, let them (bug 74762)
3439
     */
3440
    protected void constrainShellSize() {
3441
        // As long as the shell is visible on some monitor, don't change it.
3442
        Rectangle bounds = getShell().getBounds();
3443
        if (!SwtUtil.intersectsAnyMonitor(Display.getCurrent(), bounds)) {
3444
            super.constrainShellSize();
3445
        }
3446
    }
3447
3448
    /*
3449
     * Unlike dialogs, the position of the workbench window is set by the user
3450
     * and persisted across sessions. If the user wants to put the window
3451
     * offscreen or spanning multiple monitors, let them (bug 74762)
3452
     */
3453
    protected Point getInitialLocation(Point size) {
3454
        Shell shell = getShell();
3455
        if (shell != null) {
3456
            return shell.getLocation();
3457
        }
3458
3459
        return super.getInitialLocation(size);
3460
    }
3461
3462
    /**
3463
     * The <code>WorkbenchWindow</code> implementation of this method
3464
     * delegates to the window configurer.
3465
     */
3466
    protected Point getInitialSize() {
3467
        return getWindowConfigurer().getInitialSize();
3468
    }
3469
3470
    /**
3471
     * @param visible
3472
     *            whether the cool bar should be shown. This is only applicable
3473
     *            if the window configurer also wishes either the cool bar to be
3474
     *            visible.
3475
     */
3476
    public void setCoolBarVisible(boolean visible) {
3477
        boolean oldValue = coolBarVisible;
3478
        coolBarVisible = visible;
3479
        if (oldValue != coolBarVisible) {
3480
            updateLayoutDataForContents();
3481
        }
3482
    }
3483
3484
    /**
3485
     * @return whether the cool bar should be shown. This is only applicable if
3486
     *         the window configurer also wishes either the cool bar to be
3487
     *         visible.
3488
     */
3489
    public boolean getCoolBarVisible() {
3490
        return coolBarVisible;
3491
    }
3492
3493
    /**
3494
     * @param visible
3495
     *            whether the perspective bar should be shown. This is only
3496
     *            applicable if the window configurer also wishes either the
3497
     *            perspective bar to be visible.
3498
     */
3499
    public void setPerspectiveBarVisible(boolean visible) {
3500
        boolean oldValue = perspectiveBarVisible;
3501
        perspectiveBarVisible = visible;
3502
        if (oldValue != perspectiveBarVisible) {
3503
            updateLayoutDataForContents();
3504
        }
3505
    }
3506
3507
    /**
3508
     * @return whether the perspective bar should be shown. This is only
3509
     *         applicable if the window configurer also wishes either the
3510
     *         perspective bar to be visible.
3511
     */
3512
    public boolean getPerspectiveBarVisible() {
3513
        return perspectiveBarVisible;
3514
    }
3515
    
3516
    /**
3517
     * Tell the workbench window a visible state for the fastview bar. This is
3518
     * only applicable if the window configurer also wishes the fast view bar to
3519
     * be visible.
3520
     * 
3521
     * @param visible
3522
     *            <code>true</code> or <code>false</code>
3523
     */
3524
    public void setFastViewBarVisible(boolean visible) {
3525
        boolean oldValue = fastViewBarVisible;
3526
        fastViewBarVisible = visible;
3527
        if (oldValue != fastViewBarVisible) {
3528
            updateLayoutDataForContents();
3529
        }
3530
    }
3531
    
3532
    /**
3533
     * The workbench window take on the fastview bar. This is only applicable if
3534
     * the window configurer also wishes the fast view bar to be visible.
3535
     * 
3536
     * @return <code>true</code> if the workbench window thinks the fastview
3537
     *         bar should be visible.
3538
     */
3539
    public boolean getFastViewBarVisible() {
3540
        return fastViewBarVisible;
3541
    }
3542
3543
    /**
3544
     * @param visible
3545
     *            whether the perspective bar should be shown. This is only
3546
     *            applicable if the window configurer also wishes either the
3547
     *            perspective bar to be visible.
3548
     */
3549
    public void setStatusLineVisible(boolean visible) {
3550
        boolean oldValue = statusLineVisible;
3551
        statusLineVisible = visible;
3552
        if (oldValue != statusLineVisible) {
3553
            updateLayoutDataForContents();
3554
        }
3555
    }
3556
3557
    /**
3558
     * @return whether the perspective bar should be shown. This is only
3559
     *         applicable if the window configurer also wishes either the
3560
     *         perspective bar to be visible.
3561
     */
3562
    public boolean getStatusLineVisible() {
3563
        return statusLineVisible;
3564
    }
3565
3566
    /**
3567
     * Note that this will only have an effect if the default implementation of
3568
     * WorkbenchAdvisor.createWindowContents() has been invoked.
3569
     * 
3570
     * called IWorkbench
3571
     */
3572
    private void updateLayoutDataForContents() {
3573
        if (defaultLayout == null) {
3574
            return;
3575
        }
3576
3577
        // @issue this is not ideal; coolbar and perspective shortcuts should be
3578
        // separately configurable
3579
        if ((getCoolBarVisible() && getWindowConfigurer().getShowCoolBar())
3580
                || (getPerspectiveBarVisible() && getWindowConfigurer()
3581
                        .getShowPerspectiveBar())) {
3582
            if (defaultLayout.getTrim(topBarTrim.getId()) == null) {
3583
                defaultLayout.addTrim(SWT.TOP, topBarTrim);
3584
            }
3585
            topBar.setVisible(true);
3586
        } else {
3587
            defaultLayout.removeTrim(topBarTrim);
3588
            topBar.setVisible(false);
3589
        }
3590
3591
        if (fastViewBar != null) {
3592
            if (getFastViewBarVisible()
3593
                    && getWindowConfigurer().getShowFastViewBars()) {
3594
                int side = fastViewBar.getSide();
3595
3596
                if (defaultLayout.getTrim(fastViewBar.getId()) == null) {
3597
                    defaultLayout.addTrim(side, fastViewBar);
3598
                }
3599
                fastViewBar.getControl().setVisible(true);
3600
            } else {
3601
                defaultLayout.removeTrim(fastViewBar);
3602
                fastViewBar.getControl().setVisible(false);
3603
            }
3604
        }
3605
3606
        if (getStatusLineVisible() && getWindowConfigurer().getShowStatusLine()) {
3607
            if (defaultLayout.getTrim(getStatusLineTrim().getId()) == null) {
3608
                defaultLayout.addTrim(SWT.BOTTOM, getStatusLineTrim());
3609
            }
3610
            getStatusLineManager().getControl().setVisible(true);
3611
        } else {
3612
            defaultLayout.removeTrim(getStatusLineTrim());
3613
            getStatusLineManager().getControl().setVisible(false);
3614
        }
3615
3616
// RAP [rh] HeapStatus not supported  
3617
//      if (heapStatus != null) {
3618
//          if (getShowHeapStatus()) {
3619
//              if (heapStatus.getLayoutData() == null) {
3620
//                  heapStatusTrim.setWidthHint(heapStatus.computeSize(
3621
//                          SWT.DEFAULT, SWT.DEFAULT).x);
3622
//                  heapStatusTrim
3623
//                          .setHeightHint(getStatusLineManager().getControl()
3624
//                                  .computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
3625
//              }
3626
//
3627
//              if (defaultLayout.getTrim(heapStatusTrim.getId()) == null) {
3628
//                  defaultLayout.addTrim(SWT.BOTTOM, heapStatusTrim);
3629
//              }
3630
//              heapStatus.setVisible(true);
3631
//          } else {
3632
//
3633
//              defaultLayout.removeTrim(heapStatusTrim);
3634
//              heapStatus.setVisible(false);
3635
//          }
3636
//      }
3637
3638
        if (progressRegion != null) {
3639
            if (getWindowConfigurer().getShowProgressIndicator()) {
3640
                if (defaultLayout.getTrim(progressRegion.getId()) == null) {
3641
                    defaultLayout.addTrim(SWT.BOTTOM, progressRegion);
3642
                }
3643
                progressRegion.getControl().setVisible(true);
3644
            } else {
3645
                defaultLayout.removeTrim(progressRegion);
3646
                progressRegion.getControl().setVisible(false);
3647
            }
3648
        }
3649
        
3650
        defaultLayout.setCenterControl(getPageComposite());
3651
3652
        // Re-populate the trim elements
3653
        if (trimMgr2 != null)
3654
            trimMgr2.update(true, false, !topBar.getVisible());
3655
        if (trimContributionMgr != null)
3656
            trimContributionMgr.update(true,  !topBar.getVisible());
3657
    }
3658
3659
    public boolean getShowFastViewBars() {
3660
        return getWindowConfigurer().getShowFastViewBars();
3661
    }
3662
3663
    /**
3664
     * Set the layout data for the contents of the window.
3665
     */
3666
    private void setLayoutDataForContents() {
3667
        updateLayoutDataForContents();
3668
    }
3669
3670
    /**
3671
     * Returns the fast view bar.
3672
     */
3673
    public FastViewBar getFastViewBar() {
3674
        return fastViewBar;
3675
    }
3676
3677
    /**
3678
     * Returns the perspective bar.
3679
     * 
3680
     * @return Returns the perspective bar, or <code>null</code> if it has not
3681
     *         been initialized.
3682
     */
3683
    public PerspectiveBarManager getPerspectiveBar() {
3684
        return perspectiveSwitcher == null ? null : perspectiveSwitcher
3685
                .getPerspectiveBar();
3686
    }
3687
3688
    /**
3689
     * Returns the action presentation for dynamic UI
3690
     * @return action presentation
3691
     */
3692
    public ActionPresentation getActionPresentation() {
3693
        if (actionPresentation == null) {
3694
            actionPresentation = new ActionPresentation(this);
3695
        }
3696
        return actionPresentation;
3697
    }
3698
    
3699
    /**
3700
     * Return the action bar presentation used for creating toolbars.  This
3701
     * is for internal use only, used for consistency with the window.
3702
     * 
3703
     * @return the presentation used.
3704
     */
3705
    public IActionBarPresentationFactory getActionBarPresentationFactory() {
3706
        // allow replacement of the actionbar presentation
3707
        IActionBarPresentationFactory actionBarPresentation;            
3708
        AbstractPresentationFactory presentationFactory = 
3709
            getWindowConfigurer().getPresentationFactory();
3710
        if (presentationFactory instanceof IActionBarPresentationFactory) {
3711
            actionBarPresentation = ((IActionBarPresentationFactory) presentationFactory);
3712
        } else {
3713
            actionBarPresentation = new DefaultActionBarPresentationFactory();
3714
        }      
3715
        
3716
        return actionBarPresentation;           
3717
    }
3718
    
3719
    /*
3720
     * (non-Javadoc)
3721
     * 
3722
     * @see org.eclipse.jface.window.ApplicationWindow#showTopSeperator()
3723
     */
3724
    protected boolean showTopSeperator() {
3725
        return false;
3726
    }
3727
3728
    /**
3729
     * Returns a new cool bar manager for the window.
3730
     * <p>
3731
     * Subclasses may override this method to customize the cool bar manager.
3732
     * </p>
3733
     * 
3734
     * @return a cool bar manager
3735
     */
3736
    protected ICoolBarManager createCoolBarManager2(int style) {
3737
        return getActionBarPresentationFactory().createCoolBarManager();
3738
    }
3739
3740
    /**
3741
     * Returns a new tool bar manager for the window.
3742
     * <p>
3743
     * Subclasses may override this method to customize the tool bar manager.
3744
     * </p>
3745
     * @return a tool bar manager
3746
     */
3747
    protected IToolBarManager createToolBarManager2(int style) {
3748
        return getActionBarPresentationFactory().createToolBarManager();
3749
    }
3750
    
3751
    /**
3752
     * Delegate to the presentation factory.
3753
     * 
3754
     * @see org.eclipse.jface.window.ApplicationWindow#createStatusLineManager
3755
     */
3756
    protected StatusLineManager createStatusLineManager() {
3757
        // @issue ApplicationWindow and WorkbenchWindow should allow full
3758
        // IStatusLineManager
3759
        return (StatusLineManager) getWindowConfigurer()
3760
                .getPresentationFactory().createStatusLineManager();
3761
    }
3762
3763
    /**
3764
     * Delegate to the presentation factory.
3765
     * 
3766
     * @see org.eclipse.jface.window.ApplicationWindow#createStatusLine
3767
     */
3768
    protected void createStatusLine(Shell shell) {
3769
        getWindowConfigurer().getPresentationFactory().createStatusLineControl(
3770
                getStatusLineManager(), shell);
3771
    }
3772
3773
    /**
3774
     * Updates the fast view bar, if present. TODO: The fast view bar should
3775
     * update itself as necessary. All calls to this should be cleaned up.
3776
     */
3777
    public void updateFastViewBar() {
3778
        if (getFastViewBar() != null) {
3779
            getFastViewBar().update(true);
3780
        }
3781
    }
3782
3783
    /**
3784
     * @return Returns the progressRegion.
3785
     */
3786
    public ProgressRegion getProgressRegion() {
3787
        return progressRegion;
3788
    }
3789
3790
    /**
3791
     * Adds the given control to the specified side of this window's trim.
3792
     * 
3793
     * @param trim
3794
     *            the bar's IWindowTrim
3795
     * @param side
3796
     *            one of <code>SWT.LEFT</code>,<code>SWT.BOTTOM</code>,
3797
     *            or <code>SWT.RIGHT</code> (only LEFT has been tested)
3798
     */
3799
    public void addToTrim(IWindowTrim trim, int side) {
3800
        IWindowTrim reference = null;
3801
        defaultLayout.addTrim(side, trim, reference);
3802
    }
3803
3804
    /*
3805
     * (non-Javadoc)
3806
     * 
3807
     * @see org.eclipse.ui.IWorkbenchWindow#getExtensionTracker()
3808
     */
3809
    public IExtensionTracker getExtensionTracker() {
3810
        if (tracker == null) {
3811
            tracker = new UIExtensionTracker(getWorkbench().getDisplay());
3812
        }
3813
        return tracker;
3814
    }
3815
3816
    /**
3817
     * Creates the perspective customization dialog.
3818
     * 
3819
     * @param persp
3820
     *            perspective to customize
3821
     * 
3822
     * @return a new perspective customization dialog
3823
     */
3824
    public CustomizePerspectiveDialog createCustomizePerspectiveDialog(
3825
            Perspective persp) {
3826
        return new CustomizePerspectiveDialog(getWindowConfigurer(), persp);
3827
    }
3828
3829
    /**
3830
     * Returns the default page input for workbench pages opened in this window.
3831
     * 
3832
     * @return the default page input or <code>null</code> if none
3833
     */
3834
    IAdaptable getDefaultPageInput() {
3835
        return getWorkbenchImpl().getDefaultPageInput();
3836
    }
3837
3838
    /**
3839
     * Add a listener for perspective reordering.
3840
     * 
3841
     * @param listener
3842
     */
3843
    public void addPerspectiveReorderListener(IReorderListener listener) {
3844
        if (perspectiveSwitcher != null) {
3845
            perspectiveSwitcher.addReorderListener(listener);
3846
        }
3847
    }
3848
3849
// RAP [rh] HeapStatus not supported    
3850
//  /**
3851
//   * Show the heap status
3852
//   * 
3853
//   * @param selection
3854
//   */
3855
//  public void showHeapStatus(boolean selection) {
3856
//      if (selection) {
3857
//          if (heapStatus == null) {
3858
//              createHeapStatus(getShell());
3859
//              updateLayoutDataForContents();
3860
//              getShell().layout();
3861
//          }
3862
//      } else {
3863
//          if (heapStatus != null) {
3864
//              heapStatus.dispose();
3865
//              heapStatus = null;
3866
//          }
3867
//      }
3868
//
3869
//  }
3870
3871
    /*
3872
     * (non-Javadoc)
3873
     * 
3874
     * @see org.eclipse.ui.IWorkbenchWindow#getTrimManager()
3875
     */
3876
    public ITrimManager getTrimManager() {
3877
        return defaultLayout;
3878
    }
3879
3880
    /**
3881
     * Initializes all of the default command-based services for the workbench
3882
     * window.
3883
     */
3884
    private final void initializeDefaultServices() {
3885
        serviceLocator.registerService(IWorkbenchWindow.class, this);
3886
        
3887
        final ActionCommandMappingService mappingService = new ActionCommandMappingService();
3888
        serviceLocator.registerService(IActionCommandMappingService.class,
3889
                mappingService);
3890
3891
        final LegacyActionPersistence actionPersistence = new LegacyActionPersistence(
3892
                this);
3893
        serviceLocator.registerService(LegacyActionPersistence.class,
3894
                actionPersistence);
3895
        actionPersistence.read();
3896
3897
    }
3898
3899
    public final Object getService(final Class key) {
3900
        return serviceLocator.getService(key);
3901
    }
3902
3903
    public final boolean hasService(final Class key) {
3904
        return serviceLocator.hasService(key);
3905
    }
3906
    
3907
    /**
3908
     * Toggle the visibility of the coolbar/perspective bar. This method
3909
     * respects the window configurer and will only toggle visibility if the
3910
     * item in question was originally declared visible by the window advisor.
3911
     */
3912
    public void toggleToolbarVisibility() {
3913
        boolean coolbarVisible = getCoolBarVisible();
3914
        boolean perspectivebarVisible = getPerspectiveBarVisible();
3915
        // only toggle the visibility of the components that
3916
        // were on initially
3917
        if (getWindowConfigurer().getShowCoolBar()) {
3918
            setCoolBarVisible(!coolbarVisible);
3919
            firePropertyChanged(PROP_COOLBAR_VISIBLE,
3920
                    coolbarVisible ? Boolean.TRUE : Boolean.FALSE,
3921
                    !coolbarVisible ? Boolean.TRUE : Boolean.FALSE);
3922
        }
3923
        if (getWindowConfigurer().getShowPerspectiveBar()) {
3924
            setPerspectiveBarVisible(!perspectivebarVisible);
3925
            firePropertyChanged(PROP_PERSPECTIVEBAR_VISIBLE,
3926
                    coolbarVisible ? Boolean.TRUE : Boolean.FALSE,
3927
                    !coolbarVisible ? Boolean.TRUE : Boolean.FALSE);
3928
        }
3929
        getShell().layout();
3930
    }
3931
3932
    /*package*/ void addBackgroundSaveListener(IBackgroundSaveListener listener) {
3933
        backgroundSaveListeners.add(listener);
3934
    }
3935
    
3936
    /*package*/ void fireBackgroundSaveStarted() {
3937
        Object[] listeners = backgroundSaveListeners.getListeners();
3938
        for (int i = 0; i < listeners.length; i++) {
3939
            IBackgroundSaveListener listener = (IBackgroundSaveListener) listeners[i];
3940
            listener.handleBackgroundSaveStarted();
3941
        }
3942
    }
3943
3944
    /*package*/ void removeBackgroundSaveListener(IBackgroundSaveListener listener) {
3945
        backgroundSaveListeners.remove(listener);
3946
    }
3861
}
3947
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java (-7 / +40 lines)
Lines 16-32 Link Here
16
import java.util.Collection;
16
import java.util.Collection;
17
import java.util.HashSet;
17
import java.util.HashSet;
18
18
19
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IExtensionPoint;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Status;
20
import org.eclipse.equinox.http.registry.HttpContextExtensionService;
26
import org.eclipse.equinox.http.registry.HttpContextExtensionService;
21
import org.eclipse.jface.preference.IPreferenceStore;
27
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.jface.preference.PreferenceManager;
28
import org.eclipse.jface.preference.PreferenceManager;
23
import org.eclipse.jface.resource.ImageDescriptor;
29
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.resource.ImageRegistry;
30
import org.eclipse.jface.resource.ImageRegistry;
25
import org.eclipse.jface.window.Window;
31
import org.eclipse.jface.window.Window;
32
import org.eclipse.rap.ui.interactiondesign.layout.LayoutRegistry;
26
import org.eclipse.rwt.SessionSingletonBase;
33
import org.eclipse.rwt.SessionSingletonBase;
27
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.custom.BusyIndicator;
35
import org.eclipse.swt.custom.BusyIndicator;
29
import org.eclipse.ui.*;
36
import org.eclipse.ui.IEditorRegistry;
37
import org.eclipse.ui.IElementFactory;
38
import org.eclipse.ui.IPerspectiveRegistry;
39
import org.eclipse.ui.ISharedImages;
40
import org.eclipse.ui.IWorkbench;
41
import org.eclipse.ui.IWorkingSetManager;
42
import org.eclipse.ui.PlatformUI;
30
import org.eclipse.ui.internal.StartupThreading.StartupRunnable;
43
import org.eclipse.ui.internal.StartupThreading.StartupRunnable;
31
import org.eclipse.ui.internal.branding.BrandingExtension;
44
import org.eclipse.ui.internal.branding.BrandingExtension;
32
import org.eclipse.ui.internal.decorators.DecoratorManager;
45
import org.eclipse.ui.internal.decorators.DecoratorManager;
Lines 35-53 Link Here
35
import org.eclipse.ui.internal.operations.WorkbenchOperationSupport;
48
import org.eclipse.ui.internal.operations.WorkbenchOperationSupport;
36
import org.eclipse.ui.internal.progress.JobManagerAdapter;
49
import org.eclipse.ui.internal.progress.JobManagerAdapter;
37
import org.eclipse.ui.internal.progress.ProgressManager;
50
import org.eclipse.ui.internal.progress.ProgressManager;
38
import org.eclipse.ui.internal.registry.*;
51
import org.eclipse.ui.internal.registry.ActionSetRegistry;
52
import org.eclipse.ui.internal.registry.EditorRegistry;
53
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
54
import org.eclipse.ui.internal.registry.PerspectiveRegistry;
55
import org.eclipse.ui.internal.registry.PreferencePageRegistryReader;
56
import org.eclipse.ui.internal.registry.ViewRegistry;
57
import org.eclipse.ui.internal.registry.WorkingSetRegistry;
39
import org.eclipse.ui.internal.servlet.EntryPointExtension;
58
import org.eclipse.ui.internal.servlet.EntryPointExtension;
40
import org.eclipse.ui.internal.servlet.HttpServiceTracker;
59
import org.eclipse.ui.internal.servlet.HttpServiceTracker;
41
import org.eclipse.ui.internal.themes.*;
60
import org.eclipse.ui.internal.themes.IThemeRegistry;
61
import org.eclipse.ui.internal.themes.ThemeRegistry;
62
import org.eclipse.ui.internal.themes.ThemeRegistryReader;
42
import org.eclipse.ui.internal.util.BundleUtility;
63
import org.eclipse.ui.internal.util.BundleUtility;
43
import org.eclipse.ui.internal.util.SWTResourceUtil;
64
import org.eclipse.ui.internal.util.SWTResourceUtil;
44
import org.eclipse.ui.internal.wizards.*;
65
import org.eclipse.ui.internal.wizards.ExportWizardRegistry;
66
import org.eclipse.ui.internal.wizards.ImportWizardRegistry;
67
import org.eclipse.ui.internal.wizards.NewWizardRegistry;
45
import org.eclipse.ui.operations.IWorkbenchOperationSupport;
68
import org.eclipse.ui.operations.IWorkbenchOperationSupport;
46
import org.eclipse.ui.plugin.AbstractUIPlugin;
69
import org.eclipse.ui.plugin.AbstractUIPlugin;
47
import org.eclipse.ui.presentations.AbstractPresentationFactory;
70
import org.eclipse.ui.presentations.AbstractPresentationFactory;
48
import org.eclipse.ui.views.IViewRegistry;
71
import org.eclipse.ui.views.IViewRegistry;
49
import org.eclipse.ui.wizards.IWizardRegistry;
72
import org.eclipse.ui.wizards.IWizardRegistry;
50
import org.osgi.framework.*;
73
import org.osgi.framework.Bundle;
74
import org.osgi.framework.BundleContext;
75
import org.osgi.framework.BundleEvent;
76
import org.osgi.framework.BundleListener;
77
import org.osgi.framework.InvalidSyntaxException;
78
import org.osgi.framework.ServiceReference;
79
import org.osgi.framework.SynchronousBundleListener;
51
import org.osgi.util.tracker.ServiceTracker;
80
import org.osgi.util.tracker.ServiceTracker;
52
81
53
import com.ibm.icu.text.MessageFormat;
82
import com.ibm.icu.text.MessageFormat;
Lines 1043-1049 Link Here
1043
          }
1072
          }
1044
        };
1073
        };
1045
        httpContextExtensionServiceTracker.open();
1074
        httpContextExtensionServiceTracker.open();
1046
1075
        
1076
        // Initialize Layout and layoutSets.
1077
        LayoutRegistry registry = LayoutRegistry.getInstance();
1078
        registry.init();
1079
        
1047
        
1080
        
1048
// RAP [fappel]: as workbench instances in RAP run in session scope the
1081
// RAP [fappel]: as workbench instances in RAP run in session scope the
1049
//               UI bundle should be initialized in time
1082
//               UI bundle should be initialized in time
(-)Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java (-14 / +31 lines)
Lines 14-19 Link Here
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.ListenerList;
18
import org.eclipse.core.runtime.ListenerList;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.jface.util.PropertyChangeEvent;
Lines 22-27 Link Here
22
import org.eclipse.swt.graphics.Rectangle;
23
import org.eclipse.swt.graphics.Rectangle;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.ToolBar;
25
import org.eclipse.ui.IPropertyListener;
27
import org.eclipse.ui.IPropertyListener;
26
import org.eclipse.ui.ISharedImages;
28
import org.eclipse.ui.ISharedImages;
27
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.PlatformUI;
Lines 74-79 Link Here
74
    private boolean isDirty = false;
76
    private boolean isDirty = false;
75
    private boolean isBusy = false;
77
    private boolean isBusy = false;
76
    private boolean hasViewMenu = false;
78
    private boolean hasViewMenu = false;
79
80
    // RAP [hs] IAdaptable for interactiondesign API
81
    private IAdaptable adaptable;
77
   
82
   
78
    /**
83
    /**
79
     * Constructor
84
     * Constructor
Lines 283-292 Link Here
283
	 * @see org.eclipse.ui.presentations.IPresentablePart#getToolBar()
288
	 * @see org.eclipse.ui.presentations.IPresentablePart#getToolBar()
284
	 */
289
	 */
285
    public Control getToolBar() {
290
    public Control getToolBar() {
286
        if (enableOutputs) {
291
      Control result = null;
287
			return getPane().getToolBar();
292
      // RAP [hs] patched for interactiondesign API
288
		}
293
      if( adaptable != null ) {
289
		return null;
294
        result = ( Control ) adaptable.getAdapter( ToolBar.class );
295
      } else if (enableOutputs) {
296
        result = getPane().getToolBar();
297
       
298
      }
299
      return result;
290
    }
300
    }
291
301
292
    /*
302
    /*
Lines 296-302 Link Here
296
	 */
306
	 */
297
    public IPartMenu getMenu() {
307
    public IPartMenu getMenu() {
298
        boolean hasMenu;
308
        boolean hasMenu;
299
        
309
        IPartMenu result = null;
300
        if (enableOutputs) {
310
        if (enableOutputs) {
301
            hasMenu = part.hasViewMenu();
311
            hasMenu = part.hasViewMenu();
302
        } else {
312
        } else {
Lines 306-321 Link Here
306
        if (!hasMenu) {
316
        if (!hasMenu) {
307
            return null;
317
            return null;
308
        }
318
        }
309
319
        // RAP [hs] patched for interactiondesign API
310
        if (viewMenu == null) {
320
        if( adaptable != null ) {
311
            viewMenu = new IPartMenu() {
321
          viewMenu = ( IPartMenu ) adaptable.getAdapter( IPartMenu.class );
312
                public void showMenu(Point location) {
322
          
313
                    part.showViewMenu(location);
323
        } else if (viewMenu == null) {
314
                }
324
          viewMenu = new IPartMenu() {
315
            };
325
            public void showMenu(Point location) {
326
              part.showViewMenu(location);
327
            }
328
          };
316
        }
329
        }
317
330
        result = viewMenu;
318
        return viewMenu;
331
        return result;
319
    }
332
    }
320
333
321
    /* (non-Javadoc)
334
    /* (non-Javadoc)
Lines 415-419 Link Here
415
	    return getPane().getSizeFlags(width);
428
	    return getPane().getSizeFlags(width);
416
	}
429
	}
417
430
431
  public void setConfigurationAdaptable( IAdaptable adaptable ) {
432
    this.adaptable = adaptable;
433
  }
434
418
435
419
}
436
}
(-)META-INF/MANIFEST.MF (-3 / +6 lines)
Lines 11-16 Link Here
11
Bundle-Vendor: %providerName
11
Bundle-Vendor: %providerName
12
Bundle-Localization: plugin
12
Bundle-Localization: plugin
13
Export-Package: org.eclipse.rap.ui.branding,
13
Export-Package: org.eclipse.rap.ui.branding,
14
 org.eclipse.rap.ui.interactiondesign,
15
 org.eclipse.rap.ui.interactiondesign.layout,
16
 org.eclipse.rap.ui.interactiondesign.layout.model,
14
 org.eclipse.ui;ui.workbench=split;mandatory:="ui.workbench",
17
 org.eclipse.ui;ui.workbench=split;mandatory:="ui.workbench",
15
 org.eclipse.ui.about,
18
 org.eclipse.ui.about,
16
 org.eclipse.ui.actions;ui.workbench=split;mandatory:="ui.workbench",
19
 org.eclipse.ui.actions;ui.workbench=split;mandatory:="ui.workbench",
Lines 96-106 Link Here
96
 org.eclipse.equinox.http.registry,
99
 org.eclipse.equinox.http.registry,
97
 org.eclipse.osgi.services
100
 org.eclipse.osgi.services
98
Import-Package: com.ibm.icu.text,
101
Import-Package: com.ibm.icu.text,
102
 javax.servlet;version="[2.3.0,2.5.0]",
103
 javax.servlet.http;version="[2.3.0,2.5.0]",
99
 javax.xml.parsers,
104
 javax.xml.parsers,
100
 org.w3c.dom,
105
 org.w3c.dom,
101
 org.xml.sax,
106
 org.xml.sax
102
 javax.servlet;version="[2.3.0,2.5.0]",
103
 javax.servlet.http;version="[2.3.0,2.5.0]"
104
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
107
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
105
 CDC-1.0/Foundation-1.0,
108
 CDC-1.0/Foundation-1.0,
106
 J2SE-1.3
109
 J2SE-1.3
(-)Eclipse (+456 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign;
11
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.core.runtime.IExtensionPoint;
16
import org.eclipse.core.runtime.IExtensionRegistry;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.rwt.branding.AbstractBranding;
20
import org.eclipse.rwt.internal.branding.BrandingUtil;
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.graphics.Rectangle;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.ToolBar;
26
import org.eclipse.ui.IMemento;
27
import org.eclipse.ui.internal.presentations.NativeStackPresentation;
28
import org.eclipse.ui.internal.presentations.PresentablePart;
29
import org.eclipse.ui.presentations.IPartMenu;
30
import org.eclipse.ui.presentations.IPresentablePart;
31
import org.eclipse.ui.presentations.IPresentationSerializer;
32
import org.eclipse.ui.presentations.IStackPresentationSite;
33
import org.eclipse.ui.presentations.StackPresentation;
34
35
36
class ConfigurableStackProxy extends StackPresentation {
37
  
38
  public static final String STACK_PRESENTATION_ID = "stackPresentationId"; 
39
  
40
  private StackPresentation currentStackPresentation;
41
  
42
  private NativeStackPresentation nativeStackPresentation;
43
44
  private Composite parent;
45
  private IStackPresentationSite site;
46
  private String type;
47
  private String currentId;
48
  private boolean showTitle = false;
49
50
  
51
  private IConfigurationElement brandingElement;
52
  
53
  public ConfigurableStackProxy( 
54
    final Composite parent, 
55
    final IStackPresentationSite stackSite, 
56
    final String type ) 
57
  {
58
    super( stackSite );
59
    this.parent = parent;
60
    this.site = stackSite;
61
    this.type = type;
62
    currentId = "";
63
    nativeStackPresentation = new NativeStackPresentation( parent, stackSite );
64
    
65
    currentStackPresentation 
66
      = loadStackPresentations( this.type, this.site, this.parent );
67
    if( currentStackPresentation == null ) {
68
      currentStackPresentation = nativeStackPresentation;
69
    }
70
  }
71
72
  public void addPart( final IPresentablePart newPart, final Object cookie ) {
73
    StackPresentation delegate = getDelegate();
74
    if( delegate instanceof ConfigurableStack ) {
75
      IAdaptable adaptable = getConfigAdaptable();
76
      if( newPart instanceof PresentablePart ) {
77
        PresentablePart part = ( PresentablePart ) newPart;
78
        part.setConfigurationAdaptable( adaptable );
79
      }
80
    }
81
    delegate.addPart( newPart, cookie );
82
  }
83
  
84
  private boolean brandingPresentationFactoryExists() {
85
    boolean result = false;
86
    String id = getBrandingPresentationFactoryId();
87
    if( id != null ) {
88
      result = true;
89
    }
90
    return result;
91
  }
92
93
  public Point computeMinimumSize() {
94
    return getDelegate().computeMinimumSize();
95
  }
96
  
97
  public int computePreferredSize( boolean width,
98
                                   int availableParallel,
99
                                   int availablePerpendicular,
100
                                   int preferredResult )
101
  {
102
    return getDelegate().computePreferredSize( width, 
103
                                               availableParallel, 
104
                                               availablePerpendicular, 
105
                                               preferredResult );
106
  }
107
  
108
  private ConfigurableStack createStackById( final String stackId ) {
109
    ConfigurableStack result = null;
110
    IExtensionRegistry registry = Platform.getExtensionRegistry();
111
    String stackPresentationExtId = ConfigurableStack.STACK_PRESENTATION_EXT_ID;
112
    IExtensionPoint point = registry.getExtensionPoint( stackPresentationExtId );
113
    if( point != null ) {
114
      IConfigurationElement[] elements = point.getConfigurationElements();
115
      boolean found = false;
116
      for( int i = 0; i < elements.length && !found; i++ ) {
117
        String id = elements[ i ].getAttribute( "id" );
118
        //String presentationType = elements[ i ].getAttribute( "type" );
119
        if( id.equals( stackId ) ) {
120
          found = true;
121
          try {
122
          Object obj = elements[ i ].createExecutableExtension( "class" );
123
          result = ( ConfigurableStack ) obj; 
124
          result.init( site, id, parent, this );
125
          } catch( CoreException e ) {
126
            // nothing todo
127
          }
128
        }
129
      }
130
    }
131
    return result;
132
  }
133
  
134
  public void dispose() {
135
    getDelegate().dispose();
136
  }
137
138
  // Delegate methods
139
140
  private IConfigurationElement getBrandingElement() {
141
    if( brandingElement == null ) {
142
      AbstractBranding branding = BrandingUtil.findBranding();
143
      if( branding != null ) {
144
        String brandingId = branding.getId();
145
        IExtensionRegistry registry = Platform.getExtensionRegistry();
146
        String id = "org.eclipse.rap.ui.branding";
147
        IExtensionPoint brandingPoint = registry.getExtensionPoint( id );
148
        if( brandingPoint != null ) {
149
          IConfigurationElement[] elements 
150
            = brandingPoint.getConfigurationElements();
151
          
152
          boolean found = false;
153
          for( int i = 0; i < elements.length && !found; i++ ) {
154
            String tempId = elements[ i ].getAttribute( "id" );
155
            if( tempId.equals( brandingId ) ) {
156
              found = true;
157
              brandingElement = elements[ i ];
158
            }
159
          }            
160
        }
161
      }
162
    }
163
    return brandingElement;
164
  }
165
166
  private String getBrandingPresentationFactoryId() {
167
    return loadBrandingPresentationFactoryId( getBrandingElement() );
168
  }
169
170
  private IAdaptable getConfigAdaptable() {
171
    IAdaptable adaptable = new IAdaptable() {
172
173
      public Object getAdapter( Class adapter ) {
174
        Object result = null;
175
        if( currentStackPresentation instanceof ConfigurableStack ) { 
176
          ConfigurableStack stackPresentation  
177
            = ( ConfigurableStack ) currentStackPresentation;
178
          if( adapter == ToolBar.class ) {
179
            result = stackPresentation.createPartToolBar( );
180
          } else if( adapter == IPartMenu.class ) {
181
            result = stackPresentation.createViewMenu();
182
          }
183
        }
184
        return result;
185
      }
186
      
187
    };
188
    return adaptable;
189
  }
190
191
  public Control getControl() {
192
    return getDelegate().getControl();
193
  }
194
195
  public ConfigurableStack getCurrentStackPresentation() {
196
    ConfigurableStack result = null;
197
    if( currentStackPresentation instanceof ConfigurableStack ) {
198
      result = ( ConfigurableStack ) currentStackPresentation;
199
    }
200
    return result;
201
  }
202
203
  private  StackPresentation getDelegate() {
204
    StackPresentation result;
205
    if( currentStackPresentation != null ) {
206
      result = currentStackPresentation;
207
    } else {
208
      result = nativeStackPresentation;
209
    }
210
    return result;
211
  }
212
213
  protected boolean getShowTitle() {
214
    return showTitle;
215
  }
216
  
217
  public int getSizeFlags( boolean width ) {
218
    return getDelegate().getSizeFlags( width );
219
  }
220
221
  public Control[] getTabList( IPresentablePart part ) {
222
    return getDelegate().getTabList( part );
223
  }
224
225
  private String loadBrandingPresentationFactoryId( 
226
    final IConfigurationElement element )
227
  {
228
    String result = null;
229
    if( element != null ) {
230
      IConfigurationElement[] factory 
231
        = element.getChildren( "presentationFactory" );
232
      if( factory.length > 0 ) {
233
        result = factory[ 0 ].getAttribute( "id" );
234
      }
235
    }
236
    return result;
237
  }
238
239
  private ConfigurableStack loadDefaultPartStack() {
240
    ConfigurableStack result = null;
241
    IConfigurationElement element = getBrandingElement();
242
    IConfigurationElement[] factory 
243
      = element.getChildren( "presentationFactory" );
244
    if( factory.length > 0 ) {
245
      IConfigurationElement[] stacks 
246
        = factory[ 0 ].getChildren( "defaultStackPresentation" );
247
      if( stacks.length > 0 ) {
248
        String id = stacks[ 0 ].getAttribute( "id" );
249
        result = createStackById( id );
250
      }
251
    }
252
    return result;
253
  }
254
255
  private ConfigurableStack loadLayoutPartStack() {
256
    ConfigurableStack result = null;
257
    IConfigurationElement element = getBrandingElement();
258
    IConfigurationElement[] factory 
259
      = element.getChildren( "presentationFactory" );
260
    if( factory.length > 0 ) {
261
      IConfigurationElement[] stacks 
262
        = factory[ 0 ].getChildren( "stackPresentation" );
263
      if( stacks.length > 0 ) {
264
        String layoutPartId = ConfigurableStack.getLayoutPartId( site );
265
        boolean found = false;
266
        for( int i = 0; i < stacks.length && !found; i++ ) {
267
          String partId = stacks[ i ].getAttribute( "partId" );
268
          if( partId.equals( layoutPartId ) ) {
269
            String stackId = stacks[ i ].getAttribute( "id" );
270
            result = createStackById( stackId );
271
            found = true;
272
          }
273
        }
274
      }
275
    }
276
    return result;
277
  }
278
279
  private ConfigurableStack loadStackFromBranding() {
280
    ConfigurableStack result = loadLayoutPartStack();
281
    if( result == null ) {
282
      result = loadDefaultPartStack();
283
    } 
284
    return result;
285
  }
286
  
287
  /*
288
   * load the saved or default StackPresentation from extension registry
289
   */
290
  private ConfigurableStack loadStackPresentations( 
291
    final String type, 
292
    final IStackPresentationSite site,
293
    final Composite parent ) 
294
  {
295
    this.parent = parent;
296
    ConfigurableStack result = null;
297
    IExtensionRegistry registry = Platform.getExtensionRegistry();
298
    String stackPresentationExtId = ConfigurableStack.STACK_PRESENTATION_EXT_ID;
299
    IExtensionPoint point = registry.getExtensionPoint( stackPresentationExtId );
300
    if( point != null ) {
301
      IConfigurationElement[] elements = point.getConfigurationElements();
302
      
303
      String savedStackId  = ConfigurableStack.getSavedStackId( site );
304
      
305
      boolean error = false;
306
      boolean found = false;
307
      for( int i = 0; !error && !found && i < elements.length; i++ ) {
308
        
309
        String id = elements[ i ].getAttribute( "id" );
310
        String presentationType = elements[ i ].getAttribute( "type" );
311
312
        if( savedStackId.equals( IPreferenceStore.STRING_DEFAULT_DEFAULT ) ) {
313
          // No id is saved, check branding Presentationfactory
314
          if( brandingPresentationFactoryExists() ) {
315
            ConfigurableStack tempStack = loadStackFromBranding();
316
            if( tempStack != null ) {
317
              result = tempStack;
318
              currentId = id;
319
            } else {
320
              result = null;
321
            }
322
            found = true;
323
          } else {
324
            result = null;
325
            found = true;
326
          }
327
          
328
        } else {
329
          // their is a saved id, loading the stackPresentation if the id 
330
          // matches the saved id
331
          if( id.equals( savedStackId ) && presentationType.equals( type ) ) {
332
            result = createStackById( id );
333
            currentId = id;
334
            found = true;
335
          }
336
        }
337
338
      }
339
    }
340
    return result;
341
  }
342
343
  public void movePart( final IPresentablePart toMove, final Object cookie ) {
344
    getDelegate().movePart( toMove, cookie );
345
  }
346
347
  public void refreshStack() {
348
    if( !currentId.equals( "" ) ) {
349
      setCurrentStackPresentation( currentId );
350
    }
351
    
352
  }
353
354
  public void removePart( final IPresentablePart oldPart ) {
355
    getDelegate().removePart( oldPart );
356
  }
357
358
  public void restoreState( 
359
    final IPresentationSerializer context, final IMemento memento )
360
  {
361
    getDelegate().restoreState( context, memento );
362
  }
363
364
  public void saveState( 
365
    final IPresentationSerializer context, final IMemento memento ) 
366
  {
367
    getDelegate().saveState( context, memento );
368
  }
369
370
  public void selectPart( final IPresentablePart toSelect ) {
371
    getDelegate().selectPart( toSelect );
372
  }
373
374
  public void setActive( final int newState ) {
375
    getDelegate().setActive( newState );
376
  }
377
378
  public void setBounds( final Rectangle bounds ) {
379
    getDelegate().setBounds( bounds );
380
  }
381
382
  public void setCurrentStackPresentation( final String id ) {
383
    
384
    IExtensionRegistry registry = Platform.getExtensionRegistry();
385
    String stackPresentationExtId = ConfigurableStack.STACK_PRESENTATION_EXT_ID;
386
    IExtensionPoint point 
387
      = registry.getExtensionPoint( stackPresentationExtId );
388
    
389
    IConfigurationElement elements[] = point.getConfigurationElements();
390
    
391
    Object stackObj = null;
392
    for( int i = 0; stackObj == null && i < elements.length; i++ ) {
393
      String attributeId = elements[ i ].getAttribute( "id" );
394
      if( attributeId.equals( id ) ) {
395
        currentId = id;
396
        try {
397
          Rectangle bounds = currentStackPresentation.getControl().getBounds();
398
          
399
          stackObj = elements[ i ].createExecutableExtension( "class" );
400
          if( stackObj instanceof ConfigurableStack ) {
401
            
402
            ConfigurableStack newStackPresentation 
403
              = ( ConfigurableStack ) stackObj;
404
            newStackPresentation.init( site, id, parent, this );
405
406
            
407
            Control control = currentStackPresentation.getControl();
408
            control.dispose();
409
            
410
            IPresentablePart[] parts = site.getPartList();
411
            for( int j = 0; j < parts.length; j++ ) {
412
              newStackPresentation.addPart( parts[ j ], null );
413
              currentStackPresentation.removePart( parts[ j ] );
414
            }  
415
            newStackPresentation.selectPart( site.getSelectedPart() );
416
            
417
            currentStackPresentation.getControl().dispose();
418
            currentStackPresentation.dispose();
419
            currentStackPresentation = newStackPresentation;
420
            currentStackPresentation.setBounds( bounds );
421
            
422
          }
423
        } catch( CoreException e ) {
424
          e.printStackTrace();
425
        }
426
        
427
      }
428
    }   
429
    
430
  }
431
432
  protected void setShowTitle( boolean showTitle ) {
433
    this.showTitle = showTitle;
434
  }
435
436
  public void setState( final int state ) {
437
    getDelegate().setState( state );
438
  }
439
440
  public void setVisible( final boolean isVisible ) {
441
    getDelegate().setVisible( isVisible );
442
  }
443
444
  public void showPaneMenu() {
445
    getDelegate().showPaneMenu();
446
  }
447
448
  public void showPartList() {
449
    getDelegate().showPartList();
450
  }
451
452
  public void showSystemMenu() {
453
    getDelegate().showSystemMenu();
454
  }
455
    
456
}
(-)Eclipse (+157 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign.layout.model;
11
12
import java.util.HashMap;
13
import java.util.Map;
14
15
import org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder;
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.Font;
18
import org.eclipse.swt.layout.FormData;
19
20
/**
21
 * A <code>LayoutSet</code> object can hold different components for a <code>
22
 * {@link ElementBuilder}</code>. These can be <code>Image</code>, <code>Color
23
 * </code>, <code>Font</code> and <code>FormData</code> objects.
24
 * <p>
25
 * Actually this class it's just a container for additional objects.
26
 * </p>
27
 * 
28
 * @since 1.2
29
 * 
30
 * @see ElementBuilder
31
 */
32
public class LayoutSet {    
33
  
34
  private String id;
35
  private Map imageMap = new HashMap();
36
  private Map fontMap = new HashMap();
37
  private Map colorMap = new HashMap();
38
  private Map positionMap = new HashMap();
39
40
  /**
41
   * Instantiate an object of this class with a given id. This id is contributed
42
   * in the attributes of the <code>org.eclipse.ui.presentations.Layouts
43
   * </code> extension point.
44
   * 
45
   * @param id the id of the <code>LayoutSet</code>
46
   */
47
  public LayoutSet( final String id ) {
48
    this.id = id;
49
  }
50
  
51
  /**
52
   * Adds a <code>Color</code> object. The object is couples to a key, which 
53
   * is defined by the <code>{@link ElementBuilder}</code> implementation. 
54
   *  
55
   * @param key the key for the <code>color</code> object.
56
   * @param color the <code>Color</code> object to add.
57
   * 
58
   * @see ElementBuilder
59
   */
60
  public void addColor( final String key, final Color color ) {
61
    colorMap.put( key, color );
62
  }
63
  
64
  /**
65
   * Adds a <code>Font</code> object. The object is couples to a key, which 
66
   * is defined by the <code>{@link ElementBuilder}</code> implementation. 
67
   *  
68
   * @param key the key for the <code>Font</code> object.
69
   * @param font the <code>Font</code> object to add.
70
   * 
71
   * @see ElementBuilder
72
   */
73
  public void addFont( final String key, final Font font ) {
74
    fontMap.put( key, font );
75
  }
76
  
77
  /**
78
   * Adds a path of a image. This path is coupled to a key, which is defined by
79
   * the <code>{@link ElementBuilder}</code> implementation. The path of the 
80
   * image should be relative to the plug-in root, which the image belongs to.
81
   * 
82
   * @param key the key for the image path. 
83
   * @param imagePath the relative image path.
84
   * 
85
   * @see ElementBuilder
86
   */
87
  public void addImagePath( final String key, final String imagePath ) {
88
    imageMap.put( key, imagePath ); 
89
  }
90
  
91
  /**
92
   * Adds a <code>FormData</code> object. The object is couples to a key, which 
93
   * is defined by the <code>{@link ElementBuilder}</code> implementation. 
94
   * 
95
   * @param key the key for the <code>FormData</code> object.
96
   * @param position the <code>FormData</code> object to add.
97
   * 
98
   * @see ElementBuilder
99
   */
100
  public void addPosition( final String key, final FormData position ) {
101
    positionMap.put( key, position );
102
  }
103
  
104
  /**
105
   * Returns the <code>Color</code> object for the given key.
106
   * 
107
   * @param key the key for the <code>Color</code> object.
108
   * 
109
   * @return the <code>Color</code> object.
110
   */
111
  public Color getColor( final String key ) {
112
    return ( Color ) colorMap.get( key );
113
  }
114
  
115
  /**
116
   * Returns the <code>Font</code> object for the given key.
117
   * 
118
   * @param key the key for the <code>Font</code> object.
119
   * 
120
   * @return the <code>Font</code> object.
121
   */
122
  public Font getFont( final String key ) {
123
    return ( Font ) fontMap.get( key );
124
  }
125
  
126
  /**
127
   * Returns the id of a <code>LayoutSet</code> object.
128
   * 
129
   * @return the id.
130
   */
131
  public String getId() {
132
    return id;
133
  }
134
  
135
  /**
136
   * Returns the image path for the given key.
137
   * 
138
   * @param key the key for the image path.
139
   * 
140
   * @return the recursive image path.
141
   */
142
  public String getImagePath( final String key ) {
143
    return ( String ) imageMap.get( key );
144
  }
145
  
146
  /**
147
   * Returns the <code>FormData</code> object for the given key.
148
   * 
149
   * @param key the key for the <code>FormData</code> object.
150
   * 
151
   * @return the <code>FormData</code> object.
152
   */
153
  public FormData getPosition( final String key ) {
154
    return ( FormData ) positionMap.get( key );
155
  }
156
157
}
(-)Eclipse (+540 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign;
11
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.IConfigurationElement;
14
import org.eclipse.core.runtime.IExtensionPoint;
15
import org.eclipse.core.runtime.IExtensionRegistry;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.jface.action.ActionContributionItem;
18
import org.eclipse.jface.action.IContributionItem;
19
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.action.IToolBarManager;
21
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
22
import org.eclipse.jface.preference.IPreferenceStore;
23
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.IViewPart;
29
import org.eclipse.ui.IViewSite;
30
import org.eclipse.ui.IWorkbench;
31
import org.eclipse.ui.IWorkbenchPage;
32
import org.eclipse.ui.IWorkbenchWindow;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.internal.DefaultStackPresentationSite;
35
import org.eclipse.ui.internal.LayoutPart;
36
import org.eclipse.ui.internal.PartPane;
37
import org.eclipse.ui.internal.WorkbenchPage;
38
import org.eclipse.ui.internal.presentations.PresentablePart;
39
import org.eclipse.ui.internal.util.PrefUtil;
40
import org.eclipse.ui.part.ViewPart;
41
import org.eclipse.ui.plugin.AbstractUIPlugin;
42
import org.eclipse.ui.preferences.ScopedPreferenceStore;
43
import org.eclipse.ui.presentations.IPartMenu;
44
import org.eclipse.ui.presentations.IPresentablePart;
45
import org.eclipse.ui.presentations.IStackPresentationSite;
46
import org.eclipse.ui.presentations.StackPresentation;
47
48
/**
49
 * This represents an object, which extends the original <code>
50
 * {@link StackPresentation}</code>. 
51
 * <p>
52
 * You can do everything with this as you can do with the original one. It 
53
 * just provides more methods for making a StackPresentation configurable.
54
 * </p>
55
 * 
56
 * @see StackPresentation
57
 * @since 1.3
58
 */
59
public abstract class ConfigurableStack extends StackPresentation {
60
61
  /**
62
   * Extension Point ID of the StackPresentation Extension point.
63
   */
64
  public static final String STACK_PRESENTATION_EXT_ID 
65
    = "org.eclipse.rap.ui.stackPresentations";
66
  
67
  private static final String CONFIG_ACTION_NAME = "actionClass";
68
  
69
  private static IStackPresentationSite siteDummy 
70
    = new IStackPresentationSite() 
71
  {
72
73
    public void addSystemActions( IMenuManager menuManager ) {
74
      
75
    }
76
77
    public void close( IPresentablePart[] toClose ) {
78
      
79
    }
80
81
    public void dragStart( IPresentablePart beingDragged,
82
                           Point initialPosition,
83
                           boolean keyboard )
84
    {
85
      
86
    }
87
88
    public void dragStart( Point initialPosition, boolean keyboard ) {
89
      
90
    }
91
92
    public void flushLayout() {
93
      
94
    }
95
96
    public IPresentablePart[] getPartList() {
97
      return null;
98
    }
99
100
    public String getProperty( String id ) {
101
      return null;
102
    }
103
104
    public IPresentablePart getSelectedPart() {
105
      return null;
106
    }
107
108
    public int getState() {
109
      return 0;
110
    }
111
112
    public boolean isCloseable( IPresentablePart toClose ) {
113
      return false;
114
    }
115
116
    public boolean isPartMoveable( IPresentablePart toMove ) {
117
      return false;
118
    }
119
120
    public boolean isStackMoveable() {
121
      return false;
122
    }
123
124
    public void selectPart( IPresentablePart toSelect ) {
125
      
126
    }
127
128
    public void setState( int newState ) {
129
      
130
    }
131
132
    public boolean supportsState( int state ) {
133
      return false;
134
    }
135
    
136
  };
137
  /**
138
   * This method is used for getting the <code>{@link LayoutPart}</code> ID for 
139
   * a specific <code>IStackPresentationSite</code>. Their is no other 
140
   * oppertunity to get this id.
141
   * 
142
   * @param site an instance of <code>IStackPreentationSite</code>.
143
   * 
144
   * @return the unique <code>LayoutPart</code> ID defined in a Perspective or 
145
   * <code>null</code> if their is no id.
146
   * 
147
   * @see LayoutPart
148
   * @see IStackPresentationSite
149
   */
150
  public static final String getLayoutPartId( 
151
    final IStackPresentationSite site ) 
152
  {
153
    String result = null;
154
    if( site != null && site instanceof DefaultStackPresentationSite ) {
155
      DefaultStackPresentationSite defaultSite 
156
        = ( DefaultStackPresentationSite) site;
157
      result = defaultSite.getProperty( "id" );     
158
    }
159
    return result;
160
  }
161
  /**
162
   * Loads the saved <code>ConfigurableStack</code> id from the preferences
163
   * store using a specific <code>IStackPresentationSite</code>. This id is
164
   * needed to instantiate the <code>ConfigurableStack</code> for a specific
165
   * LayoutPart.
166
   * 
167
   * @param site an instance of <code>IStackPreentationSite</code>.
168
   * 
169
   * @return the saved <code>ConfigurableStack</code> id for the part 
170
   * represented by the <code>IStackPresentationSite</code> or <code>null</code>
171
   * if no id is saved.
172
   * 
173
   * @see LayoutPart
174
   * @see IStackPresentationSite
175
   */
176
  public static String getSavedStackId( final IStackPresentationSite site ) {
177
    String layoutPartId = null;
178
    String result = IPreferenceStore.STRING_DEFAULT_DEFAULT;
179
    
180
    layoutPartId = getLayoutPartId( site );
181
    
182
    if( layoutPartId != null ) {    
183
      ScopedPreferenceStore prefStore
184
        = ( ScopedPreferenceStore )PrefUtil.getAPIPreferenceStore();
185
      String stackPresentationId = ConfigurableStackProxy.STACK_PRESENTATION_ID;
186
      String stackPresentationKey = stackPresentationId + "/" + layoutPartId;
187
      result = prefStore.getString( stackPresentationKey );
188
    }
189
    
190
    return result;
191
  }
192
  private IStackPresentationSite site;
193
  private String stackPresentationId;
194
  
195
  private Composite parent;
196
  private ConfigurableStackProxy proxy;
197
    
198
  
199
  private ConfigurationAction configAction;
200
201
  protected ImageDescriptor menuIcon;
202
  
203
  /**
204
   * Instantiate an object of this class by calling the super constructor with
205
   * a dummy <code>{@link IStackPresentationSite}</code>.
206
   * 
207
   * @see IStackPresentationSite
208
   */
209
  public ConfigurableStack() {
210
    super( siteDummy );
211
  }
212
  
213
  Control createPartToolBar() {
214
    Control result = null;
215
    IToolBarManager manager = getPartToolBarManager();
216
    ConfigurationAction action = getConfigAction();
217
    IStackPresentationSite site = getSite();
218
    int actionCount = 0;
219
    if( action != null && manager != null ) {
220
      
221
      IContributionItem[] items = manager.getItems();
222
      String paneId = getPaneId( site );
223
      
224
      Composite toolBarParent = null;
225
      IPresentablePart selectedPart = site.getSelectedPart();
226
      if( selectedPart instanceof PresentablePart ) {
227
        PresentablePart part = ( PresentablePart ) selectedPart;
228
        Control nativeToolBar = part.getPane().getToolBar();
229
        if( nativeToolBar != null ) {
230
          nativeToolBar.setVisible( false );
231
          toolBarParent = nativeToolBar.getParent();
232
        }
233
        
234
      }
235
      if( toolBarParent == null ) {
236
        IWorkbench workbench = PlatformUI.getWorkbench();
237
        IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();
238
        IWorkbenchPage activePage = activeWindow.getActivePage();
239
        if( activePage instanceof WorkbenchPage ) {
240
          toolBarParent = ( ( WorkbenchPage ) activePage ).getClientComposite();
241
        }
242
      }
243
244
      for( int i = 0; i < items.length; i++ ) {
245
        items[ i ].setVisible( true );
246
      }
247
      
248
      if( toolBarParent != null ) {  
249
        IToolBarManager2 toolBarManager = null;
250
        if( items.length > 0 && ( manager instanceof IToolBarManager2 ) ) {
251
          toolBarManager = ( IToolBarManager2 ) manager;                        
252
          result = toolBarManager.createControl2( toolBarParent );
253
          toolBarManager.update( false );
254
        }
255
        
256
        for( int i = 0; i < items.length; i++ ) {
257
          if( items[ i ] instanceof ActionContributionItem ) {
258
            ActionContributionItem actionItem 
259
              = ( ActionContributionItem ) items[ i ];
260
            String actionId = actionItem.getAction().getId();
261
            boolean isVisible 
262
              = action.loadViewActionVisibility( paneId, actionId );
263
   
264
            if( isVisible ) {     
265
              actionItem.setVisible( true );
266
              actionCount++;
267
            } else {              
268
              actionItem.setVisible( false );
269
            }
270
          } 
271
        }
272
        
273
        if( toolBarManager != null && result != null ) {
274
          toolBarManager.update( false );
275
        }      
276
                        
277
      } 
278
      if( actionCount <= 0 ) {
279
        result = null;
280
      } 
281
      if( result != null ) {
282
        result.pack();
283
        result.setVisible( true );
284
      } 
285
    }
286
    
287
    return result;
288
  }
289
  
290
  IPartMenu createViewMenu() {
291
    
292
    IPartMenu result = null;
293
    if( isPartMenuVisisble() ) {    
294
      result = new IPartMenu() {
295
        public void showMenu(Point location) {
296
          IPresentablePart selectedPart = site.getSelectedPart();
297
          if( selectedPart instanceof PresentablePart ) {
298
            PresentablePart part = ( PresentablePart ) selectedPart;
299
            part.getPane().showViewMenu(location);
300
          }
301
        }
302
      };
303
    }
304
    return result;
305
  }
306
  
307
  /**
308
   * Returns an instance of <code>{@link ConfigurationAction}</code> for this
309
   * <code>ConfigurableStack</code> object, which is declared over the same 
310
   * extension.
311
   * 
312
   * @return the <code>ConfigurationAction</code> or <code>null</code> if no 
313
   * action is declared for the id holding by this object.
314
   * 
315
   * @see ConfigurationAction
316
   */
317
  public ConfigurationAction getConfigAction() {
318
    ConfigurationAction result = null;
319
    if( configAction == null ) {
320
      if( stackPresentationId != null && !stackPresentationId.equals( "" ) ) {
321
        IExtensionRegistry registry = Platform.getExtensionRegistry();
322
        String stackId = STACK_PRESENTATION_EXT_ID;
323
        IExtensionPoint point = registry.getExtensionPoint( stackId );
324
        
325
        if( point != null ) {
326
          IConfigurationElement[] elements = point.getConfigurationElements();
327
          String defaultValue = IPreferenceStore.STRING_DEFAULT_DEFAULT;
328
          String actionClass = defaultValue;
329
          
330
          boolean breakValue = true;
331
          IConfigurationElement element = null;
332
          ImageDescriptor imageDesc = null;
333
          for( int i = 0;  breakValue && i < elements.length; i++ ) {
334
            String id = elements[ i ].getAttribute( "id" );
335
            
336
            
337
            if( id.equals( stackPresentationId ) ) {
338
              
339
              actionClass = elements[ i ].getAttribute( CONFIG_ACTION_NAME );
340
              if( !actionClass.equals( defaultValue ) ) {
341
                breakValue = false;
342
                element = elements[ i ];
343
                String actionImage = element.getAttribute( "actionIcon" );
344
                String menuImage = element.getAttribute( "menuIcon" );
345
                String contributerId = element.getContributor().getName();
346
                imageDesc 
347
                  = AbstractUIPlugin.imageDescriptorFromPlugin( contributerId, 
348
                                                                actionImage );
349
                menuIcon 
350
                  = AbstractUIPlugin.imageDescriptorFromPlugin( contributerId, 
351
                                                                menuImage );
352
              }
353
            }
354
          }
355
          
356
          String defaultStore = IPreferenceStore.STRING_DEFAULT_DEFAULT;
357
          if( actionClass != null && !actionClass.equals( defaultStore ) 
358
              && element != null ) 
359
          {
360
            try {
361
              Object obj 
362
                = element.createExecutableExtension( CONFIG_ACTION_NAME );
363
              if( obj instanceof ConfigurationAction ) {
364
                configAction = ( ConfigurationAction ) obj;
365
                configAction.init( getSite(), this );
366
                if( imageDesc != null ) {
367
                  configAction.setImageDescriptor( imageDesc );
368
                }
369
              }
370
              
371
            } catch( CoreException e ) {
372
              e.printStackTrace();
373
            }
374
          }        
375
        }      
376
      }      
377
    }
378
    result = configAction;
379
    
380
    return result;
381
  }
382
  
383
  /**
384
   * This method returns the <code>{@link PartPane}</code> id defined in the 
385
   * selected <code>{@link PresentablePart}</code> of a 
386
   * <code>IStackPresentationSite</code> instance.
387
   * 
388
   * @param site an instance of <code>IStackPresentationSite</code>
389
   * 
390
   * @return the id of the <code>PartPane</code> from the selected
391
   * <code>PresentablePart</code> or an empty String if no part is selected.
392
   * 
393
   * @see PartPane
394
   * @see PresentablePart
395
   * @see IStackPresentationSite
396
   */
397
  public final String getPaneId( final IStackPresentationSite site ) {
398
    String result = "";    
399
    IPresentablePart selectedPart = site.getSelectedPart();
400
    if( selectedPart instanceof PresentablePart ) {
401
      PresentablePart part = ( PresentablePart ) selectedPart;
402
      result = part.getPane().getID();
403
    }
404
    return result;
405
  }
406
  
407
  /**
408
   * Returns the parent composite for this kind of <code>StackPresentation
409
   * </code>.
410
   * @return the parent composite
411
   */
412
  protected Composite getParent() {
413
    return parent;
414
  }
415
416
  /**
417
   * This method returns the <code>{@link IToolBarManager}</code> for the 
418
   * selected <code>{@link ViewPart}</code>.
419
   * 
420
   * @return the <code>IToolBarManager</code> or <code>null</code> if their is 
421
   * no <code>ViewPart</code> selected.
422
   * 
423
   * @see IToolBarManager
424
   * @see ViewPart
425
   */
426
  public IToolBarManager getPartToolBarManager() {
427
    IToolBarManager result = null;
428
    IStackPresentationSite site = getSite();
429
    String paneId = getPaneId( site );
430
    IWorkbench workbench = PlatformUI.getWorkbench();
431
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
432
    IWorkbenchPage activePage = window.getActivePage();
433
    if( activePage != null ) {
434
      IViewPart viewPart = activePage.findView( paneId );
435
      
436
      IActionBars bars = null;
437
      if( viewPart != null ) {    
438
        IViewSite viewSite = ( IViewSite ) viewPart.getSite();
439
        bars = viewSite.getActionBars();
440
        result = bars.getToolBarManager();
441
      }
442
    }
443
    return result;
444
  }
445
  
446
447
  
448
  /**
449
   * If this Stack is from the type standaloneview, than it will have an 
450
   * attribute called showTitle. This is a parameter of the crate method in the 
451
   * original <code>AbstractPresentationFactory</code>. This is just a separate 
452
   * method, because the creation is now automated and using proxy objects. 
453
   * To match the old behaviour, thsi method was introduced.
454
   * @return the showTitle flag for the standalone view. If the view is not 
455
   * standalone, it will return allways <code>false</code>.
456
   */
457
  protected boolean getShowTitle() {
458
    return proxy.getShowTitle();
459
  }
460
  
461
  /**
462
   * Returns the <code>{@link IStackPresentationSite}</code> holding by this 
463
   * instance.
464
   * 
465
   * @return the site used for communication between the presentation and
466
   * the workbench.
467
   * 
468
   * @see IStackPresentationSite
469
   */
470
  protected IStackPresentationSite getSite() {
471
    return site;
472
  }
473
  
474
  /**
475
   * This is called right after all necessary fields are initialized e.g. site,
476
   * stackPresentationId, parent and proxy. Subclasses can implement any 
477
   * initializaion behaviour using this mehtod.
478
   */
479
  public abstract void init();
480
481
482
  /**
483
   * This method is called right after the constructor is called. It's 
484
   * necessary for creating a <code>ConfigurableStack</code> object over an 
485
   * extension because the standard <code>StackPresentation</code> has no 
486
   * parameterless constructor.
487
   * <p>
488
   * This method just set the mandatory fields.
489
   * </p>
490
   * 
491
   * @param site the site used for communication between the presentation and
492
   * the workbench. 
493
   * @param stackId the StackPresentation ID, which is declared in the 
494
   * Extension. 
495
   * @param parent the parent composite to use for the presentation's controls. 
496
   * @param proxy the <code>{@link ConfigurableStackProxy}</code> that holds 
497
   * this instance.
498
   * 
499
   * @see ConfigurableStackProxy
500
   * @see StackPresentation
501
   */
502
  public void init( 
503
    final IStackPresentationSite site, 
504
    final String stackId, 
505
    final Composite parent,
506
    final ConfigurableStackProxy proxy ) 
507
  {
508
    this.site = site;
509
    this.stackPresentationId = stackId;
510
    this.parent = parent;
511
    this.proxy = proxy;
512
    init();
513
  }
514
  
515
  private boolean isPartMenuVisisble() {
516
    boolean result = false;
517
    if( configAction != null ) {
518
      result = configAction.isPartMenuVisible();
519
    }
520
    
521
    return result;
522
  }
523
  
524
  /**
525
   * Method to change the current StackPresentation of a part. This method just
526
   * calls the 
527
   * <code>{@link ConfigurableStackProxy#setCurrentStackPresentation(String)}
528
   * </code> method.
529
   * 
530
   * @param newStackId the id of the stack to change.
531
   * 
532
   * @see ConfigurableStackProxy
533
   */
534
  protected void setCurrentStackPresentation( final String newStackId ) {
535
    if( proxy != null ) {
536
      proxy.setCurrentStackPresentation( newStackId );
537
    }
538
  }
539
  
540
}
(-)Eclipse (+321 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign.layout;
11
12
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IExtensionRegistry;
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.rap.ui.interactiondesign.layout.model.ILayoutSetInitializer;
23
import org.eclipse.rap.ui.interactiondesign.layout.model.Layout;
24
import org.eclipse.rap.ui.interactiondesign.layout.model.LayoutSet;
25
import org.eclipse.ui.internal.util.PrefUtil;
26
27
/**
28
 * This class represents a singleton object of a registry for 
29
 * <code>{@link Layout}</code> objects. This will contain all <code>Layout
30
 * </code>s, which are contributed to the
31
 * <code>org.eclipse.ui.presentations.Layouts</code> extension point.
32
 *
33
 * @since 1.2
34
 */
35
public class LayoutRegistry {
36
  
37
  private static LayoutRegistry registry;
38
  private String layoutId;
39
  private Map layoutMap;
40
  private Layout activeLayout;
41
  private List builders;
42
  
43
  /**
44
   * This is the default <code>LayoutSet</code> id for the fallback mechanism.
45
   */
46
  public static final String DEFAULT_LAYOUT_ID 
47
    = "org.eclipse.rap.ui.defaultlayout";
48
  
49
  private static final String LAYOUT_EXT_ID 
50
    = "org.eclipse.rap.ui.layouts";
51
  
52
  /**
53
   * The key for saving key/value pairs of <code>LayoutSet</code>s.
54
   */
55
  public static final String SAVED_LAYOUT_KEY = LAYOUT_EXT_ID + ".saved";
56
  
57
  /**
58
   * Returns the singleton instance of the <code>LayoutRegistry</code> object.
59
   * 
60
   * @return the singleton instance.
61
   */
62
  public static LayoutRegistry getInstance() {
63
    if( registry == null ) {
64
      registry = new LayoutRegistry();
65
    }
66
    return registry;
67
  }
68
  
69
  private LayoutRegistry() {
70
    layoutId = DEFAULT_LAYOUT_ID;
71
    layoutMap = new HashMap();
72
    builders = new ArrayList();
73
  }
74
  
75
  private void combineLayoutSets( 
76
    final Layout layout, final Layout defaultLayout, final Layout activeLayout )
77
  {
78
    Map defaultLayoutSets = defaultLayout.getLayoutSets();
79
    Map activeLayoutSets = activeLayout.getLayoutSets();
80
    
81
    createLayoutSetFromLayout( layout, defaultLayoutSets, defaultLayout );
82
    createLayoutSetFromLayout( layout, activeLayoutSets, activeLayout );        
83
  }
84
85
  private Layout createHybridLayout() {
86
    Layout result = new Layout( layoutId );
87
    
88
    Layout defaultLayout = ( Layout ) layoutMap.get( DEFAULT_LAYOUT_ID );
89
    
90
91
    
92
    combineLayoutSets( result, defaultLayout, activeLayout );
93
    
94
    return result;
95
  }
96
  
97
  private void createLayoutSetFromLayout( 
98
    final Layout layout, final Map layoutSets, final Layout oldLayout )
99
  {
100
    Object[] keys = layoutSets.keySet().toArray();
101
    for( int i = 0; i < keys.length; i++ ) {
102
      String key = ( String ) keys[ i ];
103
      LayoutSet set = ( LayoutSet ) layoutSets.get( key );
104
      layout.clearLayoutSet( key );
105
      layout.addLayoutSet( key, set );
106
      String pluginId = oldLayout.getPluginId( key );
107
      if( pluginId != null ) {
108
        layout.setPluginIdForLayoutSet( key, pluginId );
109
      }
110
    }
111
  }
112
  
113
  private void createLayoutSets( 
114
    final IConfigurationElement[] layoutSets, final Layout layout ) 
115
  {
116
    if( layoutSets != null && layoutSets.length > 0 ) {
117
      for( int i = 0; i < layoutSets.length; i++ ) {
118
        IConfigurationElement layoutSetElement = layoutSets[ i ];
119
        
120
        String pluginId = layoutSetElement.getContributor().getName();
121
        String layoutSetId = layoutSetElement.getAttribute( "id" );
122
        
123
        layout.clearLayoutSet( layoutSetId );
124
        layout.setPluginIdForLayoutSet( layoutSetId, pluginId );
125
        LayoutSet layoutSet = layout.getLayoutSet( layoutSetId );
126
127
        try {
128
          Object initializer 
129
            = layoutSetElement.createExecutableExtension( "class" );
130
          if( initializer instanceof ILayoutSetInitializer ) {
131
            ILayoutSetInitializer layoutInitializer 
132
              = ( ILayoutSetInitializer ) initializer;
133
            layoutInitializer.initializeLayoutSet( layoutSet );
134
          }
135
          
136
        } catch( CoreException e ) {
137
          e.printStackTrace();
138
        }
139
        
140
      }      
141
    }
142
  }
143
  
144
  /**
145
   * This method will call the <code>{@link ElementBuilder#dispose()}</code>
146
   * for all registered builders.
147
   * 
148
   * @see ElementBuilder#dispose()
149
   */
150
  public void disposeBuilders() {
151
    for( int i = 0; i < builders.size(); i++ ) {
152
      ElementBuilder builder = ( ElementBuilder ) builders.get( i );
153
      builder.dispose();      
154
    }
155
  }
156
  
157
  /**
158
   * Returns the active <code>Layout</code>. If the active <code>Layout</code>
159
   * is not the default <code>Layout</code> then a hybrid <code>Layout</code>
160
   * is created. This contains the default <code>Layout</code> and the active
161
   * <code>Layout</code>. 
162
   * <p>
163
   * This is necessary because a active layout can override
164
   * single <code>LayoutSet</code>s of a <code>Layout</code> but their can also
165
   * be <code>LayoutSet</code>s, which the active <code>Layout</code> doesn't 
166
   * override.
167
   * </p>
168
   *  
169
   * @return the active layout containing default <code>LayoutSet</code>s if the
170
   * active <code>Layout</code> doesn't override all default <code>LayoutSet
171
   * </code>s.
172
   * 
173
   * @see LayoutSet
174
   * @see Layout
175
   */
176
  public Layout getActiveLayout() {
177
    Layout result = activeLayout;
178
    if( layoutId.equals( DEFAULT_LAYOUT_ID ) ) {
179
      if( result == null ) {
180
        result =  ( Layout ) layoutMap.get( layoutId );
181
        activeLayout = result;
182
      }      
183
    } else {
184
      result = createHybridLayout();
185
    }    
186
    return result;
187
  }
188
189
  /**
190
   * Returns an <code>IExtension</code> array, which contains all Layouts 
191
   * contributed to the <code>org.eclipse.ui.presentations.Layouts</code> 
192
   * extension point.
193
   * 
194
   * @return all <code>Layout</code>s as an <code>IExtension<code> array.
195
   */
196
  public IConfigurationElement[] getLayoutExtensions() {
197
    IExtensionRegistry registry = Platform.getExtensionRegistry();
198
    IConfigurationElement[] result 
199
      = registry.getConfigurationElementsFor( LAYOUT_EXT_ID );
200
    return result;
201
  }
202
  
203
  /**
204
   * Reads the saved <code>Layout</code> id from a <code>ScopedPreferenceStore
205
   * </code>.
206
   * 
207
   * @return the saved <code>Layout</code> id or 
208
   * <code>{@link IPreferenceStore#STRING_DEFAULT_DEFAULT}</code> if no id is 
209
   * saved.
210
   */
211
  public String getSavedLayoutId() {
212
    String result = IPreferenceStore.STRING_DEFAULT_DEFAULT;
213
    IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
214
    result = preferenceStore.getString( SAVED_LAYOUT_KEY );
215
    
216
    return result;
217
  }
218
219
  /**
220
   * Initialize the <code>{@link LayoutSet}</code> contributed to the
221
   * <code>org.eclipse.ui.presentations.Layouts</code> extension point. 
222
   * Additional it sets the active <code>Layout</code> to 
223
   * <code>{#DEFAULT_LAYOUT_ID}</code>.
224
   */
225
  public void init() {
226
    IConfigurationElement[] elements = getLayoutExtensions();
227
    for( int i = 0; i < elements.length; i++ ) {
228
      
229
      String id = elements[ i ].getAttribute( "id" );
230
      
231
      Layout layout = ( Layout ) layoutMap.get( id );
232
      IConfigurationElement[] layoutSets 
233
        = elements[ i ].getChildren( "layoutSet" );
234
      
235
      if( layout == null ) {        
236
        layout = initLayout( layoutSets, id );
237
        layoutMap.put( id, layout );
238
      } else {
239
        createLayoutSets( layoutSets, layout );
240
      }
241
      
242
    }
243
  }
244
245
  private Layout initLayout( 
246
    final IConfigurationElement[] configurationElements, final String id )
247
  {
248
    Layout result = ( Layout ) layoutMap.get( id );
249
    if( result == null ) {
250
      result = new Layout( id );
251
      
252
    }
253
    createLayoutSets( configurationElements, result );
254
    
255
    return result;
256
  }
257
258
  /**
259
   * This method is called, if the active <code>Layout</code> has changed. It 
260
   * will call <code>{@link ElementBuilder#dispose()}</code> for all registered
261
   * builders.
262
   * 
263
   * @see ElementBuilder#dispose()
264
   */
265
  public void notifyLayoutChanged() {
266
    disposeBuilders();
267
  }
268
  
269
  /**
270
   * Adds a <code>{@link ElementBuilder}</code> to a List of builders.
271
   * 
272
   * @param builder a instance of a <code>ElementBuilder</code>
273
   * 
274
   * @see ElementBuilder
275
   */
276
  public void registerBuilder( final ElementBuilder builder ) {
277
    builders.add( builder );
278
  }
279
  
280
  /**
281
   * Saves the new <code>Layout</code> id in a 
282
   * <code>ScopedPreferenceStore</code>.
283
   * 
284
   * @param id the new <code>Layout</code> id to save.
285
   */
286
  public void saveLayoutId( final String id ) {
287
    IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
288
    preferenceStore.putValue( SAVED_LAYOUT_KEY, id );
289
    preferenceStore.firePropertyChangeEvent( SAVED_LAYOUT_KEY, "", id );
290
  }
291
  
292
  /**
293
   * Sets the active <code>Layout</code> to the one, which belongs to the 
294
   * id in the paramter and save the new id if necessary.
295
   * 
296
   * @param id the new <code>Layout</code> id.
297
   * @param save if <code>true</code> then the new <code>Layout</code> will be
298
   * saved.
299
   */
300
  public void setActiveLayout( final String id, final boolean save ) {
301
    Layout newActive = ( Layout ) layoutMap.get( id );
302
    if( newActive != null ) {
303
      layoutId = id;
304
      activeLayout = newActive;
305
      if( save ) {
306
        saveLayoutId( layoutId );
307
      }
308
    }
309
  }
310
  
311
  /**
312
   * Removes a <code>{@link ElementBuilder}</code> from a list of builders.
313
   * 
314
   * @param builder the <code>Elementbuilder</code> to remove.
315
   * 
316
   * @see ElementBuilder
317
   */
318
  public void unregisterBuilder( final ElementBuilder builder ) {
319
    builders.remove( builder );
320
  }
321
}
(-)Eclipse (+334 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign;
11
import java.util.ArrayList;
12
import java.util.List;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.ActionContributionItem;
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.swt.widgets.ToolItem;
18
import org.eclipse.ui.internal.LayoutPart;
19
import org.eclipse.ui.internal.WorkbenchWindow;
20
import org.eclipse.ui.internal.presentations.PresentablePart;
21
import org.eclipse.ui.internal.util.PrefUtil;
22
import org.eclipse.ui.preferences.ScopedPreferenceStore;
23
import org.eclipse.ui.presentations.IPresentablePart;
24
import org.eclipse.ui.presentations.IStackPresentationSite;
25
import org.eclipse.ui.presentations.StackPresentation;
26
27
/**
28
 * This represents an object to configure different part properties e.g. 
29
 * toolitem visibility, viewmenu visibility or the 
30
 * <code>{@link ConfigurableStack}</code> for a selected part.
31
 * <p>
32
 * This is a ordinary <code>{@link Action}</code>. The 
33
 * <code>{@link #run()}</code> method can implement any configuration behaviour
34
 * e.g. a PupupDialog.
35
 * </p>
36
 * <p>
37
 * Additional this class provides methods for saving and laoding some 
38
 * presentation specific properties.
39
 * </p>
40
 * 
41
 * @since 1.2
42
 * @see Action
43
 * @see ConfigurableStack
44
 */
45
public abstract class ConfigurationAction extends Action {
46
  
47
  /**
48
   * Extracts the id of an <code>{@link ActionContributionItem}</code> from a
49
   * <code>{@link ToolItem}</code>.
50
   * @param item the <code>ToolItem</code>, which holds a 
51
   * <code>ActionContributionItem</code>.
52
   * 
53
   * @return the extracted id of an 
54
   */
55
  public static final String getActionIdFromToolItem( final ToolItem item ) {
56
    String result = "";
57
    Object data = item.getData();
58
    ActionContributionItem toolBarAction = ( ActionContributionItem ) data;
59
    result = toolBarAction.getId();
60
    return result;
61
  }
62
  private IStackPresentationSite site;
63
  
64
  private StackPresentation stackPresentation;
65
  
66
  private List configurationChangeListeners = new ArrayList();
67
  
68
  /**
69
   * Method to add a <code>{@link IConfigurationChangeListener}.
70
   * @param listener an instance of a <code>IConfigurationChangedListener
71
   * </code>.
72
   * 
73
   * @see IConfigurationChangeListener
74
   */
75
  public void addConfigurationChangeListener( 
76
    final IConfigurationChangeListener listener ) 
77
  {
78
    configurationChangeListeners.add( listener );    
79
  }
80
  
81
  /**
82
   * This method is called if the <code>{@link ConfigurableStack}</code> of a
83
   * part has changed. It just calls the 
84
   * <code>{@link IConfigurationChangeListener#presentationChanged(String)}
85
   * </code> method for all listeners added by 
86
   * <code>{@link #addConfigurationChangeListener(IConfigurationChangeListener)}
87
   * </code>.
88
   * 
89
   * @param newId the new <code>ConfigurableStack</code> id to make active.
90
   * 
91
   * @see ConfigurableStack
92
   * @see IConfigurationChangeListener
93
   */
94
  public void fireLayoutChange( final String newId ) {
95
    for( int i = 0; i < configurationChangeListeners.size(); i++ ) {
96
      IConfigurationChangeListener listener 
97
        = ( IConfigurationChangeListener ) configurationChangeListeners.get( i );
98
      listener.presentationChanged( newId );
99
      
100
    }
101
  }
102
  
103
  /**
104
   * This method can be called if the configuration of the view's toolbar has 
105
   * been changed. It calls 
106
   * <code>{@link IConfigurationChangeListener#toolBarChanged()}</code> for all
107
   * listeners registered by 
108
   * <code>{@link #addConfigurationChangeListener(IConfigurationChangeListener)}
109
   * </code>.
110
   * 
111
   * @see IConfigurationChangeListener
112
   */
113
  public void fireToolBarChange() {
114
    for( int i = 0; i < configurationChangeListeners.size(); i++ ) {
115
      IConfigurationChangeListener listener 
116
        = ( IConfigurationChangeListener ) configurationChangeListeners.get( i );
117
      listener.toolBarChanged();
118
      
119
    }
120
  }
121
  
122
  private String getActionIdentifier( 
123
    final String viewId, final String actionId )
124
  {
125
    return ConfigurableStackProxy.STACK_PRESENTATION_ID + "/"
126
      + viewId + "/" + actionId;
127
  }
128
  
129
  private String getPartMenuIdentifier( final String paneId ) {
130
    return ConfigurableStackProxy.STACK_PRESENTATION_ID + "/"
131
    + paneId + "/partMenu";
132
  }
133
  
134
  /**
135
   * This method returns the <code>IStackPresentationSite</code> from the 
136
   * <code>StackPresentation</code>, which belongs to this 
137
   * <code>ConfigurationAction</code>.
138
   * @return the <code>IStackPresentationSite</code> to communicate with the 
139
   * part.
140
   */
141
  protected IStackPresentationSite getSite() {
142
    return site;
143
  }
144
  
145
  /**
146
   * Return the <code>{@link StackPresentation}</code>, which this action 
147
   * belongs to.
148
   * 
149
   * @return the <code>StackPresentation</code> object.
150
   * 
151
   * @see ConfigurableStack
152
   */
153
  public StackPresentation getStackPresentation() {
154
    return stackPresentation;
155
  }
156
  
157
  /**
158
   * Checks if the selected part has a menu or not.
159
   * 
160
   * @return <code>true</code> if the selected part has a menu.
161
   */
162
  public boolean hasPartMenu() {
163
    boolean result = false;
164
    IPresentablePart selectedPart = site.getSelectedPart();
165
    if( selectedPart instanceof PresentablePart ) {
166
      PresentablePart part = ( PresentablePart ) selectedPart;
167
      result = part.getPane().hasViewMenu();
168
    }    
169
    return result;
170
  }
171
  
172
  /**
173
   * This method is called right after the object is instantiated to set 
174
   * different fields. These fields are necessary to get the needed 
175
   * information about the current <code>{@link WorkbenchWindow}</code> state 
176
   * e.g. the selected part or the current <code>{@link ConfigurableStack}
177
   * </code>.
178
   * 
179
   * @param site the site used for communication between the presentation and
180
   * the workbench.
181
   * @param stackPresentation the current <code>{@link StackPresentation}</code>
182
   * or <code>ConfigurableStack</code> to get the part's toolbar and so on.
183
   * 
184
   * @see ConfigurableStack
185
   * @see IStackPresentationSite
186
   * @see StackPresentation
187
   */
188
  public void init( 
189
    final IStackPresentationSite site, 
190
    final StackPresentation stackPresentation ) 
191
  {
192
    this.site = site;
193
    this.stackPresentation = stackPresentation;
194
  }
195
  
196
  /** 
197
   * Check if the part menu is set visible by the user. 
198
   * 
199
   * @return the visibility of the part menu.
200
   */
201
  public boolean isPartMenuVisible() {
202
    boolean result = false;
203
    if( stackPresentation instanceof ConfigurableStack ) {
204
      ConfigurableStack configStack = ( ConfigurableStack ) stackPresentation;
205
      String paneId = configStack.getPaneId( site );
206
      String identifier = getPartMenuIdentifier( paneId );
207
      result = loadPartmenuVisibility( identifier );
208
    }
209
    return result;
210
  }
211
    
212
  private boolean loadPartmenuVisibility( final String identifier ) {
213
    boolean result = false;
214
    IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
215
    result = preferenceStore.getBoolean( identifier );
216
    return result;    
217
  }
218
219
  /**
220
   * Returns the visibility for an <code>{@link ActionContributionItem}</code>, 
221
   * which is contributed to a view's toolbar. By default all <code>
222
   * ActionContributionItem</code>s are not visible. The visibility is stored
223
   * in a <code>ScopedPreferenceStore</code>.
224
   * 
225
   * @param viewId the id of the view that holds the 
226
   * <code>ActionContributionItem</code>. 
227
   * @param actionId the unique id of the <code>{@link Action}</code> holding by 
228
   * an <code>ActionContributionItem</code>.
229
   * 
230
   * @return the visibility of the <code>ActionContributionItem</code>. If no 
231
   * value is stored, the default value is <code>false</code>.
232
   * 
233
   * @see ActionContributionItem
234
   * @see Action
235
   * @see ScopedPreferenceStore
236
   */
237
  public boolean loadViewActionVisibility( 
238
    final String viewId, final String actionId )
239
  {
240
    boolean result = false;
241
    String identifier = getActionIdentifier( viewId, actionId );
242
    
243
    ScopedPreferenceStore prefStore 
244
      = ( ScopedPreferenceStore ) PrefUtil.getAPIPreferenceStore();
245
    result = prefStore.getBoolean( identifier );
246
    
247
    return result;
248
  }
249
250
  /**
251
   * Removes a <code>{@link IConfigurationChangeListener}</code> from this 
252
   * action.
253
   * 
254
   * @param listener the <code>IConfigurationChangeListener</code> to remove.
255
   */
256
  public void removeLayoutChangeListener( 
257
    final IConfigurationChangeListener listener ) 
258
  {
259
    boolean found = false;
260
    for( int i = 0; !found && i < configurationChangeListeners.size(); i++ ) {
261
      IConfigurationChangeListener current 
262
        = ( IConfigurationChangeListener ) configurationChangeListeners.get( i );
263
      if( current.equals( listener ) ) {
264
        configurationChangeListeners.remove( i );
265
        found = true;
266
      }
267
    }
268
  }
269
  
270
  /**
271
   * Saves the visibility of a part's menu in a 
272
   * <code>{@link ScopedPreferenceStore}</code>.
273
   * 
274
   * @param visible the new visibility to save.
275
   * 
276
   * @see ScopedPreferenceStore
277
   */
278
  public void savePartMenuVisibility( final boolean visible ) {
279
    IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
280
    if( stackPresentation instanceof ConfigurableStack ) {
281
      ConfigurableStack configStack = ( ConfigurableStack ) stackPresentation;
282
      String paneId = configStack.getPaneId( site );
283
      String identifier = getPartMenuIdentifier( paneId );
284
      preferenceStore.setValue( identifier, visible );
285
    }    
286
  }
287
288
  /**
289
   * Saves the <code>{@link ConfigurableStack}</code> id for the selected 
290
   * <code>{@link LayoutPart}</code>. 
291
   * 
292
   * @param id the unique id of the <code>ConfigurableStack</code> to save.
293
   * 
294
   * @see LayoutPart
295
   * @see ConfigurableStack
296
   */
297
  public void saveStackPresentationId( final String id ) {
298
    if( stackPresentation instanceof ConfigurableStack ) {
299
      String layoutPartId = ConfigurableStack.getLayoutPartId( site );
300
      if( site != null && layoutPartId != null ) {
301
      
302
        ScopedPreferenceStore prefStore 
303
          = ( ScopedPreferenceStore ) PrefUtil.getAPIPreferenceStore();
304
        prefStore.setValue( ConfigurableStackProxy.STACK_PRESENTATION_ID + "/"
305
                            + layoutPartId,   
306
                            id );           
307
      }  
308
    }
309
  }
310
  
311
  /**
312
   * Saves the visibility of a view action in a 
313
   * <code>{@link ScopedPreferenceStore}</code>.
314
   * 
315
   * @param viewId the id of the view, which holds the view's 
316
   * <code>{@link ActionContributionItem}</code>
317
   * @param actionId the id of the <code>ActionContributionItem</code>, which 
318
   * the new visibility belongs to.
319
   * @param visibility the value of the visibility.
320
   */
321
  public void saveViewActionVisibility( 
322
    final String viewId, final String actionId, boolean visibility )
323
  {
324
    String identifier = getActionIdentifier( viewId, actionId );
325
    
326
    ScopedPreferenceStore prefStore 
327
    = ( ScopedPreferenceStore ) PrefUtil.getAPIPreferenceStore();
328
    
329
    prefStore.setValue( identifier, visibility );
330
    
331
  }
332
   
333
  
334
}
(-)Eclipse (+352 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign;
11
12
import java.util.ArrayList;
13
import java.util.List;
14
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.IExtensionPoint;
17
import org.eclipse.core.runtime.IExtensionRegistry;
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.jface.action.IToolBarManager;
20
import org.eclipse.jface.action.MenuManager;
21
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
22
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
23
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
24
import org.eclipse.jface.preference.IPreferenceStore;
25
import org.eclipse.jface.util.IPropertyChangeListener;
26
import org.eclipse.jface.util.PropertyChangeEvent;
27
import org.eclipse.rap.ui.interactiondesign.layout.LayoutRegistry;
28
import org.eclipse.rwt.branding.AbstractBranding;
29
import org.eclipse.rwt.internal.branding.BrandingUtil;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.ui.IWindowListener;
32
import org.eclipse.ui.IWorkbench;
33
import org.eclipse.ui.IWorkbenchPage;
34
import org.eclipse.ui.IWorkbenchWindow;
35
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.internal.WorkbenchPage;
37
import org.eclipse.ui.internal.WorkbenchWindow;
38
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
39
import org.eclipse.ui.internal.util.PrefUtil;
40
import org.eclipse.ui.presentations.AbstractPresentationFactory;
41
import org.eclipse.ui.presentations.IStackPresentationSite;
42
import org.eclipse.ui.presentations.StackPresentation;
43
44
/**
45
 * <p>
46
 * The <code>PresentationFactory</code> is an enhancement of the original 
47
 * <code>{@link AbstractPresentationFactory}</code>. This factory provides
48
 * many additional possibilities, which the original one doesn't provide.
49
 * </p>
50
 * <p>
51
 * <code>{@link StackPresentation}</code> Objects shall not be created directly
52
 * by this factory. Instead their is a new Extension Point for this called 
53
 * <code>org.eclipse.rap.presentation.stackPresentations</code>. You can 
54
 * contribute <code>ConfigurableStack</code>s to this now. 
55
 * </p>
56
 * <p>
57
 * This Factory controls the appereance of:
58
 * <ul>
59
 *  <li>editors</li> 
60
 *  <li>views</li> 
61
 *  <li>standalone views</li>
62
 *  <li>view's toolbar</li>
63
 *  <li>coolbar</li>
64
 *  <li>menubar</li>
65
 *  <li>view's toolbar menu</li>
66
 *  <li>toolbar contribution items</li>
67
 * </ul> 
68
 * It represents one central point for customizing the workbench's window.
69
 * </p>
70
 * @since 1.2
71
 * 
72
 * @see ConfigurableStack
73
 * @see ConfigurationAction
74
 * @see IWindowComposer
75
 * @see AbstractPresentationFactory
76
 */
77
public abstract class PresentationFactory extends AbstractPresentationFactory 
78
  implements IActionBarPresentationFactory
79
{
80
  
81
  private final class windowListener implements IWindowListener {
82
83
    public void windowActivated( IWorkbenchWindow window ) {
84
      
85
    }
86
87
    public void windowClosed( IWorkbenchWindow window ) {
88
      
89
    }
90
91
    public void windowDeactivated( IWorkbenchWindow window ) {
92
      
93
    }
94
95
    public void windowOpened( final IWorkbenchWindow window ) {
96
      IPreferenceStore preferenceStore 
97
        = PrefUtil.getAPIPreferenceStore();
98
      preferenceStore.addPropertyChangeListener( new IPropertyChangeListener() {
99
  
100
        public void propertyChange( PropertyChangeEvent event ) {
101
          String name = event.getProperty();
102
          String layoutKey = LayoutRegistry.SAVED_LAYOUT_KEY;
103
          if( name.equals( layoutKey ) ) {
104
            workbenchWindowLayoutChanged( window );
105
          }
106
          
107
        }
108
109
      });
110
      
111
    }
112
  }
113
  
114
  /**
115
   * The key for an editor <code>ConfigurableStack</code>.
116
   */
117
  public static final String KEY_EDITOR = "editor";
118
  
119
  /**
120
   * The key for a view <code>ConfigurableStack</code>.
121
   */
122
  public static final String KEY_VIEW = "view";
123
  
124
  /**
125
   * The key for a standalone view <code>ConfigurableStack</code>.
126
   */
127
  public static final String KEY_STANDALONE_VIEW = "standaloneview";
128
  
129
  private List proxyList = new ArrayList();
130
  
131
  /**
132
   * Constructs a new instance of this class and adds a listener to the 
133
   * <code>{@link WorkbenchWindow}</code> for changing the window design on the 
134
   * fly.
135
   */
136
  public PresentationFactory() {
137
    IWorkbench workbench = PlatformUI.getWorkbench();
138
    workbench.addWindowListener( new windowListener() ); 
139
140
    // load Layout from branding because its too early in the LayoutRegistry
141
    String layoutId = loadBrandingLayoutId();
142
    if( layoutId != null ) {
143
      LayoutRegistry.getInstance().setActiveLayout( layoutId, false );
144
    }
145
  }
146
  
147
  public abstract ICoolBarManager2 createCoolBarManager();
148
  
149
  /**
150
   * Creates an editor presentation proxy for presenting editors.
151
   * <p>
152
   * The presentation creates its controls on the given parent composite.
153
   * </p>
154
   * <p> 
155
   * The presentation itself can be contributed to the 
156
   * extension point 
157
   * <code>org.eclipse.ui.presentations.StackPresentations</code>.
158
   * </p>
159
   * 
160
   * @param parent
161
   *            the parent composite to use for the presentation's controls.
162
   * @param site
163
   *            the site used for communication between the presentation and
164
   *            the workbench.
165
   * @return a newly created part presentation proxy.
166
   */
167
  public final StackPresentation createEditorPresentation( 
168
    final Composite parent,
169
    final IStackPresentationSite site )
170
  {
171
    ConfigurableStackProxy result 
172
      = new ConfigurableStackProxy( parent, site, KEY_EDITOR );
173
    proxyList.add( result );
174
    return result;   
175
  }
176
  
177
  /**
178
   * Instantiate the <code>{@link MenuManager}</code> object for the window's
179
   * menubar.
180
   * 
181
   * @return the menubar manager
182
   * 
183
   * @see MenuManager
184
   */
185
  public abstract MenuManager createMenuBarManager();   
186
  
187
  /**
188
   * Instantiate the <code>{@link MenuManager}</code> object for the part's
189
   * menu.
190
   * 
191
   * @return the partmenu manager
192
   */
193
  public abstract MenuManager createPartMenuManager();
194
  
195
  /**
196
   * Creates a stack presentation proxy for presenting regular docked views.
197
   * <p>
198
   * The presentation creates its controls on the given parent composite.
199
   * </p>
200
   * <p> 
201
   * The presentation itself can be contributed to the 
202
   * extension point 
203
   * <code>org.eclipse.ui.presentations.StackPresentations</code>.
204
   * </p>
205
   * 
206
   * @param parent
207
   *            the parent composite to use for the presentation's controls.
208
   * @param site
209
   *            the site used for communication between the presentation and
210
   *            the workbench.
211
   * @param showTitle
212
   *            <code>true</code> to show the title for the view,
213
   *            <code>false</code> to hide it.
214
   * @return a newly created part presentation proxy
215
   */
216
  public final StackPresentation createStandaloneViewPresentation( 
217
    final Composite parent,
218
    final IStackPresentationSite site,
219
    final boolean showTitle )
220
  {
221
    ConfigurableStackProxy result 
222
      = new ConfigurableStackProxy( parent, site, KEY_STANDALONE_VIEW );
223
    if( showTitle ) {
224
      result.setShowTitle( showTitle );
225
    }
226
    proxyList.add( result );
227
    return result;     
228
  }
229
230
  public abstract IToolBarContributionItem createToolBarContributionItem( 
231
    final IToolBarManager toolBarManager, final String id );
232
233
  public abstract IToolBarManager2 createToolBarManager(); 
234
  
235
  /**
236
   * Creates a standalone stack presentation proxy for presenting a standalone 
237
   * view. A standalone view cannot be docked together with other views. 
238
   * The title of a standalone view may be hidden.
239
   * <p>
240
   * The presentation creates its controls on the given parent composite.
241
   * </p>
242
   * <p> 
243
   * The presentation itself can be contributed to the 
244
   * extension point 
245
   * <code>org.eclipse.ui.presentations.StackPresentations</code>.
246
   * </p>
247
   * 
248
   * @param parent
249
   *            the parent composite to use for the presentation's controls.
250
   * @param site
251
   *            the site used for communication between the presentation and
252
   *            the workbench.
253
   * @return a newly created part presentation proxy.
254
   */
255
  public final StackPresentation createViewPresentation( 
256
    final Composite parent, final IStackPresentationSite site )
257
  {
258
    ConfigurableStackProxy result 
259
      = new ConfigurableStackProxy( parent, site, KEY_VIEW );
260
    proxyList.add( result );
261
    return result;    
262
  }
263
264
  
265
  public abstract IToolBarManager2 createViewToolBarManager();
266
267
  /**
268
   * This method is called within the <code>{@link WorkbenchWindow}</code> to
269
   * couple the presentation factory and the design of the 
270
   * <code>WorkbenchWindow</code>.
271
   * 
272
   * @return a newly created <code>{@link IWindowComposer}</code> object, which 
273
   * defines the design of a <code>WorkbenchWindow</code>.
274
   * 
275
   * @see IWindowComposer
276
   */
277
  public abstract IWindowComposer createWindowComposer( );
278
279
  private String loadBrandingDefaultLayoutId( 
280
    final IConfigurationElement element )
281
  {
282
    String result = null;
283
    IConfigurationElement[] factory 
284
      = element.getChildren( "presentationFactory" );
285
    if( factory.length > 0 ) {
286
      result = factory[ 0 ].getAttribute( "defaultLayoutId" );
287
    }
288
    return result;
289
  }
290
291
  private String loadBrandingLayoutId() {
292
    String result = null;
293
    AbstractBranding branding = BrandingUtil.findBranding();
294
    if( branding != null ) {
295
      String brandingId = branding.getId();
296
      IExtensionRegistry registry = Platform.getExtensionRegistry();
297
      String id = "org.eclipse.rap.ui.branding";
298
      IExtensionPoint brandingPoint = registry.getExtensionPoint( id );
299
      if( brandingPoint != null ) {
300
        IConfigurationElement[] elements 
301
          = brandingPoint.getConfigurationElements();
302
        boolean found = false;
303
        for( int i = 0; i < elements.length && !found; i++ ) {
304
          String tempId = elements[ i ].getAttribute( "id" );
305
          if( tempId.equals( brandingId ) ) {
306
            found = true;
307
            result = loadBrandingDefaultLayoutId( elements[ i ] );
308
          }
309
        }
310
      }
311
    }
312
    return result;
313
    
314
  }
315
  
316
  private void refreshStackPresentations( ) {
317
    for( int i = 0; i < proxyList.size(); i++ ) {
318
      ConfigurableStackProxy proxy 
319
        = ( ConfigurableStackProxy ) proxyList.get( i );
320
      proxy.refreshStack();
321
    }
322
  }
323
  
324
  private void workbenchWindowLayoutChanged( final IWorkbenchWindow window ) {
325
326
    Composite newStackComposite = null;
327
    if( window instanceof WorkbenchWindow ) {
328
      WorkbenchWindow wbWindow = ( WorkbenchWindow ) window;
329
      LayoutRegistry registry = LayoutRegistry.getInstance();
330
      registry.disposeBuilders();
331
      newStackComposite = wbWindow.changeWindowLayoutSet();
332
      
333
    }
334
    
335
    refreshStackPresentations();
336
    
337
    IWorkbenchPage activePage = window.getActivePage();
338
    if( activePage instanceof WorkbenchPage ) {
339
      WorkbenchPage page = ( WorkbenchPage ) activePage;
340
      Composite parent = page.getClientComposite().getParent();
341
      if( parent != null ) {
342
        Composite stackComposite = parent.getParent();
343
        if( stackComposite != null && newStackComposite != null ) {          
344
          stackComposite.setLayoutData( newStackComposite.getLayoutData() );
345
          newStackComposite.getParent().layout( true, true );
346
          newStackComposite.dispose();          
347
        }        
348
      }
349
    }
350
  }
351
  
352
}
(-)Eclipse (+84 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign;
11
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.Shell;
14
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
15
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
16
17
/**
18
 * This interface is only used to bind some 
19
 * <code>{@link WorkbenchWindowAdvisor}</code> methods to a presentation. This 
20
 * is necessary to create components like a header or footer for a RAP 
21
 * application. But the methods can also be used to customize existing 
22
 * components like the perspective switcher or the toolbar and so on.
23
 * <p>
24
 * An instance of this interface is created in the 
25
 * <code>{@link PresentationFactory#createWindowComposer()}</code> method.
26
 * </p>
27
 * 
28
 * @since 1.2
29
 * 
30
 * @see WorkbenchWindowAdvisor
31
 * @see PresentationFactory#createWindowComposer()
32
 *
33
 */
34
public interface IWindowComposer {
35
  
36
  /**
37
   * Creates the contents of the window.
38
   * <p>
39
   * The default implementation of the <code>{@link WorkbenchWindowAdvisor}
40
   * </code> adds a menu bar, a cool bar, a status line, 
41
   * a perspective bar, and a fast view bar.  The visibility of these controls
42
   * can be configured using the <code>setShow*</code> methods on
43
   * <code>IWorkbenchWindowConfigurer</code>.
44
   * </p>
45
   * 
46
   * @param shell the window's shell
47
   * @param configurer the <code>{@link IWorkbenchWindowConfigurer}<code> because
48
   * the instance of the configurer is a field in the 
49
   * <code>WorkbenchWindowAdvisor</code> but not accessable in the 
50
   * <code>{@link PresentationFactory}</code>.
51
   * 
52
   * @return the result is used to call 
53
   * <code>{@link IWorkbenchWindowConfigurer#createPageComposite}</code>.
54
   * 
55
   * @see WorkbenchWindowAdvisor#createWindowContents(Shell)
56
   * @see IWorkbenchWindowConfigurer#createMenuBar
57
   * @see IWorkbenchWindowConfigurer#createCoolBarControl
58
   * @see IWorkbenchWindowConfigurer#createStatusLineControl
59
   * @see IWorkbenchWindowConfigurer#createPageComposite
60
   * @see PresentationFactory#createWindowComposer()
61
   */
62
  public Composite createWindowContents( 
63
    final Shell shell, final IWorkbenchWindowConfigurer configurer );
64
                 
65
  /**
66
   * @see WorkbenchWindowAdvisor#postWindowCreate()
67
   * @param configurer the <code>{@link IWorkbenchWindowConfigurer}<code> 
68
   * because the instance of the configurer is a field in the 
69
   * <code>WorkbenchWindowAdvisor</code> but not accessable in the 
70
   * <code>{@link PresentationFactory}</code>.
71
   */
72
  public void postWindowCreate( final IWorkbenchWindowConfigurer configurer );
73
                 
74
  /**
75
   * @see WorkbenchWindowAdvisor#preWindowOpen()
76
   * 
77
   * @param configurer the <code>{@link IWorkbenchWindowConfigurer}<code> 
78
   * because the instance of the configurer is a field in the 
79
   * <code>WorkbenchWindowAdvisor</code> but not accessable in the 
80
   * <code>{@link PresentationFactory}</code>.
81
   */
82
  public void preWindowOpen( final IWorkbenchWindowConfigurer configurer );
83
  
84
}
(-)Eclipse (+292 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign.layout;
11
12
import org.eclipse.jface.preference.IPreferenceStore;
13
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.rap.ui.interactiondesign.layout.model.Layout;
15
import org.eclipse.rap.ui.interactiondesign.layout.model.LayoutSet;
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.Font;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.layout.FormData;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.ui.plugin.AbstractUIPlugin;
25
26
/**
27
 * A <code>ElementBuilder</code> represents the super class for all custom
28
 * builders. With a custom builder you can construct complex objects e.g. a 
29
 * header, which needs nine or less images and additional information about
30
 * placing logos or other images.
31
 * <p>
32
 * To fit as much as possible patterns of web components we introduce this
33
 * <code>ElementBuilder</code>. This concept use the builder design pattern.
34
 * So, an instantiation can look like: <code>ElementBuilder builder = new
35
 * HeaderBuilder(param, param)</code>. The benefit of this technique is, that
36
 * you can work against a defined api and you can change the implementation
37
 * easily.
38
 * </p>
39
 * <p>
40
 * Every builder needs a <code>{@link LayoutSet}</code>, which can be 
41
 * contributed to the <code>org.eclipse.ui.presentations.Layouts</code> 
42
 * extension point.
43
 * </p>
44
 * The point is, every builder should regard, that a <code>LayoutSet</code> 
45
 * can define more or less images depending on the contribution in the 
46
 * extension. E.g. a header can hold nine images, but i also can hold just 
47
 * three. So, the builder have to look that the component is build correctly.
48
 * </p>
49
 * 
50
 * @since 1.2
51
 * 
52
 * @see LayoutSet
53
 */
54
public abstract class ElementBuilder {
55
56
  private Composite parent;
57
  private Layout layout;
58
  private LayoutSet layoutSet;
59
  
60
  /**
61
   * This constructor stores the parent composite and instantiate a 
62
   * <code>{@link LayoutSet}</code> for this instance. The <code>LayoutSet
63
   * </code> can be used to create images, fonts, colors or postion data. 
64
   * This depends on what is defined for a specific builder.
65
   * <p>
66
   * Subclasses have to call this constructor because it register the object
67
   * in the <code>{@link LayoutRegistry}</code>
68
   * </p>
69
   * 
70
   * @param parent the parent <code>{@link Composite}</code> for the component 
71
   * to build.
72
   * @param layoutSetId the id of the <code>LayoutSet</code>, which belongs to 
73
   * this instance.
74
   * 
75
   * @see LayoutSet
76
   * @see LayoutRegistry#registerBuilder(ElementBuilder)
77
   * @see Composite
78
   */
79
  public ElementBuilder( final Composite parent, final String layoutSetId ) 
80
  {
81
    this.parent = parent;
82
    LayoutRegistry registry = LayoutRegistry.getInstance();
83
    String savedLayoutId = registry.getSavedLayoutId();
84
    if( !savedLayoutId.equals( IPreferenceStore.STRING_DEFAULT_DEFAULT ) ) {
85
      registry.setActiveLayout( savedLayoutId, false );
86
    }
87
    layout = registry.getActiveLayout();
88
    if( layout != null ) {
89
      layoutSet = layout.getLayoutSet( layoutSetId );
90
      registry.registerBuilder( this );
91
    } else {
92
      throw new IllegalArgumentException( "no layout registered with default " +
93
      		"id (LayoutRegistry.DEFAULT_LAYOUT_ID) or no layout activated " +
94
      		"over branding extension." );
95
    }
96
  }
97
98
99
  /**
100
   * Clients can call this method to add non standard components to the builder
101
   * e.g. a logo placed on a label to show in a header.
102
   * <p>
103
   * So, subclasses can implement or ignore this method depending on their 
104
   * needs.
105
   * </p>
106
   * <p>
107
   * Clients have to call this method before calling 
108
   * <code>{@link #build()}</code>. 
109
   * </p>
110
   * 
111
   * @param control an instance of a <code>Cotrol</code> e.g. a <code>Composite
112
   * </code> containing a image.
113
   * @param layoutData can be any position information for the control. 
114
   * Usually it's a instance of <code>FormData</code>.
115
   * 
116
   * @see FormData
117
   * @see GridData
118
   */
119
  public abstract void addControl( 
120
    final Control control, final Object layoutData );
121
  
122
  /**
123
   * This method do the same as <code>{@link #addControl(Control, Object)}
124
   * </code>. The only difference is, that the position information can be 
125
   * loaded by the <code>{@link LayoutSet#getPosition(String)}</code> 
126
   * method.
127
   * 
128
   * @param control an instance of a <code>Control</code> e.g. a <code>Composite
129
   * </code> containing an image.
130
   * @param positionId the unique id of a position data holding by the <code>
131
   * LayoutSet</code> for this object.
132
   * 
133
   * @see LayoutSet#getPosition(String)
134
   * @see LayoutSet#addPosition(String, FormData)
135
   */
136
  public abstract void addControl( 
137
    final Control control, final String positionId );
138
  
139
  /**
140
   * Subclasses can implement this method and process it. E.g. if a client
141
   * want to add a logo for a header directly and not over the 
142
   * <code>{@link #addControl(Control, Object)}</code> method in a 
143
   * <code>Composite</code>.
144
   * 
145
   * @param image an instance of a <code>Image</code> to add.
146
   * @param layoutData can be any position information for the <code>Image</code>. 
147
   * Usually it's an instance of <code>FormData</code>.
148
   * 
149
   * @see FormData
150
   * @see GridData
151
   */
152
  public abstract void addImage( final Image image, final Object layoutData );
153
  
154
  /**
155
   * This method do the same as <code>{@link #addImage(Image, Object)}</code>.
156
   * The only difference is, that the position information can be 
157
   * loaded by the <code>{@link LayoutSet#getPosition(String)}</code> 
158
   * method.
159
   * 
160
   * @param image an instance of an <code>Image</code> to add.
161
   * @param positionId the unique id of a position data holding by the <code>
162
   * LayoutSet</code> for this object.
163
   * 
164
   * @see LayoutSet#getPosition(String)
165
   * @see LayoutSet#addPosition(String, FormData)
166
   */
167
  public abstract void addImage( final Image image, final String positionId );
168
  
169
  /**
170
   * This is the most important method in a builder. If a client call this, the
171
   * builder have to build the needed component e.g. a header or footer 
172
   * regarding the defined <code>LayoutSet</code>.
173
   */
174
  public abstract void build();
175
  
176
  /**
177
   * Subclasses can use this method to create an image by means of it's path in
178
   * the <code>LayoutSet</code>.
179
   * 
180
   * @param path the path for the image to create.
181
   * 
182
   * @return the created image.
183
   * 
184
   * @see LayoutSet#addImagePath(String, String)
185
   * @see LayoutSet#getImagePath(String)
186
   */
187
  protected Image createImage( final String path ) {
188
    Image result = null;
189
    if( path != null ) {
190
      String id = layout.getPluginId( layoutSet.getId() );
191
      ImageDescriptor descriptor
192
        = AbstractUIPlugin.imageDescriptorFromPlugin( id, path );
193
      result = descriptor.createImage();
194
    }
195
    return result;
196
  }
197
  
198
  /**
199
   * Subclasses should dispose all created or rather added <code>Control</code>s 
200
   * and <code>Image</code>s in this method.
201
   */
202
  public abstract void dispose();
203
  
204
  /**
205
   * Returns a <code>Color</code> object by it's id defined in the 
206
   * <code>LayoutSet</code>
207
   * 
208
   * @param colorId the id of the color.
209
   * 
210
   * @return the created <code>Color</code> object.
211
   * 
212
   * @see LayoutSet#addColor(String, Color)
213
   * @see LayoutSet#getColor(String)
214
   */
215
  public Color getColor( final String colorId ) {
216
    return layoutSet.getColor( colorId );
217
  }
218
  
219
  /**
220
   * Subclasses should implement this method to return the component, 
221
   * which is created during the <code>{@link #build()}</code> call.
222
   *    
223
   * @return the <code>{@link Control}</code> created in the 
224
   * <code>{@link #build()}</code> method.
225
   */
226
  public abstract Control getControl();
227
  
228
  /**
229
   * Returns a <code>Font</code> object by it's id defined in the 
230
   * <code>LayoutSet</code>
231
   * 
232
   * @param fontID the id of the font.
233
   * 
234
   * @return the created font object.
235
   * 
236
   * @see LayoutSet#addFont(String, Font)
237
   * @see LayoutSet#getFont(String)
238
   */
239
  public Font getFont( final String fontID ) {
240
    return layoutSet.getFont( fontID );
241
  }
242
  
243
  /**
244
   * Return the image by its id in the <code>LayoutSet</code>. This method
245
   * just extract the image path and call <code>{@link #createImage(String)}
246
   * </code>.
247
   * 
248
   * @param imageId the id of the image defined in the <code>LayoutSet</code>.
249
   * 
250
   * @return the created image.
251
   * 
252
   * @see LayoutSet#getImagePath(String)
253
   * @see LayoutSet#addImagePath(String, String)
254
   */
255
  public Image getImage( final String imageId ) {
256
    Image result = null;
257
    String imagePath = layoutSet.getImagePath( imageId );
258
    if( imagePath != null ) {
259
      result = createImage( imagePath );
260
    }    
261
    return result;
262
  }
263
  
264
  /**
265
   * This returns the <code>LayoutSet</code> for this builder. The layoutset 
266
   * contains all images, fonts, formdatas and colors, which are relevant for 
267
   * the whole builder layout.
268
   * @return the <code>LayoutSet</code> object
269
   */
270
  protected LayoutSet getLayoutSet() {
271
    return layoutSet;
272
  }
273
  
274
  /**
275
   * Returns the parent, which was set in <code>
276
   * {@link #ElementBuilder(Composite, String)}</code>.
277
   * 
278
   * @return the parent <code>Composite</code>. 
279
   */
280
  protected Composite getParent() {
281
    return parent;
282
  }
283
  
284
  /**
285
   * Should return the size from the representative component of the builder. 
286
   *  
287
   * @return the size as a Point. <code>Point.x</code> means the width and 
288
   * <code>Point.y</code> means the height of the component.
289
   */
290
  public abstract Point getSize();
291
  
292
}
(-)Eclipse (+59 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign;
11
12
/**
13
 * This interface can be used to react on configuration changes e.g. the 
14
 * <code>{@link ConfigurableStack}</code> or the visibility of view toolbar 
15
 * items. 
16
 * <p>
17
 * You can register an instance of this in the 
18
 * <code>{@link ConfigurationAction}</code> of a <code>ConfigurableStack</code>
19
 * if it has one.
20
 * </p>
21
 * 
22
 * @since 1.2
23
 * 
24
 * @see ConfigurableStack
25
 * @see ConfigurationAction
26
 */
27
public interface IConfigurationChangeListener {
28
  
29
  /**
30
   * This method is called if the <code>{@link ConfigurableStack}</code> of a
31
   * part has changed. 
32
   * <p> 
33
   * An instance of this e.g. can call 
34
   * <code>{@link ConfigurableStackProxy#setCurrentStackPresentation(String)}
35
   * <code> with the new id to change the <code>ConfigurableStack</code> on the
36
   * fly.
37
   * </p>
38
   *  
39
   * @param newStackPresentationId the id of the new 
40
   * <code>ConfigurableStack</code> for the selected part.
41
   * 
42
   * @see ConfigurableStack
43
   * @see ConfigurableStackProxy#setCurrentStackPresentation(String)
44
   */
45
  public void presentationChanged( final String newStackPresentationId );
46
  
47
  /**
48
   * This method is called if the visibility of the views's toolbar items or
49
   * menu has changed.
50
   * <p>
51
   * <code>{@link ConfigurableStack}</code> objects can use this e.g. to refresh 
52
   * the part toolbar.
53
   * </p> 
54
   * 
55
   * @see ConfigurableStack
56
   */
57
  public void toolBarChanged();
58
  
59
}
(-)Eclipse (+148 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign.layout.model;
11
12
import java.util.HashMap;
13
import java.util.Map;
14
15
/**
16
 * This class represents the <code>org.eclipse.ui.presentations.Layouts</code>
17
 * extension point. This means, that it can be hold any number of <code>
18
 * {@link LayoutSet}</code> objects. 
19
 * <p>
20
 * This class is like a manager for <code>LayoutSet</code> objects.
21
 * </p>
22
 * 
23
 * @since 1.2
24
 *
25
 */
26
public class Layout {
27
28
  private Map layoutSets = new HashMap();
29
  private Map pluginIdMap = new HashMap();
30
  private String id;
31
  
32
  /**
33
   * Instantiate a object of this class and sets the unique id, which is 
34
   * contributed to the <code>org.eclipse.ui.presentations.Layouts
35
   * </code> extension point.
36
   * 
37
   * @param id the unique <code>Layout</code> id.
38
   */
39
  public Layout( final String id ) {
40
    this.id = id;
41
  }
42
  
43
  /**
44
   * Adds a existing <code>LayoutSet</code> object to this <code>Layout</code>.
45
   * 
46
   * @param id the id of the <code>LayoutSet</code> to add.
47
   * @param set the <code>LayoutSet</code> object to add.
48
   */
49
  public void addLayoutSet( final String id, final LayoutSet set ) {
50
    layoutSets.put( id, set );
51
  }
52
    
53
  /**
54
   * This method removes a <code>LayoutSet</code> object completely from this 
55
   * instance.
56
   * 
57
   * @param layoutSetId the id of the <code>LayoutSet</code> object to remove.
58
   */
59
  public void clearLayoutSet( final String layoutSetId ) {
60
    LayoutSet set = ( LayoutSet ) layoutSets.get( layoutSetId );
61
    if( set != null ) {
62
      layoutSets.remove( layoutSetId );
63
      pluginIdMap.remove( layoutSetId );
64
    }
65
  }
66
  
67
  /**
68
   * Returns the <code>Layout</code> id, which was set by calling <code>
69
   * {@link #Layout(String)}</code>.
70
   * 
71
   * @return the id.
72
   */
73
  public String getId() {
74
    return id;
75
  }
76
  
77
  /**
78
   * Returns an instance of a <code>LayoutSet</code> object for the given id. If
79
   * the instance does not yet exists it will be created.
80
   * 
81
   * @param layoutSetId the id of the wanted <code>LayoutSet</code> object.
82
   * 
83
   * @return a instance of a <code>LayoutSet</code> object with the given id.
84
   */
85
  public LayoutSet getLayoutSet( final String layoutSetId ) {
86
    LayoutSet result = ( LayoutSet ) layoutSets.get( layoutSetId );
87
    if( result == null ) {
88
      result = new LayoutSet( layoutSetId );
89
      layoutSets.put( layoutSetId, result );
90
    }
91
    return result;
92
  }
93
  
94
  /**
95
   * Returns a <code>Map</code> object that contains all <code>LayoutSet</code>
96
   * objects for this <code>Layout</code>.
97
   * 
98
   * @return all <code>LayoutSet</code> object for this <code>Layout</code>.
99
   */
100
  public Map getLayoutSets() {
101
    return layoutSets;
102
  }
103
  
104
  /**
105
   * Returns the plug-in id for the <code>LayoutSet</code> object with the given 
106
   * id.
107
   * 
108
   * @param layoutSetId the id of the <code>LayoutSet</code> object.
109
   * 
110
   * @return the id of the plug-in, which declares the </code>LayoutSet</code>.
111
   */
112
  public String getPluginId( final String layoutSetId ) {
113
    String result = "";
114
    result = ( String ) pluginIdMap.get( layoutSetId );
115
    return result;
116
  }
117
  
118
  /**
119
   * Checks if the object holds a <code>LayoutSet</code> object with the given
120
   * <code>LayoutSet</code> id.
121
   * 
122
   * @param layoutSetId the <code>LayoutSet</code> id to check.
123
   * 
124
   * @return <code>true</code> if this object holds a instance of the <code>
125
   * LayoutSet</code> with the given id.
126
   * 
127
   * @see LayoutSet#getId()
128
   */
129
  public boolean layoutSetExist( final String layoutSetId ) {
130
    return layoutSets.containsKey( layoutSetId );
131
  }
132
  
133
  /**
134
   * Different <code>LayoutSet</code> objects can have different bundles. 
135
   * Therefore it's necessary to know the plug-in id e.g. to create images and 
136
   * so on.
137
   * 
138
   * @param layoutSetId the id of the <code>LayoutSet</code> object, which the 
139
   * plug-in id belongs to.
140
   * @param pluginId the id of the plug-in, which contribute to the <code>
141
   * org.eclipse.ui.presentations.Layouts</code> extension point.
142
   */
143
  public void setPluginIdForLayoutSet( 
144
    final String layoutSetId, final String pluginId ) {
145
    pluginIdMap.put( layoutSetId, pluginId );
146
  }
147
   
148
}
(-)Eclipse (+44 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2008 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.ui.interactiondesign.layout.model;
11
12
/**
13
 * This interface is implemented by the class defined in the attributes of the
14
 * <code>org.eclipse.ui.presentations.Layouts</code> extension point.
15
 * <p>
16
 * Classes implementing this interface to add components to a 
17
 * <code>{@link LayoutSet}</code> object. 
18
 *
19
 * @since 1.2
20
 */
21
public interface ILayoutSetInitializer {
22
  
23
  /**
24
   * This method is automatically called by the <code>LayoutRegistry</code> 
25
   * instance during the initialization process. This happens on the plug-in
26
   * activation.
27
   * <p>
28
   * Clients should add <code>Image</code>, <code>Font</code>, <code>Color
29
   * </code> and <code>FormData</code> objects to the given 
30
   * <code>LayoutSet</code>.
31
   * </p>
32
   * 
33
   * @param layoutSet the <code>LayoutSet</code> instance you should add 
34
   * components.
35
   * 
36
   * @see LayoutSet#addColor(String, org.eclipse.swt.graphics.Color)
37
   * @see LayoutSet#addFont(String, org.eclipse.swt.graphics.Font)
38
   * @see LayoutSet#addImagePath(String, String)
39
   * @see LayoutSet#addPosition(String, org.eclipse.swt.layout.FormData)
40
   */
41
  public void initializeLayoutSet( final LayoutSet layoutSet );
42
  
43
  
44
}
(-)plugin.xml (+2 lines)
Lines 73-78 Link Here
73
   <extension-point id="org.eclipse.ui.workingSets" name="%ExtPoint.workingSets" schema="schema/workingSets.exsd"/>
73
   <extension-point id="org.eclipse.ui.workingSets" name="%ExtPoint.workingSets" schema="schema/workingSets.exsd"/>
74
   <extension-point id="org.eclipse.ui.browserSupport" name="%ExtPoint.browserSupport" schema="schema/browserSupport.exsd"/>
74
   <extension-point id="org.eclipse.ui.browserSupport" name="%ExtPoint.browserSupport" schema="schema/browserSupport.exsd"/>
75
   <extension-point id="org.eclipse.ui.internalTweaklets" name="%ExtPoint.tweaklets" schema="schema/internalTweaklets.exsd"/>
75
   <extension-point id="org.eclipse.ui.internalTweaklets" name="%ExtPoint.tweaklets" schema="schema/internalTweaklets.exsd"/>
76
   <extension-point id="layouts" name="%ExtPoint.layouts" schema="schema/rap/layouts.exsd"/>
77
   <extension-point id="stackPresentations" name="%ExtPoint.configurableStackPresentation" schema="schema/rap/stackPresentations.exsd"/>
76
   
78
   
77
   <extension
79
   <extension
78
         point="org.eclipse.ui.contexts">
80
         point="org.eclipse.ui.contexts">
(-)build.properties (-1 / +3 lines)
Lines 14-20 Link Here
14
               plugin.xml,\
14
               plugin.xml,\
15
               about.html,\
15
               about.html,\
16
               .,\
16
               .,\
17
               META-INF/
17
               META-INF/,\
18
               patch.jar
18
src.includes = about.html,\
19
src.includes = about.html,\
19
               schema/
20
               schema/
20
source.. = src/
21
source.. = src/
22
source.patch.jar = src/
(-)plugin.properties (+2 lines)
Lines 66-71 Link Here
66
ExtPoint.browserSupport = Browser Support
66
ExtPoint.browserSupport = Browser Support
67
ExtPoint.statusHandlers = Status Handlers
67
ExtPoint.statusHandlers = Status Handlers
68
ExtPoint.tweaklets = Tweaklets (internal/experimental)
68
ExtPoint.tweaklets = Tweaklets (internal/experimental)
69
ExtPoint.layouts = Layouts
70
ExtPoint.configurableStackPresentation = Configurable Stacks
69
71
70
Views.Category.Basic = General
72
Views.Category.Basic = General
71
Views.IntroAdapter = Welcome
73
Views.IntroAdapter = Welcome
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 1-9 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
Eclipse-ExtensibleAPI: true
2
Bundle-ManifestVersion: 2
3
Bundle-ManifestVersion: 2
3
Bundle-Name: %Plugin.name
4
Bundle-Name: %Plugin.name
4
Bundle-SymbolicName: org.eclipse.rap.ui; singleton:=true
5
Bundle-SymbolicName: org.eclipse.rap.ui; singleton:=true
5
Bundle-Version: 1.2.0.qualifier
6
Bundle-Version: 1.2.0.qualifier
6
Bundle-ClassPath: .
7
Bundle-ClassPath: patch.jar,
8
 .
7
Bundle-Activator: org.eclipse.ui.internal.UIPlugin
9
Bundle-Activator: org.eclipse.ui.internal.UIPlugin
8
Bundle-ActivationPolicy: lazy
10
Bundle-ActivationPolicy: lazy
9
Bundle-Vendor: %Plugin.providerName
11
Bundle-Vendor: %Plugin.providerName
(-)schema/rap/branding.exsd (-26 / +102 lines)
Lines 2-10 Link Here
2
<!-- Schema file written by PDE -->
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.rap.ui" xmlns="http://www.w3.org/2001/XMLSchema">
3
<schema targetNamespace="org.eclipse.rap.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
4
<annotation>
5
      <appInfo>
5
      <appinfo>
6
         <meta.schema plugin="org.eclipse.rap.ui" id="branding" name="Branding"/>
6
         <meta.schema plugin="org.eclipse.rap.ui" id="branding" name="Branding"/>
7
      </appInfo>
7
      </appinfo>
8
      <documentation>
8
      <documentation>
9
         The branding extension points allows you to have a RCP-like branding functionality but with additional aspects regarding web applications. You can specify values for the used servlet name or the favicon. Additionally you&apos;re able to group entrypoints together to one branding which helps you to brand external entrypoints.
9
         The branding extension points allows you to have a RCP-like branding functionality but with additional aspects regarding web applications. You can specify values for the used servlet name or the favicon. Additionally you&apos;re able to group entrypoints together to one branding which helps you to brand external entrypoints.
10
      </documentation>
10
      </documentation>
Lines 12-20 Link Here
12
12
13
   <element name="extension">
13
   <element name="extension">
14
      <annotation>
14
      <annotation>
15
         <appInfo>
15
         <appinfo>
16
            <meta.element />
16
            <meta.element />
17
         </appInfo>
17
         </appinfo>
18
      </annotation>
18
      </annotation>
19
      <complexType>
19
      <complexType>
20
         <sequence minOccurs="1" maxOccurs="unbounded">
20
         <sequence minOccurs="1" maxOccurs="unbounded">
Lines 39-47 Link Here
39
               <documentation>
39
               <documentation>
40
                  
40
                  
41
               </documentation>
41
               </documentation>
42
               <appInfo>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
44
               </appinfo>
45
            </annotation>
45
            </annotation>
46
         </attribute>
46
         </attribute>
47
      </complexType>
47
      </complexType>
Lines 49-62 Link Here
49
49
50
   <element name="branding">
50
   <element name="branding">
51
      <annotation>
51
      <annotation>
52
         <appInfo>
52
         <appinfo>
53
            <meta.element labelAttribute="title"/>
53
            <meta.element labelAttribute="title"/>
54
         </appInfo>
54
         </appinfo>
55
      </annotation>
55
      </annotation>
56
      <complexType>
56
      <complexType>
57
         <sequence>
57
         <sequence>
58
            <element ref="additionalHeaders" minOccurs="0" maxOccurs="1"/>
58
            <element ref="additionalHeaders" minOccurs="0" maxOccurs="1"/>
59
            <element ref="associatedEntrypoints" minOccurs="0" maxOccurs="1"/>
59
            <element ref="associatedEntrypoints" minOccurs="0" maxOccurs="1"/>
60
            <element ref="presentationFactory" minOccurs="0" maxOccurs="1"/>
60
         </sequence>
61
         </sequence>
61
         <attribute name="id" type="string" use="required">
62
         <attribute name="id" type="string" use="required">
62
            <annotation>
63
            <annotation>
Lines 91-99 Link Here
91
               <documentation>
92
               <documentation>
92
                  The title attribute is responsible for the title of the RAP application. This will show up in the browser window or as title of the tab in the browser.
93
                  The title attribute is responsible for the title of the RAP application. This will show up in the browser window or as title of the tab in the browser.
93
               </documentation>
94
               </documentation>
94
               <appInfo>
95
               <appinfo>
95
                  <meta.attribute translatable="true"/>
96
                  <meta.attribute translatable="true"/>
96
               </appInfo>
97
               </appinfo>
97
            </annotation>
98
            </annotation>
98
         </attribute>
99
         </attribute>
99
         <attribute name="favicon" type="string">
100
         <attribute name="favicon" type="string">
Lines 101-109 Link Here
101
               <documentation>
102
               <documentation>
102
                  If you have a logo or something for your web application you put its path here so it can be displayed as icon in the browser near the adressbar or in the favourites. Be sure you specify a file in the .ico format as most browsers don&apos;t accept other image types as favicons.
103
                  If you have a logo or something for your web application you put its path here so it can be displayed as icon in the browser near the adressbar or in the favourites. Be sure you specify a file in the .ico format as most browsers don&apos;t accept other image types as favicons.
103
               </documentation>
104
               </documentation>
104
               <appInfo>
105
               <appinfo>
105
                  <meta.attribute kind="resource"/>
106
                  <meta.attribute kind="resource"/>
106
               </appInfo>
107
               </appinfo>
107
            </annotation>
108
            </annotation>
108
         </attribute>
109
         </attribute>
109
         <attribute name="body" type="string">
110
         <attribute name="body" type="string">
Lines 111-119 Link Here
111
               <documentation>
112
               <documentation>
112
                  You can define any valid html file to be used as body of the RAP startup page. You can put whatever you want in it as long as it does not break the page.
113
                  You can define any valid html file to be used as body of the RAP startup page. You can put whatever you want in it as long as it does not break the page.
113
               </documentation>
114
               </documentation>
114
               <appInfo>
115
               <appinfo>
115
                  <meta.attribute kind="resource"/>
116
                  <meta.attribute kind="resource"/>
116
               </appInfo>
117
               </appinfo>
117
            </annotation>
118
            </annotation>
118
         </attribute>
119
         </attribute>
119
         <attribute name="exitConfirmationClass" type="string">
120
         <attribute name="exitConfirmationClass" type="string">
Lines 129-137 Link Here
129
This will only work in browsers of the Mozilla family and Internet Explorer.
130
This will only work in browsers of the Mozilla family and Internet Explorer.
130
&lt;/p&gt;
131
&lt;/p&gt;
131
               </documentation>
132
               </documentation>
132
               <appInfo>
133
               <appinfo>
133
                  <meta.attribute kind="java" basedOn=":org.eclipse.rap.ui.branding.IExitConfirmation"/>
134
                  <meta.attribute kind="java" basedOn=":org.eclipse.rap.ui.branding.IExitConfirmation"/>
134
               </appInfo>
135
               </appinfo>
135
            </annotation>
136
            </annotation>
136
         </attribute>
137
         </attribute>
137
      </complexType>
138
      </complexType>
Lines 239-247 Link Here
239
240
240
   <element name="entrypoint">
241
   <element name="entrypoint">
241
      <annotation>
242
      <annotation>
242
         <appInfo>
243
         <appinfo>
243
            <meta.element labelAttribute="id"/>
244
            <meta.element labelAttribute="id"/>
244
         </appInfo>
245
         </appinfo>
245
         <documentation>
246
         <documentation>
246
            An element which references to an existing entrypoint defined by &lt;code&gt;org.eclipse.rap.ui.entrypoint&lt;/code&gt;.
247
            An element which references to an existing entrypoint defined by &lt;code&gt;org.eclipse.rap.ui.entrypoint&lt;/code&gt;.
247
         </documentation>
248
         </documentation>
Lines 257-275 Link Here
257
      </complexType>
258
      </complexType>
258
   </element>
259
   </element>
259
260
261
   <element name="presentationFactory">
262
      <complexType>
263
         <sequence>
264
            <element ref="stackPresentation" minOccurs="0" maxOccurs="unbounded"/>
265
            <element ref="defaultStackPresentation" minOccurs="0" maxOccurs="1"/>
266
         </sequence>
267
         <attribute name="id" type="string" use="required">
268
            <annotation>
269
               <documentation>
270
                  The id of the PresentationFactory to load.
271
               </documentation>
272
            </annotation>
273
         </attribute>
274
         <attribute name="defaultLayoutId" type="string">
275
            <annotation>
276
               <documentation>
277
                  The id of the default Layout to load.
278
               </documentation>
279
            </annotation>
280
         </attribute>
281
         <attribute name="name" type="string">
282
            <annotation>
283
               <documentation>
284
                  
285
               </documentation>
286
            </annotation>
287
         </attribute>
288
      </complexType>
289
   </element>
290
291
   <element name="stackPresentation">
292
      <complexType>
293
         <attribute name="id" type="string" use="required">
294
            <annotation>
295
               <documentation>
296
                  The id of the StackPresentation
297
               </documentation>
298
            </annotation>
299
         </attribute>
300
         <attribute name="partId" type="string" use="required">
301
            <annotation>
302
               <documentation>
303
                  The id of the part to couple with the id of the StackPresentation.
304
               </documentation>
305
            </annotation>
306
         </attribute>
307
         <attribute name="name" type="string">
308
            <annotation>
309
               <documentation>
310
                  
311
               </documentation>
312
            </annotation>
313
         </attribute>
314
      </complexType>
315
   </element>
316
317
   <element name="defaultStackPresentation">
318
      <complexType>
319
         <attribute name="id" type="string" use="required">
320
            <annotation>
321
               <documentation>
322
                  The id of the StackPresentation, which is loaded if no mapping for parts and stackPresentations exists.
323
               </documentation>
324
            </annotation>
325
         </attribute>
326
         <attribute name="name" type="string">
327
            <annotation>
328
               <documentation>
329
                  
330
               </documentation>
331
            </annotation>
332
         </attribute>
333
      </complexType>
334
   </element>
335
260
   <annotation>
336
   <annotation>
261
      <appInfo>
337
      <appinfo>
262
         <meta.section type="since"/>
338
         <meta.section type="since"/>
263
      </appInfo>
339
      </appinfo>
264
      <documentation>
340
      <documentation>
265
         RAP 1.0
341
         RAP 1.0
266
      </documentation>
342
      </documentation>
267
   </annotation>
343
   </annotation>
268
344
269
   <annotation>
345
   <annotation>
270
      <appInfo>
346
      <appinfo>
271
         <meta.section type="examples"/>
347
         <meta.section type="examples"/>
272
      </appInfo>
348
      </appinfo>
273
      <documentation>
349
      <documentation>
274
         &lt;pre&gt;
350
         &lt;pre&gt;
275
&lt;extension
351
&lt;extension
Lines 290-298 Link Here
290
   </annotation>
366
   </annotation>
291
367
292
   <annotation>
368
   <annotation>
293
      <appInfo>
369
      <appinfo>
294
         <meta.section type="apiInfo"/>
370
         <meta.section type="apiInfo"/>
295
      </appInfo>
371
      </appinfo>
296
      <documentation>
372
      <documentation>
297
         There is no API available for branding.
373
         There is no API available for branding.
298
      </documentation>
374
      </documentation>
Lines 300-308 Link Here
300
376
301
377
302
   <annotation>
378
   <annotation>
303
      <appInfo>
379
      <appinfo>
304
         <meta.section type="copyright"/>
380
         <meta.section type="copyright"/>
305
      </appInfo>
381
      </appinfo>
306
      <documentation>
382
      <documentation>
307
         Copyright (c) 2007 Innoopract Informationssysteme GmbH and others.&lt;br&gt;
383
         Copyright (c) 2007 Innoopract Informationssysteme GmbH and others.&lt;br&gt;
308
All rights reserved. This program and the accompanying materials are made
384
All rights reserved. This program and the accompanying materials are made
(-)schema/rap/stackPresentations.exsd (+191 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.rap.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.eclipse.rap.ui" id="stackPresentations" name="StackPresentations"/>
7
      </appinfo>
8
      <documentation>
9
         This extension point is used to register &lt;code&gt;ConfigurableStack&lt;/code&gt;s. This object extending a ordinary &lt;code&gt;StackPresentation&lt;/code&gt; so it can be used to style a &lt;code&gt;LayoutPart&lt;/code&gt;. To register such a &lt;code&gt;ConfigurableStack&lt;/code&gt; only makes sence if the PresentationFactory is a &lt;code&gt;org.eclipse.rap.presentation.PresentationFactory&lt;/code&gt;. Because only this PresentationFactory can handle a &lt;code&gt;ConfigurableStack&lt;/code&gt;.&lt;br&gt;
10
This extension point is also used to couple a &lt;code&gt;ConfigurationAction&lt;/code&gt; to such a &lt;code&gt;ConfigurableStack&lt;/code&gt;. With this you can implement different configuration behaviours for different &lt;code&gt;ConfigurableStack&lt;/code&gt; implementations.&lt;br&gt;
11
You can define default StackPresentations for a part using the &lt;code&gt;org.eclipse.rap.ui.branding&lt;/code&gt; extension point.
12
      </documentation>
13
   </annotation>
14
15
   <element name="extension">
16
      <annotation>
17
         <appinfo>
18
            <meta.element />
19
         </appinfo>
20
      </annotation>
21
      <complexType>
22
         <sequence minOccurs="1" maxOccurs="unbounded">
23
            <element ref="stackPresentation" minOccurs="1" maxOccurs="unbounded"/>
24
         </sequence>
25
         <attribute name="point" type="string" use="required">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="id" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
            </annotation>
38
         </attribute>
39
         <attribute name="name" type="string">
40
            <annotation>
41
               <documentation>
42
                  
43
               </documentation>
44
               <appinfo>
45
                  <meta.attribute translatable="true"/>
46
               </appinfo>
47
            </annotation>
48
         </attribute>
49
      </complexType>
50
   </element>
51
52
   <element name="stackPresentation">
53
      <complexType>
54
         <attribute name="id" type="string" use="required">
55
            <annotation>
56
               <documentation>
57
                  The identifier for the ConfigurableStack. This is for load and save such a part presentation.
58
               </documentation>
59
            </annotation>
60
         </attribute>
61
         <attribute name="class" type="string" use="required">
62
            <annotation>
63
               <documentation>
64
                  An implementation of &lt;code&gt;ConfigurableStack&lt;/code&gt;
65
               </documentation>
66
               <appinfo>
67
                  <meta.attribute kind="java" basedOn="org.eclipse.rap.ui.interactiondesign.ConfigurableStack:"/>
68
               </appinfo>
69
            </annotation>
70
         </attribute>
71
         <attribute name="name" type="string" use="required">
72
            <annotation>
73
               <documentation>
74
                  The name of ConfigurableStack, this is just to give it a readable name.
75
               </documentation>
76
            </annotation>
77
         </attribute>
78
         <attribute name="type" use="required">
79
            <annotation>
80
               <documentation>
81
                  This defines the type where the ConfigurableStack can be used. there are three possible types: Editor, View and StandaloneView.
82
               </documentation>
83
            </annotation>
84
            <simpleType>
85
               <restriction base="string">
86
                  <enumeration value="editor">
87
                  </enumeration>
88
                  <enumeration value="view">
89
                  </enumeration>
90
                  <enumeration value="standaloneview">
91
                  </enumeration>
92
               </restriction>
93
            </simpleType>
94
         </attribute>
95
         <attribute name="actionClass" type="string">
96
            <annotation>
97
               <documentation>
98
                  An implementation of &lt;code&gt;ConfigurationAction&lt;/code&gt;.
99
With this action you can implement configuration bahaviour e.g. this action can create a popup dialog that shows configuration elements.
100
               </documentation>
101
               <appinfo>
102
                  <meta.attribute kind="java" basedOn="org.eclipse.rap.ui.interactiondesign.RAPConfigurationAction:"/>
103
               </appinfo>
104
            </annotation>
105
         </attribute>
106
         <attribute name="actionIcon" type="string">
107
            <annotation>
108
               <documentation>
109
                  The icon for the ConfigurationAction.
110
               </documentation>
111
               <appinfo>
112
                  <meta.attribute kind="resource"/>
113
               </appinfo>
114
            </annotation>
115
         </attribute>
116
         <attribute name="menuIcon" type="string">
117
            <annotation>
118
               <documentation>
119
                  The icon for a view&apos;s menu if it has one.
120
               </documentation>
121
               <appinfo>
122
                  <meta.attribute kind="resource"/>
123
               </appinfo>
124
            </annotation>
125
         </attribute>
126
      </complexType>
127
   </element>
128
129
   <annotation>
130
      <appinfo>
131
         <meta.section type="since"/>
132
      </appinfo>
133
      <documentation>
134
         RAP 1.2
135
      </documentation>
136
   </annotation>
137
138
   <annotation>
139
      <appinfo>
140
         <meta.section type="examples"/>
141
      </appinfo>
142
      <documentation>
143
         &lt;pre&gt;
144
&lt;extension
145
         point=&quot;org.eclipse.ui.presentations.StackPresentations&quot;&gt;
146
      &lt;stackPresentation
147
            actionClass=&quot;org.eclipse.rap.ui.interactiondesign.example.configaction.ExampleConfigAction&quot;
148
            actionIcon=&quot;icons/configure.png&quot;
149
            class=&quot;org.eclipse.rap.ui.interactiondesign.example.stacks.NavigationPaneStackPresentation&quot;
150
            id=&quot;org.eclipse.rap.ui.interactiondesign.navigationPaneStackPresentation&quot;
151
            menuIcon=&quot;icons/menuIcon.gif&quot;
152
            name=&quot;Navigation Pane&quot;
153
            type=&quot;view&quot;&gt;
154
      &lt;/stackPresentation&gt;
155
&lt;/extension&gt;      
156
&lt;/pre&gt;
157
      </documentation>
158
   </annotation>
159
160
   <annotation>
161
      <appinfo>
162
         <meta.section type="apiinfo"/>
163
      </appinfo>
164
      <documentation>
165
         Each stackPresentation has to extend &lt;code&gt;org.eclipse.rap.ui.interactiondesign.ConfigurableStack&lt;/code&gt; to handle different mechanisms, e.g. stackPresentation changing on the fly and so on.
166
      </documentation>
167
   </annotation>
168
169
   <annotation>
170
      <appinfo>
171
         <meta.section type="implementation"/>
172
      </appinfo>
173
      <documentation>
174
         A detailed implementation example can be found in the &lt;code&gt;org.eclipse.rap.presentation.example&lt;/code&gt; project. This project defines two different &lt;code&gt;ConfigurableStack&lt;/code&gt; implementations.
175
      </documentation>
176
   </annotation>
177
178
   <annotation>
179
      <appinfo>
180
         <meta.section type="copyright"/>
181
      </appinfo>
182
      <documentation>
183
         Copyright (c) 2008 EclipseSource and others. All rights reserved. This
184
program and the accompanying materials are made available under the terms of
185
the Eclipse Public License v1.0 which accompanies this distribution, and is
186
available at &lt;a 
187
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
188
      </documentation>
189
   </annotation>
190
191
</schema>
(-)schema/rap/layouts.exsd (+194 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.rap.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.eclipse.rap.ui" id="layouts" name="Layouts"/>
7
      </appinfo>
8
      <documentation>
9
         This extension point is used to register a custom Layout. This means a grafical Layout not a Layout from the programmers point of view.&lt;br&gt;
10
Every Layout can hold attributes called LayoutSets. A LayoutSet is a simple container for images, fonts, colors and position data. These sets are usually coupled to a &lt;code&gt;ElementBuilder&lt;/code&gt;.&lt;br&gt;
11
A Layout can override LayoutSets of other Layouts. These overriden LayoutSets are used if the user switch the Layout during runtime.&lt;br&gt;
12
The default Layout can be defined by contributing to the &lt;code&gt;org.eclipse.rap.ui.branding&lt;/code&gt; extension point. If there is no default Layout defined a fallback mechanism will be used to show the standard Layout.
13
      </documentation>
14
   </annotation>
15
16
   <element name="extension">
17
      <annotation>
18
         <appinfo>
19
            <meta.element />
20
         </appinfo>
21
      </annotation>
22
      <complexType>
23
         <sequence>
24
            <element ref="layout" minOccurs="1" maxOccurs="unbounded"/>
25
         </sequence>
26
         <attribute name="point" type="string" use="required">
27
            <annotation>
28
               <documentation>
29
                  
30
               </documentation>
31
            </annotation>
32
         </attribute>
33
         <attribute name="id" type="string">
34
            <annotation>
35
               <documentation>
36
                  
37
               </documentation>
38
            </annotation>
39
         </attribute>
40
         <attribute name="name" type="string">
41
            <annotation>
42
               <documentation>
43
                  
44
               </documentation>
45
               <appinfo>
46
                  <meta.attribute translatable="true"/>
47
               </appinfo>
48
            </annotation>
49
         </attribute>
50
      </complexType>
51
   </element>
52
53
   <element name="layoutSet">
54
      <complexType>
55
         <attribute name="id" type="string" use="required">
56
            <annotation>
57
               <documentation>
58
                  The unique identifier for a LayoutSet. This id can be used to override a LayoutSet in a different Layout.
59
               </documentation>
60
            </annotation>
61
         </attribute>
62
         <attribute name="name" type="string">
63
            <annotation>
64
               <documentation>
65
                  This optional attribute is just to give the LayoutSet a readable name.
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
         <attribute name="class" type="string" use="required">
70
            <annotation>
71
               <documentation>
72
                  The definition of a LayoutSet. This is a class that has to implement the ILayoutSetInitializer interface.
73
               </documentation>
74
               <appinfo>
75
                  <meta.attribute kind="java" basedOn=":org.eclipse.rap.ui.interactiondesign.elements.model.ILayoutSetInitializer"/>
76
               </appinfo>
77
            </annotation>
78
         </attribute>
79
      </complexType>
80
   </element>
81
82
   <element name="layout">
83
      <complexType>
84
         <sequence>
85
            <element ref="layoutSet" minOccurs="1" maxOccurs="unbounded"/>
86
         </sequence>
87
         <attribute name="id" type="string" use="required">
88
            <annotation>
89
               <documentation>
90
                  
91
               </documentation>
92
            </annotation>
93
         </attribute>
94
         <attribute name="name" type="string">
95
            <annotation>
96
               <documentation>
97
                  
98
               </documentation>
99
            </annotation>
100
         </attribute>
101
      </complexType>
102
   </element>
103
104
   <annotation>
105
      <appinfo>
106
         <meta.section type="since"/>
107
      </appinfo>
108
      <documentation>
109
         RAP 1.2
110
      </documentation>
111
   </annotation>
112
113
   <annotation>
114
      <appinfo>
115
         <meta.section type="examples"/>
116
      </appinfo>
117
      <documentation>
118
         The following is an example of a Layout with three LayoutSets: 
119
&lt;p&gt;
120
&lt;pre&gt;
121
&lt;extension
122
         id=&quot;org.eclipse.presentation.example.layout&quot;
123
         name=&quot;Example Layout&quot;
124
         point=&quot;org.eclipse.ui.presentations.Layouts&quot;&gt;
125
      &lt;LayoutSet
126
            class=&quot;org.eclipse.rap.ui.interactiondesign.example.layoutset.HeaderLayoutSet2&quot;
127
            id=&quot;header.layoutset&quot;
128
            name=&quot;Header2&quot;&gt;
129
      &lt;/LayoutSet&gt;
130
      &lt;LayoutSet
131
            class=&quot;org.eclipse.rap.ui.interactiondesign.example.layoutset.MacBarLayoutSet2&quot;
132
            id=&quot;macBar.layoutset&quot;
133
            name=&quot;MacBar 2&quot;&gt;
134
      &lt;/LayoutSet&gt;
135
      &lt;LayoutSet
136
            class=&quot;org.eclipse.rap.ui.interactiondesign.example.layoutset.FooterLayoutSet2&quot;
137
            id=&quot;footer.layoutset&quot;
138
            name=&quot;Footer&quot;&gt;
139
      &lt;/LayoutSet&gt;
140
      &lt;LayoutSet
141
            class=&quot;org.eclipse.rap.ui.interactiondesign.example.layoutset.NavigationPaneLayoutSet2&quot;
142
            id=&quot;navigationpane.layoutset&quot;
143
            name=&quot;NavigationPane&quot;&gt;
144
      &lt;/LayoutSet&gt;
145
   &lt;/extension&gt;
146
 &lt;/pre&gt;
147
 &lt;/p&gt;
148
      </documentation>
149
   </annotation>
150
151
   <annotation>
152
      <appinfo>
153
         <meta.section type="apiinfo"/>
154
      </appinfo>
155
      <documentation>
156
         Each LayoutSet in a Layout has to implement the &lt;code&gt;ILayoutSetInitializer&lt;/code&gt; interface. The method within is called during the plugin activation to initialize components like images or fonts for this LayoutSet. This implementation can look like this:
157
158
&lt;pre&gt;
159
public class HeaderLayoutSet implements ILayoutSetInitializer {
160
  public void initializeLayoutSet( LayoutSet layoutSet ) {
161
    layoutSet.addImagePath( HeaderBuilderData.LEFT, &quot;icons/headerLeft.png&quot; );
162
    layoutSet.addImagePath( HeaderBuilderData.CENTER, &quot;icons/headerCenter.png&quot; );
163
    layoutSet.addImagePath( HeaderBuilderData.RIGHT, &quot;icons/headerRight.png&quot; );
164
    layoutSet.addImagePath( HeaderBuilderData.LOGO, &quot;icons/headerLogo.png&quot; );
165
    addHeaderPositions( layoutSet );
166
  }
167
}
168
&lt;/pre&gt;
169
      </documentation>
170
   </annotation>
171
172
   <annotation>
173
      <appinfo>
174
         <meta.section type="implementation"/>
175
      </appinfo>
176
      <documentation>
177
         A detailed implementation example can be found in the &lt;code&gt;org.eclipse.rap.presentation.example&lt;/code&gt; project. This project defines two Layouts and a bunch of LayoutSets. They look not pretty but they do their job.
178
      </documentation>
179
   </annotation>
180
181
   <annotation>
182
      <appinfo>
183
         <meta.section type="copyright"/>
184
      </appinfo>
185
      <documentation>
186
         Copyright (c) 2008 EclipseSource and others. All rights reserved. This
187
program and the accompanying materials are made available under the terms of
188
the Eclipse Public License v1.0 which accompanies this distribution, and is
189
available at &lt;a 
190
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
191
      </documentation>
192
   </annotation>
193
194
</schema>

Return to bug 261795