Search in sources :

Example 26 with StringTokenizer

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);
        }
    }
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AddEnumerationsCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteCommand(org.eclipse.wst.xsd.ui.internal.common.commands.DeleteCommand) Shell(org.eclipse.swt.widgets.Shell) StringTokenizer(com.ibm.icu.util.StringTokenizer) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EnumerationsDialog(org.eclipse.wst.xsd.ui.internal.widgets.EnumerationsDialog) Display(org.eclipse.swt.widgets.Display)

Example 27 with StringTokenizer

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);
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) UpdateXSDPatternFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDPatternFacetCommand) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RegexWizard(org.eclipse.wst.xsd.ui.internal.wizards.RegexWizard) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) AddEnumerationsCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand) DeleteCommand(org.eclipse.wst.xsd.ui.internal.common.commands.DeleteCommand) Shell(org.eclipse.swt.widgets.Shell) StringTokenizer(com.ibm.icu.util.StringTokenizer) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) ChangeToLocalSimpleTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EnumerationsDialog(org.eclipse.wst.xsd.ui.internal.widgets.EnumerationsDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Display(org.eclipse.swt.widgets.Display)

Example 28 with StringTokenizer

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;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) CreateElementAction(org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction) Action(org.eclipse.jface.action.Action) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DOMAttribute(org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 29 with StringTokenizer

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;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer)

Example 30 with StringTokenizer

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();
        }
    }
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Aggregations

StringTokenizer (com.ibm.icu.util.StringTokenizer)53 ArrayList (java.util.ArrayList)9 List (java.util.List)6 HashSet (java.util.HashSet)4 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)4 Attr (org.w3c.dom.Attr)4 Set (java.util.Set)3 Point (org.eclipse.swt.graphics.Point)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 InputStream (java.io.InputStream)2 Iterator (java.util.Iterator)2 Pattern (java.util.regex.Pattern)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 IDocument (org.eclipse.jface.text.IDocument)2