Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 54347 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/ide/messages.properties (+1 lines)
Lines 1190-1195 Link Here
1190
PathVariableSelectionDialog.ExtensionDialog.description = Choose extension to {0}
1190
PathVariableSelectionDialog.ExtensionDialog.description = Choose extension to {0}
1191
1191
1192
MessageDialogWithToggle.defaultToggleMessage = &Do not show this message again
1192
MessageDialogWithToggle.defaultToggleMessage = &Do not show this message again
1193
UserPreferencePromptDialog.defaultToggleMessage = &Do not show this message again
1193
1194
1194
# ==============================================================================
1195
# ==============================================================================
1195
# Editor Framework
1196
# Editor Framework
(-)src/org/eclipse/ui/internal/ide/dialogs/UserPreferencePromptDialog.java (+351 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.ide.dialogs;
13
14
import org.eclipse.jface.dialogs.IDialogConstants;
15
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionAdapter;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
27
28
29
/**
30
 * A message dialog which also allows the user to adjust a toggle setting.
31
 * 
32
 * This is typically used to allow the user to indicate whether the dialog
33
 * should be shown in the future.
34
 */
35
public class UserPreferencePromptDialog extends MessageDialog {
36
	public static final String ALWAYS = "always"; //$NON-NLS-1$
37
	public static final String NEVER = "never"; //$NON-NLS-1$
38
	public static final String PROMPT = "prompt"; //$NON-NLS-1$
39
	public static final String OK = "ok"; //$NON-NLS-1$
40
	
41
	/**
42
	 * The message displayed to the user, with the toggle button
43
	 */
44
	protected String toggleMessage = null;
45
	protected boolean toggleState = false;
46
	protected Button toggleButton = null;
47
	
48
	/**
49
	 * The preference store which will be affected by the toggle button.
50
	 */
51
	protected IPreferenceStore prefStore = null;
52
	
53
	/**
54
	 * The preference store key that will be used to store the value.
55
	 */
56
	protected String prefKey = null; 
57
	
58
	/**
59
	 * Creates a message dialog with a toggle.
60
	 * See the superclass constructor for info on the other parameters.
61
	 * 
62
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
63
	 *   for the default message ("Do not show this message again").
64
	 * @param toggleState the initial state for the toggle 
65
	 * 
66
	 */
67
	public UserPreferencePromptDialog(Shell parentShell, String dialogTitle, Image image, String message, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, String toggleMessage, boolean toggleState) {
68
		super(parentShell, dialogTitle, image, message, dialogImageType, dialogButtonLabels, defaultIndex);
69
		this.toggleMessage = toggleMessage;
70
		this.toggleState = toggleState; 
71
	}
72
	
73
	/**
74
	 * Returns the toggle state.  This can be called even after the dialog
75
	 * is closed.
76
	 * 
77
	 * @return <code>true</code> if the toggle button is checked, 
78
	 *   <code>false</code> if not
79
	 */
80
	public boolean getToggleState() {
81
		return toggleState;
82
	}
83
84
	/**
85
	 * @param prefKey The prefKey to set.
86
	 */
87
	public void setPrefKey(String prefKey) {
88
		this.prefKey = prefKey;
89
	}
90
	/**
91
	 * @param prefStore The prefStore to set.
92
	 */
93
	public void setPrefStore(IPreferenceStore prefStore) {
94
		this.prefStore = prefStore;
95
	}
96
	
97
	/* (non-Javadoc)
98
	 * Method declared in Dialog.
99
	 */
100
	protected Control createDialogArea(Composite parent) {
101
		Composite dialogArea = (Composite) super.createDialogArea(parent);
102
		toggleButton = createToggleButton(dialogArea);
103
		return dialogArea;
104
	}
105
	
106
	/**
107
	 * Creates a toggle button with the toggle message and state.
108
	 */
109
	protected Button createToggleButton(Composite parent) {
110
		final Button button= new Button(parent, SWT.CHECK | SWT.LEFT);
111
		String text = toggleMessage; 
112
		if (text == null) {
113
			text = IDEWorkbenchMessages.getString("UserPreferencePromptDialog.defaultToggleMessage"); //$NON-NLS-1$
114
		}
115
		button.setText(text);
116
		button.setSelection(toggleState);
117
		
118
		GridData data = new GridData(SWT.NONE);
119
		data.horizontalSpan= 2;
120
		data.horizontalAlignment= GridData.CENTER;
121
		button.setLayoutData(data);
122
		button.setFont(parent.getFont());
123
		
124
		button.addSelectionListener(new SelectionAdapter() {
125
			public void widgetSelected(SelectionEvent e) {
126
				toggleState = button.getSelection();
127
			}
128
			
129
		});
130
		return button;
131
	}
132
	
133
	/**
134
	 * Returns the toggle button.
135
	 * 
136
	 * @return the toggle button
137
	 */
138
	protected Button getToggleButton() {
139
		return toggleButton;
140
	}
141
	
142
	
143
	
144
	/* (non-Javadoc)
145
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
146
	 */
147
	protected void buttonPressed(int buttonId) {
148
		super.buttonPressed(buttonId);
149
		
150
		if (buttonId != IDialogConstants.CANCEL_ID && toggleState && prefStore != null && prefKey != null) {
151
			if (buttonId == IDialogConstants.YES_ID) {
152
				prefStore.setValue(prefKey, ALWAYS);
153
			} else if (buttonId == IDialogConstants.NO_ID) {
154
				prefStore.setValue(prefKey, NEVER);
155
			} else if (buttonId == IDialogConstants.OK_ID) {
156
				prefStore.setValue(prefKey, OK);
157
			}
158
		}
159
	}
160
	
161
	/**
162
	 * Convenience method to open a simple confirm (OK/Cancel) dialog.
163
	 *
164
	 * @param parent the parent shell of the dialog, or <code>null</code> if none
165
	 * @param title the dialog's title, or <code>null</code> if none
166
	 * @param message the message
167
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
168
	 *   for the default message ("Don't show me this message again").
169
	 * @param toggleState the initial state for the toggle 
170
	 * @param store the IPreference store in which the user's preference should be persisted
171
	 * @param key the key to use when persisting the user's preference
172
	 * @return the dialog, after being closed by the user, which the client can
173
	 * 		only call <code>getReturnCode()</code> or <code>getToggleState()</code>
174
	 */
175
	public static UserPreferencePromptDialog openOkCancelConfirm(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) {
176
		UserPreferencePromptDialog dialog = new UserPreferencePromptDialog(
177
				parent,
178
				title,
179
				null,	// accept the default window icon
180
				message,
181
				QUESTION,
182
				new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL},
183
				0,		// OK is the default
184
				toggleMessage,
185
				toggleState);
186
		dialog.prefStore = store;
187
		dialog.prefKey = key;
188
		dialog.open();
189
		return dialog;
190
	}
191
192
	
193
	/**
194
	 * Convenience method to open a standard error dialog.
195
	 *
196
	 * @param parent the parent shell of the dialog, or <code>null</code> if none
197
	 * @param title the dialog's title, or <code>null</code> if none
198
	 * @param message the message
199
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
200
	 *   for the default message ("Don't show me this message again").
201
	 * @param toggleState the initial state for the toggle 
202
	 * @param store the IPreference store in which the user's preference should be persisted
203
	 * @param key the key to use when persisting the user's preference
204
 	 * @return the dialog, after being closed by the user, which the client can
205
	 * 		only call <code>getReturnCode()</code> or <code>getToggleState()</code>
206
	 */
207
	public static UserPreferencePromptDialog openError(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) {
208
		UserPreferencePromptDialog dialog = new UserPreferencePromptDialog(
209
				parent,
210
				title,
211
				null,	// accept the default window icon
212
				message,
213
				ERROR,
214
				new String[] {IDialogConstants.OK_LABEL},
215
				0,		// ok is the default
216
				toggleMessage,
217
				toggleState);
218
		dialog.prefStore = store;
219
		dialog.prefKey = key;
220
		dialog.open();
221
		return dialog;
222
	}
223
	
224
	/**
225
	 * Convenience method to open a standard information dialog.
226
	 *
227
	 * @param parent the parent shell of the dialog, or <code>null</code> if none
228
	 * @param title the dialog's title, or <code>null</code> if none
229
	 * @param message the message
230
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
231
	 *   for the default message ("Don't show me this message again").
232
	 * @param toggleState the initial state for the toggle 
233
 	 * @param store the IPreference store in which the user's preference should be persisted
234
	 * @param key the key to use when persisting the user's preference
235
236
	 * @return the dialog, after being closed by the user, which the client can
237
	 * 		only call <code>getReturnCode()</code> or <code>getToggleState()</code>
238
	 */
239
	public static UserPreferencePromptDialog openInformation(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) {
240
		UserPreferencePromptDialog dialog = new UserPreferencePromptDialog(
241
				parent, 
242
				title, 
243
				null, // accept the default window icon
244
				message, 
245
				INFORMATION, 
246
				new String[] { IDialogConstants.OK_LABEL }, 
247
				0,		// ok is the default 
248
				toggleMessage,
249
				toggleState);
250
		dialog.prefStore = store;
251
		dialog.prefKey = key;
252
		dialog.open();
253
		return dialog;
254
	}
255
	
256
	/**
257
	 * Convenience method to open a simple Yes/No question dialog.
258
	 *
259
	 * @param parent the parent shell of the dialog, or <code>null</code> if none
260
	 * @param title the dialog's title, or <code>null</code> if none
261
	 * @param message the message
262
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
263
	 *   for the default message ("Don't show me this message again").
264
	 * @param toggleState the initial state for the toggle
265
 	 * @param store the IPreference store in which the user's preference should be persisted
266
	 * @param key the key to use when persisting the user's preference
267
 
268
	 * @return the dialog, after being closed by the user, which the client can
269
	 * 		only call <code>getReturnCode()</code> or <code>getToggleState()</code>
270
	 */
271
	public static UserPreferencePromptDialog openYesNoQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) {
272
		UserPreferencePromptDialog dialog = new UserPreferencePromptDialog(
273
				parent,
274
				title,
275
				null,	// accept the default window icon
276
				message,
277
				QUESTION,
278
				new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL},
279
				0,		// yes is the default
280
				toggleMessage,
281
				toggleState);
