use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateStringLengthFacetCommand in project webtools.sourceediting by eclipse.
the class XSDFacetSection method doHandleEvent.
protected void doHandleEvent(Event event) {
super.doHandleEvent(event);
Command command = null;
boolean doUpdateMax = false, doUpdateMin = false;
boolean doSetInput = false;
String minValue = minLengthText.getText().trim();
String maxValue = maxLengthText.getText().trim();
XSDLengthFacet lengthFacet = xsdSimpleTypeDefinition.getLengthFacet();
XSDMinLengthFacet minLengthFacet = xsdSimpleTypeDefinition.getMinLengthFacet();
XSDMaxLengthFacet maxLengthFacet = xsdSimpleTypeDefinition.getMaxLengthFacet();
XSDMinInclusiveFacet minInclusiveFacet = xsdSimpleTypeDefinition.getMinInclusiveFacet();
XSDMinExclusiveFacet minExclusiveFacet = xsdSimpleTypeDefinition.getMinExclusiveFacet();
XSDMaxInclusiveFacet maxInclusiveFacet = xsdSimpleTypeDefinition.getMaxInclusiveFacet();
XSDMaxExclusiveFacet maxExclusiveFacet = xsdSimpleTypeDefinition.getMaxExclusiveFacet();
String currentMinInclusive = null, currentMinExclusive = null, currentMaxInclusive = null, currentMaxExclusive = null;
if (minInclusiveFacet != null) {
currentMinInclusive = minInclusiveFacet.getLexicalValue();
}
if (minExclusiveFacet != null) {
currentMinExclusive = minExclusiveFacet.getLexicalValue();
}
if (maxInclusiveFacet != null) {
currentMaxInclusive = maxInclusiveFacet.getLexicalValue();
}
if (maxExclusiveFacet != null) {
currentMaxExclusive = maxExclusiveFacet.getLexicalValue();
}
String currentLength = null, currentMin = null, currentMax = null;
if (lengthFacet != null) {
currentLength = lengthFacet.getLexicalValue();
}
if (minLengthFacet != null) {
currentMin = minLengthFacet.getLexicalValue();
}
if (maxLengthFacet != null) {
currentMax = maxLengthFacet.getLexicalValue();
}
if (event.widget == minLengthText) {
try {
if (minValue.length() > 0) {
if (!isNumericBaseType) {
Number big = new BigInteger(minValue);
big.toString();
if (minLengthFacet != null) {
if (minValue.equals(currentMin) || minValue.equals(currentLength))
return;
} else {
if (maxValue != null && minValue.equals(maxValue) && lengthFacet != null) {
return;
}
}
} else {
if (// $NON-NLS-1$
xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) {
BigDecimal bigDecimal = new BigDecimal(minValue);
bigDecimal.toString();
if ((currentMinInclusive != null && minValue.equals(currentMinInclusive)) || (currentMinExclusive != null && minValue.equals(currentMinExclusive))) {
return;
}
} else {
Number big = new BigInteger(minValue);
big.toString();
}
minimumInclusiveCheckbox.setEnabled(true);
}
} else {
if (!isNumericBaseType) {
if (currentMin == null && currentLength == null)
return;
} else {
if (currentMinInclusive == null && minimumInclusiveCheckbox.getSelection()) {
return;
} else if (currentMinExclusive == null && !minimumInclusiveCheckbox.getSelection()) {
return;
}
}
minimumInclusiveCheckbox.setEnabled(false);
minValue = null;
}
doUpdateMin = true;
} catch (NumberFormatException e) {
// TODO show error message
doUpdateMin = false;
}
}
if (event.widget == maxLengthText) {
try {
if (maxValue.length() > 0) {
if (!isNumericBaseType) {
Number big = new BigInteger(maxValue);
big.toString();
if (maxLengthFacet != null) {
if (maxValue.equals(currentMax) || maxValue.equals(currentLength))
return;
} else {
if (minValue != null && maxValue.equals(minValue) && lengthFacet != null) {
return;
}
}
} else {
if (// $NON-NLS-1$
xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) {
BigDecimal bigDecimal = new BigDecimal(maxValue);
bigDecimal.toString();
} else {
Number big = new BigInteger(maxValue);
big.toString();
}
maximumInclusiveCheckbox.setEnabled(true);
}
} else {
if (!isNumericBaseType) {
if (currentMax == null && currentLength == null)
return;
} else {
if (currentMaxInclusive == null && maximumInclusiveCheckbox.getSelection()) {
return;
} else if (currentMaxExclusive == null && !maximumInclusiveCheckbox.getSelection()) {
return;
}
maximumInclusiveCheckbox.setEnabled(false);
}
maxValue = null;
}
doUpdateMax = true;
} catch (NumberFormatException e) {
doUpdateMax = false;
// TODO show error message
}
}
if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace()) && (doUpdateMax || doUpdateMin)) {
XSDSimpleTypeDefinition anonymousSimpleType = null;
CompoundCommand compoundCommand = new CompoundCommand();
ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = null;
if (input instanceof XSDFeature) {
anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature) input, xsdSimpleTypeDefinition);
if (anonymousSimpleType == null) {
anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition);
changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature) input);
changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
compoundCommand.add(changeToAnonymousCommand);
doSetInput = true;
}
if (!isNumericBaseType) {
// $NON-NLS-1$
UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", anonymousSimpleType);
if (doUpdateMax) {
updateCommand.setMax(maxValue);
}
if (doUpdateMin) {
updateCommand.setMin(minValue);
}
compoundCommand.add(updateCommand);
} else {
UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, anonymousSimpleType, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
if (doUpdateMax) {
updateCommand.setMax(maxValue);
}
if (doUpdateMin) {
updateCommand.setMin(minValue);
}
compoundCommand.add(updateCommand);
}
command = compoundCommand;
getCommandStack().execute(command);
} else if (input instanceof XSDSimpleTypeDefinition) {
if (!isNumericBaseType) {
// $NON-NLS-1$
UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition);
if (doUpdateMax) {
updateCommand.setMax(maxValue);
}
if (doUpdateMin) {
updateCommand.setMin(minValue);
}
command = updateCommand;
} else {
UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
if (doUpdateMax) {
updateCommand.setMax(maxValue);
}
if (doUpdateMin) {
updateCommand.setMin(minValue);
}
command = updateCommand;
}
getCommandStack().execute(command);
}
} else {
if (!isNumericBaseType) {
// $NON-NLS-1$
UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition);
if (doUpdateMax) {
updateCommand.setMax(maxValue);
}
if (doUpdateMin) {
updateCommand.setMin(minValue);
}
getCommandStack().execute(updateCommand);
} else {
UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
if (doUpdateMax) {
updateCommand.setMax(maxValue);
}
if (doUpdateMin) {
updateCommand.setMin(minValue);
}
getCommandStack().execute(updateCommand);
}
}
refresh();
if (doSetInput)
setInput(getPart(), getSelection());
}
Aggregations