Skip to main content
summaryrefslogtreecommitdiffstats
blob: c27d56238bc6e2fbf92e17a8986bf5cfff570701 (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
/*******************************************************************************
 * Copyright (c) 2009, 2013 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.core.internal.facet;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.jpa.core.JpaPlatform;
import org.eclipse.jpt.jpa.core.JpaPreferences;
import org.eclipse.jpt.jpa.core.JptJpaCoreMessages;
import org.eclipse.jpt.jpa.core.internal.plugin.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformManager;

/**
 * See <code>org.eclipse.jpt.jpa.core/plugin.xml:org.eclipse.wst.common.project.facet.core.facets</code>.
 * <p>
 * <strong>NB:</strong> We could get the default values from the JPA project
 * (instead of from the preferences);
 * but that exposes us to deadlocks (see bug 406352): We have a lock on the
 * faceted project here and would be waiting for the JPA project to be built;
 * meanwhile, the JPA project manager is building the JPA project and could be
 * waiting on a lock on the faceted project....
 */
public class JpaFacetVersionChangeDataModelProvider
	extends JpaFacetDataModelProvider
{
	/**
	 * default constructor used by extension point
	 */
	public JpaFacetVersionChangeDataModelProvider() {
		super();
	}


	// ********** default values **********

	@Override
	protected JpaPlatform.Config getDefaultPlatformConfig() {
		String id = JpaPreferences.getJpaPlatformID(this.getProject());
		return (id == null) ? null : this.getPlatformConfig(id);
	}

	protected JpaPlatform.Config getPlatformConfig(String id) {
		JpaPlatformManager jpaPlatformManager = this.getJpaPlatformManager();
		return (jpaPlatformManager == null) ? null : jpaPlatformManager.getJpaPlatformConfig(id);
	}

	@Override
	protected String getDefaultConnectionName() {
		return JpaPreferences.getConnectionProfileName(this.getProject());
	}

	@Override
	protected Boolean getDefaultUserWantsToOverrideDefaultCatalog() {
		return Boolean.valueOf(this.getDefaultUserWantsToOverrideDefaultCatalog_());
	}

	protected boolean getDefaultUserWantsToOverrideDefaultCatalog_() {
		return this.getDefaultCatalogIdentifier() != null;
	}

	@Override
	protected String getDefaultCatalogIdentifier() {
		return JpaPreferences.getUserOverrideDefaultCatalog(this.getProject());
	}

	@Override
	protected Boolean getDefaultUserWantsToOverrideDefaultSchema() {
		return Boolean.valueOf(this.getDefaultUserWantsToOverrideDefaultSchema_());
	}

	protected boolean getDefaultUserWantsToOverrideDefaultSchema_() {
		return this.getDefaultSchemaIdentifier() != null;
	}

	@Override
	protected String getDefaultSchemaIdentifier() {
		return JpaPreferences.getUserOverrideDefaultSchema(this.getProject());
	}

	@Override
	protected Boolean getDefaultDiscoverAnnotatedClasses() {
		return Boolean.valueOf(this.getDefaultDiscoverAnnotatedClasses_());
	}

	protected boolean getDefaultDiscoverAnnotatedClasses_() {
		return JpaPreferences.getDiscoverAnnotatedClasses(this.getProject());
	}

	protected IProject getProject() {
		return ResourcesPlugin.getWorkspace().getRoot().getProject(this.getProjectName());
	}

	protected String getProjectName() {
		return this.getStringProperty(FACET_PROJECT_NAME);
	}


	// ********** valid property descriptors **********

	@Override
	protected Iterable<JpaPlatform.Config> buildValidPlatformConfigs() {
		// add existing platform to list of choices
		Iterable<JpaPlatform.Config> validPlatformConfigs = super.buildValidPlatformConfigs();
		if (! IterableTools.contains(validPlatformConfigs, this.getDefaultPlatformConfig())) {
			validPlatformConfigs = IterableTools.insert(this.getDefaultPlatformConfig(), validPlatformConfigs);
		}
		return validPlatformConfigs;
	}


	// ********** validation **********

	@Override
	protected IStatus validatePlatform() {
		IStatus status = super.validatePlatform();
		if (status.isOK()) {
			if (! this.getPlatformConfig().supportsJpaFacetVersion(this.getProjectFacetVersion())) {
				status = JptJpaCorePlugin.instance().buildErrorStatus(JptJpaCoreMessages.VALIDATE_PLATFORM_DOES_NOT_SUPPORT_FACET_VERSION);
			}
		}
		return status;
	}
}

Back to the top