Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 62218 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/presentations/R21EditorStackPresentation.java (-815 / +901 lines)
Lines 11-17 Link Here
11
package org.eclipse.ui.internal.presentations;
11
package org.eclipse.ui.internal.presentations;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
14
16
17
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.jface.action.GroupMarker;
18
import org.eclipse.jface.action.GroupMarker;
16
import org.eclipse.jface.action.IMenuManager;
19
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.MenuManager;
20
import org.eclipse.jface.action.MenuManager;
Lines 36-43 Link Here
36
import org.eclipse.swt.widgets.Event;
39
import org.eclipse.swt.widgets.Event;
37
import org.eclipse.swt.widgets.Listener;
40
import org.eclipse.swt.widgets.Listener;
38
import org.eclipse.swt.widgets.Menu;
41
import org.eclipse.swt.widgets.Menu;
42
import org.eclipse.ui.IMemento;
39
import org.eclipse.ui.IPropertyListener;
43
import org.eclipse.ui.IPropertyListener;
40
import org.eclipse.ui.internal.IPreferenceConstants;
44
import org.eclipse.ui.internal.IPreferenceConstants;
45
import org.eclipse.ui.internal.IWorkbenchConstants;
41
import org.eclipse.ui.internal.WorkbenchPlugin;
46
import org.eclipse.ui.internal.WorkbenchPlugin;
42
import org.eclipse.ui.internal.WorkbenchWindow;
47
import org.eclipse.ui.internal.WorkbenchWindow;
43
import org.eclipse.ui.internal.dnd.DragUtil;
48
import org.eclipse.ui.internal.dnd.DragUtil;
Lines 49-54 Link Here
49
import org.eclipse.ui.internal.presentations.r21.widgets.CTabItem;
54
import org.eclipse.ui.internal.presentations.r21.widgets.CTabItem;
50
import org.eclipse.ui.presentations.IPartMenu;
55
import org.eclipse.ui.presentations.IPartMenu;
51
import org.eclipse.ui.presentations.IPresentablePart;
56
import org.eclipse.ui.presentations.IPresentablePart;
57
import org.eclipse.ui.presentations.IPresentationSerializer;
52
import org.eclipse.ui.presentations.IStackPresentationSite;
58
import org.eclipse.ui.presentations.IStackPresentationSite;
53
import org.eclipse.ui.presentations.PresentationUtil;
59
import org.eclipse.ui.presentations.PresentationUtil;
54
import org.eclipse.ui.presentations.StackDropResult;
60
import org.eclipse.ui.presentations.StackDropResult;
Lines 65-895 Link Here
65
 */
71
 */
