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