Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d11067e20b40f96cffc9979305b5e39dbe8bbb50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.examples.pessimistic.ui;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.team.examples.pessimistic.IPessimisticFilesystemConstants;
import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * A preference page for the <code>PessimisticFilesystemProviderPlugin</code>.
 */
public class PessimisticPreferencesPage
	extends PreferencePage
	implements IWorkbenchPreferencePage {

	/*
	 * Widget for the files are edited preference
	 */
	private Combo filesAreEditedCombo;
	/*
	 * Widget for the files are edited without a context preference
	 */
	private Combo filesAreEditedNoPromptCombo;	
	/*
	 * Widget for the files are saved preference
	 */
	private Combo filesAreSavedCombo;
	/*
	 * Widget for the files are edited preference
	 */
	private Combo addToControlCombo;
	/*
	 * Widget for the change file contents preference
	 */
	private Button changeFileContents;
	/*
	 * Widget for the fail validate edit preference
	 */
	private Button failValidateEdit;
	
	/*
	 * Option strings for the files are edited preference.
	 */
	private static final String[] EDIT_OPTION_STRINGS= 
		new String[] { 
			"Prompt to checkout", 
			"Checkout", 
			"Do nothing", };
	/*
	 * Option values for the files are edited preference.
	 */
	private static final int[] EDIT_OPTION_KEYS=
		new int[] { 
			IPessimisticFilesystemConstants.OPTION_PROMPT,
			IPessimisticFilesystemConstants.OPTION_AUTOMATIC,
			IPessimisticFilesystemConstants.OPTION_DO_NOTHING, };
			
	/*
	 * Option strings for the files are edited without a context preference.
	 */
	private static final String[] EDIT_NO_PROMPT_OPTION_STRINGS= 
		new String[] { 
			"Checkout", 
			"Do nothing", };		

	/*
	 * Option strings for the files are saved preference.
	 */
	private static final String[] SAVE_OPTION_STRINGS= 
		new String[] { 
			"Checkout", 
			"Do nothing", };
	/*
	 * Option values for the files are saved preference.
	 */
	private static final int[] SAVE_OPTION_KEYS=
		new int[] { 
			IPessimisticFilesystemConstants.OPTION_AUTOMATIC,
			IPessimisticFilesystemConstants.OPTION_DO_NOTHING, };
			
	/*
	 * Option strings for the add to control preference.
	 */
	private static final String[] ADD_TO_CONTROL_OPTION_STRINGS=
		new String[] {
			"Prompt to add to control",
			"Add to control",
			"Do nothing", };
	/*
	 * Option values for the add to control preference.
	 */
	private static final int[] ADD_TO_CONTROL_OPTION_KEYS=
		new int[] { 
			IPessimisticFilesystemConstants.OPTION_PROMPT,
			IPessimisticFilesystemConstants.OPTION_AUTOMATIC,
			IPessimisticFilesystemConstants.OPTION_DO_NOTHING, };		
	

	@Override
	protected IPreferenceStore doGetPreferenceStore() {
		return PessimisticFilesystemProviderPlugin.getInstance().getPreferenceStore();
	}


	/*
	 * Sets the layout to be a grid layout with the given number of columns.
	 */
	protected void setDefaultLayout(Composite group, int columns) {
		GridLayout layout = new GridLayout();
		group.setLayout(layout);

		GridData data =
			new GridData(
				GridData.VERTICAL_ALIGN_FILL
					| GridData.HORIZONTAL_ALIGN_FILL
					| GridData.GRAB_HORIZONTAL);

		layout.numColumns = columns;
		group.setLayoutData(data);
	}

	@Override
	protected Control createContents(Composite parent) {
		Composite composite = new Composite(parent, SWT.NULL);
		setDefaultLayout(composite, 1);

		Composite options = new Composite(composite, SWT.NULL);
		setDefaultLayout(options, 2);

		Label label = new Label(options, SWT.NONE);
		label.setText("File handling:");
		GridData gridData = new GridData();
		gridData.horizontalSpan = 2;
		gridData.horizontalAlignment = GridData.FILL;
		label.setLayoutData(gridData);

		label = new Label(options, SWT.NONE);
		label.setText("When checked in files are edited:");
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		label.setLayoutData(gridData);		

		filesAreEditedCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY);
		gridData = new GridData();
		gridData.horizontalSpan= 1;
		gridData.horizontalAlignment = GridData.FILL;
		filesAreEditedCombo.setLayoutData(gridData);	
		filesAreEditedCombo.setItems(EDIT_OPTION_STRINGS);

		label = new Label(options, SWT.NONE);
		label.setText("When checked in files are edited programmatically:");
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		label.setLayoutData(gridData);		

		filesAreEditedNoPromptCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY);
		gridData = new GridData();
		gridData.horizontalSpan= 1;
		gridData.horizontalAlignment = GridData.FILL;
		filesAreEditedNoPromptCombo.setLayoutData(gridData);	
		filesAreEditedNoPromptCombo.setItems(EDIT_NO_PROMPT_OPTION_STRINGS);
		
		label = new Label(options, SWT.NONE);
		label.setText("When checked in files are saved:");
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		label.setLayoutData(gridData);
		
		filesAreSavedCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY);
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		filesAreSavedCombo.setLayoutData(gridData);
		filesAreSavedCombo.setItems(SAVE_OPTION_STRINGS);

		label = new Label(options, SWT.NONE);
		label.setText("When files are created:");
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		label.setLayoutData(gridData);
		
		addToControlCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY);
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		addToControlCombo.setLayoutData(gridData);
		addToControlCombo.setItems(ADD_TO_CONTROL_OPTION_STRINGS);

		options = new Composite(composite, SWT.NULL);
		setDefaultLayout(options, 1);

		label = new Label(options, SWT.NONE);
		label.setText("Error cases:");
		gridData = new GridData();
		gridData.horizontalSpan = 1;
		gridData.horizontalAlignment = GridData.FILL;
		label.setLayoutData(gridData);

		failValidateEdit= new Button(options, SWT.CHECK | SWT.LEFT);
		failValidateEdit.setText("Fail validate edit");
		gridData = new GridData();
		failValidateEdit.setLayoutData(gridData);

		changeFileContents= new Button(options, SWT.CHECK | SWT.LEFT);
		changeFileContents.setText("Touch files during validate edit");
		gridData = new GridData();
		changeFileContents.setLayoutData(gridData);

		updatePreferencePage();

		return composite;
	}

	@Override
	public void init(IWorkbench workbench) {
		// do nothing
	}

	@Override
	protected void performDefaults() {
		IPreferenceStore store = getPreferenceStore();

		filesAreEditedCombo.select(
			getEditOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED)));
		filesAreEditedNoPromptCombo.select(
			getEditNoPromptOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT)));
		filesAreSavedCombo.select(
			getSaveOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED)));
		addToControlCombo.select(
			getAddToControlOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL)));			
		failValidateEdit.setSelection(
			store.getDefaultBoolean(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT));
		changeFileContents.setSelection(
			store.getDefaultBoolean(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT));
		super.performDefaults();
	}

	@Override
	public boolean performOk() {
		IPreferenceStore store = getPreferenceStore();

		int selectionIndex = filesAreEditedCombo.getSelectionIndex();
		if (selectionIndex != -1)
			store.setValue(
				IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED,
				EDIT_OPTION_KEYS[selectionIndex]);
		selectionIndex = filesAreEditedNoPromptCombo.getSelectionIndex();
		if (selectionIndex != -1)
			store.setValue(
				IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT,
				SAVE_OPTION_KEYS[selectionIndex]);
		selectionIndex = filesAreSavedCombo.getSelectionIndex();
		if (selectionIndex != -1)
			store.setValue(
				IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED,
				SAVE_OPTION_KEYS[selectionIndex]);
		selectionIndex = addToControlCombo.getSelectionIndex();
		if (selectionIndex != -1)
			store.setValue(
				IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL,
				ADD_TO_CONTROL_OPTION_KEYS[selectionIndex]);
		store.setValue(
			IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT, 
			failValidateEdit.getSelection());		
		store.setValue(
			IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT,
			changeFileContents.getSelection());
		return true;
	}

	/*
	 * Sets the widgets to have the state stored in the preferences.
	 */
	protected void updatePreferencePage() {
		IPreferenceStore store = getPreferenceStore();

		filesAreEditedCombo.select(
			getEditOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED)));
		filesAreEditedNoPromptCombo.select(
			getEditNoPromptOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT)));			
		filesAreSavedCombo.select(
			getSaveOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED)));
		addToControlCombo.select(
			getAddToControlOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL)));
		failValidateEdit.setSelection(
			store.getBoolean(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT));
		changeFileContents.setSelection(
			store.getBoolean(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT));
	}
	
	/*
	 * Answers the index of the given key.
	 */	
	protected int getEditOptionIndex(int key) {
		for(int i= 0; i < EDIT_OPTION_KEYS.length; i++) {
			if (EDIT_OPTION_KEYS[i] == key)
				return i;
		}
		return -1;
	}
	
	/*
	 * Answers the index of the given key.
	 */	
	protected int getSaveOptionIndex(int key) {
		for(int i= 0; i < SAVE_OPTION_KEYS.length; i++) {
			if (SAVE_OPTION_KEYS[i] == key)
				return i;
		}
		return -1;
	}
	
	/*
	 * Answers the index of the given key.
	 */	
	protected int getEditNoPromptOptionIndex(int key) {
		for(int i= 0; i < SAVE_OPTION_KEYS.length; i++) {
			if (SAVE_OPTION_KEYS[i] == key)
				return i;
		}
		return -1;
	}			
	
	/*
	 * Answers the index of the given key.
	 */	
	protected int getAddToControlOptionIndex(int key) {
		for(int i= 0; i < ADD_TO_CONTROL_OPTION_KEYS.length; i++) {
			if (ADD_TO_CONTROL_OPTION_KEYS[i] == key)
				return i;
		}
		return -1;
	}

}

Back to the top