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 321294
Collapse All | Expand All

(-)Eclipse (+534 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal;
12
13
import org.eclipse.jface.util.Util;
14
import org.eclipse.jface.viewers.ILabelProvider;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.jface.viewers.TableViewer;
18
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.jface.viewers.ViewerFilter;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.KeyEvent;
22
import org.eclipse.swt.events.KeyListener;
23
import org.eclipse.swt.events.ModifyEvent;
24
import org.eclipse.swt.events.ModifyListener;
25
import org.eclipse.swt.events.MouseAdapter;
26
import org.eclipse.swt.events.MouseEvent;
27
import org.eclipse.swt.events.MouseMoveListener;
28
import org.eclipse.swt.events.SelectionAdapter;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.events.SelectionListener;
31
import org.eclipse.swt.events.TraverseEvent;
32
import org.eclipse.swt.events.TraverseListener;
33
import org.eclipse.swt.graphics.Color;
34
import org.eclipse.swt.graphics.FontMetrics;
35
import org.eclipse.swt.graphics.GC;
36
import org.eclipse.swt.graphics.Point;
37
import org.eclipse.swt.graphics.Rectangle;
38
import org.eclipse.swt.layout.FillLayout;
39
import org.eclipse.swt.layout.GridData;
40
import org.eclipse.swt.layout.GridLayout;
41
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Item;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Menu;
46
import org.eclipse.swt.widgets.MenuItem;
47
import org.eclipse.swt.widgets.Shell;
48
import org.eclipse.swt.widgets.Table;
49
import org.eclipse.swt.widgets.TableItem;
50
import org.eclipse.swt.widgets.Text;
51
import org.eclipse.ui.internal.misc.StringMatcher;
52
53
/**
54
 * @since 3.0
55
 */
56
public abstract class AbstractTableInformationControl {
57
58
	/**
59
	 * The NamePatternFilter selects the elements which match the given string
60
	 * patterns.
61
	 */
62
	protected class NamePatternFilter extends ViewerFilter {
63
64
		/*
65
		 * (non-Javadoc) Method declared on ViewerFilter.
66
		 */
67
		public boolean select(Viewer viewer, Object parentElement, Object element) {
68
			StringMatcher matcher = getMatcher();
69
			if (matcher == null || !(viewer instanceof TableViewer)) {
70
				return true;
71
			}
72
			TableViewer tableViewer = (TableViewer) viewer;
73
74
			String matchName = ((ILabelProvider) tableViewer.getLabelProvider()).getText(element);
75
76
			if (matchName == null) {
77
				return false;
78
			}
79
			// A dirty editor's label will start with dirty prefix, this prefix
80
			// should not be taken in consideration when matching with a pattern
81
			if (matchName.startsWith("*")) { //$NON-NLS-1$
82
				matchName = matchName.substring(1);
83
			}
84
			return matcher.match(matchName);
85
		}
86
	}
87
88
	/** The control's shell */
89
	private Shell fShell;
90
91
	/** The composite */
92
	private Composite fComposite;
93
94
	/** The control's text widget */
95
	private Text fFilterText;
96
97
	/** The control's table widget */
98
	private TableViewer fTableViewer;
99
100
	/** The current string matcher */
101
	private StringMatcher fStringMatcher;
102
103
	/**
104
	 * Creates an information control with the given shell as parent. The given
105
	 * styles are applied to the shell and the table widget.
106
	 * 
107
	 * @param parent
108
	 *            the parent shell
109
	 * @param shellStyle
110
	 *            the additional styles for the shell
111
	 * @param controlStyle
112
	 *            the additional styles for the control
113
	 */
114
	public AbstractTableInformationControl(Shell parent, int shellStyle, int controlStyle) {
115
		fShell = new Shell(parent, shellStyle);
116
		fShell.setLayout(new FillLayout());
117
118
		// Composite for filter text and viewer
119
		fComposite = new Composite(fShell, SWT.RESIZE);
120
		GridLayout layout = new GridLayout(1, false);
121
		fComposite.setLayout(layout);
122
		createFilterText(fComposite);
123
124
		fTableViewer = createTableViewer(fComposite, controlStyle);
125
126
		final Table table = fTableViewer.getTable();
127
		table.addKeyListener(new KeyListener() {
128
			public void keyPressed(KeyEvent e) {
129
				switch (e.keyCode) {
130
				case SWT.ESC:
131
					dispose();
132
					break;
133
				case SWT.DEL:
134
					removeSelectedItems();
135
					e.character = SWT.NONE;
136
					e.doit = false;
137
					break;
138
				case SWT.ARROW_UP:
139
					if (table.getSelectionIndex() == 0) {
140
						// on the first item, going up should grant focus to
141
						// text field
142
						fFilterText.setFocus();
143
					}
144
					break;
145
				case SWT.ARROW_DOWN:
146
					if (table.getSelectionIndex() == table.getItemCount() - 1) {
147
						// on the last item, going down should grant focus to
148
						// the text field
149
						fFilterText.setFocus();
150
					}
151
					break;
152
				}
153
			}
154
155
			public void keyReleased(KeyEvent e) {
156
				// do nothing
157
			}
158
		});
159
160
		table.addSelectionListener(new SelectionListener() {
161
			public void widgetSelected(SelectionEvent e) {
162
				// do nothing;
163
			}
164
165
			public void widgetDefaultSelected(SelectionEvent e) {
166
				gotoSelectedElement();
167
			}
168
		});
169
170
		/*
171
		 * Bug in GTK, see SWT bug: 62405 Editor drop down performance slow on
172
		 * Linux-GTK on mouse move. Rather then removing the support altogether
173
		 * this feature has been worked around for GTK only as we expect that
174
		 * newer versions of GTK will no longer exhibit this quality and we will
175
		 * be able to have the desired support running on all platforms. See
176
		 * comment https://bugs.eclipse.org/bugs/show_bug.cgi?id=62405#c22 TODO:
177
		 * remove this code once bug 62405 is fixed for the mainstream GTK
178
		 * version
179
		 */
180
		final int ignoreEventCount = Util.isGtk() ? 4 : 1;
181
182
		table.addMouseMoveListener(new MouseMoveListener() {
183
			TableItem fLastItem = null;
184
			int lastY = 0;
185
			int itemHeightdiv4 = table.getItemHeight() / 4;
186
			int tableHeight = table.getBounds().height;
187
			Point tableLoc = table.toDisplay(0, 0);
188
			int divCount = 0;
189
190
			public void mouseMove(MouseEvent e) {
191
				if (divCount == ignoreEventCount) {
192
					divCount = 0;
193
				}
194
				if (table.equals(e.getSource()) & ++divCount == ignoreEventCount) {
195
					Object o = table.getItem(new Point(e.x, e.y));
196
					if (fLastItem == null ^ o == null) {
197
						table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(
198
								SWT.CURSOR_HAND));
199
					}
200
					if (o instanceof TableItem && lastY != e.y) {
201
						lastY = e.y;
202
						if (!o.equals(fLastItem)) {
203
							fLastItem = (TableItem) o;
204
							table.setSelection(new TableItem[] { fLastItem });
205
						} else if (e.y < itemHeightdiv4) {
206
							// Scroll up
207
							Item item = fTableViewer.scrollUp(e.x + tableLoc.x, e.y + tableLoc.y);
208
							if (item instanceof TableItem) {
209
								fLastItem = (TableItem) item;
210
								table.setSelection(new TableItem[] { fLastItem });
211
							}
212
						} else if (e.y > tableHeight - itemHeightdiv4) {
213
							// Scroll down
214
							Item item = fTableViewer.scrollDown(e.x + tableLoc.x, e.y + tableLoc.y);
215
							if (item instanceof TableItem) {
216
								fLastItem = (TableItem) item;
217
								table.setSelection(new TableItem[] { fLastItem });
218
							}
219
						}
220
					} else if (o == null) {
221
						fLastItem = null;
222
					}
223
				}
224
			}
225
		});
226
227
		table.addMouseListener(new MouseAdapter() {
228
			public void mouseUp(MouseEvent e) {
229
				if (table.getSelectionCount() < 1) {
230
					return;
231
				}
232
233
				if (e.button == 1) {
234
					if (table.equals(e.getSource())) {
235
						Object o = table.getItem(new Point(e.x, e.y));
236
						TableItem selection = table.getSelection()[0];
237
						if (selection.equals(o)) {
238
							gotoSelectedElement();
239
						}
240
					}
241
				}
242
				if (e.button == 3) {
243
					TableItem tItem = fTableViewer.getTable().getItem(new Point(e.x, e.y));
244
					if (tItem != null) {
245
						Menu menu = new Menu(fTableViewer.getTable());
246
						MenuItem mItem = new MenuItem(menu, SWT.NONE);
247
						mItem.setText(WorkbenchMessages.PartPane_close);
248
						mItem.addSelectionListener(new SelectionAdapter() {
249
							public void widgetSelected(SelectionEvent selectionEvent) {
250
								removeSelectedItems();
251
							}
252
						});
253
						menu.setVisible(true);
254
					}
255
				}
256
			}
257
		});
258
259
		fShell.addTraverseListener(new TraverseListener() {
260
			public void keyTraversed(TraverseEvent e) {
261
				switch (e.detail) {
262
				case SWT.TRAVERSE_PAGE_NEXT:
263
					e.detail = SWT.TRAVERSE_NONE;
264
					e.doit = true;
265
					{
266
						int n = table.getItemCount();
267
						if (n == 0)
268
							return;
269
270
						int i = table.getSelectionIndex() + 1;
271
						if (i >= n)
272
							i = 0;
273
						table.setSelection(i);
274
					}
275
					break;
276
277
				case SWT.TRAVERSE_PAGE_PREVIOUS:
278
					e.detail = SWT.TRAVERSE_NONE;
279
					e.doit = true;
280
					{
281
						int n = table.getItemCount();
282
						if (n == 0)
283
							return;
284
285
						int i = table.getSelectionIndex() - 1;
286
						if (i < 0)
287
							i = n - 1;
288
						table.setSelection(i);
289
					}
290
					break;
291
				}
292
			}
293
		});
294
295
		setInfoSystemColor();
296
		installFilter();
297
	}
298
299
	/**
300
	 * Removes the selected items from the list and closes their corresponding
301
	 * tabs Selects the next item in the list or disposes it if its presentation
302
	 * is disposed
303
	 */
304
	protected void removeSelectedItems() {
305
		int selInd = fTableViewer.getTable().getSelectionIndex();
306
		if (deleteSelectedElements()) {
307
			return;
308
		}
309
		fTableViewer.refresh();
310
		if (selInd >= fTableViewer.getTable().getItemCount()) {
311
			selInd = fTableViewer.getTable().getItemCount() - 1;
312
		}
313
		if (selInd >= 0) {
314
			fTableViewer.getTable().setSelection(selInd);
315
		}
316
	}
317
318
	protected abstract TableViewer createTableViewer(Composite parent, int style);
319
320
	public TableViewer getTableViewer() {
321
		return fTableViewer;
322
	}
323
324
	protected Text createFilterText(Composite parent) {
325
		fFilterText = new Text(parent, SWT.NONE);
326
327
		GridData data = new GridData();
328
		GC gc = new GC(parent);
329
		gc.setFont(parent.getFont());
330
		FontMetrics fontMetrics = gc.getFontMetrics();
331
		gc.dispose();
332
333
		data.heightHint = org.eclipse.jface.dialogs.Dialog.convertHeightInCharsToPixels(
334
				fontMetrics, 1);
335
		data.horizontalAlignment = GridData.FILL;
336
		data.verticalAlignment = GridData.BEGINNING;
337
		fFilterText.setLayoutData(data);
338
339
		fFilterText.addKeyListener(new KeyListener() {
340
			public void keyPressed(KeyEvent e) {
341
				switch (e.keyCode) {
342
				case SWT.CR:
343
				case SWT.KEYPAD_CR:
344
					gotoSelectedElement();
345
					break;
346
				case SWT.ARROW_DOWN:
347
					fTableViewer.getTable().setFocus();
348
					fTableViewer.getTable().setSelection(0);
349
					break;
350
				case SWT.ARROW_UP:
351
					fTableViewer.getTable().setFocus();
352
					fTableViewer.getTable()
353
							.setSelection(fTableViewer.getTable().getItemCount() - 1);
354
					break;
355
				case SWT.ESC:
356
					dispose();
357
					break;
358
				}
359
			}
360
361
			public void keyReleased(KeyEvent e) {
362
				// do nothing
363
			}
364
		});
365
366
		// Horizontal separator line
367
		Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);
368
		separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
369
370
		return fFilterText;
371
	}
