Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3cab96dfd47f1cbbeb37e2db77cdba9eb1601888 (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
/***************************************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others. 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: IBM Corporation - initial API and implementation
 **************************************************************************************************/
/*
 * Created on Oct 31, 2003
 * 
 * To change the template for this generated file go to Window>Preferences>Java>Code
 * Generation>Code and Comments
 */
package org.eclipse.jst.j2ee.application.internal.operations;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jst.common.jdt.internal.integration.JavaProjectCreationDataModel;
import org.eclipse.jst.j2ee.internal.project.J2EECreationResourceHandler;
import org.eclipse.jst.j2ee.internal.servertarget.ServerTargetDataModel;
import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModel;
import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel;
import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelEvent;
import org.eclipse.wst.common.internal.emfworkbench.operation.EditModelOperationDataModel;
import org.eclispe.wst.common.frameworks.internal.plugin.WTPCommonPlugin;

/**
 * This dataModel is a common super class used to create J2EE Components.
 * 
 * This class (and all its fields and methods) is likely to change during the WTP 1.0 milestones as
 * the new project structures are adopted. Use at your own risk.
 * 
 * @since WTP 1.0
 */
public abstract class J2EEArtifactCreationDataModelOld extends EditModelOperationDataModel {
	/**
	 * An optional dataModel propertyName for a <code>Boolean</code> type. The default value is
	 * <code>Boolean.TRUE</code>. If this property is set to <code>Boolean.TRUE</code> then a
	 * default deployment descriptor and supporting bindings files will be generated.
	 */
	public static final String CREATE_DEFAULT_FILES = "J2EEArtifactCreationDataModel.CREATE_DEFAULT_FILES"; //$NON-NLS-1$

	/**
	 * An optional dataModel property for a <code>Boolean</code> type. The default value is
	 * <code>Boolean.TRUE</code>. If this property is set to <code>Boolean.TRUE</code> then the
	 * server target specified by dataModel property <code>SERVER_TARGET_ID</code> will be set on
	 * the generated artifact.
	 * 
	 * @see SERVER_TARGET_ID
	 */
	public static final String ADD_SERVER_TARGET = "J2EEArtifactCreationDataModel.ADD_SERVER_TARGET"; //$NON-NLS-1$

	/**
	 * Optional, type String
	 */
	public static final String FINAL_PERSPECTIVE = "J2EEArtifactCreationDataModel.FINAL_PERSPECTIVE"; //$NON-NLS-1$

	/**
	 * An optonal dataModel propertyName for a <code>java.lang.String</code> type. Sets the local
	 * file system location for the described project. The path must be either an absolute file
	 * system path, or a relative path whose first segment is the name of a defined workspace path
	 * variable. The default value is the workspace's default location.
	 * 
	 * @see ProjectCreationDataModel.PROJECT_LOCATION
	 */
	public static final String PROJECT_LOCATION = ProjectCreationDataModel.PROJECT_LOCATION;

	/**
	 * An optional dataModel property for a <code>java.lang.String</code> type. This is used to
	 * specify the server target and is required if the <code>ADD_SERVER_TARGET</code> property is
	 * set to <code>Boolean.TRUE</code>.
	 * 
	 * @see ServerTargetDataModel.RUNTIME_TARGET_ID
	 */
	public static final String SERVER_TARGET_ID = ServerTargetDataModel.RUNTIME_TARGET_ID;
	public static final String CLASSPATH_ENTRIES = JavaProjectCreationDataModel.CLASSPATH_ENTRIES;

	protected static final String IS_ENABLED = "J2EEArtifactCreationDataModel.IS_ENABLED"; //$NON-NLS-1$

	private static final String NESTED_MODEL_PROJECT_CREATION = "J2EEArtifactCreationDataModel.NESTED_MODEL_PROJECT_CREATION"; //$NON-NLS-1$
	private static final String NESTED_MODEL_SERVER_TARGET = "J2EEArtifactCreationDataModel.NESTED_MODEL_SERVER_TARGET"; //$NON-NLS-1$

	private ProjectCreationDataModel projectDataModel;
	private ServerTargetDataModel serverTargetDataModel;

	protected void initValidBaseProperties() {
		addValidBaseProperty(CREATE_DEFAULT_FILES);
		addValidBaseProperty(ADD_SERVER_TARGET);
		addValidBaseProperty(IS_ENABLED);
		addValidBaseProperty(FINAL_PERSPECTIVE);
		super.initValidBaseProperties();
	}

	protected void initNestedModels() {
		super.initNestedModels();
		initProjectModel();
		addNestedModel(NESTED_MODEL_PROJECT_CREATION, projectDataModel);

		serverTargetDataModel = new ServerTargetDataModel();
		addNestedModel(NESTED_MODEL_SERVER_TARGET, serverTargetDataModel);
	}

	protected void initProjectModel() {
		projectDataModel = new ProjectCreationDataModel();
	}

	/**
	 * @param projectDataModel
	 *            The projectDataModel to set.
	 */
	protected final void setProjectDataModel(ProjectCreationDataModel projectDataModel) {
		this.projectDataModel = projectDataModel;
	}

	public final ProjectCreationDataModel getProjectDataModel() {
		return projectDataModel;
	}

	protected boolean doSetProperty(String propertyName, Object propertyValue) {
		super.doSetProperty(propertyName, propertyValue);
		if (EditModelOperationDataModel.PROJECT_NAME.equals(propertyName)) {
			projectDataModel.setProperty(ProjectCreationDataModel.PROJECT_NAME, propertyValue);
			serverTargetDataModel.setProperty(ServerTargetDataModel.PROJECT_NAME, propertyValue);
		} else if (IS_ENABLED.equals(propertyName)) {
			notifyEnablementChange(SERVER_TARGET_ID);
			notifyEnablementChange(PROJECT_NAME);
		}
		return true;
	}

	public final ServerTargetDataModel getServerTargetDataModel() {
		return serverTargetDataModel;
	}

	protected Boolean basicIsEnabled(String propertyName) {
		return (Boolean) getProperty(IS_ENABLED);
	}

	public void propertyChanged(WTPOperationDataModelEvent event) {
		if (event.getFlag() == WTPOperationDataModelEvent.PROPERTY_CHG) {
			WTPOperationDataModel dm = event.getDataModel();
			if (dm == projectDataModel || dm == serverTargetDataModel) {
				String prop = event.getPropertyName();
				if (prop.equals(ProjectCreationDataModel.PROJECT_NAME) || prop.equals(ServerTargetDataModel.PROJECT_NAME)) {
					setProperty(PROJECT_NAME, event.getProperty()); //setting on outer will synch
					// all others
					return;
				}
			}
		}
		super.propertyChanged(event);
	}

	protected IStatus doValidateProperty(String propertyName) {
		if (propertyName.equals(PROJECT_NAME)) {
			IStatus status = projectDataModel.validateProperty(ProjectCreationDataModel.PROJECT_NAME);
			String projectName = getStringProperty(PROJECT_NAME);
			if (status.isOK()) {
				if (projectName.indexOf("#") != -1) { //$NON-NLS-1$
					String errorMessage = J2EECreationResourceHandler.getString("InvalidCharsError"); //$NON-NLS-1$
					return WTPCommonPlugin.createErrorStatus(errorMessage);
				}
			} else
				return status;

		} else if (propertyName.equals(NESTED_MODEL_VALIDATION_HOOK)) {
			return OK_STATUS;
		}
		return super.doValidateProperty(propertyName);
	}

	protected Object getDefaultProperty(String propertyName) {
		if (propertyName.equals(CREATE_DEFAULT_FILES) || propertyName.equals(ADD_SERVER_TARGET) || propertyName.equals(IS_ENABLED)) {
			return Boolean.TRUE;
		}
		return super.getDefaultProperty(propertyName);
	}

	protected boolean isResultProperty(String propertyName) {
		if (propertyName.equals(FINAL_PERSPECTIVE))
			return true;
		return super.isResultProperty(propertyName);
	}
}

Back to the top