use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class XSDDeleteTypeDefinition method doAction.
@Override
public IStatus doAction() {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
ArrayList<Object> objList = new ArrayList<Object>();
Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getSchemaContentProvider());
Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getTypeContentProvider());
XSDTypeDefinition usingElement = findUsingElement(selection, objList);
if (usingElement != null) {
String message = getInfoDialogMessage(usingElement);
MessageDialog.openInformation(page.getSite().getShell(), Messages.XSDDeleteTypeDefinition_ConfirmDel, message);
return Status.CANCEL_STATUS;
}
// edit by ymli; fix the bug:0012228. Made the multiple types can be deleted.
for (Iterator<XSDTypeDefinition> iter = selection.iterator(); iter.hasNext(); ) {
XSDTypeDefinition type = iter.next();
if (type instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
if (xsdSimpType != null) {
simpleType = xsdSimpType;
}
schema.getContents().remove(simpleType);
} else {
XSDComplexTypeDefinition complxType = (XSDComplexTypeDefinition) type;
if (xsdCmpexType != null) {
complxType = xsdCmpexType;
}
schema.getContents().remove(complxType);
}
}
xsdSimpType = null;
xsdCmpexType = null;
page.refresh();
page.markDirty();
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class XSDEditComplexTypeAction method doAction.
@Override
public IStatus doAction() {
try {
ISelection selection = page.getTreeViewer().getSelection();
IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
XSDComplexTypeDefinition decl = (XSDComplexTypeDefinition) ((IStructuredSelection) selection).getFirstElement();
String oldName = decl.getName();
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditComplexTypeAction_EditComplexType, Messages.XSDEditComplexTypeAction_EnterNameForEntity, oldName, new IInputValidator() {
public String isValid(String newText) {
if (// $NON-NLS-1$
(newText == null) || "".equals(newText))
return Messages.XSDEditComplexTypeAction_ComplexTypeCannotBeEmpty;
if (// $NON-NLS-1$
Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches() || // $NON-NLS-1$//$NON-NLS-2$
newText.trim().replaceAll("\\s", "").length() != newText.trim().length())
return Messages.XSDEditComplexTypeAction_NameCannotContainEmpty;
if (!XSDUtil.isValidatedXSDName(newText)) {
return Messages.InvalidName_Message;
}
EList list = schema.getTypeDefinitions();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
Object d = iter.next();
if (d instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) d;
if (type.getName().equals(newText.trim()))
return Messages.XSDEditComplexTypeAction_ComplexAlreadyExists;
}
}
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Dialog.CANCEL) {
return Status.CANCEL_STATUS;
}
decl.setName(id.getValue().trim());
Util.updateReferenceToXSDTypeDefinition(page.getSite(), decl, provider);
page.refresh();
page.markDirty();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.XSDEditComplexTypeAction_ErrorEditEntity + e.getLocalizedMessage());
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class XSDAbstractNewXPathAction method updateElementForAddedfield.
protected void updateElementForAddedfield(XSDIdentityConstraintDefinition icd, String fieldName) {
if (icd == null || fieldName == null)
return;
XSDElementDeclaration entity = (XSDElementDeclaration) icd.getContainer();
XSDComplexTypeDefinition ctype = (XSDComplexTypeDefinition) entity.getTypeDefinition();
if (ctype.getContent() instanceof XSDParticle) {
XSDParticleImpl particle = (XSDParticleImpl) ctype.getContent();
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) particle.getTerm();
EList<XSDParticle> particles = group.getParticles();
for (XSDParticle part : particles) {
if (part.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration el = (XSDElementDeclaration) part.getTerm();
if (el.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
if (fieldName.equals(el.getName())) {
part.setMinOccurs(1);
part.setMaxOccurs(1);
break;
}
}
}
}
}
}
entity.updateElement();
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class XSDAddComplexTypeElementAction method init.
private boolean init() {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
if (selection.getFirstElement() instanceof XSDParticle) {
selParticle = (XSDParticle) selection.getFirstElement();
if (!(selParticle.getContainer() instanceof XSDModelGroup)) {
return false;
}
modelGroup = (XSDModelGroup) selParticle.getContainer();
} else {
if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) selection.getFirstElement();
if (!(ctd.getContent() instanceof XSDParticle)) {
return false;
}
if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) {
return false;
}
;
modelGroup = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm();
} else if (selection.getFirstElement() instanceof XSDParticle) {
modelGroup = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm();
} else if (selection.getFirstElement() instanceof XSDModelGroup) {
modelGroup = (XSDModelGroup) selection.getFirstElement();
} else {
log.info(Messages.bind(Messages._UnkownSection, selection.getFirstElement().getClass().getName(), selection.getFirstElement().toString()));
return false;
}
}
return true;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class XSDAddComplexTypeElementAction method openDialog.
private int openDialog() {
XSDSimpleTypeDefinition simpleTypeDefinition = schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName);
List<XSDComplexTypeDefinition> types = Util.getComplexTypes(schema);
dialogR = new ComplexTypeInputDialogR(page.getSite().getShell(), Messages._AddCType, modelGroup, schema, types, simpleTypeDefinition, false, false);
dialogR.setBlockOnOpen(true);
int ret = dialogR.open();
return ret;
}
Aggregations