KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.jface.action.Action;
14 import org.eclipse.ui.internal.ViewPane;
15 import org.eclipse.ui.internal.WorkbenchMessages;
16 import org.eclipse.ui.internal.WorkbenchPage;
17 import org.eclipse.ui.presentations.IPresentablePart;
18 import org.eclipse.ui.presentations.IStackPresentationSite;
19
20 public class SystemMenuDetach extends Action implements ISelfUpdatingAction {
21
22     private ViewPane viewPane;
23     private IStackPresentationSite site;
24     private WorkbenchPage page;
25
26     public SystemMenuDetach(IStackPresentationSite site) {
27         this.site = site;
28         setText(WorkbenchMessages.PartPane_detach);
29         update();
30     }
31     
32     public void update() {
33         IPresentablePart presentablePart = site.getSelectedPart();
34         setEnabled(presentablePart != null && site.isPartMoveable(presentablePart));
35         if(viewPane != null){
36             setChecked(!viewPane.isDocked());
37             page = viewPane.getPage();
38         }
39     }
40     
41     public boolean shouldBeVisible() {
42         if(page != null) {
43             return page.getActivePerspective().getPresentation().canDetach();
44         }
45         return false;
46     }
47     
48     public void dispose() {
49         site = null;
50     }
51
52     public void setPane(ViewPane current){
53         viewPane = current;
54         update();
55     }
56         
57     public void run() {
58         if(site != null){
59             if(!isChecked()){
60                 viewPane.doDetach();
61             }
62             else{
63                 viewPane.doAttach();
64             }
65         }
66     }
67
68 }
69
Popular Tags