Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e18c095491349493d59640ee2f547a20a5059060 (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
/*******************************************************************************
 * Copyright (c) 2008, 2012 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;

import java.util.ArrayList;
import java.util.ListIterator;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Caching;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Connection;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Customization;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.caching.PersistenceXmlCachingTab;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.connection.PersistenceXmlConnectionTab;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.customization.PersistenceXmlCustomizationTab;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.general.EclipseLinkPersistenceUnitGeneralTab;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.options.PersistenceXmlOptionsTab;
import org.eclipse.jpt.jpa.ui.editors.JpaPageComposite;
import org.eclipse.jpt.jpa.ui.internal.persistence.PersistenceUnitPropertiesTab;
import org.eclipse.jpt.jpa.ui.internal.persistence.PersistenceXmlUiFactory;
import org.eclipse.swt.widgets.Composite;

public class EclipseLinkPersistenceXmlUiFactory implements PersistenceXmlUiFactory
{
	// ********** constructors **********
	
	public EclipseLinkPersistenceXmlUiFactory() {
		super();
	}

	// **************** persistence unit composites ****************************
	
	public ListIterator<JpaPageComposite> createPersistenceUnitComposites(
						PropertyValueModel<PersistenceUnit> subjectHolder,
						Composite parent,
						WidgetFactory widgetFactory) {

		ArrayList<JpaPageComposite> pages = new ArrayList<JpaPageComposite>(8);

		pages.add(this.buildGeneralTab(subjectHolder, parent, widgetFactory));
		pages.add(this.buildConnectionTab(subjectHolder, parent, widgetFactory));
		pages.add(this.buildCustomizationTab(subjectHolder, parent, widgetFactory));
		pages.add(this.buildCachingTab(subjectHolder, parent, widgetFactory));
		pages.add(this.buildOptionsTab(subjectHolder, parent, widgetFactory));
		pages.add(this.buildPropertiesTab(subjectHolder, parent, widgetFactory));

		return pages.listIterator();
	}

	// ********** persistence unit tabs **********
	
	protected EclipseLinkPersistenceUnitGeneralTab buildGeneralTab(
				PropertyValueModel<PersistenceUnit> subjectHolder,
				Composite parent,
				WidgetFactory widgetFactory) {

		return new EclipseLinkPersistenceUnitGeneralTab(subjectHolder, parent, widgetFactory);
	}
	
	protected PersistenceXmlConnectionTab<? extends Connection> buildConnectionTab(
				PropertyValueModel<PersistenceUnit> subjectHolder,
				Composite parent,
				WidgetFactory widgetFactory) {

		return new PersistenceXmlConnectionTab<Connection>( this.buildConnectionHolder(subjectHolder), parent, widgetFactory);
	}
	
	protected PersistenceXmlCustomizationTab<? extends Customization> buildCustomizationTab(
				PropertyValueModel<PersistenceUnit> subjectHolder,
				Composite parent,
				WidgetFactory widgetFactory) {

		return new PersistenceXmlCustomizationTab<Customization>(this.buildCustomizationHolder(subjectHolder), parent, widgetFactory);
	}
	
	protected PersistenceXmlCachingTab<? extends Caching> buildCachingTab(
				PropertyValueModel<PersistenceUnit> subjectHolder,
				Composite parent,
				WidgetFactory widgetFactory) {
		PropertyValueModel<Caching> cachingHolder = this.buildCachingHolder(subjectHolder);

		return new PersistenceXmlCachingTab<Caching>(cachingHolder, parent, widgetFactory);
	}
	
	protected PersistenceXmlOptionsTab<? extends PersistenceUnit> buildOptionsTab(
				PropertyValueModel<PersistenceUnit> subjectHolder,
				Composite parent,
				WidgetFactory widgetFactory) {

		return new PersistenceXmlOptionsTab<PersistenceUnit>(subjectHolder, parent, widgetFactory);
	}
	
	protected PersistenceUnitPropertiesTab buildPropertiesTab(
				PropertyValueModel<PersistenceUnit> subjectHolder,
				Composite parent,
				WidgetFactory widgetFactory) {

		return new PersistenceUnitPropertiesTab(subjectHolder, parent, widgetFactory);
	}

	// ********** private methods **********
	
	private PropertyValueModel<Connection> buildConnectionHolder(
				PropertyValueModel<PersistenceUnit> subjectHolder) {
		return new TransformationPropertyValueModel<PersistenceUnit, Connection>(subjectHolder) {
			@Override
			protected Connection transform_(PersistenceUnit value) {

				return ((EclipseLinkPersistenceUnit) value).getConnection();
			}
		};
	}
	
	protected PropertyValueModel<Customization> buildCustomizationHolder(
				PropertyValueModel<PersistenceUnit> subjectHolder) {
		return new TransformationPropertyValueModel<PersistenceUnit, Customization>(subjectHolder) {
			@Override
			protected Customization transform_(PersistenceUnit value) {
				return ((EclipseLinkPersistenceUnit) value).getCustomization();
			}
		};
	}
	
	protected PropertyValueModel<Caching> buildCachingHolder(
				PropertyValueModel<PersistenceUnit> subjectHolder) {
		return new TransformationPropertyValueModel<PersistenceUnit, Caching>(subjectHolder) {
			@Override
			protected Caching transform_(PersistenceUnit value) {
				return ((EclipseLinkPersistenceUnit) value).getCaching();
			}
		};
	}
}

Back to the top