View | Details | Raw Unified | Return to bug 191938 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ohf/h3et/ui/properties/H3ETPropertyPage.java (-33 / +240 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ohf.h3et.ui.properties;
11
package org.eclipse.ohf.h3et.ui.properties;
12
12
13
import java.util.HashMap;
14
import java.util.Set;
15
13
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Path;
15
import org.eclipse.jface.preference.PreferencePage;
22
import org.eclipse.jface.preference.PreferencePage;
16
import org.eclipse.ohf.h3et.mif.core.repositorycontext.H3ETProjectConfiguration;
23
import org.eclipse.ohf.h3et.mif.core.repositorycontext.H3ETProjectConfiguration;
17
import org.eclipse.ohf.h3et.ui.H3ETMessages;
24
import org.eclipse.ohf.h3et.ui.H3ETMessages;
Lines 22-53 Link Here
22
import org.eclipse.swt.widgets.Button;
29
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.swt.widgets.Event;
25
import org.eclipse.swt.widgets.Label;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.swt.widgets.Listener;
26
import org.eclipse.swt.widgets.Text;
35
import org.eclipse.swt.widgets.Text;
27
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.dialogs.PropertyPage;
37
import org.eclipse.ui.dialogs.PropertyPage;
38
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
29
39
30
/**
40
/**
31
 * Workbench property page for H3ET projects
41
 * Workbench property page for H3ET projects
42
 * 
32
 * @author bbanfai
43
 * @author bbanfai
33
 */
44
 */
34
public class H3ETPropertyPage extends PropertyPage {
45
public class H3ETPropertyPage extends PropertyPage
46
{
35
47
36
	private static final int TEXT_FIELD_WIDTH = 50;
48
	private static final int TEXT_FIELD_WIDTH = 50;
37
49
38
	private Text modelPath;
50
	private Text modelPath;
51
39
	private Text vocabPath;
52
	private Text vocabPath;
53
40
	private Text dataTypePath;
54
	private Text dataTypePath;
55
41
	private Text fragmentPath;
56
	private Text fragmentPath;
57
42
	private Text templateConfigFile;
58
	private Text templateConfigFile;
43
	
59
44
	private Button ukModeCheckBox;
60
	private Button ukModeCheckBox;
45
61
46
	public H3ETPropertyPage() {
62
	// True if all field is valid on the page
63
	private boolean isPageValid = false;
64
65
	/**
66
	 * Modifylistener for modelPath
67
	 */
68
	private Listener modelPathModifyListener = new Listener()
69
	{
70
		public void handleEvent(Event e)
71
		{
72
			isPageValid = validate(modelPath, IResource.FOLDER, false);
73
		}
74
	};
75
76
	/**
77
	 * Modifylistener for modelPath
78
	 */
79
	private Listener vocabPathModifyListener = new Listener()
80
	{
81
		public void handleEvent(Event e)
82
		{
83
			isPageValid = validate(vocabPath, IResource.FOLDER, false);
84
		}
85
	};
86
87
	/**
88
	 * Modifylistener for dataType
89
	 */
90
	private Listener dataTypePathModifyListener = new Listener()
91
	{
92
		public void handleEvent(Event e)
93
		{
94
			isPageValid = validate(dataTypePath, IResource.FOLDER, false);
95
		}
96
	};
97
98
	/**
99
	 * Modifylistener for fragmentPath
100
	 */
101
	private Listener fragmentPathModifyListener = new Listener()
102
	{
103
		public void handleEvent(Event e)
104
		{
105
			isPageValid = validate(fragmentPath, IResource.FOLDER, false);
106
		}
107
	};
108
109
	/**
110
	 * Modifylistener for templateConfigFile
111
	 */
112
	private Listener templateConfigFileModifyListener = new Listener()
113
	{
114
		public void handleEvent(Event e)
115
		{
116
			isPageValid = validate(templateConfigFile, IResource.FOLDER
117
					| IResource.FILE, true);
118
		}
119
	};
120
121
	/**
122
	 * errorMessage contains the occured errors
123
	 */
124
	private HashMap<Object, String> errorMessages = new HashMap<Object, String>();
125
126
	public H3ETPropertyPage()
127
	{
47
		super();
128
		super();
48
	}
129
	}
49
130
50
	private void addFirstSection(Composite parent) {
131
	private void addFirstSection(Composite parent)
132
	{
51
		Composite composite = createDefaultComposite(parent);
133
		Composite composite = createDefaultComposite(parent);
52
134
53
		// Label for path field
135
		// Label for path field
Lines 60-66 Link Here
60
				.toString());
142
				.toString());
61
	}
143
	}
62
144
63
	private void addSeparator(Composite parent) {
145
	private void addSeparator(Composite parent)
146
	{
64
		Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
147
		Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
65
		GridData gridData = new GridData();
148
		GridData gridData = new GridData();
66
		gridData.horizontalAlignment = GridData.FILL;
149
		gridData.horizontalAlignment = GridData.FILL;
Lines 68-74 Link Here
68
		separator.setLayoutData(gridData);
151
		separator.setLayoutData(gridData);
69
	}
152
	}
70
153
71
	private void addSecondSection(Composite parent) {
154
	private void addSecondSection(Composite parent)
155
	{
72
		Composite composite = createDefaultComposite(parent);
156
		Composite composite = createDefaultComposite(parent);
73
157
74
		GridData gd = new GridData();
158
		GridData gd = new GridData();
Lines 97-106 Link Here
97
181
98
		fragmentPath = new Text(composite, SWT.SINGLE | SWT.BORDER);
182
		fragmentPath = new Text(composite, SWT.SINGLE | SWT.BORDER);
99
		fragmentPath.setLayoutData(gd);
183
		fragmentPath.setLayoutData(gd);
100
		
184
101
		Label templateConfigFileLabel = new Label(composite, SWT.NONE);
185
		Label templateConfigFileLabel = new Label(composite, SWT.NONE);
102
		templateConfigFileLabel.setText("Template configuration file:");
186
		templateConfigFileLabel.setText("Template configuration file:");
103
		
187
104
		templateConfigFile = new Text(composite, SWT.SINGLE | SWT.BORDER);
188
		templateConfigFile = new Text(composite, SWT.SINGLE | SWT.BORDER);
105
		templateConfigFile.setLayoutData(gd);
189
		templateConfigFile.setLayoutData(gd);
106
190
Lines 117-126 Link Here
117
	 * @see PreferencePage#createContents(Composite)
201
	 * @see PreferencePage#createContents(Composite)
118
	 */
202
	 */
119
	@Override
203
	@Override
120
	protected Control createContents(Composite parent) {
204
	protected Control createContents(Composite parent)
121
        //Help for the property page
205
	{
122
        PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, H3ETProjectContextConstants.H3ET_PROPERTY_PAGE);
206
		// Help for the property page
123
		
207
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
208
				H3ETProjectContextConstants.H3ET_PROPERTY_PAGE);
209
124
		Composite composite = new Composite(parent, SWT.NONE);
210
		Composite composite = new Composite(parent, SWT.NONE);
125
		GridLayout layout = new GridLayout();
211
		GridLayout layout = new GridLayout();
126
		composite.setLayout(layout);
212
		composite.setLayout(layout);
Lines 134-140 Link Here
134
		return composite;
220
		return composite;
135
	}
221
	}
136
222
137
	private Composite createDefaultComposite(Composite parent) {
223
	private Composite createDefaultComposite(Composite parent)
224
	{
138
		Composite composite = new Composite(parent, SWT.NULL);
225
		Composite composite = new Composite(parent, SWT.NULL);
139
		GridLayout layout = new GridLayout();
226
		GridLayout layout = new GridLayout();
140
		layout.numColumns = 2;
227
		layout.numColumns = 2;
Lines 147-183 Link Here
147
		return composite;
234
		return composite;
148
	}
235
	}
149
236
150
	private void initializeFields() {
237
	private void initializeFields()
238
	{
151
239
152
		IProject project = (IProject) getElement();
240
		IProject project = (IProject) getElement();
153
		H3ETProjectConfiguration projectConfiguration = H3ETProjectConfiguration
241
		H3ETProjectConfiguration projectConfiguration = H3ETProjectConfiguration
154
				.getConfiguration(project);
242
				.getConfiguration(project);
155
243
156
		if (projectConfiguration != null) {
244
		if (projectConfiguration != null)
245
		{
157
			modelPath.setText(projectConfiguration.getModelPath());
246
			modelPath.setText(projectConfiguration.getModelPath());
158
			vocabPath.setText(projectConfiguration.getVocabPath());
247
			vocabPath.setText(projectConfiguration.getVocabPath());
159
			dataTypePath.setText(projectConfiguration.getDataTypePath());
248
			dataTypePath.setText(projectConfiguration.getDataTypePath());
160
			fragmentPath.setText(projectConfiguration.getFragmentPath());
249
			fragmentPath.setText(projectConfiguration.getFragmentPath());
161
			templateConfigFile.setText(projectConfiguration.getTemplateConfigFile());
250
			templateConfigFile.setText(projectConfiguration
251
					.getTemplateConfigFile());
162
			ukModeCheckBox.setSelection(projectConfiguration.isUKMode());
252
			ukModeCheckBox.setSelection(projectConfiguration.isUKMode());
163
		} else {
253
254
			modelPath.addListener(SWT.Modify, modelPathModifyListener);
255
256
			vocabPath.addListener(SWT.Modify, vocabPathModifyListener);
257
258
			dataTypePath.addListener(SWT.Modify, dataTypePathModifyListener);
259
260
			fragmentPath.addListener(SWT.Modify, fragmentPathModifyListener);
261
262
			templateConfigFile.addListener(SWT.Modify,
263
					templateConfigFileModifyListener);
264
265
		} else
266
		{
164
			modelPath.setText("Could not find set preference.");
267
			modelPath.setText("Could not find set preference.");
165
			vocabPath.setText("Could not find set preference.");
268
			vocabPath.setText("Could not find set preference.");
166
			dataTypePath.setText("Could not find set preference.");
269
			dataTypePath.setText("Could not find set preference.");
167
			fragmentPath.setText("Could not find set preference.");
270
			fragmentPath.setText("Could not find set preference.");
168
			templateConfigFile.setText("Could not find set preference.");
271
			templateConfigFile.setText("Could not find set preference.");
169
		}
272
		}
273
274
		validate();
170
	}
275
	}
171
276
172
	/*
277
	/*
173
	 * (non-Javadoc)
278
	 * (non-Javadoc)
279
	 * 
174
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
280
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
175
	 */
281
	 */
176
	@Override
282
	@Override
177
	protected void performDefaults() {
283
	protected void performDefaults()
284
	{
178
285
179
		// should always be if nature is set correctly!
286
		// should always be if nature is set correctly!
180
		if (getElement() instanceof IProject) {
287
		if (getElement() instanceof IProject)
288
		{
181
			modelPath
289
			modelPath
182
					.setText(H3ETProjectConfiguration.MODEL_PATH_DEFAULT_VALUE);
290
					.setText(H3ETProjectConfiguration.MODEL_PATH_DEFAULT_VALUE);
183
			vocabPath
291
			vocabPath
Lines 195-219 Link Here
195
303
196
	/*
304
	/*
197
	 * (non-Javadoc)
305
	 * (non-Javadoc)
306
	 * 
198
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
307
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
199
	 */
308
	 */
200
	@Override
309
	@Override
201
	public boolean performOk() {
310
	public boolean performOk()
311
	{
312
313
		if (isPageValid)
314
		{
315
316
			// should always be if nature is set correctly for the project
317
			if (getElement() instanceof IProject)
318
			{
319
				H3ETProjectConfiguration projectConfiguration = H3ETProjectConfiguration
320
						.getConfiguration((IProject) getElement());
321
				projectConfiguration.setModelPath(modelPath.getText().trim());
322
				projectConfiguration.setVocabPath(vocabPath.getText().trim());
323
				projectConfiguration.setDataTypePath(dataTypePath.getText().trim());
324
				projectConfiguration.setFragmentPath(fragmentPath.getText().trim());
325
				projectConfiguration.setTemplateConfigFile(templateConfigFile
326
						.getText().trim());
327
				projectConfiguration.setUKMode(ukModeCheckBox.getSelection());
328
329
				// calling store also sets the configuration as a session
330
				// property
331
				projectConfiguration.store();
332
			}
333
			return true;
334
		} else
335
			return false;
336
	}
337
338
	/**
339
	 * Check whether textfields contain valid data or not.
340
	 * 
341
	 * @return boolean data type
342
	 */
343
	private boolean validate()
344
	{
202
345
203
		// should always be if nature is set correctly for the project
346
		return validate(modelPath, IResource.FOLDER, false)
204
		if (getElement() instanceof IProject) {
347
				&& validate(vocabPath, IResource.FOLDER, false)
205
			H3ETProjectConfiguration projectConfiguration = H3ETProjectConfiguration
348
				&& validate(dataTypePath, IResource.FOLDER, false)
206
					.getConfiguration((IProject) getElement());
349
				&& validate(fragmentPath, IResource.FOLDER, false)
207
			projectConfiguration.setModelPath(modelPath.getText());
350
				&& validate(templateConfigFile, IResource.FOLDER
208
			projectConfiguration.setVocabPath(vocabPath.getText());
351
						| IResource.FILE, true);
209
			projectConfiguration.setDataTypePath(dataTypePath.getText());
352
	}
210
			projectConfiguration.setFragmentPath(fragmentPath.getText());
211
			projectConfiguration.setTemplateConfigFile(templateConfigFile.getText());
212
			projectConfiguration.setUKMode(ukModeCheckBox.getSelection());
213
353
214
			// calling store also sets the configuration as a session property
354
	/**
215
			projectConfiguration.store();
355
	 * Check wheter given text field contains valid data or not.
356
	 * 
357
	 * @param text
358
	 * @param typeMask
359
	 * @return
360
	 */
361
	private boolean validate(Text text, int typeMask, boolean emptyAllowed)
362
	{
363
		try
364
		{
365
366
			if (!emptyAllowed && text.getText().trim().equals("")) {//$NON-NLS-1$
367
368
				String errorMessage = ((typeMask & IResource.FILE) != 0) ? "File must be specified"
369
						: "Path must be specified";
370
				errorMessages.put(text, errorMessage);
371
				setErrorMessage(errorMessage);
372
373
			} else
374
			{
375
				IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
376
				IPath path = new Path(text.getText());
377
				String[] segments = path.segments();
378
				boolean valid = true;
379
380
				for (String segment : segments)
381
				{
382
					//some of the segment is a " " sequence, dont deal with them
383
					if (segment.contentEquals(" "))
384
					{
385
						continue;
386
					}
387
388
					IStatus textStatus = workspace.validateName(segment.trim(),
389
							typeMask);
390
391
					if (!textStatus.isOK())
392
					{
393
						errorMessages.put(text, textStatus.getMessage());
394
395
						setErrorMessage(textStatus.getMessage());
396
						valid = false;
397
						break;
398
					}
399
				}
400
401
				if (valid)
402
				{
403
					errorMessages.remove(text);
404
405
					if (errorMessages.isEmpty())
406
					{
407
						setErrorMessage(null);
408
						return true;
409
					} else
410
					{
411
						Set<Object> keys = errorMessages.keySet();
412
						setErrorMessage(errorMessages.get(keys.iterator()
413
								.next()));
414
					}
415
				}
416
			}
417
418
		} catch (Exception e)
419
		{
420
			errorMessages.put(text, e.getMessage());
421
			setErrorMessage(e.getMessage());
216
		}
422
		}
217
		return true;
423
424
		return false;
218
	}
425
	}
219
}
426
}

Return to bug 191938