372
373
	private void setInfoSystemColor() {
374
		Display display = fShell.getDisplay();
375
		setForegroundColor(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
376
		setBackgroundColor(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
377
	}
378
379
	private void installFilter() {
380
		fFilterText.setText(""); //$NON-NLS-1$
381
382
		fFilterText.addModifyListener(new ModifyListener() {
383
			public void modifyText(ModifyEvent e) {
384
				String text = ((Text) e.widget).getText();
385
				int length = text.length();
386
				if (length > 0 && text.charAt(length - 1) != '*') {
387
					text = text + '*';
388
				}
389
				setMatcherString(text);
390
			}
391
		});
392
	}
393
394
	/**
395
	 * The string matcher has been modified. The default implementation
396
	 * refreshes the view and selects the first macthed element
397
	 */
398
	private void stringMatcherUpdated() {
399
		// refresh viewer to refilter
400
		fTableViewer.getControl().setRedraw(false);
401
		fTableViewer.refresh();
402
		selectFirstMatch();
403
		fTableViewer.getControl().setRedraw(true);
404
	}
405
406
	/**
407
	 * Sets the patterns to filter out for the receiver.
408
	 * <p>
409
	 * The following characters have special meaning: ? => any character * =>
410
	 * any string
411
	 * </p>
412
	 */
413
	private void setMatcherString(String pattern) {
414
		if (pattern.length() == 0) {
415
			fStringMatcher = null;
416
		} else {
417
			boolean ignoreCase = pattern.toLowerCase().equals(pattern);
418
			fStringMatcher = new StringMatcher(pattern, ignoreCase, false);
419
		}
420
		stringMatcherUpdated();
421
	}
422
423
	private StringMatcher getMatcher() {
424
		return fStringMatcher;
425
	}
426
427
	/**
428
	 * Implementers can modify
429
	 */
430
	protected Object getSelectedElement() {
431
		return ((IStructuredSelection) fTableViewer.getSelection()).getFirstElement();
432
	}
433
434
	protected abstract void gotoSelectedElement();
435
436
	/**
437
	 * Delete all selected elements.
438
	 * 
439
	 * @return <code>true</code> if there are no elements left after deletion.
440
	 */
441
	protected abstract boolean deleteSelectedElements();
442
443
	/**
444
	 * Selects the first element in the table which matches the current filter
445
	 * pattern.
446
	 */
447
	protected void selectFirstMatch() {
448
		Table table = fTableViewer.getTable();
449
		Object element = findElement(table.getItems());
450
		if (element != null) {
451
			fTableViewer.setSelection(new StructuredSelection(element), true);
452
		} else {
453
			fTableViewer.setSelection(StructuredSelection.EMPTY);
454
		}
455
	}
456
457
	private Object findElement(TableItem[] items) {
458
		ILabelProvider labelProvider = (ILabelProvider) fTableViewer.getLabelProvider();
459
		for (int i = 0; i < items.length; i++) {
460
			Object element = items[i].getData();
461
			if (fStringMatcher == null) {
462
				return element;
463
			}
464
465
			if (element != null) {
466
				String label = labelProvider.getText(element);
467
				if (label == null) {
468
					return null;
469
				}
470
				// remove the dirty prefix from the editor's label
471
				if (label.startsWith("*")) { //$NON-NLS-1$
472
					label = label.substring(1);
473
				}
474
				if (fStringMatcher.match(label)) {
475
					return element;
476
				}
477
			}
478
		}
479
		return null;
480
	}
481
482
	public void setVisible(boolean visible) {
483
		fShell.setVisible(visible);
484
	}
485
486
	public void dispose() {
487
		if (fShell != null) {
488
			if (!fShell.isDisposed()) {
489
				fShell.dispose();
490
			}
491
			fShell = null;
492
			fTableViewer = null;
493
			fComposite = null;
494
			fFilterText = null;
495
		}
496
	}
497
498
	public Point computeSizeHint() {
499
		return fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
500
	}
501
502
	public void setLocation(Point location) {
503
		Rectangle trim = fShell.computeTrim(0, 0, 0, 0);
504
		Point textLocation = fComposite.getLocation();
505
		location.x += trim.x - textLocation.x;
506
		location.y += trim.y - textLocation.y;
507
		fShell.setLocation(location);
508
	}
509
510
	public void setSize(int width, int height) {
511
		fShell.setSize(width, height);
512
	}
513
514
	public Shell getShell() {
515
		return fShell;
516
	}
517
518
	private void setForegroundColor(Color foreground) {
519
		fTableViewer.getTable().setForeground(foreground);
520
		fFilterText.setForeground(foreground);
521
		fComposite.setForeground(foreground);
522
	}
523
524
	private void setBackgroundColor(Color background) {
525
		fTableViewer.getTable().setBackground(background);
526
		fFilterText.setBackground(background);
527
		fComposite.setBackground(background);
528
	}
529
530
	public void setFocus() {
531
		fShell.forceFocus();
532
		fFilterText.setFocus();
533
	}
534
}
(-)Eclipse (+149 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal;
13
14
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
import org.eclipse.e4.ui.model.application.ui.MUIElement;
19
import org.eclipse.e4.ui.model.application.ui.MUILabel;
20
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
21
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
23
import org.eclipse.e4.ui.workbench.modeling.EPartService;
24
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
25
import org.eclipse.emf.common.util.URI;
26
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.jface.viewers.ArrayContentProvider;
28
import org.eclipse.jface.viewers.ColumnLabelProvider;
29
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
30
import org.eclipse.jface.viewers.TableViewer;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.graphics.Image;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Event;
36
import org.eclipse.swt.widgets.Listener;
37
import org.eclipse.swt.widgets.Shell;
38
import org.eclipse.swt.widgets.Table;
39
40
public class BasicPartList extends AbstractTableInformationControl {
41
42
	private class BasicStackListLabelProvider extends ColumnLabelProvider {
43
44
		public String getText(Object element) {
45
			return ((MUILabel) element).getLabel();
46
		}
47
48
		public Image getImage(Object element) {
49
			return getLabelImage(((MUILabel) element).getIconURI());
50
		}
51
52
		public String getToolTipText(Object element) {
53
			return ((MUILabel) element).getTooltip();
54
		}
55
56
		public boolean useNativeToolTip(Object object) {
57
			return true;
58
		}
59
	}
60
61
	private Map<String, Image> images = new HashMap<String, Image>();
62
63
	private ISWTResourceUtilities utils;
64
65
	private MPartStack input;
66
67
	private EPartService partService;
68
69
	public BasicPartList(Shell parent, int shellStyle, int treeStyler, EPartService partService,
70
			MPartStack input, ISWTResourceUtilities utils) {
71
		super(parent, shellStyle, treeStyler);
72
		this.partService = partService;
73
		this.input = input;
74
		this.utils = utils;
75
	}
76
77
	private Image getLabelImage(String iconURI) {
78
		Image image = images.get(iconURI);
79
		if (image == null) {
80
			ImageDescriptor descriptor = utils.imageDescriptorFromURI(URI.createURI(iconURI));
81
			image = descriptor.createImage();
82
			images.put(iconURI, image);
83
		}
84
		return image;
85
	}
86
87
	protected TableViewer createTableViewer(Composite parent, int style) {
88
		Table table = new Table(parent, SWT.SINGLE | (style & ~SWT.MULTI));
89
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
90
		TableViewer tableViewer = new TableViewer(table);
91
		tableViewer.addFilter(new NamePatternFilter());
92
		tableViewer.setContentProvider(ArrayContentProvider.getInstance());
93
		tableViewer.setLabelProvider(new BasicStackListLabelProvider());
94
95
		ColumnViewerToolTipSupport.enableFor(tableViewer);
96
		table.addListener(SWT.Dispose, new Listener() {
97
			public void handleEvent(Event event) {
98
				for (Image image : images.values()) {
99
					image.dispose();
100
				}
101
			}
102
		});
103
		return tableViewer;
104
	}
105
106
	private List<Object> getInput() {
107
		List<Object> list = new ArrayList<Object>();
108
		for (MUIElement element : input.getChildren()) {
109
			if (element instanceof MPlaceholder) {
110
				element = ((MPlaceholder) element).getRef();
111
			}
112
113
			if (element.isToBeRendered() && element.isVisible() && element instanceof MPart) {
114
				list.add(element);
115
			}
116
		}
117
		return list;
118
	}
119
120
	public void setInput() {
121
		getTableViewer().setInput(getInput());
122
		selectFirstMatch();
123
	}
124
125
	protected void gotoSelectedElement() {
126
		Object selectedElement = getSelectedElement();
127
128
		// close the shell
129
		dispose();
130
131
		if (selectedElement instanceof MPart) {
132
			partService.activate((MPart) selectedElement);
133
		}
134
	}
135
136
	protected boolean deleteSelectedElements() {
137
		Object selectedElement = getSelectedElement();
138
		if (selectedElement != null) {
139
			partService.hidePart((MPart) selectedElement);
140
141
			if (getInput().isEmpty()) {
142
				getShell().dispose();
143
				return true;
144
			}
145
		}
146
		return false;
147
148
	}
149
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-1 / +1 lines)
Lines 2497-2503 Link Here
2497
		return mpart == null ? false : partService.isPartVisible(mpart);
2497
		return mpart == null ? false : partService.isPartVisible(mpart);
2498
    }
2498
    }
