Skip to main content
summaryrefslogtreecommitdiffstats
blob: 56f0bee90acea3a640dae6d741dabdcb6c3f086c (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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/*******************************************************************************
 * <copyright>
 *
 * Copyright (c) 2005, 2010 SAP AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Stefan Dimov - initial API, implementation and documentation
 *
 * </copyright>
 *
 *******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferenceInitializer;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferencesPage;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PropertyPage;

public class JPADiagramPropertyPage extends PropertyPage {
	
	public static final String PROJECT_SETTINGS_PATH = "/.settings/org.eclipse.jpt.jpadiagrameditor.ui";	//$NON-NLS-1$;
	protected IProject project = null;
	protected boolean isJPA10Project = false;				//$NON-NLS-1$;
	
	private Properties editorProps;
	
	private Text txtDefaultFolderField;
	private Text txtDefaultEntityPackageField;
	private Text txtDefaultTableNamePrefix;
	private Button checkDirectEditAffectsClass;
	private Group groupAccessType;
	private Group groupCollectionType;
	private Button btnFieldBasedAccess;
	private Button btnPropertyBasedAccess;
	private Button btnCollectionType;
	private Button btnListType;
	private Button btnSetType;
	private Button btnMapType;
	private Button checkOneToManyOldStyle;

	private boolean propsModified = false;

	static private final String QUALIFIER 								= "org.eclipse.jpt.jpadiagrameditor.ui";						//$NON-NLS-1$
	static public final QualifiedName PROP_DEFAULT_DIAGRAM_FOLDER		= new QualifiedName(QUALIFIER, "diagramFolder");			//$NON-NLS-1$;	
	static public final QualifiedName PROP_DEFAULT_PACKAGE 				= new QualifiedName(QUALIFIER, "defaultPackage");			//$NON-NLS-1$
	static public final QualifiedName PROP_DEFAULT_TABLE_NAME_PREFIX 	= new QualifiedName(QUALIFIER, "defaultTableNamePrefix");	//$NON-NLS-1$;
	static public final QualifiedName PROP_DIRECT_EDIT_AFFECTS_CLASS 	= new QualifiedName(QUALIFIER, "directEditAffectsClass");	//$NON-NLS-1$;
	static public final QualifiedName PROP_ACCESS_TYPE 					= new QualifiedName(QUALIFIER, "accessType");				//$NON-NLS-1$;
	static public final QualifiedName PROP_COLLECTION_TYPE 				= new QualifiedName(QUALIFIER, "collectionType");			//$NON-NLS-1$;
	static public final QualifiedName PROP_ONE_TO_MANY_OLD_STYLE		= new QualifiedName(QUALIFIER, "oneToManyOldStyle");		//$NON-NLS-1$;
	

    public static final String COLLECTION_TYPE = "java.util.Collection"; //$NON-NLS-1$
    public static final String LIST_TYPE = "java.util.List"; //$NON-NLS-1$
    public static final String SET_TYPE = "java.util.Set"; //$NON-NLS-1$
    public static final String MAP_TYPE = "java.util.Map"; //$NON-NLS-1$

	
	private IPreferenceStore store = JPADiagramEditorPlugin.getDefault().getPreferenceStore();

	@Override
	protected Control createContents(Composite parent) {
		final Composite composite = createCompositeContainer(parent);
		project = (IProject)getElement().getAdapter(IProject.class);
		isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(project, "1.0");				//$NON-NLS-1$;		
		loadProperties();
		createDefaultFolderControl(composite);
		createDefaultPackageControl(composite);
		createDefaultTableNamePrefixControl(composite);
		createDirectEditAffectsClassControl(composite);
		createAccessTypeControl(composite);
		createDefaultCollectionTypeControl(composite);
		if (!isJPA10Project)
			createOneToManyOldStyleControl(composite);
		Dialog.applyDialogFont(composite);
		validatePage();
		return composite;		
	}
	
	private Composite createCompositeContainer(Composite parent) {	
		final Composite composite= new Composite(parent, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		GridLayout gl = new GridLayout();
		gl.numColumns = 2;
		composite.setLayout(gl);
		return composite;
	}
		
	private void createDefaultFolderControl(Composite composite) {
		Label lblDefaultFolder = new Label(composite, SWT.FILL); 
		lblDefaultFolder.setText(JPAEditorMessages.JPAEditorPreferencesPage_defaultFolderControlLabel);
		lblDefaultFolder.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_defaultFolderControlTooltip);
		GridData gd = new GridData();
		lblDefaultFolder.setLayoutData(gd);	
		txtDefaultFolderField = new Text(composite, SWT.FLAT | SWT.BORDER | SWT.FILL);
		lblDefaultFolder.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_defaultFolderControlTooltip);
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gd.grabExcessHorizontalSpace = true;
		txtDefaultFolderField.setLayoutData(gd);
		
	    String defaultFolder = editorProps.getProperty(PROP_DEFAULT_DIAGRAM_FOLDER.getLocalName());
	    txtDefaultFolderField.setText(defaultFolder);
	    txtDefaultFolderField.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_defaultFolderControlTooltip);
	    txtDefaultFolderField.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				validatePage();
				propsModified = true;
			}			
		});
	}
	
		
	private void createDefaultPackageControl(Composite composite) {
		Label lblDefaultPackage = new Label(composite, SWT.FILL); 
		lblDefaultPackage.setText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultPackageToUse);
		lblDefaultPackage.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultPackageMsg);
		GridData gd = new GridData();
		lblDefaultPackage.setLayoutData(gd);	
		txtDefaultEntityPackageField = new Text(composite, SWT.FLAT | SWT.BORDER | SWT.FILL);
		lblDefaultPackage.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultPackageMsg);
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gd.grabExcessHorizontalSpace = true;
		txtDefaultEntityPackageField.setLayoutData(gd);
		
	    String defaultPackageName = editorProps.getProperty(PROP_DEFAULT_PACKAGE.getLocalName());
		txtDefaultEntityPackageField.setText(defaultPackageName);
		txtDefaultEntityPackageField.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultPackageMsg);
		txtDefaultEntityPackageField.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				validatePage();
				propsModified = true;
			}			
		});
	}
	
	private void createDefaultTableNamePrefixControl(Composite composite) {
		Label lblDefaultTableNamePrfix = new Label(composite, SWT.FILL); 
		lblDefaultTableNamePrfix.setText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultTableNameLabel);
		lblDefaultTableNamePrfix.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultTableNamePrefixMsg);
		GridData gd = new GridData();
		lblDefaultTableNamePrfix.setLayoutData(gd);	
		txtDefaultTableNamePrefix = new Text(composite, SWT.FLAT | SWT.BORDER);
		lblDefaultTableNamePrfix.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultTableNamePrefixMsg);
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gd.grabExcessHorizontalSpace = true;
		txtDefaultTableNamePrefix.setLayoutData(gd);
		
	    String defaultTableNamePrefix =  editorProps.getProperty(PROP_DEFAULT_TABLE_NAME_PREFIX.getLocalName());
		txtDefaultTableNamePrefix.setText(defaultTableNamePrefix);	
		txtDefaultTableNamePrefix.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultTableNamePrefixMsg);
		txtDefaultTableNamePrefix.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				validatePage();
				propsModified = true;
			}			
		});		
	}
	
	private void createDirectEditAffectsClassControl(Composite composite) {
		checkDirectEditAffectsClass = new Button(composite, SWT.FLAT | SWT.CHECK);
		checkDirectEditAffectsClass.setText(JPAEditorMessages.JPAEditorPreferencesPage_directEditAffectsClass);
		checkDirectEditAffectsClass.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_directEditAffectsClassTooltip);
		checkDirectEditAffectsClass.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
		
		boolean defaultDirectEditAffectsClass = Boolean.parseBoolean(editorProps.getProperty(PROP_DIRECT_EDIT_AFFECTS_CLASS.getLocalName()));
		checkDirectEditAffectsClass.setSelection(defaultDirectEditAffectsClass);
		checkDirectEditAffectsClass.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});			
	}
	
	private void createOneToManyOldStyleControl(Composite composite) {
		checkOneToManyOldStyle = new Button(composite, SWT.FLAT | SWT.CHECK);
		checkOneToManyOldStyle.setText(JPAEditorMessages.JPAEditorPropertyPage_oneToManyOldStyle);
		checkOneToManyOldStyle.setToolTipText(JPAEditorMessages.JPAEditorPropertyPage_oneToManyOldStyleTooltip);
		checkOneToManyOldStyle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
		
		boolean defaultDirectEditAffectsClass = Boolean.parseBoolean(editorProps.getProperty(PROP_ONE_TO_MANY_OLD_STYLE.getLocalName()));
		checkOneToManyOldStyle.setSelection(defaultDirectEditAffectsClass);
		checkOneToManyOldStyle.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});			
	}
	
	
	
	private void createDefaultCollectionTypeControl(Composite composite) {
		groupCollectionType = new Group(composite, 0);
		groupCollectionType.setText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultCollectionTypeSectionTittle);
		groupCollectionType.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultCollectionTypeSectionDescription);
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gd.grabExcessHorizontalSpace = true;
		gd.horizontalSpan = 2;
		groupCollectionType.setLayoutData(gd);
		
		GridLayout gl = new GridLayout();
		gl.numColumns = 1;
		groupCollectionType.setLayout(gl);
		
		String defaultCollectionType = editorProps.getProperty(PROP_COLLECTION_TYPE.getLocalName());
		
		createCollectionTypeButton(composite, gd, defaultCollectionType);
		createListTypeButton(composite, gd, defaultCollectionType);
		createSetTypeButton(composite, gd, defaultCollectionType);
		createMapTypeButton(composite, gd, defaultCollectionType);

	}
	
	private void createAccessTypeControl(Composite composite) {
		groupAccessType = new Group(composite, 0);
		groupAccessType.setText(JPAEditorMessages.JPAEditorPreferencesPage_entityAccessTypeButtonGroupLabel);
		groupAccessType.setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_entityAccessTypeButtonGroupTooltip);
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gd.grabExcessHorizontalSpace = true;
		gd.horizontalSpan = 2;
		groupAccessType.setLayoutData(gd);
		
		GridLayout gl = new GridLayout();
		gl.numColumns = 1;
		groupAccessType.setLayout(gl);
		
		String defaultAccessType = editorProps.getProperty(PROP_ACCESS_TYPE.getLocalName());
		
		createFieldAccessButton(composite, gd, defaultAccessType);
		createPropertyAccessButton(composite, gd, defaultAccessType);
	}
	
	private void createCollectionTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
		btnCollectionType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
		btnCollectionType.setText(COLLECTION_TYPE);
		gd = new GridData();
		btnCollectionType.setLayoutData(gd);
		btnCollectionType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_COLLECTION_TYPE));
		btnCollectionType.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});
	}
	
	private void createListTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
		btnListType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
		btnListType.setText(LIST_TYPE);
		gd = new GridData();
		btnListType.setLayoutData(gd);
		btnListType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_LIST_TYPE));
		btnListType.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});
	}
	
	private void createSetTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
		btnSetType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
		btnSetType.setText(SET_TYPE);
		gd = new GridData();
		btnSetType.setLayoutData(gd);
		btnSetType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_SET_TYPE));
		btnSetType.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});
	}
	
	private void createMapTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
		btnMapType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
		btnMapType.setText(MAP_TYPE);
		gd = new GridData();
		btnMapType.setLayoutData(gd);
		btnMapType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_MAP_TYPE));
		btnMapType.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});
	}	
	
	private void createFieldAccessButton(Composite composite, GridData gd, String defaultAccessType) {
		btnFieldBasedAccess = new Button(groupAccessType, SWT.RADIO | SWT.FLAT);
		btnFieldBasedAccess.setText(JPAEditorMessages.JPAEditorPreferencesPage_entityFieldBasedAccessButtonLabel);
		gd = new GridData();
		btnFieldBasedAccess.setLayoutData(gd);
		btnFieldBasedAccess.setSelection(defaultAccessType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_ACCESS_FIELD_BASED));
		btnFieldBasedAccess.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});
	}
	
	private void createPropertyAccessButton(Composite composite, GridData gd, String defaultAccessType) {
		btnPropertyBasedAccess = new Button(groupAccessType, SWT.RADIO | SWT.FLAT);
		btnPropertyBasedAccess.setText(JPAEditorMessages.JPAEditorPreferencesPage_entityPropertyBasedAccessButtonLabel);
		gd = new GridData();
		btnPropertyBasedAccess.setLayoutData(gd);	
		btnPropertyBasedAccess.setSelection(defaultAccessType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_ACCESS_PROPERTY_BASED));
		btnPropertyBasedAccess.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				propsModified = true;
			}
			public void widgetDefaultSelected(SelectionEvent e) {}			
		});		
	}
	
    protected void performDefaults() {
	    String defaultFolder = store.getString(JPAEditorPreferenceInitializer.PROPERTY_DIAGRAM_FOLDER);
		txtDefaultFolderField.setText(defaultFolder);		
	    String defaultPackageName = store.getString(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_PACKAGE);
		txtDefaultEntityPackageField.setText(defaultPackageName);		
	    String defaultTableNamePrefix =  store.getString(JPAEditorPreferenceInitializer.PROPERTY_TABLE_NAME_PREFIX);
		txtDefaultTableNamePrefix.setText(defaultTableNamePrefix);		  
	    boolean defaultDirectEditAffectsClass = store.getBoolean(JPAEditorPreferenceInitializer.PROPERTY_DIRECT_EDIT_CLASS_NAME);
		checkDirectEditAffectsClass.setSelection(defaultDirectEditAffectsClass);
		String defaultAccessType = store.getString(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_ACCESS_TYPE);
		btnFieldBasedAccess.setSelection(defaultAccessType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_ACCESS_FIELD_BASED));
		btnPropertyBasedAccess.setSelection(defaultAccessType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_ACCESS_PROPERTY_BASED));		
		String defaultCollectionType = store.getString(JPAEditorPreferenceInitializer.PROPERTY_DEFAULT_COLLECTION_TYPE);
		btnCollectionType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_COLLECTION_TYPE));
		btnListType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_LIST_TYPE));		
		btnSetType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_SET_TYPE));
		btnMapType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_MAP_TYPE));
	    boolean defaultOneToManyOldStyle = store.getBoolean(JPAEditorPreferenceInitializer.PROPERTY_ONE_TO_MANY_OLD_STYLE);
	    if (!isJPA10Project)
	    	checkOneToManyOldStyle.setSelection(defaultOneToManyOldStyle);		
		super.performDefaults();
    }
    
    synchronized protected void validatePage() {
    	IStatus statFolder = JPAEditorPreferencesPage.validateDefaultFolder(txtDefaultFolderField.getText().trim(), 
    																		project.getName());
    	IStatus statPack = JPAEditorPreferencesPage.validateDefaultPackage(txtDefaultEntityPackageField.getText().trim());
    	IStatus statPref = JPAEditorPreferencesPage.validateTableNamePrefix(txtDefaultTableNamePrefix.getText().trim());
    	if (statFolder.getSeverity() == IStatus.ERROR) {
    		setErrorMessage(statFolder.getMessage());
    		setValid(false);
    		return;
    	}    	    	
    	if (statPack.getSeverity() == IStatus.ERROR) {
    		setErrorMessage(statPack.getMessage());
    		setValid(false);
    		return;
    	} 
    	if (statPref.getSeverity() == IStatus.ERROR) {
    		setErrorMessage(statPref.getMessage());
    		setValid(false);
    		return;
    	}
    	setErrorMessage(null);
    	setValid(true);
    	if (statPack.getSeverity() == IStatus.WARNING) {   		
    		setMessage(statPack.getMessage(), IMessageProvider.WARNING);
    		return;
    	}
    	if (statPref.getSeverity() == IStatus.WARNING) {   		
    		setMessage(statPref.getMessage(), IMessageProvider.WARNING);
    		return;
    	}
    	setMessage(null, IMessageProvider.NONE);
    }
    
    protected void performApply() {
    	saveSettingsIfModified();
    }
    
    public boolean performOk() {
    	return saveSettingsIfModified();
    }
    
    private boolean saveSettingsIfModified() {
    	if (propsModified) {
    		boolean saved = saveSettings();
    		propsModified = !saved;
    		return saved;
    	}
    	return true;
    }
    
    private boolean saveSettings() {
    	putNewValsInProps();
		IProject project = (IProject)getElement().getAdapter(IProject.class);
		Path path = new Path(PROJECT_SETTINGS_PATH);
		IFile quartzDataXMLFile = project.getFile(path);	
		File file = new File(quartzDataXMLFile.getLocation().toOSString());
		OutputStream os = null; 
		try {
			os = new FileOutputStream(file); 
			editorProps.store(os, "This file contains JPA Diagram Editor settings");	//$NON-NLS-1$;
			os.close();
			return true;
		} catch (IOException e) {
			MessageDialog.openError(Display.getCurrent().getActiveShell(), 
									JPAEditorMessages.JPADiagramPropertyPage_errSavePropsMsgTitle, 
									JPAEditorMessages.JPADiagramPropertyPage_errSavePropsMsgText);
			return false;
		}
	}
	
	private void putNewValsInProps() {
		editorProps.put(PROP_DEFAULT_DIAGRAM_FOLDER.getLocalName(), txtDefaultFolderField.getText().trim());
		editorProps.put(PROP_DEFAULT_PACKAGE.getLocalName(), txtDefaultEntityPackageField.getText().trim());
		editorProps.put(PROP_DEFAULT_TABLE_NAME_PREFIX.getLocalName(), txtDefaultTableNamePrefix.getText().trim());
		editorProps.put(PROP_DIRECT_EDIT_AFFECTS_CLASS.getLocalName(), "" + checkDirectEditAffectsClass.getSelection());	//$NON-NLS-1$;
		editorProps.put(PROP_ACCESS_TYPE.getLocalName(), btnFieldBasedAccess.getSelection() ? JPAEditorPreferenceInitializer.PROPERTY_VAL_ACCESS_FIELD_BASED : JPAEditorPreferenceInitializer.PROPERTY_VAL_ACCESS_PROPERTY_BASED);		
		editorProps.put(PROP_COLLECTION_TYPE.getLocalName(), getCollectionProperty());
		if (!isJPA10Project)
			editorProps.put(PROP_ONE_TO_MANY_OLD_STYLE.getLocalName(), "" + checkOneToManyOldStyle.getSelection());	//$NON-NLS-1$;
	}
	
	
	private String getCollectionProperty(){
		if (btnCollectionType.getSelection())
			return JPAEditorPreferenceInitializer.PROPERTY_VAL_COLLECTION_TYPE;
		else if (btnListType.getSelection())
			return JPAEditorPreferenceInitializer.PROPERTY_VAL_LIST_TYPE;
		else if (btnSetType.getSelection())
			return JPAEditorPreferenceInitializer.PROPERTY_VAL_SET_TYPE;
		else if (btnMapType.getSelection())
			return JPAEditorPreferenceInitializer.PROPERTY_VAL_MAP_TYPE;
		return null;
	}
	
	private Properties createDefaultProps() {
		return createDefaultProps(store);
	}
	
	static private Properties createDefaultProps(IPreferenceStore store) {
		Properties editorDefaultProps = new Properties(); 
		editorDefaultProps.setProperty(PROP_DEFAULT_DIAGRAM_FOLDER.getLocalName(), store.getString(JPAEditorPreferenceInitializer.PROPERTY_DIAGRAM_FOLDER));		
		editorDefaultProps.setProperty(PROP_DEFAULT_PACKAGE.getLocalName(), store.getString(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_PACKAGE));
		editorDefaultProps.setProperty(PROP_DEFAULT_TABLE_NAME_PREFIX.getLocalName(), store.getString(JPAEditorPreferenceInitializer.PROPERTY_TABLE_NAME_PREFIX));
		editorDefaultProps.setProperty(PROP_DIRECT_EDIT_AFFECTS_CLASS.getLocalName(), "" + store.getBoolean(JPAEditorPreferenceInitializer.PROPERTY_DIRECT_EDIT_CLASS_NAME));	//$NON-NLS-1$;
		editorDefaultProps.setProperty(PROP_ACCESS_TYPE.getLocalName(), store.getString(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_ACCESS_TYPE));		
		editorDefaultProps.setProperty(PROP_COLLECTION_TYPE.getLocalName(), store.getString(JPAEditorPreferenceInitializer.PROPERTY_DEFAULT_COLLECTION_TYPE));
		editorDefaultProps.setProperty(PROP_ONE_TO_MANY_OLD_STYLE.getLocalName(), "" + store.getBoolean(JPAEditorPreferenceInitializer.PROPERTY_ONE_TO_MANY_OLD_STYLE));	//$NON-NLS-1$;
		
		
		return editorDefaultProps;
	}

	
	private void loadProperties() {
		Properties defaultProps = createDefaultProps();
		editorProps = new Properties(defaultProps);
		
		IProject project = (IProject)getElement().getAdapter(IProject.class);
		Path path = new Path(PROJECT_SETTINGS_PATH);
		IFile editorProjectProperties = project.getFile(path);
		
		File propertiesFile = new File(editorProjectProperties.getLocation().toOSString());
		if (propertiesFile.exists()) {
			InputStream is = null;
			try {
				is = new FileInputStream(propertiesFile);
				editorProps.load(is);	
				is.close();
			} catch (IOException e) {
				// ignore
			}
		}
	}
	
	static public Properties loadProperties(IProject project) {
		IPreferenceStore store = JPADiagramEditorPlugin.getDefault().getPreferenceStore();
		Properties defaultProps = createDefaultProps(store);
		Properties editorProps = new Properties(defaultProps);
		
		Path path = new Path(PROJECT_SETTINGS_PATH);
		IFile editorProjectProperties = project.getFile(path);
		
		File propertiesFile = new File(editorProjectProperties.getLocation().toOSString());
		if (propertiesFile.exists()) {
			InputStream is = null;
			try {
				is = new FileInputStream(propertiesFile);
				editorProps.load(is);	
				is.close();
			} catch (IOException e) {
				// ignore
			}
		}
		return editorProps;
	}
	
	public static String getDefaultFolder(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return getDefaultFolder(project, props);
	}
	
	public static String getDefaultPackage(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return getDefaultPackage(project, props);
	}
	
	public static String getDefaultTablePrefixName(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return getDefaultTablePrefixName(project, props);
	}
	
	public static boolean doesDirecteEditingAffectClassNameByDefault(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return doesDirecteEditingAffectClassNameByDefault(project, props);
	}
	
	public static boolean isAccessFieldBased(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return isAccessFieldBased(project, props);
	}	
	
	public static boolean isCollectionType(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return isCollectionType(project, props);
	}
	
	public static boolean isListType(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return isListType(project, props);
	}
	
	public static boolean isSetType(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return isSetType(project, props);
	}
	
	public static boolean isMapType(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return isMapType(project, props);
	}	
	
	public static boolean shouldOneToManyUnidirBeOldStyle(IProject project) {
		Properties props = JPADiagramPropertyPage.loadProperties(project);
		return shouldOneToManyUnidirBeOldStyle(project, props);
	}	

//---------------------------------------------------------------------------------------------------

	public static String getDefaultFolder(IProject project, Properties props) {
		return props.getProperty(PROP_DEFAULT_DIAGRAM_FOLDER.getLocalName());
	}
	
	public static String getDefaultPackage(IProject project, Properties props) {
		return props.getProperty(PROP_DEFAULT_PACKAGE.getLocalName());
	}
	
	public static String getDefaultTablePrefixName(IProject project, Properties props) {
		return props.getProperty(PROP_DEFAULT_TABLE_NAME_PREFIX.getLocalName());
	}
	
	public static boolean doesDirecteEditingAffectClassNameByDefault(IProject project, Properties props) {
		return Boolean.parseBoolean(props.getProperty(PROP_DIRECT_EDIT_AFFECTS_CLASS.getLocalName()));
	}
	
	public static boolean isAccessFieldBased(IProject project, Properties props) {
		String accessType = props.getProperty(PROP_ACCESS_TYPE.getLocalName());
		return accessType.equals("field");	//$NON-NLS-1$;
	}	
	
	public static boolean isCollectionType(IProject project, Properties props) {
		String accessType = props.getProperty(PROP_COLLECTION_TYPE.getLocalName());
		return accessType.equals("collection");	//$NON-NLS-1$;
	}
	
	public static boolean isListType(IProject project, Properties props) {
		String accessType = props.getProperty(PROP_COLLECTION_TYPE.getLocalName());
		return accessType.equals("list");	//$NON-NLS-1$;
	}
	
	public static boolean isSetType(IProject project, Properties props) {
		String accessType = props.getProperty(PROP_COLLECTION_TYPE.getLocalName());
		return accessType.equals("set");	//$NON-NLS-1$;
	}
	
	public static boolean isMapType(IProject project, Properties props) {
		String accessType = props.getProperty(PROP_COLLECTION_TYPE.getLocalName());
		return accessType.equals("map");	//$NON-NLS-1$;
	}	
	
	public static boolean shouldOneToManyUnidirBeOldStyle(IProject project, Properties props) {
		return Boolean.parseBoolean(props.getProperty(PROP_ONE_TO_MANY_OLD_STYLE.getLocalName()));
	}

}

Back to the top