66
public class R21EditorStackPresentation extends StackPresentation {
72
public class R21EditorStackPresentation extends StackPresentation {
67
73
68
    /** the tab folder */
74
	/** the tab folder */
69
    private CTabFolder tabFolder;
75
	private CTabFolder tabFolder;
70
76
71
    /** the drag listener */
77
	/** the drag listener */
72
    private Listener dragListener = new Listener() {
78
	private Listener dragListener = new Listener() {
73
74
        public void handleEvent(Event event) {
75
            Point localPos = new Point(event.x, event.y);
76
            CTabItem tabUnderPointer = tabFolder.getItem(localPos);
77
78
            if (tabUnderPointer == null) {
79
                // drag the entire stack
80
                if (getSite().isStackMoveable())
81
                    getSite().dragStart(tabFolder.toDisplay(localPos), false);
82
                return;
83
            }
84
85
            IPresentablePart part = getPartForTab(tabUnderPointer);
86
87
            if (getSite().isPartMoveable(part)) {
88
                // drag the part
89
                getSite().dragStart(part, tabFolder.toDisplay(localPos), false);
90
            }
91
        }
92
    };
93
94
    /** the listener that will close the tab */
95
    private CTabFolderListener closeListener = new CTabFolderListener() {
96
97
        public void itemClosed(CTabFolderEvent e) {
98
            CTabItem item = (CTabItem) e.item;
99
            if (null != item) {
100
                e.doit = false; // otherwise tab is auto disposed on return
101
                getSite().close(new IPresentablePart[] { getPartForTab(item) });
102
            }
103
        }
104
    };
105
106
    /** the current part */
107
    private IPresentablePart current;
108
109
    /** the system menu */
110
    private MenuManager systemMenuManager = new MenuManager();
111
112
    /** the shared preference store */
113
    private static IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault()
114
            .getPreferenceStore();
115
79
80
		public void handleEvent(Event event) {
81
			Point localPos = new Point(event.x, event.y);
82
			CTabItem tabUnderPointer = tabFolder.getItem(localPos);
83
84
			if (tabUnderPointer == null) {
85
				// drag the entire stack
86
				if (getSite().isStackMoveable())
87
					getSite().dragStart(tabFolder.toDisplay(localPos), false);
88
				return;
89
			}
90
91
			IPresentablePart part = getPartForTab(tabUnderPointer);
92
93
			if (getSite().isPartMoveable(part)) {
94
				// drag the part
95
				getSite().dragStart(part, tabFolder.toDisplay(localPos), false);
96
			}
97
		}
98
	};
99
100
	/** the listener that will close the tab */
101
	private CTabFolderListener closeListener = new CTabFolderListener() {
102
103
		public void itemClosed(CTabFolderEvent e) {
104
			CTabItem item = (CTabItem) e.item;
105
			if (null != item) {
106
				e.doit = false; // otherwise tab is auto disposed on return
107
				getSite().close(new IPresentablePart[] { getPartForTab(item) });
108
			}
109
		}
110
	};
111
112
	/** the current part */
113
	private IPresentablePart current;
114
115
	/** the system menu */
116
	private MenuManager systemMenuManager = new MenuManager();
117
118
	/** the shared preference store */
119
	private static IPreferenceStore preferenceStore = WorkbenchPlugin
120
			.getDefault().getPreferenceStore();
116
121
117
	// don't reset this dynamically, so just keep the information static.
122
	// don't reset this dynamically, so just keep the information static.
118
	// see bug:
123
	// see bug:
119
	//   75422 [Presentations] Switching presentation to R21 switches immediately, but only partially
124
	// 75422 [Presentations] Switching presentation to R21 switches immediately,
120
    private static int tabPos = preferenceStore.getInt(IPreferenceConstants.EDITOR_TAB_POSITION);
125
	// but only partially
121
126
	private static int tabPos = preferenceStore
122
    /** the tab item property holding the part */
127
			.getInt(IPreferenceConstants.EDITOR_TAB_POSITION);
123
    private final static String TAB_DATA = R21EditorStackPresentation.class
128
124
            .getName()
129
	/** the tab item property holding the part */
125
            + ".partId"; //$NON-NLS-1$
130
	private final static String TAB_DATA = R21EditorStackPresentation.class
126
131
			.getName()
127
    /** the mouse listener for setting focus */
132
			+ ".partId"; //$NON-NLS-1$
128
    private MouseListener mouseListener = new MouseAdapter() {
133
129
134
	/** the mouse listener for setting focus */
130
        /*
135
	private MouseListener mouseListener = new MouseAdapter() {
131
         * (non-Javadoc)
136
132
         * 
137
		/*
133
         * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
138
		 * (non-Javadoc)
134
         */
139
		 * 
135
        public void mouseDown(MouseEvent e) {
140
		 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
136
            if (e.widget instanceof Control) {
141
		 */
137
                Control ctrl = (Control) e.widget;
142
		public void mouseDown(MouseEvent e) {
138
143
			if (e.widget instanceof Control) {
139
                Point globalPos = ctrl.toDisplay(new Point(e.x, e.y));
144
				Control ctrl = (Control) e.widget;
140
145
141
                CTabItem newItem = tabFolder.getItem(tabFolder
146
				Point globalPos = ctrl.toDisplay(new Point(e.x, e.y));
142
                        .toControl(globalPos));
147
143
                if (newItem != null) {
148
				CTabItem newItem = tabFolder.getItem(tabFolder
144
149
						.toControl(globalPos));
145
                    // show menu over icon
150
				if (newItem != null) {
146
                    if ((e.button == 1) && overImage(newItem, e.x)) {
151
147
                        getSite().selectPart(getPartForTab(newItem));
152
					// show menu over icon
148
                        showSystemMenu();
153
					if ((e.button == 1) && overImage(newItem, e.x)) {
149
                    }
154
						getSite().selectPart(getPartForTab(newItem));
150
155
						showSystemMenu();
151
                    // PR#1GDEZ25 - If selection will change in mouse up ignore
156
					}
152
                    // mouse down.
157
153
                    CTabItem oldItem = tabFolder.getSelection();
158
					// PR#1GDEZ25 - If selection will change in mouse up ignore
154
                    if (newItem != oldItem)
159
					// mouse down.
155
                        return;
160
					CTabItem oldItem = tabFolder.getSelection();
156
                }
161
					if (newItem != oldItem)
157
162
						return;
158
                // set focus
163
				}
159
                if (current != null) {
164
160
                    current.setFocus();
165
				// set focus
166
				if (current != null) {
167
					current.setFocus();
168
				}
169
			}
170
		}
171
172
		/*
173
		 * (non-Javadoc)
174
		 * 
175
		 * @see org.eclipse.swt.events.MouseAdapter#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
176
		 */
177
		public void mouseDoubleClick(MouseEvent e) {
178
			if (getSite().getState() == IStackPresentationSite.STATE_MAXIMIZED) {
179
				getSite().setState(IStackPresentationSite.STATE_RESTORED);
180
			} else {
181
				getSite().setState(IStackPresentationSite.STATE_MAXIMIZED);
182
			}
183
		}
184
	};
185
186
	/**
187
	 * Return true if <code>x</code> is over the tab item image.
188
	 * 
189
	 * @return true if <code>x</code> is over the tab item image
190
	 */
191
	static boolean overImage(CTabItem item, int x) {
192
		Rectangle imageBounds = item.getImage().getBounds();
193
		return x < (item.getBounds().x + imageBounds.x + imageBounds.width);
194
	}
195
196
	/** the menu listener for showing the menu */
197
	private Listener menuListener = new Listener() {
198
199
		/*
200
		 * (non-Javadoc)
201
		 * 
202
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
203
		 */
204
		public void handleEvent(Event event) {
205
			Point pos = new Point(event.x, event.y);
206
			showSystemMenu(pos);
207
		}
208
	};
209
210
	/** the selection listener */
211
	private Listener selectionListener = new Listener() {
212
213
		public void handleEvent(Event e) {
214
			IPresentablePart item = getPartForTab((CTabItem) e.item);
215
			if (item != null)
216
				getSite().selectPart(item);
217
		}
218
	};
219
220
	private Listener resizeListener = new Listener() {
221
222
		public void handleEvent(Event e) {
223
			setControlSize();
224
		}
225
	};
226
227
	/** a property change listener for the parts */
228
	private IPropertyListener childPropertyChangeListener = new IPropertyListener() {
229
230
		public void propertyChanged(Object source, int property) {
231
			if (source instanceof IPresentablePart) {
232
				IPresentablePart part = (IPresentablePart) source;
233
				childPropertyChanged(part, property);
234
			}
235
		}
236
	};
237
238
	/** a dispose listener to do some cleanups when a tab is disposed */
239
	private DisposeListener tabDisposeListener = new DisposeListener() {
240
241
		public void widgetDisposed(DisposeEvent e) {
242
			if (e.widget instanceof CTabItem) {
243
				CTabItem item = (CTabItem) e.widget;
244
				IPresentablePart part = getPartForTab(item);
245
				part.removePropertyListener(childPropertyChangeListener);
246
			}
247
		}
248
	};
249
250
	/** the shell listener for upgrading the gradient */
251
	private ShellAdapter shellListener = new ShellAdapter() {
252
253
		public void shellActivated(ShellEvent event) {
254
			updateGradient();
255
		}
256
257
		public void shellDeactivated(ShellEvent event) {
258
			updateGradient();
259
		}
260
	};
261
262
	/**
263
	 * Create a new presentation stack.
264
	 * 
265
	 * @param parent
266
	 *            the parent widget
267
	 * @param stackSite
268
	 *            the site
269
	 */
270
	public R21EditorStackPresentation(Composite parent,
271
			IStackPresentationSite stackSite) {
272
		super(stackSite);
273
274
		// create the tab folder
275
		tabFolder = new CTabFolder(parent, tabPos | SWT.BORDER);
276
277
		// minimum tab width
278
		tabFolder.MIN_TAB_WIDTH = preferenceStore
279
				.getInt(IPreferenceConstants.EDITOR_TAB_WIDTH);
280
281
		// prevent close button and scroll buttons from taking focus
282
		tabFolder.setTabList(new Control[0]);
283
284
		// enable close button in tab folder
285
		tabFolder.addCTabFolderListener(closeListener);
286
287
		// listener to switch between visible tabItems
288
		tabFolder.addListener(SWT.Selection, selectionListener);
289
290
		// listener to resize visible components
291
		tabFolder.addListener(SWT.Resize, resizeListener);
292
293
		// listen for mouse down on tab to set focus, show system menu and
294
		// maximize/restore.
295
		tabFolder.addMouseListener(mouseListener);
296
297
		// the menu
298
		tabFolder.addListener(SWT.MenuDetect, menuListener);
299
300
		// register drag listener
301
		PresentationUtil.addDragListener(tabFolder, dragListener);
302
303
		// add the shell listener to track shell activations
304
		// TODO: check if workaround can be removed (see bug 55458)
305
		tabFolder.getShell().addShellListener(shellListener);
306
307
		// initialize system menu
308
		populateSystemMenu(systemMenuManager);
309
	}
310
311
	/**
312
	 * Initializes the specified menu manager.
313
	 * 
314
	 * @param menuManager
315
	 */
316
	private void populateSystemMenu(IMenuManager menuManager) {
317
318
		menuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
319
		menuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
320
		menuManager.add(new UpdatingActionContributionItem(
321
				new SystemMenuRestore(getSite())));
322
		menuManager.add(new SystemMenuMove(getSite(), getPaneName()));
323
		menuManager.add(new GroupMarker("size")); //$NON-NLS-1$
324
		menuManager.add(new GroupMarker("state")); //$NON-NLS-1$
325
		// systemMenuManager.add(new UpdatingActionContributionItem(new
326
		// SystemMenuMinimize(getSite())));
327
		menuManager.add(new UpdatingActionContributionItem(
328
				new SystemMenuMaximize(getSite())));
329
		menuManager.add(new Separator("close")); //$NON-NLS-1$
330
		menuManager.add(new UpdatingActionContributionItem(new SystemMenuClose(
331
				getSite())));
332
333
		getSite().addSystemActions(menuManager);
334
	}
335
336
	/**
337
	 * Returns the index of the tab for the given part, or returns
338
	 * tabFolder.getItemCount() if there is no such tab.
339
	 * 
340
	 * @param part
341
	 *            part being searched for
342
	 * @return the index of the tab for the given part, or the number of tabs if
343
	 *         there is no such tab
344
	 */
345
	private final int indexOf(IPresentablePart part) {
346
		if (part == null)
347
			return tabFolder.getItemCount();
348
349
		CTabItem[] items = tabFolder.getItems();
350
		for (int idx = 0; idx < items.length; idx++)
351
			if (part == getPartForTab(items[idx]))
352
				return idx;
353
354
		return items.length;
355
	}
356
357
	/**
358
	 * Returns the tab for the given part, or null if there is no such tab
359
	 * 
360
	 * @param part
361
	 *            the part being searched for
362
	 * @return the tab for the given part, or null if there is no such tab
363
	 */
364
	protected final CTabItem getTab(IPresentablePart part) {
365
		CTabItem[] items = tabFolder.getItems();
366
		int idx = indexOf(part);
367
		return idx < items.length ? items[idx] : null;
368
	}
369
370
	/**
371
	 * @param part
372
	 * @param property
373
	 */
374
	protected void childPropertyChanged(IPresentablePart part, int property) {
375
		initTab(getTab(part), part);
376
	}
377
378
	protected final IPresentablePart getPartForTab(CTabItem item) {
379
		return (IPresentablePart) item.getData(TAB_DATA);
380
	}
381
382
	protected CTabFolder getTabFolder() {
383
		return tabFolder;
384
	}
385
386
	/**
387
	 * Answer whether the receiver is disposed.
388
	 * 
389
	 * @return boolean <code>true</code> if disposed
390
	 */
391
	public boolean isDisposed() {
392
		return tabFolder == null || tabFolder.isDisposed();
393
	}
394
395
	/**
396
	 * Set the size of a page in the folder.
397
	 */
398
	private void setControlSize() {
399
		if (current != null && tabFolder != null)
400
			current.setBounds(calculatePageBounds(tabFolder));
401
	}
402
403
	/**
404
	 * Calculate the bounds of the client area inside the folder
405
	 * 
406
	 * @param folder
407
	 * @return Rectangle the bounds of the client
408
	 */
409
	public static Rectangle calculatePageBounds(CTabFolder folder) {
410
		if (folder == null)
411
			return new Rectangle(0, 0, 0, 0);
412
413
		Rectangle bounds = folder.getBounds();
414
		Rectangle offset = folder.getClientArea();
415
		bounds.x += offset.x;
416
		bounds.y += offset.y;
417
		bounds.width = offset.width;
418
		bounds.height = offset.height;
419
		return bounds;
420
	}
421
422
	/*
423
	 * (non-Javadoc)
424
	 * 
425
	 * @see org.eclipse.ui.internal.skins.Presentation#dispose()
426
	 */
427
	public void dispose() {
428
		if (isDisposed())
429
			return;
430
431
		// remove shell listener
432
		tabFolder.getShell().removeShellListener(shellListener);
433
434
		// remove close listener
435
		tabFolder.removeCTabFolderListener(closeListener);
436
437
		// remove drag listener
438
		PresentationUtil.removeDragListener(tabFolder, dragListener);
439
440
		// dispose system menu manager
441
		systemMenuManager.dispose();
442
		systemMenuManager.removeAll();
443
444
		// dispose tab folder
445
		tabFolder.dispose();
446
		tabFolder = null;
447
	}
448
449
	/** the active state */
450
	private int activeState = AS_INACTIVE;
451
452
	/**
453
	 * Update the tab folder's colours to match the current theme settings and
454
	 * active state
455
	 */
456
	private void updateGradient() {
457
458
		if (isDisposed())
459
			return;
460
461
		Color fgColor;
462
		Color[] bgColors;
463
		int[] bgPercents;
464
		boolean vertical = false;
465
		if (activeState == AS_ACTIVE_FOCUS) {
466
			if (getShellActivated()) {
467
				fgColor = R21Colors.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
468
				bgColors = R21Colors.getActiveEditorGradient();
469
				bgPercents = R21Colors.getActiveEditorGradientPercents();
470
			} else {
471
				fgColor = R21Colors
472
						.getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
473
				bgColors = R21Colors.getDeactivatedEditorGradient();
474
				bgPercents = R21Colors.getDeactivatedEditorGradientPercents();
475
			}
476
477
		} else if (activeState == AS_ACTIVE_NOFOCUS) {
478
			fgColor = R21Colors.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
479
			bgColors = R21Colors.getActiveNoFocusEditorGradient();
480
			bgPercents = R21Colors.getActiveNoFocusEditorGradientPercents();
481
		} else {
482
			fgColor = null;
483
			bgColors = null;
484
			bgPercents = null;
485
		}
486
487
		drawGradient(fgColor, bgColors, bgPercents, vertical);
488
	}
489
490
	/**
491
	 * Sets the gradient for the selected tab
492
	 * 
493
	 * @param fgColor
494
	 * @param bgColors
495
	 * @param percentages
496
	 * @param vertical
497
	 */
498
	protected void drawGradient(Color fgColor, Color[] bgColors,
499
			int[] percentages, boolean vertical) {
500
		tabFolder.setSelectionForeground(fgColor);
501
		tabFolder.setSelectionBackground(bgColors, percentages);
502
		tabFolder.update();
503
	}
504
505
	/**
506
	 * Return whether the window's shell is activated
507
	 */
508
	/* package */boolean getShellActivated() {
509
		Window window = getWindow();
510
		if (window instanceof WorkbenchWindow)
511
			return ((WorkbenchWindow) window).getShellActivated();
512
		return false;
513
	}
514
515
	/**
516
	 * Returns the top level window.
517
	 * 
518
	 * @return Window the window for the receiver
519
	 */
520
	public Window getWindow() {
521
		Control ctrl = getControl();
522
		if (ctrl != null) {
523
			Object data = ctrl.getShell().getData();
524
			if (data instanceof Window)
525
				return (Window) data;
526
		}
527
		return null;
528
	}
529
530
	/**
531
	 * Creates the tab item for the specified part.
532
	 * 
533
	 * @param part
534
	 * @param tabIndex
535
	 * @return the tab item for the part
536
	 */
537
	private CTabItem createPartTab(IPresentablePart part, int tabIndex) {
538
		CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE, tabIndex);
539
		tabItem.setData(TAB_DATA, part);
540
		part.addPropertyListener(childPropertyChangeListener);
541
		tabItem.addDisposeListener(tabDisposeListener);
542
		initTab(tabItem, part);
543
		return tabItem;
544
	}
545
546
	/**
547
	 * Initializes a tab for the given part. Sets the text, icon, tool tip, etc.
548
	 * This will also be called whenever a relevant property changes in the part
549
	 * to reflect those changes in the tab. Subclasses may override to change
550
	 * the appearance of tabs for a particular part.
551
	 * 
552
	 * @param tabItem
553
	 *            tab for the part
554
	 * @param part
555
	 *            the part being displayed
556
	 */
557
	protected void initTab(CTabItem tabItem, IPresentablePart part) {
558
559
		// set tab text and tooltip
560
		tabItem.setText(getLabelText(part, true, false));
561
		tabItem.setToolTipText(getLabelToolTipText(part));
562
563
		// set tab image
564
		tabItem.setImage(getLabelImage(part));
565
566
		// following code allows a disabled image
567
		// but the result was distracting: didn't see any disabled image
568
569
		// Image image = getLabelImage(part);
570
		// boolean useColorIcons = false; // should we use a preference setting?
571
		//
572
		// if (image == null || image.isDisposed()) {
573
		// // normal image
574
		// tabItem.setImage(null);
575
		// // disabled image
576
		// if (!useColorIcons) {
577
		// Image disableImage = tabItem.getDisabledImage();
578
		// if (disableImage != null) {
579
		// disableImage.dispose();
580
		// tabItem.setDisabledImage(null);
581
		// }
582
		// }
583
		// } else if (!image.equals(tabItem.getImage())) {
584
		// // normal image
585
		// tabItem.setImage(image);
586
		// // disabled image
587
		// if (!useColorIcons) {
588
		// Image disableImage = tabItem.getDisabledImage();
589
		// if (disableImage != null)
590
		// disableImage.dispose();
591
		// Display display = tabItem.getDisplay();
592
		// disableImage = new Image(display, image, SWT.IMAGE_DISABLE);
593
		// tabItem.setDisabledImage(disableImage);
594
		// }
595
		// }
596
597
	}
598
599
	/**
600
	 * Returns the label text that should be used for the tab item for the
601
	 * specified part
602
	 * 
603
	 * @param presentablePart
604
	 * @param dirtyLeft
605
	 * @param includePath
606
	 * @return a formated label text
607
	 */
608
	String getLabelText(IPresentablePart presentablePart, boolean dirtyLeft,
609
			boolean includePath) {
610
		String title = presentablePart.getName().trim();
611
		String text = title;
612
613
		if (includePath) {
614
			String titleTooltip = presentablePart.getTitleToolTip().trim();
615
616
			if (titleTooltip.endsWith(title))
617
				titleTooltip = titleTooltip.substring(0,
618
						titleTooltip.lastIndexOf(title)).trim();
619
620
			if (titleTooltip.endsWith("\\")) //$NON-NLS-1$
621
				titleTooltip = titleTooltip.substring(0,
622
						titleTooltip.lastIndexOf("\\")).trim(); //$NON-NLS-1$
623
624
			if (titleTooltip.endsWith("/")) //$NON-NLS-1$
625
				titleTooltip = titleTooltip.substring(0,
626
						titleTooltip.lastIndexOf("/")).trim(); //$NON-NLS-1$
627
628
			if (titleTooltip.length() >= 1)
629
				text += " - " + titleTooltip; //$NON-NLS-1$
630
		}
631
632
		if (presentablePart.isDirty()) {
633
			if (dirtyLeft)
634
				text = "* " + text; //$NON-NLS-1$
635
			else
636
				text = text + " *"; //$NON-NLS-1$
637
		}
638
639
		return text;
640
	}
641
642
	/**
643
	 * Returns the image used for the tab item
644
	 * 
645
	 * @param presentablePart
646
	 * @return an image
647
	 */
648
	Image getLabelImage(IPresentablePart presentablePart) {
649
		return presentablePart.getTitleImage();
650
	}
651
652
	/**
653
	 * Returns the tool tip text used for the tab item
654
	 * 
655
	 * @param presentablePart
656
	 * @return a tool tip text
657
	 */
658
	String getLabelToolTipText(IPresentablePart presentablePart) {
659
		return presentablePart.getTitleToolTip();
660
	}
661
662
	/*
663
	 * (non-Javadoc)
664
	 * 
665
	 * @see org.eclipse.ui.internal.skins.StackPresentation#addPart(org.eclipse.ui.internal.skins.IPresentablePart,
666
	 *      org.eclipse.ui.internal.skins.IPresentablePart)
667
	 */
668
	public void addPart(IPresentablePart newPart, Object cookie) {
669
670
		int idx;
671
672
		if (cookie instanceof Integer) {
673
			idx = ((Integer) cookie).intValue();
674
		} else {
675
			// Select a location for newly inserted parts
676
			idx = tabFolder.getItemCount();
677
		}
678
679
		addPart(newPart, idx);
680
	}
681
682
	/**
683
	 * Adds the given presentable part to this presentation at the given index.
684
	 * Does nothing if a tab already exists for the given part.
685
	 * 
686
	 * @param newPart
687
	 * @param index
688
	 */
689
	public void addPart(IPresentablePart newPart, int index) {
690
		// If we already have a tab for this part, do nothing
691
		if (getTab(newPart) != null) {
692
			return;
693
		}
694
		createPartTab(newPart, index);
695
696
		// setControlSize();
697
	}
698
699
	/*
700
	 * (non-Javadoc)
701
	 * 
702
	 * @see org.eclipse.ui.internal.skins.StackPresentation#removePart(org.eclipse.ui.internal.skins.IPresentablePart)
703
	 */
704
	public void removePart(IPresentablePart oldPart) {
705
		if (current == oldPart)
706
			current = null;
707
708
		CTabItem item = getTab(oldPart);
709
		if (item == null) {
710
			return;
711
		}
712
		oldPart.setVisible(false);
713
714
		item.dispose();
715
	}
716
717
	/*
718
	 * (non-Javadoc)
719
	 * 
720
	 * @see org.eclipse.ui.internal.skins.StackPresentation#selectPart(org.eclipse.ui.internal.skins.IPresentablePart)
721
	 */
722
	public void selectPart(IPresentablePart toSelect) {
723
		if (toSelect == current) {
724
			return;
725
		}
726
727
		if (current != null) {
728
			current.setVisible(false);
729
		}
730
731
		current = toSelect;
732
733
		if (current != null) {
734
			tabFolder.setSelection(indexOf(current));
735
			current.setVisible(true);
736
			setControlSize();
737
738
		}
739
	}
740
741
	/*
742
	 * (non-Javadoc)
743
	 * 
744
	 * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
745
	 */
746
	public void setBounds(Rectangle bounds) {
747
		tabFolder.setBounds(bounds);
748
		setControlSize();
749
	}
750
751
	/*
752
	 * (non-Javadoc)
753
	 * 
754
	 * @see org.eclipse.ui.internal.skins.Presentation#computeMinimumSize()
755
	 */
756
	public Point computeMinimumSize() {
757
		return Geometry.getSize(tabFolder.computeTrim(0, 0, 0, 0));
758
	}
759
760
	/*
761
	 * (non-Javadoc)
762
	 * 
763
	 * @see org.eclipse.ui.internal.skins.Presentation#setVisible(boolean)
764
	 */
765
	public void setVisible(boolean isVisible) {
766
		if (current != null)
767
			current.setVisible(isVisible);
768
769
		getTabFolder().setVisible(isVisible);
770
	}
771
772
	/*
773
	 * (non-Javadoc)
774
	 * 
775
	 * @see org.eclipse.ui.internal.skins.Presentation#setState(int)
776
	 */
777
	public void setState(int state) {
778
		// tabFolder.setMinimized(state == IPresentationSite.STATE_MINIMIZED);
779
		// tabFolder.setMaximized(state == IPresentationSite.STATE_MAXIMIZED);
780
	}
781
782
	/**
783
	 * Returns the system menu manager.
784
	 * 
785
	 * @return the system menu manager
786
	 */
787
	public IMenuManager getSystemMenuManager() {
788
		return systemMenuManager;
789
	}
790
791
	/**
792
	 * Shows the system context menu at the specified location
793
	 * 
794
	 * @param point
795
	 */
796
	protected void showSystemMenu(Point point) {
797
		Menu aMenu = systemMenuManager.createContextMenu(tabFolder.getParent());
798
		systemMenuManager.update(true);
799
		aMenu.setLocation(point.x, point.y);
800
		aMenu.setVisible(true);
801
	}
802
803
	/*
804
	 * (non-Javadoc)
805
	 * 
806
	 * @see org.eclipse.ui.internal.skins.Presentation#getControl()
807
	 */
808
	public Control getControl() {
809
		return tabFolder;
810
	}
811
812
	/*
813
	 * (non-Javadoc)
814
	 * 
815
	 * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control,
816
	 *      org.eclipse.swt.graphics.Point)
817
	 */
818
	public StackDropResult dragOver(Control currentControl, Point location) {
819
820
		// Determine which tab we're currently dragging over
821
		Point localPos = tabFolder.toControl(location);
822
		final CTabItem tabUnderPointer = tabFolder.getItem(localPos);
823
824
		// This drop target only deals with tabs... if we're not dragging over
825
		// a tab, exit.
826
		if (tabUnderPointer == null)
827
			return null;
828
829
		// workaround when left tab is dragged over next
830
		int dragOverIndex = tabFolder.indexOf(tabUnderPointer);
831
832
		return new StackDropResult(Geometry.toDisplay(tabFolder,
833
				tabUnderPointer.getBounds()), new Integer(dragOverIndex));
834
	}
835
836
	/*
837
	 * (non-Javadoc)
838
	 * 
839
	 * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu()
840
	 */
841
	public void showSystemMenu() {
842
		if (null != current) {
843
			// switch to the editor
844
			CTabItem item = getTab(current);
845
			getSite().selectPart(getCurrentPart());
846
			Rectangle bounds = item.getBounds();
847
			int y = bounds.height;
848
			if (getTabFolder().getTabPosition() == SWT.BOTTOM)
849
				y += bounds.y;
850
			showSystemMenu(getTabFolder().toDisplay(bounds.x, y));
851
		}
852
	}
853
854
	/*
855
	 * (non-Javadoc)
856
	 * 
857
	 * @see org.eclipse.ui.presentations.StackPresentation#showPaneMenu()
858
	 */
859
	public void showPaneMenu() {
860
		IPartMenu menu = getPartMenu();
861
862
		if (null != menu) {
863
			CTabItem tab = getTab(getCurrentPart());
864
865
			if (null != tab && null != tab.getControl()) {
866
				Rectangle bounds = DragUtil.getDisplayBounds(tab.getControl());
867
				menu.showMenu(new Point(bounds.x, bounds.y + bounds.height));
868
			}
869
		}
870
	}
871
872
	/**
873
	 * Returns the IPartMenu for the currently selected part, or null if the
874
	 * current part does not have a menu.
875
	 * 
876
	 * @return the IPartMenu for the currently selected part or null if none
877
	 */
878
	protected IPartMenu getPartMenu() {
879
		IPresentablePart part = getCurrentPart();
880
		if (part == null) {
881
			return null;
882
		}
883
884
		return part.getMenu();
885
	}
886
887
	/*
888
	 * (non-Javadoc)
889
	 * 
890
	 * @see org.eclipse.ui.presentations.StackPresentation#getTabList(IPresentablePart)
891
	 */
892
	public Control[] getTabList(IPresentablePart part) {
893
		ArrayList list = new ArrayList();
894
		if (getControl() != null)
895
			list.add(getControl());
896
		if (part.getToolBar() != null)
897
			list.add(part.getToolBar());
898
		if (part.getControl() != null)
899
			list.add(part.getControl());
900
		return (Control[]) list.toArray(new Control[list.size()]);
901
	}
902
903
	/*
904
	 * (non-Javadoc)
905
	 * 
906
	 * @see org.eclipse.ui.presentations.StackPresentation#getCurrentPart()
907
	 */
908
	public IPresentablePart getCurrentPart() {
909
		return current;
910
	}
911
912
	protected String getPaneName() {
913
		return R21PresentationMessages.getString("EditorPane.moveEditor"); //$NON-NLS-1$ 
914
	}
915
916
	/*
917
	 * (non-Javadoc)
918
	 * 
919
	 * @see org.eclipse.ui.presentations.StackPresentation#setActive(int)
920
	 */
921
	public void setActive(int newState) {
922
		activeState = newState;
923
		updateGradient();
924
	}
925
	
926
    /**
927
     * Restores a presentation from a previously stored state
928
     * 
929
     * @param serializer (not null)
930
     * @param savedState (not null)
931
     */
932
    public void restoreState(IPresentationSerializer serializer, IMemento savedState) {
933
        IMemento[] parts = savedState.getChildren(IWorkbenchConstants.TAG_PART);
934
        
935
        for (int idx = 0; idx < parts.length; idx++) {
936
            String id = parts[idx].getString(IWorkbenchConstants.TAG_ID);
937
            
938
            if (id != null) {
939
                IPresentablePart part = serializer.getPart(id);
940
                
941
                if (part != null) {
942
                    addPart(part, tabFolder.getItemCount());
161
                }
943
                }
162
            }
944
            } 
163
        }
164
165
        /*
166
         * (non-Javadoc)
167
         * 
168
         * @see org.eclipse.swt.events.MouseAdapter#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
169
         */
170
        public void mouseDoubleClick(MouseEvent e) {
171
            if (getSite().getState() == IStackPresentationSite.STATE_MAXIMIZED) {
172
                getSite().setState(IStackPresentationSite.STATE_RESTORED);
173
            } else {
174
                getSite().setState(IStackPresentationSite.STATE_MAXIMIZED);
175
            }
176
        }
177
    };
178
179
    /**
180
     * Return true if <code>x</code> is over the tab item image.
181
     * 
182
     * @return true if <code>x</code> is over the tab item image
183
     */
184
    static boolean overImage(CTabItem item, int x) {
185
        Rectangle imageBounds = item.getImage().getBounds();
186
        return x < (item.getBounds().x + imageBounds.x + imageBounds.width);
187
    }
188
189
    /** the menu listener for showing the menu */
190
    private Listener menuListener = new Listener() {
191
192
        /*
193
         * (non-Javadoc)
194
         * 
195
         * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
196
         */
197
        public void handleEvent(Event event) {
198
            Point pos = new Point(event.x, event.y);
199
            showSystemMenu(pos);
200
        }
201
    };
202
203
    /** the selection listener */
204
    private Listener selectionListener = new Listener() {
205
206
        public void handleEvent(Event e) {
207
            IPresentablePart item = getPartForTab((CTabItem) e.item);
208
            if (item != null)
209
                getSite().selectPart(item);
210
        }
211
    };
212
213
    private Listener resizeListener = new Listener() {
214
215
        public void handleEvent(Event e) {
216
            setControlSize();
217
        }
218
    };
219
220
    /** a property change listener for the parts */
221
    private IPropertyListener childPropertyChangeListener = new IPropertyListener() {
222
223
        public void propertyChanged(Object source, int property) {
224
            if (source instanceof IPresentablePart) {
225
                IPresentablePart part = (IPresentablePart) source;
226
                childPropertyChanged(part, property);
227
            }
228
        }
229
    };
230
231
    /** a dispose listener to do some cleanups when a tab is disposed */
232
    private DisposeListener tabDisposeListener = new DisposeListener() {
233
234
        public void widgetDisposed(DisposeEvent e) {
235
            if (e.widget instanceof CTabItem) {
236
                CTabItem item = (CTabItem) e.widget;
237
                IPresentablePart part = getPartForTab(item);
238
                part.removePropertyListener(childPropertyChangeListener);
239
            }
240
        }
241
    };
242
243
    /** the shell listener for upgrading the gradient */
244
    private ShellAdapter shellListener = new ShellAdapter() {
245
246
        public void shellActivated(ShellEvent event) {
247
            updateGradient();
248
        }
249
250
        public void shellDeactivated(ShellEvent event) {
251
            updateGradient();
252
        }
253
    };
254
255
    /**
256
     * Create a new presentation stack.
257
     * 
258
     * @param parent the parent widget
259
     * @param stackSite the site
260
     */
261
    public R21EditorStackPresentation(Composite parent,
262
            IStackPresentationSite stackSite) {
263
        super(stackSite);
264
265
        // create the tab folder
266
        tabFolder = new CTabFolder(parent, tabPos | SWT.BORDER);
267
268
        // minimum tab width
269
        tabFolder.MIN_TAB_WIDTH = preferenceStore
270
                .getInt(IPreferenceConstants.EDITOR_TAB_WIDTH);
271
272
        // prevent close button and scroll buttons from taking focus
273
        tabFolder.setTabList(new Control[0]);
274
275
        // enable close button in tab folder
276
        tabFolder.addCTabFolderListener(closeListener);
277
278
        // listener to switch between visible tabItems
279
        tabFolder.addListener(SWT.Selection, selectionListener);
280
281
        // listener to resize visible components
282
        tabFolder.addListener(SWT.Resize, resizeListener);
283
284
        // listen for mouse down on tab to set focus, show system menu and
285
        // maximize/restore.
286
        tabFolder.addMouseListener(mouseListener);
287
288
        // the menu
289
        tabFolder.addListener(SWT.MenuDetect, menuListener);
290
291
        // register drag listener
292
        PresentationUtil.addDragListener(tabFolder, dragListener);
293
294
        // add the shell listener to track shell activations
295
        // TODO: check if workaround can be removed (see bug 55458)
296
        tabFolder.getShell().addShellListener(shellListener);
297
298
        // initialize system menu
299
        populateSystemMenu(systemMenuManager);
300
    }
301
302
    /**
303
     * Initializes the specified menu manager.
304
     * 
305
     * @param menuManager
306
     */
307
    private void populateSystemMenu(IMenuManager menuManager) {
308
309
        menuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
310
        menuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
311
        menuManager.add(new UpdatingActionContributionItem(
312
                new SystemMenuRestore(getSite())));
313
        menuManager.add(new SystemMenuMove(getSite(), getPaneName()));
314
        menuManager.add(new GroupMarker("size")); //$NON-NLS-1$
315
        menuManager.add(new GroupMarker("state")); //$NON-NLS-1$
316
        //systemMenuManager.add(new UpdatingActionContributionItem(new
317
        // SystemMenuMinimize(getSite())));
318
        menuManager.add(new UpdatingActionContributionItem(
319
                new SystemMenuMaximize(getSite())));
320
        menuManager.add(new Separator("close")); //$NON-NLS-1$
321
        menuManager.add(new UpdatingActionContributionItem(new SystemMenuClose(
322
                getSite())));
323
324
        getSite().addSystemActions(menuManager);
325
    }
326
327
    /**
328
     * Returns the index of the tab for the given part, or returns
329
     * tabFolder.getItemCount() if there is no such tab.
330
     * 
331
     * @param part
332
     *            part being searched for
333
     * @return the index of the tab for the given part, or the number of tabs if
334
     *         there is no such tab
335
     */
336
    private final int indexOf(IPresentablePart part) {
337
        if (part == null)
338
            return tabFolder.getItemCount();
339
340
        CTabItem[] items = tabFolder.getItems();
341
        for (int idx = 0; idx < items.length; idx++)
342
            if (part == getPartForTab(items[idx]))
343
                return idx;
344
345
        return items.length;
346
    }
347
348
    /**
349
     * Returns the tab for the given part, or null if there is no such tab
350
     * 
351
     * @param part
352
     *            the part being searched for
353
     * @return the tab for the given part, or null if there is no such tab
354
     */
355
    protected final CTabItem getTab(IPresentablePart part) {
356
        CTabItem[] items = tabFolder.getItems();
357
        int idx = indexOf(part);
358
        return idx < items.length ? items[idx] : null;
359
    }
360
361
    /**
362
     * @param part
363
     * @param property
364
     */
365
    protected void childPropertyChanged(IPresentablePart part, int property) {
366
        initTab(getTab(part), part);
367
    }
368
369
    protected final IPresentablePart getPartForTab(CTabItem item) {
370
        return (IPresentablePart) item.getData(TAB_DATA);
371
    }
372
373
    protected CTabFolder getTabFolder() {
374
        return tabFolder;
375
    }
376
377
    /**
378
     * Answer whether the receiver is disposed.
379
     * @return boolean <code>true</code> if disposed
380
     */
381
    public boolean isDisposed() {
382
        return tabFolder == null || tabFolder.isDisposed();
383
    }
384
385
    /**
386
     * Set the size of a page in the folder.
387
     */
388
    private void setControlSize() {
389
        if (current != null && tabFolder != null)
390
            current.setBounds(calculatePageBounds(tabFolder));
391
    }
392
393
    /**
394
     * Calculate the bounds of the client area inside the folder
395
     * @param folder
396
     * @return Rectangle the bounds of the client
397
     */
398
    public static Rectangle calculatePageBounds(CTabFolder folder) {
399
        if (folder == null)
400
            return new Rectangle(0, 0, 0, 0);
401
402
        Rectangle bounds = folder.getBounds();
403
        Rectangle offset = folder.getClientArea();
404
        bounds.x += offset.x;
405
        bounds.y += offset.y;
406
        bounds.width = offset.width;
407
        bounds.height = offset.height;
408
        return bounds;
409
    }
410
411
    /*
412
     * (non-Javadoc)
413
     * 
414
     * @see org.eclipse.ui.internal.skins.Presentation#dispose()
415
     */
416
    public void dispose() {
417
        if (isDisposed())
418
            return;
419
420
        // remove shell listener
421
        tabFolder.getShell().removeShellListener(shellListener);
422
423
        // remove close listener
424
        tabFolder.removeCTabFolderListener(closeListener);
425
426
        // remove drag listener
427
        PresentationUtil.removeDragListener(tabFolder, dragListener);
428
429
        // dispose system menu manager
430
        systemMenuManager.dispose();
431
        systemMenuManager.removeAll();
432
433
        // dispose tab folder
434
        tabFolder.dispose();
435
        tabFolder = null;
436
    }
437
438
    /** the active state */
439
    private int activeState = AS_INACTIVE;
440
441
    /**
442
     * Update the tab folder's colours to match the current theme settings and
443
     * active state
444
     */
445
    private void updateGradient() {
446
447
        if (isDisposed())
448
            return;
449
450
        Color fgColor;
451
        Color[] bgColors;
452
        int[] bgPercents;
453
        boolean vertical = false;
454
        if (activeState == AS_ACTIVE_FOCUS) {
455
            if (getShellActivated()) {
456
                fgColor = R21Colors.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
457
                bgColors = R21Colors.getActiveEditorGradient();
458
                bgPercents = R21Colors.getActiveEditorGradientPercents();
459
            } else {
460
                fgColor = R21Colors
461
                        .getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
462
                bgColors = R21Colors.getDeactivatedEditorGradient();
463
                bgPercents = R21Colors.getDeactivatedEditorGradientPercents();
464
            }
465
466
        } else if (activeState == AS_ACTIVE_NOFOCUS) {
467
            fgColor = R21Colors.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
468
            bgColors = R21Colors.getActiveNoFocusEditorGradient();
469
            bgPercents = R21Colors.getActiveNoFocusEditorGradientPercents();
470
        } else {
471
            fgColor = null;
472
            bgColors = null;
473
            bgPercents = null;
474
        }
945
        }
475
476
        drawGradient(fgColor, bgColors, bgPercents, vertical);
477
    }
946
    }
