|
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 |
} |