01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.presentations;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.ui.internal.WorkbenchMessages;
14: import org.eclipse.ui.presentations.IPresentablePart;
15: import org.eclipse.ui.presentations.IStackPresentationSite;
16:
17: /**
18: * This convenience class provides a "close" system menu item that closes
19: * the currently selected pane in a presentation. Presentations can use
20: * this to add a close item to their system menu.
21: *
22: * @since 3.0
23: */
24: public final class SystemMenuClose extends Action implements
25: ISelfUpdatingAction {
26:
27: private IStackPresentationSite site;
28: private IPresentablePart part;
29:
30: public SystemMenuClose(IStackPresentationSite site) {
31: this .site = site;
32: setText(WorkbenchMessages.PartPane_close);
33: }
34:
35: public void dispose() {
36: site = null;
37: }
38:
39: public void run() {
40: if (part != null) {
41: site.close(new IPresentablePart[] { part });
42: }
43: }
44:
45: public void setTarget(IPresentablePart presentablePart) {
46: this .part = presentablePart;
47: setEnabled(presentablePart != null
48: && site.isCloseable(presentablePart));
49: }
50:
51: /* (non-Javadoc)
52: * @see org.eclipse.ui.internal.presentations.ISelfUpdatingAction#update()
53: */
54: public void update() {
55: setTarget(site.getSelectedPart());
56: }
57:
58: /* (non-Javadoc)
59: * @see org.eclipse.ui.internal.presentations.ISelfUpdatingAction#shouldBeVisible()
60: */
61: public boolean shouldBeVisible() {
62: return true;
63: }
64: }
|