478
947
    
479
    /**
948
    
480
     * Sets the gradient for the selected tab
481
     * 
482
     * @param fgColor
483
     * @param bgColors
484
     * @param percentages
485
     * @param vertical
486
     */
487
    protected void drawGradient(Color fgColor, Color[] bgColors,
488
            int[] percentages, boolean vertical) {
489
        tabFolder.setSelectionForeground(fgColor);
490
        tabFolder.setSelectionBackground(bgColors, percentages);
491
        tabFolder.update();
492
    }
493
494
    /**
495
     * Return whether the window's shell is activated
496
     */
497
    /* package */boolean getShellActivated() {
498
        Window window = getWindow();
499
        if (window instanceof WorkbenchWindow)
500
            return ((WorkbenchWindow) window).getShellActivated();
501
        return false;
502
    }
503
504
    /**
505
     * Returns the top level window.
506
     * @return Window the window for the receiver
507
     */
508
    public Window getWindow() {
509
        Control ctrl = getControl();
510
        if (ctrl != null) {
511
            Object data = ctrl.getShell().getData();
512
            if (data instanceof Window)
513
                return (Window) data;
514
        }
515
        return null;
516
    }
517
518
    /**
519
     * Creates the tab item for the specified part.
520
     * 
521
     * @param part
522
     * @param tabIndex
523
     * @return the tab item for the part
524
     */
525
    private CTabItem createPartTab(IPresentablePart part, int tabIndex) {
526
        CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE, tabIndex);
527
        tabItem.setData(TAB_DATA, part);
528
        part.addPropertyListener(childPropertyChangeListener);
529
        tabItem.addDisposeListener(tabDisposeListener);
530
        initTab(tabItem, part);
531
        return tabItem;
532
    }
533
534
    /**
535
     * Initializes a tab for the given part. Sets the text, icon, tool tip, etc.
536
     * This will also be called whenever a relevant property changes in the part
537
     * to reflect those changes in the tab. Subclasses may override to change
538
     * the appearance of tabs for a particular part.
539
     * 
540
     * @param tabItem
541
     *            tab for the part
542
     * @param part
543
     *            the part being displayed
544
     */
545
    protected void initTab(CTabItem tabItem, IPresentablePart part) {
546
547
        // set tab text and tooltip
548
        tabItem.setText(getLabelText(part, true, false));
549
        tabItem.setToolTipText(getLabelToolTipText(part));
550
551
        // set tab image
552
        tabItem.setImage(getLabelImage(part));
553
554
        // following code allows a disabled image
555
        // but the result was distracting: didn't see any disabled image
556
557
        //Image image = getLabelImage(part);
558
        //boolean useColorIcons = false; // should we use a preference setting?
559
        //
560
        //if (image == null || image.isDisposed()) {
561
        //// normal image
562
        //tabItem.setImage(null);
563
        //// disabled image
564
        //if (!useColorIcons) {
565
        //Image disableImage = tabItem.getDisabledImage();
566
        //if (disableImage != null) {
567
        //disableImage.dispose();
568
        //tabItem.setDisabledImage(null);
569
        //}
570
        //}
571
        //} else if (!image.equals(tabItem.getImage())) {
572
        //// normal image
573
        //    tabItem.setImage(image);
574
        //// disabled image
575
        //if (!useColorIcons) {
576
        //Image disableImage = tabItem.getDisabledImage();
577
        //if (disableImage != null)
578
        //disableImage.dispose();
579
        //Display display = tabItem.getDisplay();
580
        //disableImage = new Image(display, image, SWT.IMAGE_DISABLE);
581
        //tabItem.setDisabledImage(disableImage);
582
        //}
583
        //}
584
585
    }
586
587
    /**
588
     * Returns the label text that should be used for the tab item for the
589
     * specified part
590
     * 
591
     * @param presentablePart
592
     * @param dirtyLeft
593
     * @param includePath
594
     * @return a formated label text
595
     */
596
    String getLabelText(IPresentablePart presentablePart, boolean dirtyLeft,
597
            boolean includePath) {
598
        String title = presentablePart.getName().trim();
599
        String text = title;
600
601
        if (includePath) {
602
            String titleTooltip = presentablePart.getTitleToolTip().trim();
603
604
            if (titleTooltip.endsWith(title))
605
                titleTooltip = titleTooltip.substring(0,
606
                        titleTooltip.lastIndexOf(title)).trim();
607
608
            if (titleTooltip.endsWith("\\")) //$NON-NLS-1$
609
                titleTooltip = titleTooltip.substring(0,
610
                        titleTooltip.lastIndexOf("\\")).trim(); //$NON-NLS-1$
611
612
            if (titleTooltip.endsWith("/")) //$NON-NLS-1$
613
                titleTooltip = titleTooltip.substring(0,
614
                        titleTooltip.lastIndexOf("/")).trim(); //$NON-NLS-1$
615
616
            if (titleTooltip.length() >= 1)
617
                text += " - " + titleTooltip; //$NON-NLS-1$
618
        }
619
620
        if (presentablePart.isDirty()) {
621
            if (dirtyLeft)
622
                text = "* " + text; //$NON-NLS-1$
623
            else
624
                text = text + " *"; //$NON-NLS-1$
625
        }
626
627
        return text;
628
    }
