01: /*******************************************************************************
02: * Copyright (c) 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Common Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/cpl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.presentation.wrappedtabs;
11:
12: import org.eclipse.jface.action.ContributionItem;
13: import org.eclipse.swt.SWT;
14: import org.eclipse.swt.events.SelectionAdapter;
15: import org.eclipse.swt.events.SelectionEvent;
16: import org.eclipse.swt.widgets.Menu;
17: import org.eclipse.swt.widgets.MenuItem;
18:
19: /**
20: * @since 3.0
21: */
22: public class CloseAllContributionItem extends ContributionItem {
23: private WrappedTabsPartPresentation presentation;
24:
25: private SelectionAdapter selectionListener = new SelectionAdapter() {
26: public void widgetSelected(SelectionEvent e) {
27: presentation.close(presentation.getParts());
28: }
29: };
30:
31: public CloseAllContributionItem(
32: WrappedTabsPartPresentation presentation) {
33: this .presentation = presentation;
34: }
35:
36: public void dispose() {
37: super .dispose();
38: presentation = null;
39: selectionListener = null;
40: }
41:
42: public void fill(Menu menu, int index) {
43: if (presentation.getParts().length > 1) {
44: MenuItem item = new MenuItem(menu, SWT.NONE, index);
45: item.setText("Close all");
46: item.addSelectionListener(selectionListener);
47: }
48: }
49:
50: public boolean isDynamic() {
51: // Returning true here ensures that the fill(...) method will be called whenever
52: // the context menu opens
53: return true;
54: }
55: }
|