282
		dialog.prefStore = store;
283
		dialog.prefKey = key;
284
		dialog.open();
285
		return dialog;
286
	}
287
288
	/**
289
	 * Convenience method to open a simple question Yes/No/Cancel dialog.
290
	 *
291
	 * @param parent the parent shell of the dialog, or <code>null</code> if none
292
	 * @param title the dialog's title, or <code>null</code> if none
293
	 * @param message the message
294
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
295
	 *   for the default message ("Don't show me this message again").
296
	 * @param toggleState the initial state for the toggle 
297
	 * @param store the IPreference store in which the user's preference should be persisted
298
	 * @param key the key to use when persisting the user's preference
299
	 * @return the dialog, after being closed by the user, which the client can
300
	 * 		only call <code>getReturnCode()</code> or <code>getToggleState()</code>
301
	 */
302
	public static UserPreferencePromptDialog openYesNoCancelQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) {
303
		UserPreferencePromptDialog dialog = new UserPreferencePromptDialog(
304
				parent,
305
				title,
306
				null,	// accept the default window icon
307
				message,
308
				QUESTION,
309
				new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL},
310
				0,		// YES is the default
311
				toggleMessage,
312
				toggleState);
313
		dialog.prefStore = store;
314
		dialog.prefKey = key;
315
		dialog.open();
