Search in sources :

Example 6 with XSDPatternFacet

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

the class SpecificConstraintsWidget method doModify.

public void doModify(Object element, String property, Object value) {
    setButtonStates(this.kind);
    if (element instanceof TableItem && (value != null)) {
        TableItem item = (TableItem) element;
        if (item.getData() instanceof XSDPatternFacet) {
            XSDPatternFacet patternFacet = (XSDPatternFacet) item.getData();
            patternFacet.setLexicalValue((String) value);
            item.setData(patternFacet);
            item.setText((String) value);
        } else if (item.getData() instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) item.getData();
            SetXSDFacetValueCommand command = new SetXSDFacetValueCommand(Messages._UI_ACTION_SET_ENUMERATION_VALUE, enumFacet);
            command.setValue((String) value);
            commandStack.execute(command);
            item.setData(enumFacet);
            item.setText((String) value);
        }
    }
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) TableItem(org.eclipse.swt.widgets.TableItem) SetXSDFacetValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetXSDFacetValueCommand)

Example 7 with XSDPatternFacet

use of org.eclipse.xsd.XSDPatternFacet 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 8 with XSDPatternFacet

use of org.eclipse.xsd.XSDPatternFacet in project tmdm-common by Talend.

the class MetadataRepository method setFieldData.

private void setFieldData(XSDSimpleTypeDefinition simpleSchemaType, MetadataExtensible field) {
    EList<XSDConstrainingFacet> facets = simpleSchemaType.getFacetContents();
    List<String> enumerationList = new ArrayList<String>();
    for (XSDConstrainingFacet currentFacet : facets) {
        if (currentFacet instanceof XSDMaxLengthFacet) {
            field.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinLengthFacet) {
            // this is the minLengthFacet
            field.setData(MetadataRepository.DATA_MIN_LENGTH, String.valueOf(((XSDMinLengthFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDLengthFacet) {
            // this is the lengthFacet
            field.setData(MetadataRepository.DATA_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
        } else if (currentFacet instanceof XSDTotalDigitsFacet) {
            // this is the totalDigits
            field.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDFractionDigitsFacet) {
            // this is the fractionDigits
            field.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDPatternFacet) {
            // this is the patternFacet
            field.setData(MetadataRepository.PATTERN, String.valueOf(((XSDPatternFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMaxExclusiveFacet) {
            // this is the  maxExclusiveFacet
            field.setData(MetadataRepository.MAX_EXCLUSIVE, String.valueOf(((XSDMaxExclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinExclusiveFacet) {
            // this is the  minExclusiveFacet
            field.setData(MetadataRepository.MIN_EXCLUSIVE, String.valueOf(((XSDMinExclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMaxInclusiveFacet) {
            // this is the  maxInclusiveFacet
            field.setData(MetadataRepository.MAX_INCLUSIVE, String.valueOf(((XSDMaxInclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinInclusiveFacet) {
            // this is the  minInclusiveFacet
            field.setData(MetadataRepository.MIN_INCLUSIVE, String.valueOf(((XSDMinInclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDEnumerationFacet) {
            // this is the  enumeration
            enumerationList.add(String.valueOf(((XSDEnumerationFacet) currentFacet).getLexicalValue()));
        }
    }
    field.setData(MetadataRepository.ENUMERATION_LIST, enumerationList);
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) ArrayList(java.util.ArrayList) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet)

Example 9 with XSDPatternFacet

use of org.eclipse.xsd.XSDPatternFacet in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editPattern.

private void editPattern() {
    List currentValues = std.getPatternFacets();
    ArrayList stringValues = new ArrayList();
    for (Iterator iter = currentValues.iterator(); iter.hasNext(); ) {
        XSDPatternFacet facet = (XSDPatternFacet) iter.next();
        stringValues.add(facet.getLexicalValue());
    }
    dialog = new FacetsListInputDialog(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            newValues = ((FacetsListInputDialog) dialog).getItems();
            dialog.close();
        }
    }, page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle1, stringValues);
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    std.getFacetContents().removeAll(currentValues);
    for (Iterator iter = newValues.iterator(); iter.hasNext(); ) {
        String element = (String) iter.next();
        XSDPatternFacet f = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
        f.setLexicalValue(element);
        std.getFacetContents().add(f);
    }
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)9 ArrayList (java.util.ArrayList)5 XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)5 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)4 Iterator (java.util.Iterator)3 List (java.util.List)3 SimpleTypeInputDialog (com.amalto.workbench.dialogs.SimpleTypeInputDialog)2 EList (org.eclipse.emf.common.util.EList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 XSDConstrainingFacet (org.eclipse.xsd.XSDConstrainingFacet)2 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)2 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)2 XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)2 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)2 XSDMaxInclusiveFacet (org.eclipse.xsd.XSDMaxInclusiveFacet)2 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)2 XSDMinExclusiveFacet (org.eclipse.xsd.XSDMinExclusiveFacet)2 XSDMinInclusiveFacet (org.eclipse.xsd.XSDMinInclusiveFacet)2 XSDMinLengthFacet (org.eclipse.xsd.XSDMinLengthFacet)2