Search in sources :

Example 36 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class AddXSDEnumerationFacetAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        int index = -1;
        AddEnumerationsCommand command = null;
        XSDSimpleTypeDefinition st = null;
        if (selection instanceof XSDSimpleTypeDefinition) {
            st = (XSDSimpleTypeDefinition) selection;
            command = new AddEnumerationsCommand(getText(), st);
        } else if (selection instanceof XSDEnumerationFacet) {
            st = ((XSDEnumerationFacet) selection).getSimpleTypeDefinition();
            index = st.getFacetContents().indexOf(selection);
            doDirectEdit = true;
            command = new AddEnumerationsCommand(getText(), st, getId(), index);
        } else if (// Support for Complex Type's simple Content with enumerations
        selection instanceof XSDComplexTypeDefinition) {
            st = (XSDSimpleTypeDefinition) ((XSDComplexTypeDefinition) selection).getContent();
            command = new AddEnumerationsCommand(getText(), st);
        } else // null
        {
            return;
        }
        List enumList = st.getEnumerationFacets();
        // $NON-NLS-1$
        String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
        command.setValue(newName);
        getCommandStack().execute(command);
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) List(java.util.List) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) AddEnumerationsCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand)

Example 37 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class RedefineSimpleTypeCommand method doExecute.

protected void doExecute() {
    XSDSimpleTypeDefinition redefinedSimpleTypeDefinition = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    redefinedSimpleTypeDefinition.setName(redefinableComponent.getName());
    redefinedSimpleTypeDefinition.setBaseTypeDefinition((XSDSimpleTypeDefinition) redefinableComponent);
    addedXSDConcreteComponent = redefinedSimpleTypeDefinition;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition)

Example 38 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class SetBaseTypeAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        boolean complexType = selection instanceof XSDComplexTypeDefinition;
        boolean simpleType = selection instanceof XSDSimpleTypeDefinition;
        if (complexType || simpleType) {
            if (getWorkbenchPart() instanceof IEditorPart) {
                IEditorPart editor = (IEditorPart) getWorkbenchPart();
                ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
                ComponentSpecification newValue;
                IComponentDialog dialog = null;
                dialog = manager.getBrowseDialog();
                if (dialog != null) {
                    if (simpleType) {
                        ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
                    }
                    if (dialog.createAndOpen() == Window.OK) {
                        newValue = dialog.getSelectedComponent();
                        manager.modifyComponentReference(selection, newValue);
                    }
                }
            }
        }
    }
}
Also used : IComponentDialog(org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog) XSDComplexTypeBaseTypeEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSearchListDialogDelegate(org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)

Example 39 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDImpl method getEnumeratedValuesForSimpleType.

private static void getEnumeratedValuesForSimpleType(XSDTypeDefinition type, List result) {
    List enumerationFacets = ((XSDSimpleTypeDefinition) type).getEnumerationFacets();
    for (Iterator i = enumerationFacets.iterator(); i.hasNext(); ) {
        XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next();
        List values = enumFacet.getValue();
        for (Iterator j = values.iterator(); j.hasNext(); ) {
            Object o = j.next();
            if (o != null) {
                if (!result.contains(o)) {
                    result.add(o.toString());
                }
            }
        }
    }
}
Also used : XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Iterator(java.util.Iterator) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) EObject(org.eclipse.emf.ecore.EObject)

Example 40 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition 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)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11