316
		return dialog;
317
	}
318
	
319
	/**
320
	 * Convenience method to open a standard warning dialog.
321
	 *
322
	 * @param parent the parent shell of the dialog, or <code>null</code> if none
323
	 * @param title the dialog's title, or <code>null</code> if none
324
	 * @param message the message
325
	 * @param toggleMessage the message for the toggle control, or <code>null</code> 
326
	 *   for the default message ("Don't show me this message again").
327
	 * @param toggleState the initial state for the toggle
328
 	 * @param store the IPreference store in which the user's preference should be persisted
329
	 * @param key the key to use when persisting the user's preference	  
330
	 * @return the dialog, after being closed by the user, which the client can
331
	 * 		only call <code>getReturnCode()</code> or <code>getToggleState()</code>
332
	 */
333
	public static UserPreferencePromptDialog openWarning(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) {
334
		UserPreferencePromptDialog dialog = new UserPreferencePromptDialog(
335
				parent,
336
				title,
337
				null,	// accept the default window icon
338
				message,
339
				WARNING,
340
				new String[] {IDialogConstants.OK_LABEL},
341
				0,		// ok is the default
342
				toggleMessage,
343
				toggleState);
344
		dialog.open();
345
		dialog.prefStore = store;
346
		dialog.prefKey = key;
347
		return dialog;
348
	}
349
	
350
351
}

Return to bug 54347