629
630
    /**
631
     * Returns the image used for the tab item
632
     * 
633
     * @param presentablePart
634
     * @return an image
635
     */
636
    Image getLabelImage(IPresentablePart presentablePart) {
637
        return presentablePart.getTitleImage();
638
    }
639
640
    /**
641
     * Returns the tool tip text used for the tab item
642
     * 
643
     * @param presentablePart
644
     * @return a tool tip text
645
     */
646
    String getLabelToolTipText(IPresentablePart presentablePart) {
647
        return presentablePart.getTitleToolTip();
648
    }
649
650
    /* (non-Javadoc)
949
    /* (non-Javadoc)
651
     * @see org.eclipse.ui.internal.skins.StackPresentation#addPart(org.eclipse.ui.internal.skins.IPresentablePart, org.eclipse.ui.internal.skins.IPresentablePart)
950
     * @see org.eclipse.ui.presentations.StackPresentation#saveState(org.eclipse.ui.presentations.IPresentationSerializer, org.eclipse.ui.IMemento)
652
     */
653
    public void addPart(IPresentablePart newPart, Object cookie) {
654
655
        int idx;
656
657
        if (cookie instanceof Integer) {
658
            idx = ((Integer) cookie).intValue();
659
        } else {
660
            // Select a location for newly inserted parts
661
            idx = tabFolder.getItemCount();
662
        }
663
664
        if (getTab(newPart) != null) {
665
            return;
666
        }
667
668
        createPartTab(newPart, idx);
669
    }
670
671
    /*
672
     * (non-Javadoc)
673
     * 
674
     * @see org.eclipse.ui.internal.skins.StackPresentation#removePart(org.eclipse.ui.internal.skins.IPresentablePart)
675
     */
676
    public void removePart(IPresentablePart oldPart) {
677
        if (current == oldPart)
678
            current = null;
679
680
        CTabItem item = getTab(oldPart);
681
        if (item == null) {
682
            return;
683
        }
684
        oldPart.setVisible(false);
685
686
        item.dispose();
687
    }
688
689
    /*
690
     * (non-Javadoc)
691
     * 
692
     * @see org.eclipse.ui.internal.skins.StackPresentation#selectPart(org.eclipse.ui.internal.skins.IPresentablePart)
693
     */
951
     */
694
    public void selectPart(IPresentablePart toSelect) {
952
    public void saveState(IPresentationSerializer context, IMemento memento) {
695
        if (toSelect == current) {
953
        super.saveState(context, memento);
696
            return;
954
        
697
        }
955
        List parts = getPresentableParts();
698
956
        
699
        if (current != null) {
957
        Iterator iter = parts.iterator();
700
            current.setVisible(false);
958
        while (iter.hasNext()) {
701
        }
959
            IPresentablePart next = (IPresentablePart)iter.next();
702
960
            
703
        current = toSelect;
961
            IMemento childMem = memento.createChild(IWorkbenchConstants.TAG_PART);
704
962
            childMem.putString(IWorkbenchConstants.TAG_ID, context.getId(next));
705
        if (current != null) {
963
        }
706
            tabFolder.setSelection(indexOf(current));
964
    }
707
            current.setVisible(true);
965
    
708
            setControlSize();
966
    /**
709
967
     * Returns the List of IPresentablePart currently in this presentation
710
        }
968
     */
711
    }
969
    private List getPresentableParts() {
712
970
        Assert.isTrue(!isDisposed());
713
    /*
971
        
714
     * (non-Javadoc)
972
        CTabItem[] items = tabFolder.getItems();
715
     * 
973
        List result = new ArrayList(items.length);
716
     * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
974
        
717
     */
975
        for (int idx = 0; idx < tabFolder.getItemCount(); idx++) {
718
    public void setBounds(Rectangle bounds) {
976
            result.add(getPartForTab(items[idx]));
719
        tabFolder.setBounds(bounds);
720
        setControlSize();
721
    }
722
723
    /*
724
     * (non-Javadoc)
725
     * 
726
     * @see org.eclipse.ui.internal.skins.Presentation#computeMinimumSize()
727
     */
728
    public Point computeMinimumSize() {
729
        return Geometry.getSize(tabFolder.computeTrim(0, 0, 0, 0));
730
    }
731
732
    /*
733
     * (non-Javadoc)
734
     * 
735
     * @see org.eclipse.ui.internal.skins.Presentation#setVisible(boolean)
736
     */
737
    public void setVisible(boolean isVisible) {
738
        if (current != null)
739
            current.setVisible(isVisible);
740
741
        getTabFolder().setVisible(isVisible);
742
    }
743
744
    /*
745
     * (non-Javadoc)
746
     * 
747
     * @see org.eclipse.ui.internal.skins.Presentation#setState(int)
748
     */
749
    public void setState(int state) {
750
        //		tabFolder.setMinimized(state == IPresentationSite.STATE_MINIMIZED);
751
        //		tabFolder.setMaximized(state == IPresentationSite.STATE_MAXIMIZED);
752
    }
753
754
    /**
755
     * Returns the system menu manager.
756
     * 
757
     * @return the system menu manager
758
     */
759
    public IMenuManager getSystemMenuManager() {
760
        return systemMenuManager;
761
    }
762
763
    /**
764
     * Shows the system context menu at the specified location
765
     * 
766
     * @param point
767
     */
768
    protected void showSystemMenu(Point point) {
769
        Menu aMenu = systemMenuManager.createContextMenu(tabFolder.getParent());
770
        systemMenuManager.update(true);
771
        aMenu.setLocation(point.x, point.y);
772
        aMenu.setVisible(true);
773
    }
774
775
    /*
776
     * (non-Javadoc)
777
     * 
778
     * @see org.eclipse.ui.internal.skins.Presentation#getControl()
779
     */
780
    public Control getControl() {
781
        return tabFolder;
782
    }
783
784
    /*
785
     * (non-Javadoc)
786
     * 
787
     * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control,
788
     *      org.eclipse.swt.graphics.Point)
789
     */
790
    public StackDropResult dragOver(Control currentControl, Point location) {
791
792
        // Determine which tab we're currently dragging over
793
        Point localPos = tabFolder.toControl(location);
794
        final CTabItem tabUnderPointer = tabFolder.getItem(localPos);
795
796
        // This drop target only deals with tabs... if we're not dragging over
797
        // a tab, exit.
798
        if (tabUnderPointer == null)
799
            return null;
800
801
        // workaround when left tab is dragged over next
802
        int dragOverIndex = tabFolder.indexOf(tabUnderPointer);
803
804
        return new StackDropResult(Geometry.toDisplay(tabFolder,
805
                tabUnderPointer.getBounds()), new Integer(dragOverIndex));
806
    }
807
808
    /*
809
     * (non-Javadoc)
810
     * 
811
     * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu()
812
     */
813
    public void showSystemMenu() {
814
        if (null != current) {
815
            // switch to the editor
816
            CTabItem item = getTab(current);
817
            getSite().selectPart(getCurrentPart());
818
            Rectangle bounds = item.getBounds();
819
            int y = bounds.height;
820
            if (getTabFolder().getTabPosition() == SWT.BOTTOM)
821
                y += bounds.y;
822
            showSystemMenu(getTabFolder().toDisplay(bounds.x, y));
823
        }
824
    }
825
826
    /*
827
     * (non-Javadoc)
828
     * 
829
     * @see org.eclipse.ui.presentations.StackPresentation#showPaneMenu()
830
     */
831
    public void showPaneMenu() {
832
        IPartMenu menu = getPartMenu();
833
834
        if (null != menu) {
835
            CTabItem tab = getTab(getCurrentPart());
836
837
            if (null != tab && null != tab.getControl()) {
838
                Rectangle bounds = DragUtil.getDisplayBounds(tab.getControl());
839
                menu.showMenu(new Point(bounds.x, bounds.y + bounds.height));
840
            }
841
        }
842
    }
843
844
    /**
845
     * Returns the IPartMenu for the currently selected part, or null if the
846
     * current part does not have a menu.
847
     * 
848
     * @return the IPartMenu for the currently selected part or null if none
849
     */
850
    protected IPartMenu getPartMenu() {
851
        IPresentablePart part = getCurrentPart();
852
        if (part == null) {
853
            return null;
854
        }
977
        }
855
978
        
856
        return part.getMenu();
979
        return result;
857
    }
858
859
    /*
860
     * (non-Javadoc)
861
     * 
862
     * @see org.eclipse.ui.presentations.StackPresentation#getTabList(IPresentablePart)
863
     */
864
    public Control[] getTabList(IPresentablePart part) {
865
        ArrayList list = new ArrayList();
866
        if (getControl() != null)
867
            list.add(getControl());
868
        if (part.getToolBar() != null)
869
            list.add(part.getToolBar());
870
        if (part.getControl() != null)
871
            list.add(part.getControl());
872
        return (Control[]) list.toArray(new Control[list.size()]);
873
    }
980
    }
874
875
    /*
876
     * (non-Javadoc)
877
     * 
878
     * @see org.eclipse.ui.presentations.StackPresentation#getCurrentPart()
879
     */
880
    public IPresentablePart getCurrentPart() {
881
        return current;
882
    }
883
884
    protected String getPaneName() {
885
        return R21PresentationMessages.getString("EditorPane.moveEditor"); //$NON-NLS-1$ 
886
    }
887
888
    /* (non-Javadoc)
889
     * @see org.eclipse.ui.presentations.StackPresentation#setActive(int)
890
     */
891
    public void setActive(int newState) {
892
        activeState = newState;
893
        updateGradient();
894
    }
981
    }
895
}
(-)src/org/eclipse/ui/internal/presentations/R21BasicStackPresentation.java (-987 / +1108 lines)
Lines 7-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Gunnar Wagenknecht - some contributions (bug fixes and enhancements)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
12
package org.eclipse.ui.internal.presentations;
12
13
13
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
14
17
18
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.jface.action.GroupMarker;
19
import org.eclipse.jface.action.GroupMarker;
16
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.MenuManager;
21
import org.eclipse.jface.action.MenuManager;
Lines 40-46 Link Here
40
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.swt.widgets.ToolBar;
45
import org.eclipse.swt.widgets.ToolBar;
42
import org.eclipse.swt.widgets.ToolItem;
46
import org.eclipse.swt.widgets.ToolItem;
47
import org.eclipse.ui.IMemento;
43
import org.eclipse.ui.IPropertyListener;
48
import org.eclipse.ui.IPropertyListener;
49
import org.eclipse.ui.internal.IWorkbenchConstants;
44
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
50
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
45
import org.eclipse.ui.internal.WorkbenchImages;
51
import org.eclipse.ui.internal.WorkbenchImages;
46
import org.eclipse.ui.internal.dnd.DragUtil;
52
import org.eclipse.ui.internal.dnd.DragUtil;
Lines 51-1057 Link Here
51
import org.eclipse.ui.internal.util.Util;
57
import org.eclipse.ui.internal.util.Util;
52
import org.eclipse.ui.presentations.IPartMenu;
58
import org.eclipse.ui.presentations.IPartMenu;
53
import org.eclipse.ui.presentations.IPresentablePart;
59
import org.eclipse.ui.presentations.IPresentablePart;
60
import org.eclipse.ui.presentations.IPresentationSerializer;
54
import org.eclipse.ui.presentations.IStackPresentationSite;
61
import org.eclipse.ui.presentations.IStackPresentationSite;
55
import org.eclipse.ui.presentations.PresentationUtil;
62
import org.eclipse.ui.presentations.PresentationUtil;
56
import org.eclipse.ui.presentations.StackDropResult;
63
import org.eclipse.ui.presentations.StackDropResult;
57
import org.eclipse.ui.presentations.StackPresentation;
64
import org.eclipse.ui.presentations.StackPresentation;
58
65
59
/**
66
/**
60
 * Base class for StackPresentations that display IPresentableParts in a CTabFolder. 
67
 * Base class for StackPresentations that display IPresentableParts in a
68
 * CTabFolder.
61
 * 
69
 * 
62
 * @since 3.0
70
 * @since 3.0
63
 */
71
 */
