use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method doAction.
@Override
public IStatus doAction() {
try {
conceptList = WorkbenchClipboard.getWorkbenchClipboard().getConcepts();
XSDFactory factory = XSDFactory.eINSTANCE;
if (!conceptList.isEmpty()) {
// List<String> concepts = new ArrayList<String>();
int index = 0;
for (Iterator<XSDElementDeclaration> it = conceptList.iterator(); it.hasNext(); ) {
if (conceptList.get(index).getSchema() != null) {
// concepts = Util.getConcepts(conceptList.get(index).getSchema());
typeList = Util.getTypeDefinition(conceptList.get(index).getSchema());
}
index++;
Object concept = it.next();
if (concept instanceof XSDElementDeclaration) {
// edit by ymli,fix the bug:0011523. let the element(simple or complex) can be pasted
// if (concepts.contains(((XSDElementDeclaration) concept).getName())) {
XSDElementDeclaration copy_concept = (XSDElementDeclaration) concept;
XSDElementDeclaration new_copy_concept = factory.createXSDElementDeclaration();
new_copy_concept = (XSDElementDeclaration) copy_concept.cloneConcreteComponent(true, false);
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDPasteConceptAction_CopyElement, Messages.XSDPasteConceptAction_DialogTip, Messages.bind(Messages.XSDPasteConceptAction_CopyOf, copy_concept.getName()), new IInputValidator() {
public String isValid(String newText) {
if ((newText == null) || "".equals(newText)) {
return Messages.XSDPasteConceptAction_NameCannNotbeEmpty;
}
EList<XSDElementDeclaration> list = schema.getElementDeclarations();
for (XSDElementDeclaration d : list) {
if (d.getName().equalsIgnoreCase(newText)) {
return Messages.XSDPasteConceptAction_EntityAlreadyExists;
}
}
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
new_copy_concept.setName(id.getValue());
for (int i = 0; i < new_copy_concept.getIdentityConstraintDefinitions().size(); i++) {
String name = new_copy_concept.getIdentityConstraintDefinitions().get(i).getName().replaceAll(copy_concept.getName(), new_copy_concept.getName());
new_copy_concept.getIdentityConstraintDefinitions().get(i).setName(name);
}
if (new_copy_concept.getAnonymousTypeDefinition() == null) {
XSDComplexTypeDefinition copyType = (XSDComplexTypeDefinition) copy_concept.getTypeDefinition().cloneConcreteComponent(true, false);
String originalName = copyType.getName();
// $NON-NLS-1$
String typeName = "Copy_of_" + originalName;
copyType.setName(typeName);
schema.getContents().add(copyType);
new_copy_concept.setTypeDefinition(copyType);
}
new_copy_concept.updateElement();
schema.getContents().add(new_copy_concept);
addAnnotationForXSDElementDeclaration(copy_concept, new_copy_concept);
}
}
Map<String, XSDTypeDefinition> typeDef = Util.getTypeDefinition(schema);
for (XSDTypeDefinition type : copyTypeSet) {
if (typeDef.containsKey(type.getName())) {
continue;
}
XSDTypeDefinition typedefinitionClone = null;
if (type instanceof XSDComplexTypeDefinition) {
typedefinitionClone = factory.createXSDComplexTypeDefinition();
typedefinitionClone = (XSDComplexTypeDefinition) type.cloneConcreteComponent(true, false);
schema.getContents().add(typedefinitionClone);
addAnnotationForComplexType((XSDComplexTypeDefinition) type, (XSDComplexTypeDefinition) typedefinitionClone);
} else if (type instanceof XSDSimpleTypeDefinition) {
schema.getContents().add((XSDSimpleTypeDefinition) type.cloneConcreteComponent(true, false));
}
}
schema.getElement();
// WSDataModel wsObject = (WSDataModel)
// (page.getXObject().getWsObject());
// wsObject.getXsdSchema();//.setXsdSchema(Util.nodeToString(
// schema.getDocument()));
/*
* String schema1 = ((XSDTreeContentProvider) page.getViewer()
* .getContentProvider()).getXSDSchemaAsString(); wsObject.setXsdSchema(schema1); XMLEditor
* xmleditor=((XObjectEditor)page.getEditor()).getXmlEditor(); xmleditor.refresh(page.getXObject());
*/
page.markDirty();
page.refresh();
// page.refreshData();
getOperationHistory();
WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
typeList.clear();
return Status.OK_STATUS;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 0) {
copyElements();
WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
page.markDirty();
page.refresh();
// page.refreshData();
getOperationHistory();
return Status.OK_STATUS;
} else {
return Status.CANCEL_STATUS;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg1, e.getLocalizedMessage()));
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDSetAnnotationDocumentationAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent) selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetXX_ExceptionInfo, selection.getFirstElement().getClass().getName()));
}
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetXX_DialogTitle, Messages.XSDSetXX_DialogTip, struc.getDocumentation(), new IInputValidator() {
public String isValid(String newText) {
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
// $NON-NLS-1$
struc.setDocumentation("".equals(id.getValue()) ? null : id.getValue());
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetXX_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDEditFacetAction method editMinInclusive.
private void editMinInclusive() {
XSDMinInclusiveFacet currentValue = std.getMinInclusiveFacet();
String stringValue = null;
if (currentValue != null) {
stringValue = currentValue.getLexicalValue();
}
boolean isDateType = true;
dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle10, Messages.XSDEditFacetAction_DialogTitle10Tip, stringValue);
if (dialog == null) {
isDateType = false;
dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle10, Messages.XSDEditFacetAction_DialogTitle10Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
IInputValidator() {
public String isValid(String newText) {
if (newText.trim().isEmpty()) {
return null;
}
return isValidBoundaryNumber(std, newText);
}
});
}
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return;
}
if (currentValue != null) {
std.getFacetContents().remove(currentValue);
}
String input = ((InputDialog) dialog).getValue();
if (!input.trim().isEmpty()) {
XSDMinInclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinInclusiveFacet();
if (isDateType) {
f.setLexicalValue(input.trim());
std.getFacetContents().add(f);
} else if (Double.parseDouble(input) >= 0) {
// $NON-NLS-1$
f.setLexicalValue("" + getValidBoundaryNumber(std, input));
std.getFacetContents().add(f);
}
}
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDEditFacetAction method editFractionDigits.
private void editFractionDigits() {
XSDFractionDigitsFacet currentValue = std.getFractionDigitsFacet();
String stringValue = null;
if (currentValue != null) {
stringValue = currentValue.getLexicalValue();
}
dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle7, Messages.XSDEditFacetAction_DialogTitle7Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
IInputValidator() {
public String isValid(String newText) {
if (newText.trim().isEmpty()) {
return null;
}
int val;
try {
val = Integer.parseInt(newText);
} catch (Exception e) {
return Messages.XSDEditFacetAction_ValueMustBeXX;
}
if (val < 0) {
return Messages.XSDEditFacetAction_ValueMustBeXX;
}
return null;
}
});
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return;
}
if (currentValue != null) {
std.getFacetContents().remove(currentValue);
}
String input = ((InputDialog) dialog).getValue();
if (!input.trim().isEmpty()) {
int intValue = Integer.parseInt(input);
if (intValue >= 0) {
XSDFractionDigitsFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDFractionDigitsFacet();
// $NON-NLS-1$
f.setLexicalValue("" + intValue);
std.getFacetContents().add(f);
}
}
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDEditFacetAction method editMaxExclusive.
private void editMaxExclusive() {
XSDMaxExclusiveFacet currentValue = std.getMaxExclusiveFacet();
String stringValue = null;
if (currentValue != null) {
stringValue = currentValue.getLexicalValue();
}
boolean isDateType = true;
dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle9, Messages.XSDEditFacetAction_DialogTitle9Tip, stringValue);
if (dialog == null) {
isDateType = false;
dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle9, Messages.XSDEditFacetAction_DialogTitle9Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
IInputValidator() {
public String isValid(String newText) {
if (newText.trim().isEmpty()) {
return null;
}
return isValidBoundaryNumber(std, newText);
}
});
}
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return;
}
if (currentValue != null) {
std.getFacetContents().remove(currentValue);
}
String input = ((InputDialog) dialog).getValue();
if (!input.trim().isEmpty()) {
XSDMaxExclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMaxExclusiveFacet();
if (isDateType) {
f.setLexicalValue(input.trim());
std.getFacetContents().add(f);
} else if (Double.parseDouble(input) >= 0) {
// $NON-NLS-1$
f.setLexicalValue("" + getValidBoundaryNumber(std, input));
std.getFacetContents().add(f);
}
}
}
Aggregations