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: import org.eclipse.ui.presentations.IPresentablePart;
19:
20: /**
21: * @since 3.0
22: */
23: public class CloseContributionItem extends ContributionItem {
24: private WrappedTabsPartPresentation presentation;
25:
26: private SelectionAdapter selectionListener = new SelectionAdapter() {
27: public void widgetSelected(SelectionEvent e) {
28: presentation.close(new IPresentablePart[] { presentation
29: .getCurrent() });
30: }
31: };
32:
33: public CloseContributionItem(
34: WrappedTabsPartPresentation presentation) {
35: this .presentation = presentation;
36: }
37:
38: public void dispose() {
39: super .dispose();
40: presentation = null;
41: selectionListener = null;
42: }
43:
44: public void fill(Menu menu, int index) {
45: MenuItem item = new MenuItem(menu, SWT.NONE, index);
46: item.setText("Close");
47: item.addSelectionListener(selectionListener);
48:
49: IPresentablePart current = presentation.getCurrent();
50: item.setEnabled(current != null);
51: }
52:
53: public boolean isDynamic() {
54: return true;
55: }
56: }
|