KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > SystemMenuClose


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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.presentations;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.ui.internal.WorkbenchMessages;
15 import org.eclipse.ui.presentations.IPresentablePart;
16 import org.eclipse.ui.presentations.IStackPresentationSite;
17
18 /**
19  * This convenience class provides a "close" system menu item that closes
20  * the currently selected pane in a presentation. Presentations can use
21  * this to add a close item to their system menu.
22  *
23  * @since 3.0
24  */

25 public final class SystemMenuClose extends Action implements 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 && site.isCloseable(presentablePart));
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.internal.presentations.ISelfUpdatingAction#update()
52      */

53     public void update() {
54         setTarget(site.getSelectedPart());
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.ui.internal.presentations.ISelfUpdatingAction#shouldBeVisible()
59      */

60     public boolean shouldBeVisible() {
61         return true;
62     }
63 }
64
Popular Tags