KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > framelist > UpAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.views.framelist;
12
13 import org.eclipse.osgi.util.NLS;
14 import org.eclipse.ui.ISharedImages;
15 import org.eclipse.ui.PlatformUI;
16 import org.eclipse.ui.internal.views.framelist.FrameListMessages;
17
18 /**
19  * Generic "Up" action which goes to the parent frame for the current frame.
20  */

21 public class UpAction extends FrameAction {
22
23     /**
24      * Constructs a new action for the specified frame list.
25      *
26      * @param frameList the frame list
27      */

28     public UpAction(FrameList frameList) {
29         super(frameList);
30         setText(FrameListMessages.Up_text);
31         ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
32         setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_UP));
33         setDisabledImageDescriptor(images
34                 .getImageDescriptor(ISharedImages.IMG_TOOL_UP_DISABLED));
35         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
36                 IFrameListHelpContextIds.UP_ACTION);
37         update();
38     }
39
40     Frame getParentFrame(int flags) {
41         return getFrameList().getSource().getFrame(IFrameSource.PARENT_FRAME,
42                 flags);
43     }
44
45     String JavaDoc getToolTipText(Frame parentFrame) {
46         if (parentFrame != null) {
47             String JavaDoc text = parentFrame.getToolTipText();
48             if (text != null && text.length() > 0) {
49                 return NLS.bind(FrameListMessages.Up_toolTipOneArg, text);
50             }
51         }
52         return FrameListMessages.Up_toolTip;
53
54     }
55
56     /**
57      * Calls <code>gotoFrame</code> on the frame list with a frame
58      * representing the parent of the current input.
59      */

60     public void run() {
61         Frame parentFrame = getParentFrame(IFrameSource.FULL_CONTEXT);
62         if (parentFrame != null) {
63             getFrameList().gotoFrame(parentFrame);
64         }
65     }
66
67     /**
68      * Updates this action's enabled state and tool tip text.
69      * This action is enabled only when there is a parent frame for the current
70      * frame in the frame list.
71      * The tool tip text is "Up to " plus the tool tip text for the parent
72      * frame.
73      */

74     public void update() {
75         super.update();
76         Frame parentFrame = getParentFrame(0);
77         setEnabled(parentFrame != null);
78         setToolTipText(getToolTipText(parentFrame));
79     }
80 }
81
Popular Tags