Java Reference
In-Depth Information
if (index == 0) {
name = "";
typeName = newString.substring(index + 1);
} else if (index > 0) {
name = newString.substring(0, index).trim();
typeName = newString.substring(index + 1).trim();
} else if (index == -1 && newString.length() > 0) {
name = newString;
typeName = "";
} else {
name = "";
typeName = "";
}
final Attribute attribute = getAttribute(element);
final Datatype dataType = findType(typeName, attribute);
TransactionalEditingDomain editingDomain = TransactionUtil
.getEditingDomain(attribute);
return new AbstractTransactionalCommand(editingDomain, "",
Collections.singletonList(
WorkspaceSynchronizer.getFile(attribute.eResource()))) {
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor
monitor, IAdaptable info) throws ExecutionException {
if (newString.length() == 0) {
return CommandResult.newErrorCommandResult(
"Invalid input");
}
attribute.setName(name);
attribute.setDataType(dataType);
return CommandResult.newOKCommandResult();
}
};
}
private Datatype findType( final String typeName,
final Attribute attribute) {
Datatype type = null ;
if (typeName.length() > 0) {
EList<Resource> resources =
attribute.eResource().getResourceSet().getResources();
for (Resource resource : resources) {
for (EObject object : resource.getContents()) {
if (object instanceof org.eclipse.oocore.Package) {
type = findInPackage((org.eclipse.oocore.Package)
object, typeName);
if (type != null ) return type;
}
}
}
}
return type;
}
Search WWH ::




Custom Search