64
public class R21BasicStackPresentation extends StackPresentation {
72
public class R21BasicStackPresentation extends StackPresentation {
65
73
66
    private R21PaneFolder paneFolder;
74
	private R21PaneFolder paneFolder;
67
75
68
    private IPresentablePart current;
76
	private IPresentablePart current;
69
77
70
    private boolean activeState = false;
78
	private boolean activeState = false;
71
79
72
    private MenuManager systemMenuManager = new MenuManager();
80
	private MenuManager systemMenuManager = new MenuManager();
73
81
74
    private CLabel titleLabel;
82
	private CLabel titleLabel;
75
83
76
    private boolean shellActive = true;
84
	private boolean shellActive = true;
77
85
78
    private final static String TAB_DATA = R21BasicStackPresentation.class
86
	private final static String TAB_DATA = R21BasicStackPresentation.class
79
            .getName()
87
			.getName()
80
            + ".partId"; //$NON-NLS-1$
88
			+ ".partId"; //$NON-NLS-1$
81
89
82
    //	private PaneFolderButtonListener buttonListener = new PaneFolderButtonListener() {
90
	// private PaneFolderButtonListener buttonListener = new
83
    //		public void stateButtonPressed(int buttonId) {
91
	// PaneFolderButtonListener() {
84
    //			getSite().setState(buttonId);
92
	// public void stateButtonPressed(int buttonId) {
85
    //		}
93
	// getSite().setState(buttonId);
86
    //
94
	// }
87
    //		public void closeButtonPressed(CTabItem item) {
95
	//
88
    //			IPresentablePart part = getPartForTab(item);
96
	// public void closeButtonPressed(CTabItem item) {
89
    //			
97
	// IPresentablePart part = getPartForTab(item);
90
    //			getSite().close(part);		
98
	//			
91
    //		}
99
	// getSite().close(part);
92
    //	};
100
	// }
93
    //	
101
	// };
94
    private MouseListener mouseListener = new MouseAdapter() {
102
	//	
95
        public void mouseDown(MouseEvent e) {
103
	private MouseListener mouseListener = new MouseAdapter() {
96
            if (e.widget instanceof Control) {
104
		public void mouseDown(MouseEvent e) {
97
                Control ctrl = (Control) e.widget;
105
			if (e.widget instanceof Control) {
98
                Point globalPos = ctrl.toDisplay(new Point(e.x, e.y));
106
				Control ctrl = (Control) e.widget;
99
107
				Point globalPos = ctrl.toDisplay(new Point(e.x, e.y));
100
                // PR#1GDEZ25 - If selection will change in mouse up ignore mouse down.
108
101
                // Else, set focus.
109
				// PR#1GDEZ25 - If selection will change in mouse up ignore
102
                CTabItem newItem = paneFolder.getItem(paneFolder.getControl()
110
				// mouse down.
103
                        .toControl(globalPos));
111
				// Else, set focus.
104
                if (newItem != null) {
112
				CTabItem newItem = paneFolder.getItem(paneFolder.getControl()
105
                    CTabItem oldItem = paneFolder.getSelection();
113
						.toControl(globalPos));
106
                    if (newItem != oldItem)
114
				if (newItem != null) {
107
                        return;
115
					CTabItem oldItem = paneFolder.getSelection();
108
                }
116
					if (newItem != oldItem)
109
                if (current != null) {
117
						return;
110
                    current.setFocus();
118
				}
111
                }
119
				if (current != null) {
112
            }
120
					current.setFocus();
113
        }
121
				}
114
122
			}
115
        public void mouseDoubleClick(MouseEvent e) {
123
		}
116
            if (getSite().getState() == IStackPresentationSite.STATE_MAXIMIZED) {
124
117
                getSite().setState(IStackPresentationSite.STATE_RESTORED);
125
		public void mouseDoubleClick(MouseEvent e) {
118
            } else {
126
			if (getSite().getState() == IStackPresentationSite.STATE_MAXIMIZED) {
119
                getSite().setState(IStackPresentationSite.STATE_MAXIMIZED);
127
				getSite().setState(IStackPresentationSite.STATE_RESTORED);
120
            }
128
			} else {
121
        }
129
				getSite().setState(IStackPresentationSite.STATE_MAXIMIZED);
122
    };
130
			}
123
131
		}
124
    private MouseListener titleMouseListener = new MouseAdapter() {
132
	};
125
        public void mouseDown(MouseEvent e) {
133
126
            if (e.widget instanceof Control) {
134
	private MouseListener titleMouseListener = new MouseAdapter() {
127
                Control ctrl = (Control) e.widget;
135
		public void mouseDown(MouseEvent e) {
128
                Point globalPos = ctrl.toDisplay(new Point(0, titleLabel
136
			if (e.widget instanceof Control) {
129
                        .getBounds().height));
137
				Control ctrl = (Control) e.widget;
130
138
				Point globalPos = ctrl.toDisplay(new Point(0, titleLabel
131
                if ((e.button == 1) && overImage(e.x))
139
						.getBounds().height));
132
                    showSystemMenu(globalPos);
140
133
            }
141
				if ((e.button == 1) && overImage(e.x))
134
        }
142
					showSystemMenu(globalPos);
135
    };
143
			}
136
144
		}
137
    private Listener menuListener = new Listener() {
145
	};
138
        /* (non-Javadoc)
146
139
         * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
147
	private Listener menuListener = new Listener() {
140
         */
148
		/*
141
        public void handleEvent(Event event) {
149
		 * (non-Javadoc)
142
            Point pos = new Point(event.x, event.y);
150
		 * 
143
151
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
144
            showSystemMenu(pos);
152
		 */
145
        }
153
		public void handleEvent(Event event) {
146
    };
154
			Point pos = new Point(event.x, event.y);
147
155
148
    private Listener dragListener = new Listener() {
156
			showSystemMenu(pos);
149
        public void handleEvent(Event event) {
157
		}
150
158
	};
151
            Point localPos = new Point(event.x, event.y);
159
152
            CTabItem tabUnderPointer = paneFolder.getItem(localPos);
160
	private Listener dragListener = new Listener() {
153
161
		public void handleEvent(Event event) {
154
            // Drags on the title area drag the selected part only
162
155
            if (tabUnderPointer == null) {
163
			Point localPos = new Point(event.x, event.y);
156
                if (paneFolder.getTabPosition() == SWT.BOTTOM
164
			CTabItem tabUnderPointer = paneFolder.getItem(localPos);
157
                        && localPos.y < paneFolder.getControl().getBounds().height
165
158
                                - paneFolder.getTabHeight())
166
			// Drags on the title area drag the selected part only
159
                    tabUnderPointer = paneFolder.getSelection();
167
			if (tabUnderPointer == null) {
160
                else if (paneFolder.getTabPosition() == SWT.TOP
168
				if (paneFolder.getTabPosition() == SWT.BOTTOM
161
                        && localPos.y > paneFolder.getTabHeight())
169
						&& localPos.y < paneFolder.getControl().getBounds().height
162
                    tabUnderPointer = paneFolder.getSelection();
170
								- paneFolder.getTabHeight())
163
            }
171
					tabUnderPointer = paneFolder.getSelection();
164
172
				else if (paneFolder.getTabPosition() == SWT.TOP
165
            // Not in a tab, not in a title area, must be dragging the whole stack
173
						&& localPos.y > paneFolder.getTabHeight())
166
            if (tabUnderPointer == null) {
174
					tabUnderPointer = paneFolder.getSelection();
167
                getSite().dragStart(
175
			}
168
                        paneFolder.getControl().toDisplay(localPos), false);
176
169
                return;
177
			// Not in a tab, not in a title area, must be dragging the whole
170
            }
178
			// stack
171
179
			if (tabUnderPointer == null) {
172
            IPresentablePart part = getPartForTab(tabUnderPointer);
180
				getSite().dragStart(
173
181
						paneFolder.getControl().toDisplay(localPos), false);
174
            if (getSite().isPartMoveable(part)) {
182
				return;
175
                getSite().dragStart(part,
183
			}
176
                        paneFolder.getControl().toDisplay(localPos), false);
184
177
            }
185
			IPresentablePart part = getPartForTab(tabUnderPointer);
178
        }
186
179
    };
187
			if (getSite().isPartMoveable(part)) {
180
188
				getSite().dragStart(part,
181
    private Listener selectionListener = new Listener() {
189
						paneFolder.getControl().toDisplay(localPos), false);
182
        public void handleEvent(Event e) {
190
			}
183
            IPresentablePart item = getPartForTab((CTabItem) e.item);
191
		}
184
192
	};
185
            if (item != null) {
193
186
                getSite().selectPart(item);
194
	private Listener selectionListener = new Listener() {
187
            }
195
		public void handleEvent(Event e) {
188
        }
196
			IPresentablePart item = getPartForTab((CTabItem) e.item);
189
    };
197
190
198
			if (item != null) {
191
    private Listener resizeListener = new Listener() {
199
				getSite().selectPart(item);
192
        public void handleEvent(Event e) {
200
			}
193
            setControlSize();
201
		}
194
        }
202
	};
195
    };
203
196
204
	private Listener resizeListener = new Listener() {
197
    private IPropertyListener childPropertyChangeListener = new IPropertyListener() {
205
		public void handleEvent(Event e) {
198
        public void propertyChanged(Object source, int property) {
206
			setControlSize();
199
            if (source instanceof IPresentablePart) {
207
		}
200
                IPresentablePart part = (IPresentablePart) source;
208
	};
201
                childPropertyChanged(part, property);
209
202
            }
210
	private IPropertyListener childPropertyChangeListener = new IPropertyListener() {
203
        }
211
		public void propertyChanged(Object source, int property) {
204
    };
212
			if (source instanceof IPresentablePart) {
205
213
				IPresentablePart part = (IPresentablePart) source;
206
    private DisposeListener tabDisposeListener = new DisposeListener() {
214
				childPropertyChanged(part, property);
207
        public void widgetDisposed(DisposeEvent e) {
215
			}
208
            if (e.widget instanceof CTabItem) {
216
		}
209
                CTabItem item = (CTabItem) e.widget;
217
	};
210
218
211
                IPresentablePart part = getPartForTab(item);
219
	private DisposeListener tabDisposeListener = new DisposeListener() {
212
220
		public void widgetDisposed(DisposeEvent e) {
213
                part.removePropertyListener(childPropertyChangeListener);
221
			if (e.widget instanceof CTabItem) {
214
            }
222
				CTabItem item = (CTabItem) e.widget;
215
        }
223
216
    };
224
				IPresentablePart part = getPartForTab(item);
217
225
218
    /** the shell listener for upgrading the gradient */
226
				part.removePropertyListener(childPropertyChangeListener);
219
    private ShellAdapter shellListener = new ShellAdapter() {
227
			}
220
228
		}
221
        public void shellActivated(ShellEvent event) {
229
	};
222
            shellActive = true;
230
223
            updateGradient();
231
	/** the shell listener for upgrading the gradient */
224
        }
232
	private ShellAdapter shellListener = new ShellAdapter() {
225
233
226
        public void shellDeactivated(ShellEvent event) {
234
		public void shellActivated(ShellEvent event) {
227
            shellActive = false;
235
			shellActive = true;
228
            updateGradient();
236
			updateGradient();
229
        }
237
		}
230
    };
238
231
239
		public void shellDeactivated(ShellEvent event) {
232
    private ToolBar viewToolBar;
240
			shellActive = false;
233
241
			updateGradient();
234
    private ToolItem pullDownButton;
242
		}
235
243
	};
236
    private ToolItem closeButton;
244
237
245
	private ToolBar viewToolBar;
238
    public R21BasicStackPresentation(R21PaneFolder control,
246
239
            IStackPresentationSite stackSite) {
247
	private ToolItem pullDownButton;
240
        super(stackSite);
248
241
        paneFolder = control;
249
	private ToolItem closeButton;
242
250
243
        shellActive = paneFolder.getControl().getShell().equals(
251
	public R21BasicStackPresentation(R21PaneFolder control,
244
                control.getControl().getDisplay().getActiveShell());
252
			IStackPresentationSite stackSite) {
245
253
		super(stackSite);
246
        //		tabFolder.setMinimizeVisible(stackSite.supportsState(IStackPresentationSite.STATE_MINIMIZED));
254
		paneFolder = control;
247
        //		tabFolder.setMaximizeVisible(stackSite.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
255
248
        //				
256
		shellActive = paneFolder.getControl().getShell().equals(
249
        titleLabel = new CLabel(paneFolder.getControl(), SWT.SHADOW_NONE);
257
				control.getControl().getDisplay().getActiveShell());
250
        titleLabel.setVisible(false);
258
251
        titleLabel.moveAbove(null);
259
		// tabFolder.setMinimizeVisible(stackSite.supportsState(IStackPresentationSite.STATE_MINIMIZED));
252
        titleLabel.addMouseListener(titleMouseListener);
260
		// tabFolder.setMaximizeVisible(stackSite.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
253
        titleLabel.addMouseListener(mouseListener);
261
		//				
254
        titleLabel.addListener(SWT.MenuDetect, menuListener);
262
		titleLabel = new CLabel(paneFolder.getControl(), SWT.SHADOW_NONE);
255
        PresentationUtil.addDragListener(titleLabel, dragListener);
263
		titleLabel.setVisible(false);
256
264
		titleLabel.moveAbove(null);
257
        //ColorSchemeService.setViewTitleFont(this, titleLabel);
265
		titleLabel.addMouseListener(titleMouseListener);
258
266
		titleLabel.addMouseListener(mouseListener);
259
        viewToolBar = new ToolBar(control.getControl(), SWT.HORIZONTAL
267
		titleLabel.addListener(SWT.MenuDetect, menuListener);
260
                | SWT.FLAT);
268
		PresentationUtil.addDragListener(titleLabel, dragListener);
261
        viewToolBar.moveAbove(null);
269
262
270
		// ColorSchemeService.setViewTitleFont(this, titleLabel);
263
        pullDownButton = new ToolItem(viewToolBar, SWT.PUSH);
271
264
        //				Image img = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
272
		viewToolBar = new ToolBar(control.getControl(), SWT.HORIZONTAL
265
        Image hoverImage = WorkbenchImages
273
				| SWT.FLAT);
266
                .getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
274
		viewToolBar.moveAbove(null);
267
        pullDownButton.setDisabledImage(null); // TODO: comment this out?
275
268
        // PR#1GE56QT - Avoid creation of unnecessary image.
276
		pullDownButton = new ToolItem(viewToolBar, SWT.PUSH);
269
        pullDownButton.setImage(hoverImage);
277
		// Image img =
270
        pullDownButton.setToolTipText(R21PresentationMessages
278
		// WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
271
                .getString("BasicStackPresentation.menu.tooltip")); //$NON-NLS-1$
279
		Image hoverImage = WorkbenchImages
272
        pullDownButton.addSelectionListener(new SelectionAdapter() {
280
				.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
273
            public void widgetSelected(SelectionEvent e) {
281
		pullDownButton.setDisabledImage(null); // TODO: comment this out?
274
                showPaneMenu();
282
		// PR#1GE56QT - Avoid creation of unnecessary image.
275
            }
283
		pullDownButton.setImage(hoverImage);
276
        });
284
		pullDownButton.setToolTipText(R21PresentationMessages
277
285
				.getString("BasicStackPresentation.menu.tooltip")); //$NON-NLS-1$
278
        // listener to switch between visible tabItems
286
		pullDownButton.addSelectionListener(new SelectionAdapter() {
279
        paneFolder.getControl().addListener(SWT.Selection, selectionListener);
287
			public void widgetSelected(SelectionEvent e) {
280
288
				showPaneMenu();
281
        // listener to resize visible components
289
			}
282
        paneFolder.getControl().addListener(SWT.Resize, resizeListener);
290
		});
283
291
284
        // listen for mouse down on tab to set focus.
292
		// listener to switch between visible tabItems
285
        paneFolder.getControl().addMouseListener(mouseListener);
293
		paneFolder.getControl().addListener(SWT.Selection, selectionListener);
286
294
287
        paneFolder.getControl().addListener(SWT.MenuDetect, menuListener);
295
		// listener to resize visible components
288
296
		paneFolder.getControl().addListener(SWT.Resize, resizeListener);
289
        //		tabFolder.addButtonListener(buttonListener);
297
290
298
		// listen for mouse down on tab to set focus.
291
        PresentationUtil.addDragListener(paneFolder.getControl(), dragListener);
299
		paneFolder.getControl().addMouseListener(mouseListener);
292
300
293
        // add the shell listener to track shell activations
301
		paneFolder.getControl().addListener(SWT.MenuDetect, menuListener);
294
        // TODO: check if workaround can be removed (see bug 55458)
302
295
        paneFolder.getControl().getShell().addShellListener(shellListener);
303
		// tabFolder.addButtonListener(buttonListener);
296
304
297
        // Uncomment to allow dragging from the title label
305
		PresentationUtil.addDragListener(paneFolder.getControl(), dragListener);
298
        //		PresentationUtil.addDragListener(titleLabel, new Listener() {
306
299
        //			public void handleEvent(Event event) {
307
		// add the shell listener to track shell activations
300
        //				if (layout.isTrimOnTop()) {
308
		// TODO: check if workaround can be removed (see bug 55458)
301
        //					Point localPos = new Point(event.x, event.y);
309
		paneFolder.getControl().getShell().addShellListener(shellListener);
302
        //					getSite().dragStart(titleLabel.toDisplay(localPos), false);
310
303
        //				}
311
		// Uncomment to allow dragging from the title label
304
        //			}
312
		// PresentationUtil.addDragListener(titleLabel, new Listener() {
305
        //		});
313
		// public void handleEvent(Event event) {
306
314
		// if (layout.isTrimOnTop()) {
307
        //		// Compute the tab height
315
		// Point localPos = new Point(event.x, event.y);
308
        //		int tabHeight = viewToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
316
		// getSite().dragStart(titleLabel.toDisplay(localPos), false);
309
        //
317
		// }
310
        //		// Enforce a minimum tab height
318
		// }
311
        //		if (tabHeight < 20) {
319
		// });
312
        //			tabHeight = 20;
320
313
        //		}
321
		// // Compute the tab height
314
        //		paneFolder.setTabHeight(tabHeight);
322
		// int tabHeight = viewToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
315
        //		
323
		//
316
        populateSystemMenu(systemMenuManager);
324
		// // Enforce a minimum tab height
317
    }
325
		// if (tabHeight < 20) {
318
326
		// tabHeight = 20;
319
    /*
327
		// }
320
     * Return true if <code>x</code> is over the label image.
328
		// paneFolder.setTabHeight(tabHeight);
321
     */
329
		//		
322
    private boolean overImage(int x) {
330
		populateSystemMenu(systemMenuManager);
323
        return x < titleLabel.getImage().getBounds().width;
331
	}
324
    }
332
325
333
	/*
326
    /**
334
	 * Return true if <code>x</code> is over the label image.
327
     * @param systemMenuManager
335
	 */
328
     */
