use of org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand in project webtools.sourceediting by eclipse.
the class SpecificConstraintsWidget method widgetSelected.
public void widgetSelected(SelectionEvent e) {
XSDSimpleTypeDefinition st = input;
if (e.widget == addButton) {
List enumList = st.getEnumerationFacets();
// $NON-NLS-1$
String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
if (kind == ENUMERATION) {
CompoundCommand compoundCommand = new CompoundCommand();
XSDSimpleTypeDefinition targetSimpleType = null;
if (feature != null) {
XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input);
if (anonymousSimpleType == null) {
anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
anonymousSimpleType.setBaseTypeDefinition(input);
ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CHANGE_PATTERN, feature);
changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
compoundCommand.add(changeToAnonymousCommand);
input = anonymousSimpleType;
}
targetSimpleType = anonymousSimpleType;
} else {
targetSimpleType = input;
}
AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, targetSimpleType);
command.setValue(newName);
compoundCommand.add(command);
commandStack.execute(compoundCommand);
setInput(input);
constraintsTableViewer.refresh();
int newItemIndex = constraintsTableViewer.getTable().getItemCount() - 1;
constraintsTableViewer.editElement(constraintsTableViewer.getElementAt(newItemIndex), 0);
}
} else if (e.widget == addUsingDialogButton) {
Display display = Display.getCurrent();
// if it is null, get the default one
display = display == null ? Display.getDefault() : display;
Shell shell = display.getActiveShell();
if (kind == PATTERN) {
// $NON-NLS-1$
String initialValue = "";
RegexWizard wizard = new RegexWizard(initialValue);
WizardDialog wizardDialog = new WizardDialog(shell, wizard);
wizardDialog.setBlockOnOpen(true);
wizardDialog.create();
int result = wizardDialog.open();
if (result == Window.OK) {
String newPattern = wizard.getPattern();
CompoundCommand compoundCommand = new CompoundCommand();
XSDSimpleTypeDefinition targetSimpleType = null;
if (feature != null) {
XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input);
if (anonymousSimpleType == null) {
anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
anonymousSimpleType.setBaseTypeDefinition(input);
ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CHANGE_PATTERN, feature);
changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
compoundCommand.add(changeToAnonymousCommand);
input = anonymousSimpleType;
}
targetSimpleType = anonymousSimpleType;
} else {
targetSimpleType = input;
}
UpdateXSDPatternFacetCommand command = new UpdateXSDPatternFacetCommand(Messages._UI_ACTION_ADD_PATTERN, targetSimpleType, UpdateXSDPatternFacetCommand.ADD);
command.setValue(newPattern);
setInput(input);
compoundCommand.add(command);
commandStack.execute(compoundCommand);
facetSection.doSetInput();
}
constraintsTableViewer.refresh();
} else {
EnumerationsDialog dialog = new EnumerationsDialog(shell);
dialog.setBlockOnOpen(true);
int result = dialog.open();
if (result == Window.OK) {
String text = dialog.getText();
String delimiter = dialog.getDelimiter();
StringTokenizer tokenizer = new StringTokenizer(text, delimiter);
CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_ADD_ENUMERATIONS);
XSDSimpleTypeDefinition targetSimpleType = null;
if (feature != null) {
XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input);
if (anonymousSimpleType == null) {
anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
anonymousSimpleType.setBaseTypeDefinition(input);
// $NON-NLS-1$
ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand("", feature);
changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
compoundCommand.add(changeToAnonymousCommand);
input = anonymousSimpleType;
}
targetSimpleType = anonymousSimpleType;
} else {
targetSimpleType = input;
}
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (dialog.isPreserveWhitespace() == false) {
token = token.trim();
}
AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATIONS, targetSimpleType);
command.setValue(token);
compoundCommand.add(command);
}
commandStack.execute(compoundCommand);
}
// setInput(input);
facetSection.doSetInput();
constraintsTableViewer.refresh();
}
} else if (e.widget == deleteButton) {
StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection();
CompoundCommand compoundCommand = new CompoundCommand();
if (selection != null) {
Iterator i = selection.iterator();
if (selection.size() > 0) {
compoundCommand.setLabel(Messages._UI_ACTION_DELETE_CONSTRAINTS);
} else {
compoundCommand.setLabel(Messages._UI_ACTION_DELETE_PATTERN);
}
while (i.hasNext()) {
Object obj = i.next();
if (obj != null) {
if (obj instanceof XSDPatternFacet) {
// $NON-NLS-1$
UpdateXSDPatternFacetCommand command = new UpdateXSDPatternFacetCommand("", input, UpdateXSDPatternFacetCommand.DELETE);
command.setPatternToEdit((XSDPatternFacet) obj);
compoundCommand.add(command);
} else if (obj instanceof XSDEnumerationFacet) {
XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj;
DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet);
compoundCommand.add(deleteCommand);
}
}
}
commandStack.execute(compoundCommand);
constraintsTableViewer.refresh();
}
} else if (e.widget == editButton) {
StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection();
if (selection != null) {
Object obj = selection.getFirstElement();
if (obj instanceof XSDPatternFacet) {
XSDPatternFacet pattern = (XSDPatternFacet) obj;
String initialValue = pattern.getLexicalValue();
if (initialValue == null) {
// $NON-NLS-1$
initialValue = "";
}
Shell shell = Display.getCurrent().getActiveShell();
RegexWizard wizard = new RegexWizard(initialValue);
WizardDialog wizardDialog = new WizardDialog(shell, wizard);
wizardDialog.setBlockOnOpen(true);
wizardDialog.create();
int result = wizardDialog.open();
if (result == Window.OK) {
String newPattern = wizard.getPattern();
pattern.setLexicalValue(newPattern);
constraintsTableViewer.refresh();
}
}
}
}
setButtonStates(this.kind);
}
use of org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand 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.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand 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