2499
    
2499
    
2500
	private MUIElement findSharedArea() {
2500
	public MUIElement findSharedArea() {
2501
		MPerspective perspective = getPerspectiveStack().getSelectedElement();
2501
		MPerspective perspective = getPerspectiveStack().getSelectedElement();
2502
		return perspective == null ? null : modelService.find(IPageLayout.ID_EDITOR_AREA,
2502
		return perspective == null ? null : modelService.find(IPageLayout.ID_EDITOR_AREA,
2503
				perspective);
2503
				perspective);
(-)Eclipse UI/org/eclipse/ui/internal/WorkbookEditorsHandler.java (-7 / +62 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-19 Link Here
14
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionEvent;
16
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
18
import org.eclipse.e4.ui.model.application.ui.MUIElement;
19
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
20
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
21
import org.eclipse.e4.ui.workbench.IResourceUtilities;
22
import org.eclipse.e4.ui.workbench.modeling.EPartService;
23
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.graphics.Point;
26
import org.eclipse.swt.graphics.Rectangle;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.swt.widgets.Listener;
17
import org.eclipse.ui.IWorkbenchWindow;
29
import org.eclipse.ui.IWorkbenchWindow;
18
import org.eclipse.ui.handlers.HandlerUtil;
30
import org.eclipse.ui.handlers.HandlerUtil;
19
31
Lines 31-43 Link Here
31
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
32
	 */
44
	 */
33
	public Object execute(ExecutionEvent event) throws ExecutionException {
45
	public Object execute(ExecutionEvent event) throws ExecutionException {
34
		IWorkbenchWindow workbenchWindow = HandlerUtil
46
		IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
35
				.getActiveWorkbenchWindow(event);
47
		WorkbenchPage page = (WorkbenchPage) workbenchWindow.getActivePage();
36
		if (workbenchWindow == null) {
48
		if (page != null) {
37
			// action has been disposed
49
			MUIElement area = page.findSharedArea();
38
			return null;
50
			if (area instanceof MPlaceholder) {
51
				area = ((MPlaceholder) area).getRef();
52
			}
53
54
			MPartStack activeStack = getActiveStack(area);
55
			if (activeStack != null) {
56
				ISWTResourceUtilities utils = (ISWTResourceUtilities) HandlerUtil
57
						.getVariableChecked(event, IResourceUtilities.class.getName());
58
				EPartService partService = (EPartService) HandlerUtil.getVariableChecked(event,
59
						EPartService.class.getName());
60
				final BasicPartList editorList = new BasicPartList(workbenchWindow.getShell(),
61
						SWT.ON_TOP, SWT.V_SCROLL | SWT.H_SCROLL, partService, activeStack, utils);
62
				editorList.setInput();
63
64
				Point size = editorList.computeSizeHint();
65
				editorList.setSize(size.x, size.y);
66
67
				Rectangle bounds = workbenchWindow.getShell().getBounds();
68
				int x = (bounds.width / 2) + bounds.x;
69
				int y = (bounds.height / 2) + bounds.y;
70
				x = x - (size.x / 2);
71
				y = y - (size.y / 2);
72
73
				editorList.setLocation(new Point(x, y));
74
				editorList.setVisible(true);
75
				editorList.setFocus();
76
				editorList.getShell().addListener(SWT.Deactivate, new Listener() {
77
					public void handleEvent(Event event) {
78
						editorList.getShell().getDisplay().asyncExec(new Runnable() {
79
							public void run() {
80
								editorList.dispose();
81
							}
82
						});
83
					}
84
				});
85
			}
86
		}
87
		return null;
88
	}
89
90
	private MPartStack getActiveStack(Object element) {
91
		if (element instanceof MPartStack) {
92
			return (MPartStack) element;
93
		} else if (element instanceof MElementContainer<?>) {
94
			return getActiveStack(((MElementContainer<?>) element).getSelectedElement());
39
		}
95
		}
40
		// TODO show the list of editors in the editor area
41
		return null;
96
		return null;
42
	}
97
	}
43
98

Return to bug 321294