|
Lines 11-24
Link Here
|
| 11 |
***********************************************************************/ |
11 |
***********************************************************************/ |
| 12 |
package org.eclipse.jpt.ui.internal.wizards.entity.data.model; |
12 |
package org.eclipse.jpt.ui.internal.wizards.entity.data.model; |
| 13 |
|
13 |
|
|
|
14 |
import java.text.MessageFormat; |
| 14 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.Iterator; |
| 17 |
import java.util.List; |
| 15 |
import java.util.Set; |
18 |
import java.util.Set; |
| 16 |
|
19 |
|
|
|
20 |
import org.eclipse.core.resources.IProject; |
| 17 |
import org.eclipse.core.runtime.IStatus; |
21 |
import org.eclipse.core.runtime.IStatus; |
|
|
22 |
import org.eclipse.core.runtime.Status; |
| 23 |
import org.eclipse.jdt.core.IJavaProject; |
| 24 |
import org.eclipse.jdt.core.IType; |
| 18 |
import org.eclipse.jdt.core.JavaConventions; |
25 |
import org.eclipse.jdt.core.JavaConventions; |
|
|
26 |
import org.eclipse.jdt.core.JavaCore; |
| 27 |
import org.eclipse.jdt.core.JavaModelException; |
| 28 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
| 29 |
import org.eclipse.jem.util.emf.workbench.ProjectUtilities; |
| 30 |
import org.eclipse.jpt.ui.JptUiPlugin; |
| 19 |
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg; |
31 |
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg; |
| 20 |
import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation; |
32 |
import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation; |
| 21 |
import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages; |
33 |
import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages; |
|
|
34 |
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; |
| 22 |
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; |
35 |
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; |
| 23 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; |
36 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; |
| 24 |
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; |
37 |
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; |
|
Lines 170-180
Link Here
|
| 170 |
String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE; |
183 |
String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE; |
| 171 |
return WTPCommonPlugin.createErrorStatus(msg); |
184 |
return WTPCommonPlugin.createErrorStatus(msg); |
| 172 |
} |
185 |
} |
|
|
186 |
// Ensure that the entries in the list are valid |
| 187 |
String errorMsg = checkInputElementsTypeValidation(entities); |
| 188 |
if(errorMsg != null) |
| 189 |
return WTPCommonPlugin.createErrorStatus(errorMsg); |
| 190 |
String warningMsg = checkInputElementsTypeExistence(entities); |
| 191 |
if(warningMsg != null) |
| 192 |
return WTPCommonPlugin.createWarningStatus(warningMsg); |
| 193 |
|
| 173 |
} |
194 |
} |
| 174 |
// Return OK |
195 |
// Return OK |
| 175 |
return WTPCommonPlugin.OK_STATUS; |
196 |
return WTPCommonPlugin.OK_STATUS; |
| 176 |
} |
197 |
} |
| 177 |
|
198 |
|
|
|
199 |
private String checkInputElementsTypeValidation(List<EntityRow> inputElements){ |
| 200 |
IStatus validateFieldTypeStatus=Status.OK_STATUS; |
| 201 |
for(EntityRow entityRow: inputElements) { |
| 202 |
validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getType(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5); |
| 203 |
if(!validateFieldTypeStatus.isOK()) { |
| 204 |
break; |
| 205 |
} |
| 206 |
} |
| 207 |
if(!validateFieldTypeStatus.isOK()){ |
| 208 |
return validateFieldTypeStatus.getMessage(); |
| 209 |
} |
| 210 |
return null; |
| 211 |
} |
| 212 |
|
| 213 |
private String checkInputElementsTypeExistence(List<EntityRow> inputElements){ |
| 214 |
IStatus validateFieldTypeStatus=Status.OK_STATUS; |
| 215 |
for(EntityRow entityRow: inputElements) { |
| 216 |
IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT); |
| 217 |
IJavaProject javaProject = JavaCore.create(project); |
| 218 |
IType type=null; |
| 219 |
try { |
| 220 |
type = javaProject.findType(entityRow.getFqnTypeName()); |
| 221 |
} catch (JavaModelException e) { |
| 222 |
validateFieldTypeStatus = e.getStatus(); |
| 223 |
break; |
| 224 |
} |
| 225 |
if (type == null) { |
| 226 |
String message = MessageFormat.format( |
| 227 |
EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName()); |
| 228 |
validateFieldTypeStatus = new Status(IStatus.ERROR, |
| 229 |
JptUiPlugin.PLUGIN_ID, message); |
| 230 |
break; |
| 231 |
} |
| 232 |
} |
| 233 |
if(!validateFieldTypeStatus.isOK()){ |
| 234 |
return validateFieldTypeStatus.getMessage(); |
| 235 |
} |
| 236 |
return null; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 178 |
/** |
240 |
/** |
| 179 |
* This method is intended for internal use only. It provides a simple algorithm for detecting |
241 |
* This method is intended for internal use only. It provides a simple algorithm for detecting |
| 180 |
* if there are duplicate entries in a list. It will accept a null parameter. It will return |
242 |
* if there are duplicate entries in a list. It will accept a null parameter. It will return |