use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class EnumerationsSection method widgetSelected.
public void widgetSelected(SelectionEvent e) {
XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
if (e.widget == addButton) {
List enumList = st.getEnumerationFacets();
// $NON-NLS-1$
String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, (XSDSimpleTypeDefinition) input);
command.setValue(newName);
getCommandStack().execute(command);
enumerationsTable.refresh();
int newItemIndex = enumerationsTable.getTable().getItemCount() - 1;
enumerationsTable.editElement(enumerationsTable.getElementAt(newItemIndex), 0);
} else if (e.widget == addManyButton) {
Display display = Display.getCurrent();
// if it is null, get the default one
display = display == null ? Display.getDefault() : display;
Shell parentShell = display.getActiveShell();
EnumerationsDialog dialog = new EnumerationsDialog(parentShell);
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);
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (dialog.isPreserveWhitespace() == false) {
token = token.trim();
}
AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATIONS, (XSDSimpleTypeDefinition) input);
command.setValue(token);
compoundCommand.add(command);
}
getCommandStack().execute(compoundCommand);
}
enumerationsTable.refresh();
} else if (e.widget == deleteButton) {
StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection();
if (selection != null) {
Iterator i = selection.iterator();
CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_DELETE_ENUMERATION);
while (i.hasNext()) {
Object obj = i.next();
if (obj != null) {
if (obj instanceof XSDEnumerationFacet) {
XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj;
DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet);
compoundCommand.add(deleteCommand);
}
}
}
getCommandStack().execute(compoundCommand);
enumerationsTable.refresh();
}
} else if (e.widget == enumerationsTable.getTable()) {
StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection();
if (selection.getFirstElement() != null) {
deleteButton.setEnabled(true);
} else {
deleteButton.setEnabled(false);
}
}
}
use of com.ibm.icu.util.StringTokenizer 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 com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class XSDSimpleTypeSection method addCreateElementActionIfNotExist.
// issue (cs) this method seems to be utilizing 'old' classes, can we reimplement?
// (e.g. ChangeElementAction, XSDDOMHelper, etc)
protected boolean addCreateElementActionIfNotExist(String elementTag, String label, Element parent, Node relativeNode) {
XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
List attributes = new ArrayList();
String reuseType = null;
// parent); //$NON-NLS-1$
if (elementTag.equals(XSDConstants.RESTRICTION_ELEMENT_TAG)) {
Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false);
if (listNode != null) {
if (listNode.hasAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE))
reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE);
XSDDOMHelper.removeNodeAndWhitespace(listNode);
}
Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false);
if (unionNode != null) {
if (unionNode.hasAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE)) {
String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE);
StringTokenizer stringTokenizer = new StringTokenizer(memberAttr);
reuseType = stringTokenizer.nextToken();
}
XSDDOMHelper.removeNodeAndWhitespace(unionNode);
}
if (reuseType == null) {
reuseType = getBuiltInStringQName();
}
attributes.add(new DOMAttribute(XSDConstants.BASE_ATTRIBUTE, reuseType));
st.setItemTypeDefinition(null);
} else if (elementTag.equals(XSDConstants.LIST_ELEMENT_TAG)) {
Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false);
if (restrictionNode != null) {
reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE);
XSDDOMHelper.removeNodeAndWhitespace(restrictionNode);
}
Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false);
if (unionNode != null) {
String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE);
if (memberAttr != null) {
StringTokenizer stringTokenizer = new StringTokenizer(memberAttr);
reuseType = stringTokenizer.nextToken();
}
XSDDOMHelper.removeNodeAndWhitespace(unionNode);
}
attributes.add(new DOMAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE, reuseType));
} else if (elementTag.equals(XSDConstants.UNION_ELEMENT_TAG)) {
Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false);
if (listNode != null) {
reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE);
XSDDOMHelper.removeNodeAndWhitespace(listNode);
}
Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false);
if (restrictionNode != null) {
reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE);
XSDDOMHelper.removeNodeAndWhitespace(restrictionNode);
}
attributes.add(new DOMAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE, reuseType));
st.setItemTypeDefinition(null);
}
if (getFirstChildNodeIfExists(parent, elementTag, false) == null) {
Action action = addCreateElementAction(elementTag, label, attributes, parent, relativeNode);
action.run();
}
st.setElement(parent);
st.updateElement();
// endRecording(parent);
return true;
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class XMLSearchPattern method matches.
public boolean matches(XMLSearchPattern pattern) {
if (pattern.searchName == null)
return false;
if ("*".equals(searchName) && "*".equals(searchNamespace)) {
// $NON-NLS-1$ //$NON-NLS-2$
return true;
}
final StringTokenizer tokenizer = new StringTokenizer(pattern.searchName);
while (tokenizer.hasMoreTokens()) {
final String token = tokenizer.nextToken();
// $NON-NLS-1$
int n = token.indexOf(":");
String name = token;
// accept the default
String namespace = pattern.searchNamespace;
if (n > 0) {
final String prefix = token.substring(0, n);
name = token.substring(n + 1);
namespace = pattern.element != null ? (String) pattern.element.getNamespaceMap().get(prefix) : computeNamespaceForPrefix(pattern.domElement, prefix);
}
if (namespace == null) {
if (name.equals(searchName) || "*".equals(searchName))
return true;
} else {
if ((namespace.equals(searchNamespace) || "*".equals(searchNamespace) || ("".equals(namespace) && searchNamespace == null)) && name.equals(searchName))
return true;
}
}
return false;
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class ReferencedFileErrorDialog method setStyledText.
private void setStyledText(StyledText styledText, String text) {
// $NON-NLS-1$
String visibleMessage = "";
for (// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(markedUpDetailsMessage, "'", false); // $NON-NLS-1$
st.hasMoreTokens(); ) {
String token = st.nextToken();
visibleMessage += token;
}
styledText.setText(visibleMessage);
// dw Font font = styledText.getFont();
boolean inQuote = false;
int position = 0;
for (// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(markedUpDetailsMessage, "'", true); // $NON-NLS-1$
st.hasMoreTokens(); ) {
String token = st.nextToken();
if (// $NON-NLS-1$
token.equals("'")) {
inQuote = !inQuote;
} else {
if (inQuote) {
try {
StyleRange style = new StyleRange(position, token.length(), styledText.getForeground(), styledText.getBackground(), SWT.BOLD);
styledText.setStyleRange(style);
} catch (Exception e) {
e.printStackTrace();
}
}
position = position + token.length();
}
}
}
Aggregations