01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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.views.framelist;
11:
12: import org.eclipse.osgi.util.NLS;
13: import org.eclipse.ui.ISharedImages;
14: import org.eclipse.ui.PlatformUI;
15: import org.eclipse.ui.internal.views.framelist.FrameListMessages;
16:
17: /**
18: * Generic "Up" action which goes to the parent frame for the current frame.
19: */
20: public class UpAction extends FrameAction {
21:
22: /**
23: * Constructs a new action for the specified frame list.
24: *
25: * @param frameList the frame list
26: */
27: public UpAction(FrameList frameList) {
28: super (frameList);
29: setText(FrameListMessages.Up_text);
30: ISharedImages images = PlatformUI.getWorkbench()
31: .getSharedImages();
32: setImageDescriptor(images
33: .getImageDescriptor(ISharedImages.IMG_TOOL_UP));
34: setDisabledImageDescriptor(images
35: .getImageDescriptor(ISharedImages.IMG_TOOL_UP_DISABLED));
36: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
37: IFrameListHelpContextIds.UP_ACTION);
38: update();
39: }
40:
41: Frame getParentFrame(int flags) {
42: return getFrameList().getSource().getFrame(
43: IFrameSource.PARENT_FRAME, flags);
44: }
45:
46: String getToolTipText(Frame parentFrame) {
47: if (parentFrame != null) {
48: String text = parentFrame.getToolTipText();
49: if (text != null && text.length() > 0) {
50: return NLS.bind(FrameListMessages.Up_toolTipOneArg,
51: text);
52: }
53: }
54: return FrameListMessages.Up_toolTip;
55:
56: }
57:
58: /**
59: * Calls <code>gotoFrame</code> on the frame list with a frame
60: * representing the parent of the current input.
61: */
62: public void run() {
63: Frame parentFrame = getParentFrame(IFrameSource.FULL_CONTEXT);
64: if (parentFrame != null) {
65: getFrameList().gotoFrame(parentFrame);
66: }
67: }
68:
69: /**
70: * Updates this action's enabled state and tool tip text.
71: * This action is enabled only when there is a parent frame for the current
72: * frame in the frame list.
73: * The tool tip text is "Up to " plus the tool tip text for the parent
74: * frame.
75: */
76: public void update() {
77: super .update();
78: Frame parentFrame = getParentFrame(0);
79: setEnabled(parentFrame != null);
80: setToolTipText(getToolTipText(parentFrame));
81: }
82: }
|