KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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 java.util.Arrays JavaDoc;
14 import java.util.LinkedList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.ui.internal.WorkbenchMessages;
19 import org.eclipse.ui.presentations.IPresentablePart;
20 import org.eclipse.ui.presentations.IStackPresentationSite;
21
22 public class SystemMenuCloseOthers extends Action implements
23         ISelfUpdatingAction {
24
25     private IStackPresentationSite stackPresentation;
26     private IPresentablePart current;
27
28     public SystemMenuCloseOthers(IStackPresentationSite stackPresentation) {
29         this.stackPresentation = stackPresentation;
30         setText(WorkbenchMessages.PartPane_closeOthers);
31     }
32
33     public void dispose() {
34         stackPresentation = null;
35     }
36
37     public void run() {
38         List JavaDoc others = new LinkedList JavaDoc();
39         others.addAll(Arrays.asList(stackPresentation.getPartList()));
40         others.remove(current);
41         stackPresentation.close((IPresentablePart[]) others
42                 .toArray(new IPresentablePart[others.size()]));
43     }
44
45     public void update() {
46         setTarget(stackPresentation.getSelectedPart());
47     }
48
49     public boolean shouldBeVisible() {
50         return true;
51     }
52
53     /**
54      * @param currentSelection
55      * @since 3.1
56      */

57     public void setTarget(IPresentablePart current) {
58         this.current = current;
59         setEnabled(current != null &&
60                 stackPresentation.getPartList().length > 1);
61     }
62 }
63
Popular Tags