Skip to main content
summaryrefslogtreecommitdiffstats
blob: ca5110cdda66926a79cecbf8cf5c8a3f44390059 (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
/*******************************************************************************
 * Copyright (c) 2007, 2016 Oracle. 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:
 *     Oracle - initial API and implementation
 *******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.options;

import java.util.Collection;
import org.eclipse.jpt.common.ui.JptCommonUiMessages;
import org.eclipse.jpt.common.ui.internal.swt.widgets.ComboTools;
import org.eclipse.jpt.common.ui.internal.widgets.EnumFormComboViewer;
import org.eclipse.jpt.common.ui.internal.widgets.FolderChooserComboPane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapterXXXX;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkDdlGenerationType;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkOutputMode;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkSchemaGeneration;
import org.eclipse.jpt.jpa.eclipselink.ui.JptJpaEclipseLinkUiMessages;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.EclipseLinkHelpContextIds;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;

public class EclipseLinkPersistenceXmlSchemaGenerationComposite
	extends Pane<EclipseLinkSchemaGeneration>
{
	public EclipseLinkPersistenceXmlSchemaGenerationComposite(Pane<?> parent, PropertyValueModel<EclipseLinkSchemaGeneration> schemaGenModel, Composite parentComposite) {
		super(parent, schemaGenModel, parentComposite);
	}

	protected String getHelpID() {
		return EclipseLinkHelpContextIds.PERSISTENCE_SCHEMA_GENERATION;
	}

	@Override
	protected Composite addComposite(Composite container) {
		return addSubPane(container, 2, 0, 0, 0, 0);
	}

	@Override
	protected void initializeLayout(Composite container) {
		// DDL Generation Type:
		this.addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_SCHEMA_GENERATION_TAB_DDL_GENERATION_TYPE_LABEL);
		this.addDdlGenerationTypeCombo(container);

		// Output Mode:
		this.addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_SCHEMA_GENERATION_TAB_OUTPUT_MODE_LABEL);
		this.addBuildOutputModeCombo(container);

		// DDL Generation Location
		this.addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_SCHEMA_GENERATION_TAB_DDL_GENERATION_LOCATION_LABEL);
		this.buildDdlGenerationLocationComposite(container);

		// Create DDL File Name:
		this.addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_SCHEMA_GENERATION_TAB_CREATE_DDL_FILE_NAME_LABEL);
		Combo ddlFileNameCombo = addEditableCombo(
			container,
			this.buildDefaultCreateDdlFileNameListHolder(),
			this.buildCreateDdlFileNameHolder(),
			TransformerTools.<String>objectToStringTransformer(),
			getHelpID()
		);
		ComboTools.handleDefaultValue(ddlFileNameCombo);

		// Drop DDL File Name:
		this.addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_SCHEMA_GENERATION_TAB_DROP_DDL_FILE_NAME_LABEL);
		Combo dropDDLCombo = addEditableCombo(
			container,
			this.buildDefaultDropDdlFileNameListHolder(),
			this.buildDropDdlFileNameHolder(),
			TransformerTools.<String>objectToStringTransformer(),
			getHelpID()
		);
		ComboTools.handleDefaultValue(dropDDLCombo);
	}

	//************ DDL generation type ************

	private EnumFormComboViewer<EclipseLinkSchemaGeneration, EclipseLinkDdlGenerationType> addDdlGenerationTypeCombo(Composite container) {
		return new EnumFormComboViewer<EclipseLinkSchemaGeneration, EclipseLinkDdlGenerationType>(this, container) {
			@Override
			protected void addPropertyNames(Collection<String> propertyNames) {
				super.addPropertyNames(propertyNames);
				propertyNames.add(EclipseLinkSchemaGeneration.DDL_GENERATION_TYPE_PROPERTY);
			}

			@Override
			protected EclipseLinkDdlGenerationType[] getChoices() {
				return EclipseLinkDdlGenerationType.values();
			}

			@Override
			protected EclipseLinkDdlGenerationType getDefaultValue() {
				return this.getSubject().getDefaultDdlGenerationType();
			}

			@Override
			protected String displayString(EclipseLinkDdlGenerationType value) {
				switch (value) {
					case create_tables :
						return JptJpaEclipseLinkUiMessages.DDL_GENERATION_TYPE_COMPOSITE_CREATE_TABLES;
					case drop_and_create_tables :
						return JptJpaEclipseLinkUiMessages.DDL_GENERATION_TYPE_COMPOSITE_DROP_AND_CREATE_TABLES;
					case none :
						return JptJpaEclipseLinkUiMessages.DDL_GENERATION_TYPE_COMPOSITE_NONE;
					default :
						throw new IllegalStateException();
				}
			}

			@Override
			protected EclipseLinkDdlGenerationType getValue() {
				return this.getSubject().getDdlGenerationType();
			}

			@Override
			protected void setValue(EclipseLinkDdlGenerationType value) {
				this.getSubject().setDdlGenerationType(value);
			}

			@Override
			protected String getHelpId() {
				return getHelpID();
			}
		};
	}


	//************ output mode ************

	private EnumFormComboViewer<EclipseLinkSchemaGeneration, EclipseLinkOutputMode> addBuildOutputModeCombo(Composite container) {
		return new EnumFormComboViewer<EclipseLinkSchemaGeneration, EclipseLinkOutputMode>(this, container) {
			@Override
			protected void addPropertyNames(Collection<String> propertyNames) {
				super.addPropertyNames(propertyNames);
				propertyNames.add(EclipseLinkSchemaGeneration.OUTPUT_MODE_PROPERTY);
			}

			@Override
			protected EclipseLinkOutputMode[] getChoices() {
				return EclipseLinkOutputMode.values();
			}

			@Override
			protected EclipseLinkOutputMode getDefaultValue() {
				return this.getSubject().getDefaultOutputMode();
			}

			@Override
			protected String displayString(EclipseLinkOutputMode value) {
				switch (value) {
					case both :
						return JptJpaEclipseLinkUiMessages.OUTPUT_MODE_COMPOSITE_BOTH;
					case database :
						return JptJpaEclipseLinkUiMessages.OUTPUT_MODE_COMPOSITE_DATABASE;
					case sql_script :
						return JptJpaEclipseLinkUiMessages.OUTPUT_MODE_COMPOSITE_SQL_SCRIPT;
					default :
						throw new IllegalStateException();
				}
			}

			@Override
			protected EclipseLinkOutputMode getValue() {
				return this.getSubject().getOutputMode();
			}

			@Override
			protected void setValue(EclipseLinkOutputMode value) {
				this.getSubject().setOutputMode(value);
			}
			@Override
			protected String getHelpId() {
				return getHelpID();
			}
		};
	}


	//************ Create DDL file name ************

	private PropertyValueModel<String> buildDefaultCreateDdlFileNameHolder() {
		return new PropertyAspectAdapterXXXX<EclipseLinkSchemaGeneration, String>(this.getSubjectHolder(), EclipseLinkSchemaGeneration.DEFAULT_CREATE_FILE_NAME) {
			@Override
			protected String buildValue_() {
				return EclipseLinkPersistenceXmlSchemaGenerationComposite.this.getDefaultCreateFileNameValue(subject);
			}
		};
	}

	private ListValueModel<String> buildDefaultCreateDdlFileNameListHolder() {
		return new PropertyListValueModelAdapter<String>(
			this.buildDefaultCreateDdlFileNameHolder()
		);
	}

	private ModifiablePropertyValueModel<String> buildCreateDdlFileNameHolder() {
		return new PropertyAspectAdapterXXXX<EclipseLinkSchemaGeneration, String>(this.getSubjectHolder(), EclipseLinkSchemaGeneration.CREATE_FILE_NAME_PROPERTY) {
			@Override
			protected String buildValue_() {

				String name = subject.getCreateFileName();
				if (name == null) {
					name = EclipseLinkPersistenceXmlSchemaGenerationComposite.this.getDefaultCreateFileNameValue(subject);
				}
				return name;
			}

			@Override
			protected void setValue_(String value) {

				if (getDefaultCreateFileNameValue(subject).equals(value)) {
					value = null;
				}
				subject.setCreateFileName(value);
			}
		};
	}

	private String getDefaultCreateFileNameValue(EclipseLinkSchemaGeneration subject) {
		String defaultValue = subject.getDefaultCreateFileName();

		if (defaultValue != null) {
			return NLS.bind(
				JptCommonUiMessages.DEFAULT_WITH_ONE_PARAM,
				defaultValue
			);
		}
		return JptCommonUiMessages.DEFAULT_EMPTY;
	}


	//************ Drop DDL file name ************


	private PropertyValueModel<String> buildDefaultDropDdlFileNameHolder() {
		return new PropertyAspectAdapterXXXX<EclipseLinkSchemaGeneration, String>(this.getSubjectHolder(), EclipseLinkSchemaGeneration.DEFAULT_DROP_FILE_NAME) {
			@Override
			protected String buildValue_() {
				return EclipseLinkPersistenceXmlSchemaGenerationComposite.this.getDefaultDropDdlFileNameValue(subject);
			}
		};
	}

	private ListValueModel<String> buildDefaultDropDdlFileNameListHolder() {
		return new PropertyListValueModelAdapter<String>(
			this.buildDefaultDropDdlFileNameHolder()
		);
	}

	private ModifiablePropertyValueModel<String> buildDropDdlFileNameHolder() {
		return new PropertyAspectAdapterXXXX<EclipseLinkSchemaGeneration, String>(this.getSubjectHolder(), EclipseLinkSchemaGeneration.DROP_FILE_NAME_PROPERTY) {
			@Override
			protected String buildValue_() {

				String name = subject.getDropFileName();
				if (name == null) {
					name = EclipseLinkPersistenceXmlSchemaGenerationComposite.this.getDefaultDropDdlFileNameValue(subject);
				}
				return name;
			}

			@Override
			protected void setValue_(String value) {

				if (EclipseLinkPersistenceXmlSchemaGenerationComposite.this.getDefaultDropDdlFileNameValue(subject).equals(value)) {
					value = null;
				}
				subject.setDropFileName(value);
			}
		};
	}

	private String getDefaultDropDdlFileNameValue(EclipseLinkSchemaGeneration subject) {
		String defaultValue = subject.getDefaultDropFileName();

		if (defaultValue != null) {
			return NLS.bind(
				JptCommonUiMessages.DEFAULT_WITH_ONE_PARAM,
				defaultValue
			);
		}
		return JptCommonUiMessages.DEFAULT_EMPTY;
	}

	private Pane<EclipseLinkSchemaGeneration> buildDdlGenerationLocationComposite(Composite container) {
		return new FolderChooserComboPane<EclipseLinkSchemaGeneration>(this, container) {

			@Override
			protected ModifiablePropertyValueModel<String> buildTextHolder() {
				return new PropertyAspectAdapterXXXX<EclipseLinkSchemaGeneration, String>(
										getSubjectHolder(), EclipseLinkSchemaGeneration.APPLICATION_LOCATION_PROPERTY) {
					@Override
					protected String buildValue_() {

						String name = subject.getApplicationLocation();
						if (name == null) {
							name = defaultValue(subject);
						}
						return name;
					}

					@Override
					protected void setValue_(String value) {

						if (defaultValue(subject).equals(value)) {
							value = null;
						}
						subject.setApplicationLocation(value);
					}
				};
			}

			private String defaultValue(EclipseLinkSchemaGeneration subject) {
				String defaultValue = subject.getDefaultApplicationLocation();

				if (defaultValue != null) {
					return NLS.bind(
						JptCommonUiMessages.DEFAULT_WITH_ONE_PARAM,
						defaultValue
					);
				}
				return this.getDefaultString();
			}

			@Override
			protected String getDefaultString() {
				return JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_SCHEMA_GENERATION_TAB_DEFAULT_DOT;
			}

			@Override
			protected String getDialogMessage() {
				return JptJpaEclipseLinkUiMessages.DDL_GENERATION_LOCATION_COMPOSITE_DIALOG_MESSAGE;
			}

			@Override
			protected String getDialogTitle() {
				return JptJpaEclipseLinkUiMessages.DDL_GENERATION_LOCATION_COMPOSITE_DIALOG_TITLE;
			}
		};
	}
}

Back to the top