01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 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 java.util.Arrays;
13: import java.util.LinkedList;
14: import java.util.List;
15:
16: import org.eclipse.jface.action.Action;
17: import org.eclipse.ui.internal.WorkbenchMessages;
18: import org.eclipse.ui.presentations.IPresentablePart;
19: import org.eclipse.ui.presentations.IStackPresentationSite;
20:
21: public class SystemMenuCloseOthers extends Action implements
22: ISelfUpdatingAction {
23:
24: private IStackPresentationSite stackPresentation;
25: private IPresentablePart current;
26:
27: public SystemMenuCloseOthers(
28: 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 others = new LinkedList();
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: }
|