1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ui.internal.navigator.framelist;
15 
16 import org.eclipse.osgi.util.NLS;
17 import org.eclipse.ui.ISharedImages;
18 import org.eclipse.ui.PlatformUI;
19 
20 /**
21  * Generic "Back" action which goes back one frame,
22  * @since 3.4
23  */
24 public class BackAction extends FrameAction {
25 
26 	private static final String ID = "org.eclipse.ui.framelist.back"; //$NON-NLS-1$
27 
28 	/**
29 	 * Constructs a new action for the specified frame list.
30 	 *
31 	 * @param frameList the frame list
32 	 */
BackAction(FrameList frameList)33 	public BackAction(FrameList frameList) {
34 		super(frameList);
35 		setId(ID);
36 		setText(FrameListMessages.Back_text);
37 		ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
38 		setImageDescriptor(images
39 				.getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
40 		setDisabledImageDescriptor(images
41 				.getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
42 		PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
43 				IFrameListHelpContextIds.BACK_ACTION);
44 		update();
45 	}
46 
getPreviousFrame()47 	private Frame getPreviousFrame() {
48 		FrameList list = getFrameList();
49 		return list.getFrame(list.getCurrentIndex() - 1);
50 	}
51 
getToolTipText(Frame previousFrame)52 	private String getToolTipText(Frame previousFrame) {
53 		if (previousFrame != null) {
54 			String text = previousFrame.getToolTipText();
55 			if (text != null && text.length() > 0) {
56 				return NLS.bind(FrameListMessages.Back_toolTipOneArg, text);
57 			}
58 		}
59 		return FrameListMessages.Back_toolTip;
60 	}
61 
62 	/**
63 	 * Calls <code>back()</code> on the frame list.
64 	 */
65 	@Override
run()66 	public void run() {
67 		getFrameList().back();
68 	}
69 
70 	/**
71 	 * Updates this action's enabled state and tool tip text.
72 	 * This action is enabled only when there is a previous frame in the frame list.
73 	 * The tool tip text is "Back to " plus the tool tip text for the previous frame.
74 	 */
75 	@Override
update()76 	public void update() {
77 		super.update();
78 		Frame previousFrame = getPreviousFrame();
79 		setEnabled(previousFrame != null);
80 		setToolTipText(getToolTipText(previousFrame));
81 	}
82 
83 }
84