336
	private boolean overImage(int x) {
329
    private void populateSystemMenu(IMenuManager systemMenuManager) {
337
		return x < titleLabel.getImage().getBounds().width;
330
338
	}
331
        systemMenuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
339
332
        systemMenuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
340
	/**
333
        systemMenuManager.add(new UpdatingActionContributionItem(
341
	 * @param systemMenuManager
334
                new SystemMenuRestore(getSite())));
342
	 */
335
343
	private void populateSystemMenu(IMenuManager systemMenuManager) {
336
        systemMenuManager.add(new SystemMenuMove(getSite(), getPaneName()));
344
337
        systemMenuManager.add(new GroupMarker("size")); //$NON-NLS-1$
345
		systemMenuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
338
        systemMenuManager.add(new GroupMarker("state")); //$NON-NLS-1$
346
		systemMenuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
339
        systemMenuManager.add(new UpdatingActionContributionItem(
347
		systemMenuManager.add(new UpdatingActionContributionItem(
340
                new SystemMenuMinimize(getSite())));
348
				new SystemMenuRestore(getSite())));
341
349
342
        systemMenuManager.add(new UpdatingActionContributionItem(
350
		systemMenuManager.add(new SystemMenuMove(getSite(), getPaneName()));
343
                new SystemMenuMaximize(getSite())));
351
		systemMenuManager.add(new GroupMarker("size")); //$NON-NLS-1$
344
        systemMenuManager.add(new Separator("close")); //$NON-NLS-1$
352
		systemMenuManager.add(new GroupMarker("state")); //$NON-NLS-1$
345
        systemMenuManager.add(new UpdatingActionContributionItem(
353
		systemMenuManager.add(new UpdatingActionContributionItem(
346
                new SystemMenuClose(getSite())));
354
				new SystemMenuMinimize(getSite())));
347
355
348
        getSite().addSystemActions(systemMenuManager);
356
		systemMenuManager.add(new UpdatingActionContributionItem(
349
    }
357
				new SystemMenuMaximize(getSite())));
350
358
		systemMenuManager.add(new Separator("close")); //$NON-NLS-1$
351
    protected String getPaneName() {
359
		systemMenuManager.add(new UpdatingActionContributionItem(
352
        return R21PresentationMessages.getString("BasicStackPresentation.pane"); //$NON-NLS-1$
360
				new SystemMenuClose(getSite())));
353
    }
361
354
362
		getSite().addSystemActions(systemMenuManager);
355
    /**
363
	}
356
     * Displays the view menu as a popup
364
357
     */
365
	protected String getPaneName() {
358
    public void showPaneMenu() {
366
		return R21PresentationMessages.getString("BasicStackPresentation.pane"); //$NON-NLS-1$
359
        IPartMenu menu = getPartMenu();
367
	}
360
368
361
        if (menu != null) {
369
	/**
362
            Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar);
370
	 * Displays the view menu as a popup
363
            menu.showMenu(new Point(bounds.x, bounds.y + bounds.height));
371
	 */
364
        }
372
	public void showPaneMenu() {
365
    }
373
		IPartMenu menu = getPartMenu();
366
374
367
    /**
375
		if (menu != null) {
368
     * Returns the currently selected part, or <code>null</code>.
376
			Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar);
369
     * 
377
			menu.showMenu(new Point(bounds.x, bounds.y + bounds.height));
370
     * @return the currently selected part, or <code>null</code>
378
		}
371
     */
379
	}
372
    protected IPresentablePart getCurrent() {
380
373
        return current;
381
	/**
374
    }
382
	 * Returns the currently selected part, or <code>null</code>.
375
383
	 * 
376
    /**
384
	 * @return the currently selected part, or <code>null</code>
377
     * Returns the index of the tab for the given part, or returns tabFolder.getItemCount()
385
	 */
378
     * if there is no such tab.
386
	protected IPresentablePart getCurrent() {
379
     * 
387
		return current;
380
     * @param part part being searched for
388
	}
381
     * @return the index of the tab for the given part, or the number of tabs
389
382
     * if there is no such tab
390
	/**
383
     */
391
	 * Returns the index of the tab for the given part, or returns
384
    private final int indexOf(IPresentablePart part) {
392
	 * tabFolder.getItemCount() if there is no such tab.
385
        if (part == null) {
393
	 * 
386
            return paneFolder.getItemCount();
394
	 * @param part
387
        }
395
	 *            part being searched for
388
396
	 * @return the index of the tab for the given part, or the number of tabs if
389
        CTabItem[] items = paneFolder.getItems();
397
	 *         there is no such tab
390
398
	 */
391
        for (int idx = 0; idx < items.length; idx++) {
399
	private final int indexOf(IPresentablePart part) {
392
            IPresentablePart tabPart = getPartForTab(items[idx]);
400
		if (part == null) {
393
401
			return paneFolder.getItemCount();
394
            if (part == tabPart) {
402
		}
395
                return idx;
403
396
            }
404
		CTabItem[] items = paneFolder.getItems();
397
        }
405
398
406
		for (int idx = 0; idx < items.length; idx++) {
399
        return items.length;
407
			IPresentablePart tabPart = getPartForTab(items[idx]);
400
    }
408
401
409
			if (part == tabPart) {
402
    /**
410
				return idx;
403
     * Returns the tab for the given part, or null if there is no such tab
411
			}
404
     * 
412
		}
405
     * @param part the part being searched for
413
406
     * @return the tab for the given part, or null if there is no such tab
414
		return items.length;
407
     */
415
	}
408
    protected final CTabItem getTab(IPresentablePart part) {
416
409
        CTabItem[] items = paneFolder.getItems();
417
	/**
410
418
	 * Returns the tab for the given part, or null if there is no such tab
411
        int idx = indexOf(part);
419
	 * 
412
420
	 * @param part
413
        if (idx < items.length) {
421
	 *            the part being searched for
414
            return items[idx];
422
	 * @return the tab for the given part, or null if there is no such tab
415
        }
423
	 */
416
424
	protected final CTabItem getTab(IPresentablePart part) {
417
        return null;
425
		CTabItem[] items = paneFolder.getItems();
418
    }
426
419
427
		int idx = indexOf(part);
420
    /**
428
421
     * @param part
429
		if (idx < items.length) {
422
     * @param property
430
			return items[idx];
423
     */
431
		}
424
    protected void childPropertyChanged(IPresentablePart part, int property) {
432
425
433
		return null;
426
        CTabItem tab = getTab(part);
434
	}
427
        initTab(tab, part);
435
428
436
	/**
429
        switch (property) {
437
	 * @param part
430
        case IPresentablePart.PROP_BUSY:
438
	 * @param property
431
            break;
439
	 */
432
        case IPresentablePart.PROP_HIGHLIGHT_IF_BACK:
440
	protected void childPropertyChanged(IPresentablePart part, int property) {
433
        //	     	FontRegistry registry = 
441
434
        //			    PlatformUI.getWorkbench().
442
		CTabItem tab = getTab(part);
435
        //			    	getThemeManager().getCurrentTheme().
443
		initTab(tab, part);
436
        //			    		getFontRegistry();
444
437
        //	     	
445
		switch (property) {
438
        //	       	if(!getCurrent().equals(part))//Set bold if it does currently have focus
446
		case IPresentablePart.PROP_BUSY:
439
        //				tab.setFont(registry.getBold(IWorkbenchThemeConstants.TAB_TEXT_FONT));
447
			break;
440
        //	        break;
448
		case IPresentablePart.PROP_HIGHLIGHT_IF_BACK:
441
        case IPresentablePart.PROP_TOOLBAR:
449
			// FontRegistry registry =
442
        case IPresentablePart.PROP_PANE_MENU:
450
			// PlatformUI.getWorkbench().
443
        case IPresentablePart.PROP_TITLE:
451
			// getThemeManager().getCurrentTheme().
444
            setControlSize();
452
			// getFontRegistry();
445
            break;
453
			//	     	
446
        }
454
			// if(!getCurrent().equals(part))//Set bold if it does currently
447
    }
455
			// have focus
448
456
			// tab.setFont(registry.getBold(IWorkbenchThemeConstants.TAB_TEXT_FONT));
449
    protected final IPresentablePart getPartForTab(CTabItem item) {
457
			// break;
450
        IPresentablePart part = (IPresentablePart) item.getData(TAB_DATA);
458
		case IPresentablePart.PROP_TOOLBAR:
451
459
		case IPresentablePart.PROP_PANE_MENU:
452
        return part;
460
		case IPresentablePart.PROP_TITLE:
453
    }
461
			setControlSize();
454
462
			break;
455
    /**
463
		}
456
     * Returns the underlying tab folder for this presentation.
464
	}
457
     * 
465
458
     * @return
466
	protected final IPresentablePart getPartForTab(CTabItem item) {
459
     */
467
		IPresentablePart part = (IPresentablePart) item.getData(TAB_DATA);
460
    protected R21PaneFolder getPaneFolder() {
468
461
        return paneFolder;
469
		return part;
462
    }
470
	}
463
471
464
    /**
472
	/**
465
     * Returns true iff the underlying tab folder has been disposed.
473
	 * Returns the underlying tab folder for this presentation.
466
     * 
474
	 * 
467
     * @return
475
	 * @return
468
     */
476
	 */
469
    public boolean isDisposed() {
477
	protected R21PaneFolder getPaneFolder() {
470
        return paneFolder == null || paneFolder.isDisposed();
478
		return paneFolder;
471
    }
479
	}
472
480
473
    /**
481
	/**
474
     * Update the tab folder's colours to match the current theme settings
482
	 * Returns true iff the underlying tab folder has been disposed.
475
     * and active state
483
	 * 
476
     */
484
	 * @return
477
    protected void updateGradient() {
485
	 */
478
486
	public boolean isDisposed() {
479
        if (isDisposed())
487
		return paneFolder == null || paneFolder.isDisposed();
480
            return;
488
	}
481
489
482
        Color fgColor;
490
	/**
483
        Color[] bgColors;
491
	 * Update the tab folder's colours to match the current theme settings and
484
        int[] bgPercents;
492
	 * active state
485
        boolean vertical = false;
493
	 */
486
        if (isActive()) {
494
	protected void updateGradient() {
487
            if (getShellActivated()) {
495
488
                fgColor = R21Colors.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
496
		if (isDisposed())
489
                bgColors = R21Colors.getActiveViewGradient();
497
			return;
490
                bgPercents = R21Colors.getActiveViewGradientPercents();
498
491
            } else {
499
		Color fgColor;
492
                fgColor = R21Colors
500
		Color[] bgColors;
493
                        .getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
501
		int[] bgPercents;
494
                bgColors = R21Colors.getDeactivatedViewGradient();
502
		boolean vertical = false;
495
                bgPercents = R21Colors.getDeactivatedViewGradientPercents();
503
		if (isActive()) {
496
            }
504
			if (getShellActivated()) {
497
505
				fgColor = R21Colors.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
498
        } else {
506
				bgColors = R21Colors.getActiveViewGradient();
499
            fgColor = R21Colors.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
507
				bgPercents = R21Colors.getActiveViewGradientPercents();
500
            bgColors = null;
508
			} else {
501
            bgPercents = null;
509
				fgColor = R21Colors
502
        }
510
						.getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
503
511
				bgColors = R21Colors.getDeactivatedViewGradient();
504
        drawGradient(fgColor, bgColors, bgPercents, vertical);
512
				bgPercents = R21Colors.getDeactivatedViewGradientPercents();
505
513
			}
506
        //		Color fgColor;
514
507
        //		ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
515
		} else {
508
        //        FontRegistry fontRegistry = currentTheme.getFontRegistry();	    
516
			fgColor = R21Colors.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
509
        //		ColorRegistry colorRegistry = currentTheme.getColorRegistry();
517
			bgColors = null;
510
        //		Color [] bgColors = new Color[2];
518
			bgPercents = null;
511
        //		int [] percent = new int[1];
519
		}
512
        //		boolean vertical;
520
513
521
		drawGradient(fgColor, bgColors, bgPercents, vertical);
514
        //        if (isActive()){
522
515
        //        	
523
		// Color fgColor;
516
        //        	CTabItem item = getPaneFolder().getSelection();
524
		// ITheme currentTheme =
517
        //            if(item != null && !getPartForTab(item).isBusy()){
525
		// PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
518
        //            	Font tabFont = fontRegistry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT);
526
		// FontRegistry fontRegistry = currentTheme.getFontRegistry();
519
        ////            	item.setFont(tabFont);
527
		// ColorRegistry colorRegistry = currentTheme.getColorRegistry();
520
        //            }
528
		// Color [] bgColors = new Color[2];
521
        //            
529
		// int [] percent = new int[1];
522
        //	        fgColor = colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR);
530
		// boolean vertical;
523
        //            bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
531
524
        //            bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
532
		// if (isActive()){
525
        //            percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT);
533
		//        	
526
        //            vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL);
534
		// CTabItem item = getPaneFolder().getSelection();
527
        //		} else {
535
		// if(item != null && !getPartForTab(item).isBusy()){
528
        //	        fgColor = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);
536
		// Font tabFont =
529
        //            bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
537
		// fontRegistry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT);
530
        //            bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
538
		// // item.setFont(tabFont);
531
        //            percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT);
539
		// }
532
        //            vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL);
540
		//            
533
        //		}	
541
		// fgColor =
534
        //      
542
		// colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR);
535
        //		
543
		// bgColors[0] =
536
        //		drawGradient(fgColor, bgColors, bgPercents, false);	
544
		// colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
537
    }
545
		// bgColors[1] =
538
546
		// colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
539
    /**
547
		// percent[0] =
540
     * Draws the applicable gradient on the title area
548
		// currentTheme.getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT);
541
     * 
549
		// vertical =
542
     * @param fgColor
550
		// currentTheme.getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL);
543
     * @param bgColors
551
		// } else {
544
     * @param percentages
552
		// fgColor =
545
     * @param vertical
553
		// colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);
546
     */
554
		// bgColors[0] =
547
    public void drawGradient(Color fgColor, Color[] bgColors,
555
		// colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
548
            int[] percentages, boolean vertical) {
556
		// bgColors[1] =
549
        //		paneFolder.setSelectionForeground(fgColor);
557
		// colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
550
        //		paneFolder.setSelectionBackground(bgColors, percentages, vertical);	
558
		// percent[0] =
551
559
		// currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT);
552
        if (titleLabel == null || viewToolBar == null)
560
		// vertical =
553
            return;
561
		// currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL);
554
562
		// }
555
        titleLabel.setBackground(bgColors, percentages, vertical);
563
		//      
556
        titleLabel.setForeground(fgColor);
564
		//		
557
565
		// drawGradient(fgColor, bgColors, bgPercents, false);
558
        titleLabel.update();
566
	}
559
    }
567
560
568
	/**
561
    public boolean isActive() {
569
	 * Draws the applicable gradient on the title area
562
        return activeState;
570
	 * 
563
    }
571
	 * @param fgColor
564
572
	 * @param bgColors
565
    /**
573
	 * @param percentages
566
     * Set the size of a page in the folder.
574
	 * @param vertical
567
     * 
575
	 */
568
     * TODO: Kim here...I had to make this public so that the when the font
576
	public void drawGradient(Color fgColor, Color[] bgColors,
569
     * was updated via the color scheme service it could relayout the 
577
			int[] percentages, boolean vertical) {
570
     * presentation... calling control.getLayout() doesn't do the trick.
578
		// paneFolder.setSelectionForeground(fgColor);
571
     */
579
		// paneFolder.setSelectionBackground(bgColors, percentages, vertical);
572
    public void setControlSize() {
580
573
        // Set up the top-right controls
581
		if (titleLabel == null || viewToolBar == null)
574
        //List topRight = new ArrayList(3);
582
			return;
575
583
576
        if (current != null) {
584
		titleLabel.setBackground(bgColors, percentages, vertical);
577
            paneFolder.setTopLeft(titleLabel);
585
		titleLabel.setForeground(fgColor);
578
            titleLabel.setText(current.getTitle());
586
579
            titleLabel.setImage(current.getTitleImage());
587
		titleLabel.update();
580
            titleLabel.setVisible(true);
588
	}
581
        }
589
582
590
	public boolean isActive() {
583
        Control currentToolbar = getCurrentToolbar();
591
		return activeState;
584
        paneFolder.setTopCenter(currentToolbar);
592
	}
585
593
586
        IPartMenu partMenu = getPartMenu();
594
	/**
587
595
	 * Set the size of a page in the folder.
588
        if (partMenu != null) {
596
	 * 
589
            pullDownButton.setEnabled(true);
597
	 * TODO: Kim here...I had to make this public so that the when the font was
590
        } else {
598
	 * updated via the color scheme service it could relayout the
591
            pullDownButton.setEnabled(false);
599
	 * presentation... calling control.getLayout() doesn't do the trick.
592
        }
600
	 */
593
        paneFolder.setTopRight(viewToolBar);
601
	public void setControlSize() {
594
        viewToolBar.setVisible(true);
602
		// Set up the top-right controls
595
603
		// List topRight = new ArrayList(3);
596
        paneFolder.layout(true);
604
597
605
		if (current != null) {
598
        if (current != null) {
606
			paneFolder.setTopLeft(titleLabel);
599
            Rectangle clientArea = paneFolder.getClientArea();
607
			titleLabel.setText(current.getTitle());
600
            Rectangle bounds = paneFolder.getControl().getBounds();
608
			titleLabel.setImage(current.getTitleImage());
601
            clientArea.x += bounds.x;
609
			titleLabel.setVisible(true);
602
            clientArea.y += bounds.y;
610
		}
603
611
604
            current.setBounds(clientArea);
612
		Control currentToolbar = getCurrentToolbar();
605
        }
613
		paneFolder.setTopCenter(currentToolbar);
606
614
607
    }
615
		IPartMenu partMenu = getPartMenu();
608
616
609
    /**
617
		if (partMenu != null) {
610
     * Returns the IPartMenu for the currently selected part, or null if the current
618
			pullDownButton.setEnabled(true);
611
     * part does not have a menu.
619
		} else {
612
     * 
620
			pullDownButton.setEnabled(false);
613
     * @return the IPartMenu for the currently selected part or null if none
621
		}
614
     */
622
		paneFolder.setTopRight(viewToolBar);
615
    protected IPartMenu getPartMenu() {
623
		viewToolBar.setVisible(true);
616
        IPresentablePart part = getCurrentPart();
624
617
        if (part == null) {
625
		paneFolder.layout(true);
618
            return null;
626
619
        }
627
		if (current != null) {
620
628
			Rectangle clientArea = paneFolder.getClientArea();
621
        return part.getMenu();
629
			Rectangle bounds = paneFolder.getControl().getBounds();
622
    }
630
			clientArea.x += bounds.x;
623
631
			clientArea.y += bounds.y;
624
    /* (non-Javadoc)
632
625
     * @see org.eclipse.ui.internal.skins.Presentation#dispose()
633
			current.setBounds(clientArea);
626
     */
634
		}
627
    public void dispose() {
635
628
        if (isDisposed()) {
636
	}
629
            return;
637
630
        }
638
	/**
631
639
	 * Returns the IPartMenu for the currently selected part, or null if the
632
        // remove shell listener
640
	 * current part does not have a menu.
633
        paneFolder.getControl().getShell().removeShellListener(shellListener);
641
	 * 
634
642
	 * @return the IPartMenu for the currently selected part or null if none
635
        PresentationUtil.removeDragListener(paneFolder.getControl(),
643
	 */
636
                dragListener);
644
	protected IPartMenu getPartMenu() {
637
        PresentationUtil.removeDragListener(titleLabel, dragListener);
645
		IPresentablePart part = getCurrentPart();
638
646
		if (part == null) {
639
        systemMenuManager.dispose();
647
			return null;
640
        systemMenuManager.removeAll();
648
		}
641
        paneFolder.getControl().dispose();
649
642
        paneFolder = null;
650
		return part.getMenu();
643
651
	}
644
        titleLabel.dispose();
652
645
        titleLabel = null;
653
	/*
646
654
	 * (non-Javadoc)
647
        viewToolBar.dispose();
655
	 * 
648
    }
656
	 * @see org.eclipse.ui.internal.skins.Presentation#dispose()
649
657
	 */
650
    /* (non-Javadoc)
658
	public void dispose() {
651
     * @see org.eclipse.ui.internal.skins.Presentation#setActive(boolean)
659
		if (isDisposed()) {
652
     */
660
			return;
653
    public void setActive(boolean isActive) {
661
		}
654
        activeState = isActive;
662
655
        updateGradient();
663
		// remove shell listener
656
    }
664
		paneFolder.getControl().getShell().removeShellListener(shellListener);
657
665
658
    /**
666
		PresentationUtil.removeDragListener(paneFolder.getControl(),
659
     * Return whether the window's shell is activated
667
				dragListener);
660
     */
668
		PresentationUtil.removeDragListener(titleLabel, dragListener);
661
    /* package */boolean getShellActivated() {
669
662
        return shellActive;
670
		systemMenuManager.dispose();
663
    }
671
		systemMenuManager.removeAll();
664
672
		paneFolder.getControl().dispose();
665
    /**
673
		paneFolder = null;
666
     * Returns the top level window.
674
667
     */
675
		titleLabel.dispose();
668
    public Window getWindow() {
676
		titleLabel = null;
669
        Control ctrl = getControl();
677
670
        if (ctrl != null) {
678
		viewToolBar.dispose();
671
            Object data = ctrl.getShell().getData();
679
	}
672
            if (data instanceof Window)
680
673
                return (Window) data;
681
	/*
674
        }
682
	 * (non-Javadoc)
675
        return null;
683
	 * 
676
    }
684
	 * @see org.eclipse.ui.internal.skins.Presentation#setActive(boolean)
677
685
	 */
678
    private CTabItem createPartTab(IPresentablePart part, int tabIndex) {
686
	public void setActive(boolean isActive) {
679
        CTabItem tabItem;
687
		activeState = isActive;
680
688
		updateGradient();
681
        int style = SWT.NONE;
689
	}
682
690
683
        if (getSite().isCloseable(part))
691
	/**
684
            style |= SWT.CLOSE;
692
	 * Return whether the window's shell is activated
685
693
	 */
686
        tabItem = paneFolder.createItem(style, tabIndex);
694
	/* package */boolean getShellActivated() {
687
695
		return shellActive;
688
        tabItem.setData(TAB_DATA, part);
696
	}
689
697
690
        part.addPropertyListener(childPropertyChangeListener);
698
	/**
691
        tabItem.addDisposeListener(tabDisposeListener);
699
	 * Returns the top level window.
692
700
	 */
693
        initTab(tabItem, part);
701
	public Window getWindow() {
694
702
		Control ctrl = getControl();
695
        return tabItem;
703
		if (ctrl != null) {
696
    }
704
			Object data = ctrl.getShell().getData();
697
705
			if (data instanceof Window)
698
    // Create a close button in the title bar for the argument part (if needed).
706
				return (Window) data;
699
    private void updateCloseButton() {
707
		}
700
        // remove the close button if needed
708
		return null;
701
        if (current == null || !getSite().isCloseable(current)) {
709
	}
702
            if (closeButton != null) {
710
703
                closeButton.dispose();
711
	private CTabItem createPartTab(IPresentablePart part, int tabIndex) {
704
                closeButton = null;
712
		CTabItem tabItem;
705
713
706
                paneFolder.flush();
714
		int style = SWT.NONE;
707
            }
715
708
            return;
716
		if (getSite().isCloseable(part))
709
        }
717
			style |= SWT.CLOSE;
710
718
711
        // a close button is needed, so if its already there, we're done
719
		tabItem = paneFolder.createItem(style, tabIndex);
712
        if (closeButton != null)
720
713
            return;
721
		tabItem.setData(TAB_DATA, part);
714
722
715
        // otherwise create it
723
		part.addPropertyListener(childPropertyChangeListener);
716
        closeButton = new ToolItem(viewToolBar, SWT.PUSH);
724
		tabItem.addDisposeListener(tabDisposeListener);
717
        closeButton.setDisabledImage(null);
725
718
        closeButton.setImage(WorkbenchImages
726
		initTab(tabItem, part);
719
                .getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW));
727
720
        closeButton.setToolTipText(R21PresentationMessages
728
		return tabItem;
721
                .getString("BasicStackPresentation.close.tooltip")); //$NON-NLS-1$
729
	}
722
        closeButton.addSelectionListener(new SelectionAdapter() {
730
723
            public void widgetSelected(SelectionEvent e) {
731
	// Create a close button in the title bar for the argument part (if needed).
724
                close(getCurrent());
732
	private void updateCloseButton() {
725
            }
733
		// remove the close button if needed
726
        });
734
		if (current == null || !getSite().isCloseable(current)) {
727
735
			if (closeButton != null) {
728
        paneFolder.flush();
736
				closeButton.dispose();
729
    }
737
				closeButton = null;
730
738
731
    /**
739
				paneFolder.flush();
732
     * Initializes a tab for the given part. Sets the text, icon, tool tip,
740
			}
733
     * etc. This will also be called whenever a relevant property changes
741
			return;
734
     * in the part to reflect those changes in the tab. Subclasses may override
742
		}
735
     * to change the appearance of tabs for a particular part.
743
736
     * 
744
		// a close button is needed, so if its already there, we're done
737
     * @param tabItem tab for the part
745
		if (closeButton != null)
738
     * @param part the part being displayed
746
			return;
739
     */
747
740
    protected void initTab(CTabItem tabItem, IPresentablePart part) {
748
		// otherwise create it
741
        tabItem.setText(part.getName());
749
		closeButton = new ToolItem(viewToolBar, SWT.PUSH);
742
750
		closeButton.setDisabledImage(null);
743
        //tabItem.setImage(part.getTitleImage());
751
		closeButton.setImage(WorkbenchImages
744
752
				.getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW));
745
        String toolTipText = part.getTitleToolTip();
753
		closeButton.setToolTipText(R21PresentationMessages
746
        if (!toolTipText.equals(Util.ZERO_LENGTH_STRING)) {
754
				.getString("BasicStackPresentation.close.tooltip")); //$NON-NLS-1$
747
            tabItem.setToolTipText(toolTipText);
755
		closeButton.addSelectionListener(new SelectionAdapter() {
748
        }
756
			public void widgetSelected(SelectionEvent e) {
749
757
				close(getCurrent());
750
        //		FontRegistry registry = 
758
			}
751
        //		    PlatformUI.getWorkbench().
759
		});
752
        //		    	getThemeManager().getCurrentTheme().
760
753
        //		    		getFontRegistry();
761
		paneFolder.flush();
754
        //		
762
	}
755
        //		if(part.isBusy())
763
756
        //			tabItem.setFont(registry.getItalic(IWorkbenchThemeConstants.TAB_TEXT_FONT));
764
	/**
757
        //		else{
765
	 * Initializes a tab for the given part. Sets the text, icon, tool tip, etc.
758
        //			tabItem.setFont(registry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT));
766
	 * This will also be called whenever a relevant property changes in the part
759
        //		}			
767
	 * to reflect those changes in the tab. Subclasses may override to change
760
768
	 * the appearance of tabs for a particular part.
761
    }
769
	 * 
762
770
	 * @param tabItem
763
    /* (non-Javadoc)
771
	 *            tab for the part
764
     * @see org.eclipse.ui.internal.skins.StackPresentation#addPart(org.eclipse.ui.internal.skins.IPresentablePart, org.eclipse.ui.internal.skins.IPresentablePart)
772
	 * @param part
765
     */
773
	 *            the part being displayed
766
    public void addPart(IPresentablePart newPart, Object cookie) {
774
	 */
767
775
	protected void initTab(CTabItem tabItem, IPresentablePart part) {
768
        int idx;
776
		tabItem.setText(part.getName());
769
777
770
        if (cookie instanceof Integer) {
778
		// tabItem.setImage(part.getTitleImage());
771
            idx = ((Integer) cookie).intValue();
779
772
        } else {
780
		String toolTipText = part.getTitleToolTip();
773
            // Select a location for newly inserted parts
781
		if (!toolTipText.equals(Util.ZERO_LENGTH_STRING)) {
774
            idx = paneFolder.getItemCount();
782
			tabItem.setToolTipText(toolTipText);
775
        }
783
		}
776
784
777
        addPart(newPart, idx);
785
		// FontRegistry registry =
778
    }
786
		// PlatformUI.getWorkbench().
779
787
		// getThemeManager().getCurrentTheme().
780
    /**
788
		// getFontRegistry();
781
     * Adds the given presentable part to this presentation at the given index.
789
		//		
782
     * Does nothing if a tab already exists for the given part. 
790
		// if(part.isBusy())
783
     *
791
		// tabItem.setFont(registry.getItalic(IWorkbenchThemeConstants.TAB_TEXT_FONT));
784
     * @param newPart
792
		// else{
785
     * @param index
793
		// tabItem.setFont(registry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT));
786
     */
794
		// }
787
    public void addPart(IPresentablePart newPart, int index) {
795
788
        // If we already have a tab for this part, do nothing
796
	}
789
        if (getTab(newPart) != null) {
797
790
            return;
798
	/*
791
        }
799
	 * (non-Javadoc)
792
        createPartTab(newPart, index);
800
	 * 
793
801
	 * @see org.eclipse.ui.internal.skins.StackPresentation#addPart(org.eclipse.ui.internal.skins.IPresentablePart,
794
        setControlSize();
802
	 *      org.eclipse.ui.internal.skins.IPresentablePart)
795
    }
803
	 */
796
804
	public void addPart(IPresentablePart newPart, Object cookie) {
797
    /* (non-Javadoc)
805
798
     * @see org.eclipse.ui.internal.skins.StackPresentation#removePart(org.eclipse.ui.internal.skins.IPresentablePart)
806
		int idx;
799
     */
807
800
    public void removePart(IPresentablePart oldPart) {
808
		if (cookie instanceof Integer) {
801
        if (current == oldPart) {
809
			idx = ((Integer) cookie).intValue();
802
        	titleLabel.setImage(null);
810
		} else {
803
            current = null;
811
			// Select a location for newly inserted parts
804
        }
812
			idx = paneFolder.getItemCount();
805
813
		}
806
        CTabItem item = getTab(oldPart);
814
807
        if (item == null) {
815
		addPart(newPart, idx);
808
            return;
816
	}
809
        }
817
810
        oldPart.setVisible(false);
818
	/**
811
819
	 * Adds the given presentable part to this presentation at the given index.
812
        item.dispose();
820
	 * Does nothing if a tab already exists for the given part.
813
821
	 * 
814
        // Layout the folder again in case there is only one item
822
	 * @param newPart
815
        setControlSize();
823
	 * @param index
816
    }
824
	 */
817
825
	public void addPart(IPresentablePart newPart, int index) {
818
    /* (non-Javadoc)
826
		// If we already have a tab for this part, do nothing
819
     * @see org.eclipse.ui.internal.skins.StackPresentation#selectPart(org.eclipse.ui.internal.skins.IPresentablePart)
827
		if (getTab(newPart) != null) {
820
     */
828
			return;
821
    public void selectPart(IPresentablePart toSelect) {
829
		}
822
        if (toSelect == current) {
830
		createPartTab(newPart, index);
823
            return;
831
824
        }
832
		setControlSize();
825
833
	}
826
        if (current != null) {
834
827
            current.setVisible(false);
835
	/*
828
        }
836
	 * (non-Javadoc)
829
837
	 * 
830
        current = toSelect;
838
	 * @see org.eclipse.ui.internal.skins.StackPresentation#removePart(org.eclipse.ui.internal.skins.IPresentablePart)
831
839
	 */
832
        if (current != null) {
840
	public void removePart(IPresentablePart oldPart) {
833
            paneFolder.setSelection(indexOf(current));
841
		if (current == oldPart) {
834
            current.setVisible(true);
842
			titleLabel.setImage(null);
835
            updateCloseButton();
843
			current = null;
836
            setControlSize();
844
		}
837
        }
845
838
    }
846
		CTabItem item = getTab(oldPart);
839
847
		if (item == null) {
840
    public IPresentablePart getCurrentPart() {
848
			return;
841
        return current;
849
		}
842
    }
850
		oldPart.setVisible(false);
843
851
844
    /* (non-Javadoc)
852
		item.dispose();
845
     * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
853
846
     */
854
		// Layout the folder again in case there is only one item
847
    public void setBounds(Rectangle bounds) {
855
		setControlSize();
848
        if (getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
856
	}
849
        	bounds = Geometry.copy(bounds);
857
850
        	bounds.height = computePreferredSize(false, Integer.MAX_VALUE, bounds.width, Integer.MAX_VALUE);
858
	/*
851
        }
859
	 * (non-Javadoc)
852
    	
860
	 * 
853
        paneFolder.getControl().setBounds(bounds);
861
	 * @see org.eclipse.ui.internal.skins.StackPresentation#selectPart(org.eclipse.ui.internal.skins.IPresentablePart)
854
        setControlSize();
862
	 */
855
    }
863
	public void selectPart(IPresentablePart toSelect) {
856
864
		if (toSelect == current) {
857
    /* (non-Javadoc)
865
			return;
858
     * @see org.eclipse.ui.internal.skins.Presentation#computeMinimumSize()
866
		}
859
     */
867
860
    public Point computeMinimumSize() {
868
		if (current != null) {
861
        Point result = Geometry.getSize(paneFolder.computeTrim(0, 0, 0, 0));
869
			current.setVisible(false);
862
        
870
		}
863
        result.x += 100;
871
864
        
872
		current = toSelect;
865
        return result;
873
866
    }
874
		if (current != null) {
867
875
			paneFolder.setSelection(indexOf(current));
868
    /* (non-Javadoc)
876
			current.setVisible(true);
869
     * @see org.eclipse.ui.internal.skins.Presentation#setVisible(boolean)
877
			updateCloseButton();
870
     */
878
			setControlSize();
871
    public void setVisible(boolean isVisible) {
879
		}
872
        if (current != null) {
880
	}
873
            current.setVisible(isVisible);
881
874
        }
882
	public IPresentablePart getCurrentPart() {
875
        paneFolder.getControl().setVisible(isVisible);
883
		return current;
876
    }
884
	}
877
885
878
    /* (non-Javadoc)
886
	/*
879
     * @see org.eclipse.ui.internal.skins.Presentation#setState(int)
887
	 * (non-Javadoc)
880
     */
888
	 * 
881
    public void setState(int state) {
889
	 * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
882
        //		tabFolder.setState(state);
890
	 */
883
    }
891
	public void setBounds(Rectangle bounds) {
884
892
		if (getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
885
    /* (non-Javadoc)
893
			bounds = Geometry.copy(bounds);
886
     * @see org.eclipse.ui.internal.skins.Presentation#getSystemMenuManager()
894
			bounds.height = computePreferredSize(false, Integer.MAX_VALUE,
887
     */
895
					bounds.width, Integer.MAX_VALUE);
888
    public IMenuManager getSystemMenuManager() {
896
		}
889
        return systemMenuManager;
897
890
    }
898
		paneFolder.getControl().setBounds(bounds);
891
899
		setControlSize();
892
    /**
900
	}
893
     * @param point
901
894
     */
902
	/*
895
    protected void showSystemMenu(Point point) {
903
	 * (non-Javadoc)
896
        Menu aMenu = systemMenuManager.createContextMenu(paneFolder
904
	 * 
897
                .getControl().getParent());
905
	 * @see org.eclipse.ui.internal.skins.Presentation#computeMinimumSize()
898
        systemMenuManager.update(true);
906
	 */
899
        aMenu.setLocation(point.x, point.y);
907
	public Point computeMinimumSize() {
900
        aMenu.setVisible(true);
908
		Point result = Geometry.getSize(paneFolder.computeTrim(0, 0, 0, 0));
901
    }
909
902
910
		result.x += 100;
903
    /* (non-Javadoc)
911
904
     * @see org.eclipse.ui.internal.skins.Presentation#getControl()
912
		return result;
905
     */
913
	}
906
    public Control getControl() {
914
907
        return paneFolder.getControl();
915
	/*
908
    }
916
	 * (non-Javadoc)
909
917
	 * 
910
    /*
918
	 * @see org.eclipse.ui.internal.skins.Presentation#setVisible(boolean)
911
     * (non-Javadoc)
919
	 */
912
     * 
920
	public void setVisible(boolean isVisible) {
913
     * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control,
921
		if (current != null) {
914
     *      org.eclipse.swt.graphics.Point)
922
			current.setVisible(isVisible);
915
     */
923
		}
916
    public StackDropResult dragOver(Control currentControl, Point location) {
924
		paneFolder.getControl().setVisible(isVisible);
917
925
	}
918
        // Determine which tab we're currently dragging over
926
919
        Point localPos = paneFolder.getControl().toControl(location);
927
	/*
920
        final CTabItem tabUnderPointer = paneFolder.getItem(localPos);
928
	 * (non-Javadoc)
921
929
	 * 
922
        // This drop target only deals with tabs... if we're not dragging over
930
	 * @see org.eclipse.ui.internal.skins.Presentation#setState(int)
923
        // a tab, exit.
931
	 */
924
        if (tabUnderPointer == null)
932
	public void setState(int state) {
925
            return null;
933
		// tabFolder.setState(state);
926
934
	}
927
        // workaround when left tab is dragged over next
935
928
        int dragOverIndex = paneFolder.indexOf(tabUnderPointer);
936
	/*
929
937
	 * (non-Javadoc)
930
        return new StackDropResult(Geometry.toDisplay(paneFolder.getControl(),
938
	 * 
931
                tabUnderPointer.getBounds()), new Integer(dragOverIndex));
939
	 * @see org.eclipse.ui.internal.skins.Presentation#getSystemMenuManager()
932
    }
940
	 */
933
941
	public IMenuManager getSystemMenuManager() {
934
    /**
942
		return systemMenuManager;
935
     * Returns the toolbar control for the currently selected part, or null if none (not 
943
	}
936
     * all parts have a toolbar).
944
937
     * 
945
	/**
938
     * @return the current toolbar or null if none
946
	 * @param point
939
     */
947
	 */
940
    protected Control getCurrentToolbar() {
948
	protected void showSystemMenu(Point point) {
941
        IPresentablePart part = getCurrentPart();
949
		Menu aMenu = systemMenuManager.createContextMenu(paneFolder
942
        if (part == null) {
950
				.getControl().getParent());
943
            return null;
951
		systemMenuManager.update(true);
944
        }
952
		aMenu.setLocation(point.x, point.y);
945
953
		aMenu.setVisible(true);
946
        return part.getToolBar();
954
	}
947
    }
955
948
956
	/*
949
    /* (non-Javadoc)
957
	 * (non-Javadoc)
950
     * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu()
958
	 * 
951
     */
959
	 * @see org.eclipse.ui.internal.skins.Presentation#getControl()
952
    public void showSystemMenu() {
960
	 */
953
        IPresentablePart part = getCurrentPart();
961
	public Control getControl() {
954
        if (part != null) {
962
		return paneFolder.getControl();
955
            Rectangle bounds = DragUtil.getDisplayBounds(paneFolder
963
	}
956
                    .getControl());
964
957
965
	/*
958
            int idx = paneFolder.getSelectionIndex();
966
	 * (non-Javadoc)
959
            if (idx > -1) {
967
	 * 
960
                CTabItem item = paneFolder.getItem(idx);
968
	 * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control,
961
                Rectangle itemBounds = item.getBounds();
969
	 *      org.eclipse.swt.graphics.Point)
962
970
	 */
963
                bounds.x += itemBounds.x;
971
	public StackDropResult dragOver(Control currentControl, Point location) {
964
                bounds.y += itemBounds.y;
972
965
            }
973
		// Determine which tab we're currently dragging over
966
974
		Point localPos = paneFolder.getControl().toControl(location);
967
            Point location = new Point(bounds.x, bounds.y
975
		final CTabItem tabUnderPointer = paneFolder.getItem(localPos);
968
                    + paneFolder.getTabHeight());
976
969
            showSystemMenu(location);
977
		// This drop target only deals with tabs... if we're not dragging over
970
        }
978
		// a tab, exit.
971
    }
979
		if (tabUnderPointer == null)
972
980
			return null;
973
    /* (non-Javadoc)
981
974
     * @see org.eclipse.ui.presentations.StackPresentation#getTabList(IPresentablePart)
982
		// workaround when left tab is dragged over next
975
     */
983
		int dragOverIndex = paneFolder.indexOf(tabUnderPointer);
976
    public Control[] getTabList(IPresentablePart part) {
984
977
        ArrayList list = new ArrayList();
985
		return new StackDropResult(Geometry.toDisplay(paneFolder.getControl(),
978
        if (paneFolder.getTabPosition() == SWT.BOTTOM) {
986
				tabUnderPointer.getBounds()), new Integer(dragOverIndex));
979
            if (part.getToolBar() != null)
987
	}
980
                list.add(part.getToolBar());
988
981
            if (part.getControl() != null)
989
	/**
982
                list.add(part.getControl());
990
	 * Returns the toolbar control for the currently selected part, or null if
983
            if (getPaneFolder() != null)
991
	 * none (not all parts have a toolbar).
984
                list.add(getPaneFolder().getControl());
992
	 * 
985
        } else {
993
	 * @return the current toolbar or null if none
986
            if (getPaneFolder() != null)
994
	 */
987
                list.add(getPaneFolder().getControl());
995
	protected Control getCurrentToolbar() {
988
            if (part.getToolBar() != null)
996
		IPresentablePart part = getCurrentPart();
989
                list.add(part.getToolBar());
997
		if (part == null) {
990
            if (part.getControl() != null)
998
			return null;
991
                list.add(part.getControl());
999
		}
992
        }
1000
993
        return (Control[]) list.toArray(new Control[list.size()]);
1001
		return part.getToolBar();
994
    }
1002
	}
995
1003
996
    protected void showList(Shell parentShell, int x, int y) {
1004
	/*
997
        //        final R21PaneFolder tabFolder = getTabFolder();
1005
	 * (non-Javadoc)
998
        //
1006
	 * 
999
        //        int shellStyle = SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM;
1007
	 * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu()
1000
        //        int tableStyle = SWT.V_SCROLL | SWT.H_SCROLL;
1008
	 */
1001
        //        final BasicStackList editorList = new BasicStackList(tabFolder.getControl().getShell(),
1009
	public void showSystemMenu() {
1002
        //                shellStyle, tableStyle);
1010
		IPresentablePart part = getCurrentPart();
1003
        //        editorList.setInput(this);
1011
		if (part != null) {
1004
        //        Point size = editorList.computeSizeHint();
1012
			Rectangle bounds = DragUtil.getDisplayBounds(paneFolder
1005
        //        
1013
					.getControl());
1006
        //        Rectangle bounds = Display.getCurrent().getBounds();
1014
1007
        //        if (x + size.x > bounds.width) x = bounds.width - size.x;
1015
			int idx = paneFolder.getSelectionIndex();
1008
        //        if (y + size.y > bounds.height) y = bounds.height - size.y;
1016
			if (idx > -1) {
1009
        //        editorList.setLocation(new Point(x, y));
1017
				CTabItem item = paneFolder.getItem(idx);
1010
        //        editorList.setVisible(true);
1018
				Rectangle itemBounds = item.getBounds();
1011
        //        editorList.setFocus();
1019
1012
        //        editorList.getTableViewer().getTable().getShell().addListener(
1020
				bounds.x += itemBounds.x;
1013
        //                SWT.Deactivate, new Listener() {
1021
				bounds.y += itemBounds.y;
1014
        //
1022
			}
1015
        //                    public void handleEvent(Event event) {
1023
1016
        //                        editorList.setVisible(false);
1024
			Point location = new Point(bounds.x, bounds.y
1017
        //                    }
1025
					+ paneFolder.getTabHeight());
1018
        //                });
1026
			showSystemMenu(location);
1019
    }
1027
		}
1020
1028
	}
1021
    /*
1029
1022
     * Shows the list of tabs at the top left corner of the editor
1030
	/*
1023
     */
1031
	 * (non-Javadoc)
1024
    protected void showListDefaultLocation() {
1032
	 * 
1025
        R21PaneFolder tabFolder = getPaneFolder();
1033
	 * @see org.eclipse.ui.presentations.StackPresentation#getTabList(IPresentablePart)
1026
        Shell shell = tabFolder.getControl().getShell();
1034
	 */
1027
        Rectangle clientArea = tabFolder.getClientArea();
1035
	public Control[] getTabList(IPresentablePart part) {
1028
        Point location = tabFolder.getControl().getDisplay().map(
1036
		ArrayList list = new ArrayList();
1029
                tabFolder.getControl(), null, clientArea.x, clientArea.y);
1037
		if (paneFolder.getTabPosition() == SWT.BOTTOM) {
1030
        showList(shell, location.x, location.y);
1038
			if (part.getToolBar() != null)
1031
    }
1039
				list.add(part.getToolBar());
1032
1040
			if (part.getControl() != null)
1033
    void setSelection(CTabItem tabItem) {
1041
				list.add(part.getControl());
1034
        getSite().selectPart(getPartForTab(tabItem));
1042
			if (getPaneFolder() != null)
1035
    }
1043
				list.add(getPaneFolder().getControl());
1036
1044
		} else {
1037
    void close(IPresentablePart presentablePart) {
1045
			if (getPaneFolder() != null)
1038
        getSite().close(new IPresentablePart[] { presentablePart });
1046
				list.add(getPaneFolder().getControl());
1039
    }
1047
			if (part.getToolBar() != null)
1040
1048
				list.add(part.getToolBar());
1041
    Image getLabelImage(IPresentablePart presentablePart) {
1049
			if (part.getControl() != null)
1042
        return presentablePart.getTitleImage();
1050
				list.add(part.getControl());
1043
    }
1051
		}
1044
1052
		return (Control[]) list.toArray(new Control[list.size()]);
1045
    String getLabelText(IPresentablePart presentablePart, boolean includePath) {
1053
	}
1046
        String title = presentablePart.getTitle().trim();
1054
1047
        return title;
1055
	protected void showList(Shell parentShell, int x, int y) {
1048
    }
1056
		// final R21PaneFolder tabFolder = getTabFolder();
1049
1057
		//
1050
    /* (non-Javadoc)
1058
		// int shellStyle = SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM;
1051
     * @see org.eclipse.ui.presentations.StackPresentation#setActive(int)
1059
		// int tableStyle = SWT.V_SCROLL | SWT.H_SCROLL;
1052
     */
1060
		// final BasicStackList editorList = new
1053
    public void setActive(int newState) {
1061
		// BasicStackList(tabFolder.getControl().getShell(),
1054
        setActive(newState == AS_ACTIVE_FOCUS);
1062
		// shellStyle, tableStyle);
1055
    }
1063
		// editorList.setInput(this);
1064
		// Point size = editorList.computeSizeHint();
1065
		//        
1066
		// Rectangle bounds = Display.getCurrent().getBounds();
1067
		// if (x + size.x > bounds.width) x = bounds.width - size.x;
1068
		// if (y + size.y > bounds.height) y = bounds.height - size.y;
1069
		// editorList.setLocation(new Point(x, y));
1070
		// editorList.setVisible(true);
1071
		// editorList.setFocus();
1072
		// editorList.getTableViewer().getTable().getShell().addListener(
1073
		// SWT.Deactivate, new Listener() {
1074
		//
1075
		// public void handleEvent(Event event) {
1076
		// editorList.setVisible(false);
1077
		// }
1078
		// });
1079
	}
1080
1081
	/*
1082
	 * Shows the list of tabs at the top left corner of the editor
1083
	 */
1084
	protected void showListDefaultLocation() {
1085
		R21PaneFolder tabFolder = getPaneFolder();
1086
		Shell shell = tabFolder.getControl().getShell();
1087
		Rectangle clientArea = tabFolder.getClientArea();
1088
		Point location = tabFolder.getControl().getDisplay().map(
1089
				tabFolder.getControl(), null, clientArea.x, clientArea.y);
1090
		showList(shell, location.x, location.y);
1091
	}
1092
1093
	void setSelection(CTabItem tabItem) {
1094
		getSite().selectPart(getPartForTab(tabItem));
1095
	}
1096
1097
	void close(IPresentablePart presentablePart) {
1098
		getSite().close(new IPresentablePart[] { presentablePart });
1099
	}
1100
1101
	Image getLabelImage(IPresentablePart presentablePart) {
1102
		return presentablePart.getTitleImage();
1103
	}
1104
1105
	String getLabelText(IPresentablePart presentablePart, boolean includePath) {
1106
		String title = presentablePart.getTitle().trim();
1107
		return title;
1108
	}
1109
1110
	/*
1111
	 * (non-Javadoc)
1112
	 * 
1113
	 * @see org.eclipse.ui.presentations.StackPresentation#setActive(int)
1114
	 */
1115
	public void setActive(int newState) {
1116
		setActive(newState == AS_ACTIVE_FOCUS);
1117
	}
1118
1119
	/*
1120
	 * (non-Javadoc)
1121
	 * 
1122
	 * @see org.eclipse.ui.presentations.StackPresentation#restoreState(org.eclipse.ui.presentations.IPresentationSerializer,
1123
	 *      org.eclipse.ui.IMemento)
1124
	 */
1125
	public void restoreState(IPresentationSerializer serializer,
1126
			IMemento savedState) {
1127
		IMemento[] parts = savedState.getChildren(IWorkbenchConstants.TAG_PART);
1128
1129
		for (int idx = 0; idx < parts.length; idx++) {
1130
			String id = parts[idx].getString(IWorkbenchConstants.TAG_ID);
1131
1132
			if (id != null) {
1133
				IPresentablePart part = serializer.getPart(id);
1134
1135
				if (part != null) {
1136
					addPart(part, getPaneFolder().getItemCount());
1137
				}
1138
			}
1139
		}
1140
	}
1141
1142
	/*
1143
	 * (non-Javadoc)
1144
	 * 
1145
	 * @see org.eclipse.ui.presentations.StackPresentation#saveState(org.eclipse.ui.presentations.IPresentationSerializer,
1146
	 *      org.eclipse.ui.IMemento)
1147
	 */
1148
	public void saveState(IPresentationSerializer context, IMemento memento) {
1149
		super.saveState(context, memento);
1150
1151
		List parts = getPresentableParts();
1152
1153
		Iterator iter = parts.iterator();
1154
		while (iter.hasNext()) {
1155
			IPresentablePart next = (IPresentablePart) iter.next();
1156
1157
			IMemento childMem = memento
1158
					.createChild(IWorkbenchConstants.TAG_PART);
1159
			childMem.putString(IWorkbenchConstants.TAG_ID, context.getId(next));
1160
		}
1161
	}
1162
1163
	/**
1164
	 * Returns the List of IPresentablePart currently in this presentation
1165
	 */
1166
	private List getPresentableParts() {
1167
		Assert.isTrue(!isDisposed());
1168
1169
		CTabItem[] items = getPaneFolder().getItems();
1170
		List result = new ArrayList(items.length);
1171
1172
		for (int idx = 0; idx < getPaneFolder().getItemCount(); idx++) {
1173
			result.add(getPartForTab(items[idx]));
1174
		}
1056
1175
1176
		return result;
1177
	}
1057
}
1178
}

Return to bug 62218