1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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.jdt.internal.debug.ui.actions;
15 
16 
17 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
19 import org.eclipse.jface.dialogs.IDialogSettings;
20 
21 /**
22  * Abstract action that opens a dialog. Contains a prefix for dialog preference
23  * settings.
24  */
25 public abstract class OpenDialogAction extends RuntimeClasspathAction {
26 
27 	/**
28 	 * Attribute name for the last path used to open a file/directory chooser
29 	 * dialog.
30 	 */
31 	protected static final String LAST_PATH_SETTING = "LAST_PATH_SETTING"; //$NON-NLS-1$
32 
33 	/**
34 	 * Dialog settings prefix/qualifier
35 	 */
36 	private String fPrefix = null;
37 
38 	/**
39 	 * Constructs an action that opens a dialog.
40 	 */
OpenDialogAction(String label, IClasspathViewer viewer, String dialogSettingsPrefix)41 	public OpenDialogAction(String label, IClasspathViewer viewer, String dialogSettingsPrefix) {
42 		super(label, viewer);
43 		fPrefix = dialogSettingsPrefix;
44 	}
45 
46 	/**
47 	 * Returns the prefix of the identifier used to store dialog settings for
48 	 * this action.
49 	 */
getDialogSettingsPrefix()50 	protected String getDialogSettingsPrefix() {
51 		return fPrefix;
52 	}
53 
54 	/**
55 	 * Returns the value of the dialog setting, associated with the given
56 	 * settingName, resolved by the dialog setting prefix associated with this
57 	 * action.
58 	 *
59 	 * @param settingName unqualified setting name
60 	 * @return value or <code>null</code> if none
61 	 */
getDialogSetting(String settingName)62 	protected String getDialogSetting(String settingName) {
63 		return getDialogSettings().get(getDialogSettingsPrefix() + "." + settingName); //$NON-NLS-1$
64 	}
65 
66 	/**
67 	 * Sets the value of the dialog setting, associated with the given
68 	 * settingName, resolved by the dialog setting prefix associated with this
69 	 * action.
70 	 *
71 	 * @param settingName unqualified setting name
72 	 * @return value or <code>null</code> if none
73 	 */
setDialogSetting(String settingName, String value)74 	protected void setDialogSetting(String settingName, String value) {
75 		getDialogSettings().put(getDialogSettingsPrefix() + "." + settingName, value); //$NON-NLS-1$
76 	}
77 
78 	/**
79 	 * Returns this plug-in's dialog settings.
80 	 *
81 	 * @return IDialogSettings
82 	 */
getDialogSettings()83 	protected IDialogSettings getDialogSettings() {
84 		IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings();
85 		return settings;
86 	}
87 
88 	@Override
getActionType()89 	protected int getActionType() {
90 		return ADD;
91 	}
92 }
93