use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDFacetSection method widgetSelected.
public void widgetSelected(SelectionEvent e) {
if (e.widget == collapseWhitespaceButton) {
CompoundCommand compoundCommand = new CompoundCommand();
XSDSimpleTypeDefinition anonymousSimpleType = null;
if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
if (input instanceof XSDFeature) {
anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature) input, xsdSimpleTypeDefinition);
if (anonymousSimpleType == null) {
anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition);
ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature) input);
changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
compoundCommand.add(changeToAnonymousCommand);
}
UpdateXSDWhiteSpaceFacetCommand whiteSpaceCommand = new UpdateXSDWhiteSpaceFacetCommand(Messages._UI_ACTION_COLLAPSE_WHITESPACE, anonymousSimpleType, collapseWhitespaceButton.getSelection());
compoundCommand.add(whiteSpaceCommand);
getCommandStack().execute(compoundCommand);
}
setInput(getPart(), getSelection());
} else {
UpdateXSDWhiteSpaceFacetCommand whiteSpaceCommand = new UpdateXSDWhiteSpaceFacetCommand(Messages._UI_ACTION_COLLAPSE_WHITESPACE, xsdSimpleTypeDefinition, collapseWhitespaceButton.getSelection());
getCommandStack().execute(whiteSpaceCommand);
}
} else if (e.widget == minimumInclusiveCheckbox) {
String minValue = minLengthText.getText().trim();
if (minValue.length() == 0)
minValue = null;
UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
updateCommand.setMin(minValue);
if (minValue != null)
getCommandStack().execute(updateCommand);
} else if (e.widget == maximumInclusiveCheckbox) {
String maxValue = maxLengthText.getText().trim();
if (maxValue.length() == 0)
maxValue = null;
UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
updateCommand.setMax(maxValue);
if (maxValue != null)
getCommandStack().execute(updateCommand);
} else if (e.widget == useEnumerationsButton) {
constraintsWidget.addButton.setEnabled(true);
if (isListenerEnabled()) {
constraintsWidget.setConstraintKind(SpecificConstraintsWidget.ENUMERATION);
constraintKind = constraintsWidget.getConstraintKind();
}
} else if (e.widget == usePatternsButton) {
constraintsWidget.addButton.setEnabled(false);
if (isListenerEnabled()) {
constraintsWidget.setConstraintKind(SpecificConstraintsWidget.PATTERN);
constraintKind = constraintsWidget.getConstraintKind();
}
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition 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());
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDFacetSection method refreshValueLengths.
public void refreshValueLengths() {
XSDSimpleTypeDefinition type = xsdSimpleTypeDefinition;
XSDMinFacet minFacet = type.getMinFacet();
XSDMaxFacet maxFacet = type.getMaxFacet();
if (minFacet != null && minFacet.getRootContainer() == xsdSchema) {
if (minFacet.getElement().getLocalName().equals(XSDConstants.MINEXCLUSIVE_ELEMENT_TAG) || minFacet.getElement().getLocalName().equals(XSDConstants.MININCLUSIVE_ELEMENT_TAG)) {
minLengthText.setText(minFacet.getLexicalValue());
minimumInclusiveCheckbox.setSelection(minFacet.isInclusive());
minimumInclusiveCheckbox.setEnabled(true);
} else {
// $NON-NLS-1$
minLengthText.setText("");
}
} else {
minimumInclusiveCheckbox.setSelection(false);
minimumInclusiveCheckbox.setEnabled(false);
}
if (maxFacet != null && maxFacet.getRootContainer() == xsdSchema) {
if (maxFacet.getElement().getLocalName().equals(XSDConstants.MAXEXCLUSIVE_ELEMENT_TAG) || maxFacet.getElement().getLocalName().equals(XSDConstants.MAXINCLUSIVE_ELEMENT_TAG)) {
maxLengthText.setText(maxFacet.getLexicalValue());
maximumInclusiveCheckbox.setSelection(maxFacet.isInclusive());
maximumInclusiveCheckbox.setEnabled(true);
} else {
// $NON-NLS-1$
maxLengthText.setText("");
}
} else {
maximumInclusiveCheckbox.setSelection(false);
maximumInclusiveCheckbox.setEnabled(false);
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDFacetSection method updateInput.
private void updateInput() {
previousPrimitiveType = currentPrimitiveType;
if (input instanceof XSDFeature) {
xsdFeature = (XSDFeature) input;
typeDefinition = xsdFeature.getResolvedFeature().getType();
XSDTypeDefinition anonymousTypeDefinition = null;
if (xsdFeature instanceof XSDElementDeclaration) {
xsdElementDeclaration = (XSDElementDeclaration) xsdFeature;
anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition();
} else if (xsdFeature instanceof XSDAttributeDeclaration) {
xsdAttributeDeclaration = (XSDAttributeDeclaration) xsdFeature;
anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition();
}
if (typeDefinition instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition;
}
if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) anonymousTypeDefinition;
}
if (xsdSimpleTypeDefinition != null) {
if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition();
String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : "";
currentPrimitiveType = basePrimitiveType;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
} else {
currentPrimitiveType = xsdSimpleTypeDefinition;
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName());
}
}
} else if (input instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input;
currentPrimitiveType = xsdSimpleTypeDefinition;
// $NON-NLS-1$ //$NON-NLS-2$
titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDSimpleTypeSection method refresh.
public void refresh() {
super.refresh();
setListenerEnabled(false);
showLink(!hideHyperLink);
// $NON-NLS-1$
nameText.setText("");
// $NON-NLS-1$
varietyCombo.setText("");
// $NON-NLS-1$
typesCombo.setText("");
fillTypesCombo();
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON"));
if (input instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
String simpleTypeName = st.getName();
if (simpleTypeName != null) {
nameText.setText(simpleTypeName);
nameText.setEditable(true);
} else {
// $NON-NLS-1$);
nameText.setText("**anonymous**");
nameText.setEditable(false);
}
String variety = st.getVariety().getName();
int intVariety = st.getVariety().getValue();
XSDDOMHelper domHelper = new XSDDOMHelper();
if (domHelper.getDerivedByElementFromSimpleType(st.getElement()) != null) {
if (variety != null) {
varietyCombo.setText(variety);
if (intVariety == XSDVariety.ATOMIC) {
baseTypeDefinition = st.getBaseTypeDefinition();
// $NON-NLS-1$
String name = "";
if (baseTypeDefinition != null) {
name = baseTypeDefinition.getName();
if (name == null)
name = "";
}
typesCombo.setText(name);
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON"));
} else if (intVariety == XSDVariety.LIST) {
itemTypeDefinition = st.getItemTypeDefinition();
// $NON-NLS-1$
String name = "";
if (itemTypeDefinition != null) {
name = itemTypeDefinition.getName();
if (name == null)
name = "";
}
typesCombo.setText(name);
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_ITEM_TYPE"));
} else if (intVariety == XSDVariety.UNION) {
List memberTypesList = st.getMemberTypeDefinitions();
StringBuffer sb = new StringBuffer();
for (Iterator i = memberTypesList.iterator(); i.hasNext(); ) {
XSDSimpleTypeDefinition typeObject = (XSDSimpleTypeDefinition) i.next();
String name = typeObject.getQName();
if (name != null) {
sb.append(name);
if (i.hasNext()) {
// $NON-NLS-1$
sb.append(" ");
}
}
}
String memberTypes = sb.toString();
typesCombo.setText(memberTypes);
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES"));
}
}
}
}
setListenerEnabled(true);
}
Aggregations