Search in sources :

Example 61 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDPasteConceptAction method doAction.

@Override
public IStatus doAction() {
    try {
        conceptList = WorkbenchClipboard.getWorkbenchClipboard().getConcepts();
        XSDFactory factory = XSDFactory.eINSTANCE;
        if (!conceptList.isEmpty()) {
            // List<String> concepts = new ArrayList<String>();
            int index = 0;
            for (Iterator<XSDElementDeclaration> it = conceptList.iterator(); it.hasNext(); ) {
                if (conceptList.get(index).getSchema() != null) {
                    // concepts = Util.getConcepts(conceptList.get(index).getSchema());
                    typeList = Util.getTypeDefinition(conceptList.get(index).getSchema());
                }
                index++;
                Object concept = it.next();
                if (concept instanceof XSDElementDeclaration) {
                    // edit by ymli,fix the bug:0011523. let the element(simple or complex) can be pasted
                    // if (concepts.contains(((XSDElementDeclaration) concept).getName())) {
                    XSDElementDeclaration copy_concept = (XSDElementDeclaration) concept;
                    XSDElementDeclaration new_copy_concept = factory.createXSDElementDeclaration();
                    new_copy_concept = (XSDElementDeclaration) copy_concept.cloneConcreteComponent(true, false);
                    InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDPasteConceptAction_CopyElement, Messages.XSDPasteConceptAction_DialogTip, Messages.bind(Messages.XSDPasteConceptAction_CopyOf, copy_concept.getName()), new IInputValidator() {

                        public String isValid(String newText) {
                            if ((newText == null) || "".equals(newText)) {
                                return Messages.XSDPasteConceptAction_NameCannNotbeEmpty;
                            }
                            EList<XSDElementDeclaration> list = schema.getElementDeclarations();
                            for (XSDElementDeclaration d : list) {
                                if (d.getName().equalsIgnoreCase(newText)) {
                                    return Messages.XSDPasteConceptAction_EntityAlreadyExists;
                                }
                            }
                            return null;
                        }
                    });
                    id.setBlockOnOpen(true);
                    int ret = id.open();
                    if (ret == Window.CANCEL) {
                        return Status.CANCEL_STATUS;
                    }
                    new_copy_concept.setName(id.getValue());
                    for (int i = 0; i < new_copy_concept.getIdentityConstraintDefinitions().size(); i++) {
                        String name = new_copy_concept.getIdentityConstraintDefinitions().get(i).getName().replaceAll(copy_concept.getName(), new_copy_concept.getName());
                        new_copy_concept.getIdentityConstraintDefinitions().get(i).setName(name);
                    }
                    if (new_copy_concept.getAnonymousTypeDefinition() == null) {
                        XSDComplexTypeDefinition copyType = (XSDComplexTypeDefinition) copy_concept.getTypeDefinition().cloneConcreteComponent(true, false);
                        String originalName = copyType.getName();
                        // $NON-NLS-1$
                        String typeName = "Copy_of_" + originalName;
                        copyType.setName(typeName);
                        schema.getContents().add(copyType);
                        new_copy_concept.setTypeDefinition(copyType);
                    }
                    new_copy_concept.updateElement();
                    schema.getContents().add(new_copy_concept);
                    addAnnotationForXSDElementDeclaration(copy_concept, new_copy_concept);
                }
            }
            Map<String, XSDTypeDefinition> typeDef = Util.getTypeDefinition(schema);
            for (XSDTypeDefinition type : copyTypeSet) {
                if (typeDef.containsKey(type.getName())) {
                    continue;
                }
                XSDTypeDefinition typedefinitionClone = null;
                if (type instanceof XSDComplexTypeDefinition) {
                    typedefinitionClone = factory.createXSDComplexTypeDefinition();
                    typedefinitionClone = (XSDComplexTypeDefinition) type.cloneConcreteComponent(true, false);
                    schema.getContents().add(typedefinitionClone);
                    addAnnotationForComplexType((XSDComplexTypeDefinition) type, (XSDComplexTypeDefinition) typedefinitionClone);
                } else if (type instanceof XSDSimpleTypeDefinition) {
                    schema.getContents().add((XSDSimpleTypeDefinition) type.cloneConcreteComponent(true, false));
                }
            }
            schema.getElement();
            // WSDataModel wsObject = (WSDataModel)
            // (page.getXObject().getWsObject());
            // wsObject.getXsdSchema();//.setXsdSchema(Util.nodeToString(
            // schema.getDocument()));
            /*
                 * String schema1 = ((XSDTreeContentProvider) page.getViewer()
                 * .getContentProvider()).getXSDSchemaAsString(); wsObject.setXsdSchema(schema1); XMLEditor
                 * xmleditor=((XObjectEditor)page.getEditor()).getXmlEditor(); xmleditor.refresh(page.getXObject());
                 */
            page.markDirty();
            page.refresh();
            // page.refreshData();
            getOperationHistory();
            WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
            typeList.clear();
            return Status.OK_STATUS;
        } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 0) {
            copyElements();
            WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
            page.markDirty();
            page.refresh();
            // page.refreshData();
            getOperationHistory();
            return Status.OK_STATUS;
        } else {
            return Status.CANCEL_STATUS;
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg1, e.getLocalizedMessage()));
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) InputDialog(org.eclipse.jface.dialogs.InputDialog) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 62 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDSetAnnotationDocumentationAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent) selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetXX_ExceptionInfo, selection.getFirstElement().getClass().getName()));
        }
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetXX_DialogTitle, Messages.XSDSetXX_DialogTip, struc.getDocumentation(), new IInputValidator() {

            public String isValid(String newText) {
                return null;
            }
        });
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        // $NON-NLS-1$
        struc.setDocumentation("".equals(id.getValue()) ? null : id.getValue());
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 63 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editMinInclusive.

private void editMinInclusive() {
    XSDMinInclusiveFacet currentValue = std.getMinInclusiveFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    boolean isDateType = true;
    dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle10, Messages.XSDEditFacetAction_DialogTitle10Tip, stringValue);
    if (dialog == null) {
        isDateType = false;
        dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle10, Messages.XSDEditFacetAction_DialogTitle10Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
        IInputValidator() {

            public String isValid(String newText) {
                if (newText.trim().isEmpty()) {
                    return null;
                }
                return isValidBoundaryNumber(std, newText);
            }
        });
    }
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    String input = ((InputDialog) dialog).getValue();
    if (!input.trim().isEmpty()) {
        XSDMinInclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinInclusiveFacet();
        if (isDateType) {
            f.setLexicalValue(input.trim());
            std.getFacetContents().add(f);
        } else if (Double.parseDouble(input) >= 0) {
            // $NON-NLS-1$
            f.setLexicalValue("" + getValidBoundaryNumber(std, input));
            std.getFacetContents().add(f);
        }
    }
}
Also used : XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 64 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editFractionDigits.

private void editFractionDigits() {
    XSDFractionDigitsFacet currentValue = std.getFractionDigitsFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle7, Messages.XSDEditFacetAction_DialogTitle7Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
    IInputValidator() {

        public String isValid(String newText) {
            if (newText.trim().isEmpty()) {
                return null;
            }
            int val;
            try {
                val = Integer.parseInt(newText);
            } catch (Exception e) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            if (val < 0) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            return null;
        }
    });
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    String input = ((InputDialog) dialog).getValue();
    if (!input.trim().isEmpty()) {
        int intValue = Integer.parseInt(input);
        if (intValue >= 0) {
            XSDFractionDigitsFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDFractionDigitsFacet();
            // $NON-NLS-1$
            f.setLexicalValue("" + intValue);
            std.getFacetContents().add(f);
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 65 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editMaxExclusive.

private void editMaxExclusive() {
    XSDMaxExclusiveFacet currentValue = std.getMaxExclusiveFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    boolean isDateType = true;
    dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle9, Messages.XSDEditFacetAction_DialogTitle9Tip, stringValue);
    if (dialog == null) {
        isDateType = false;
        dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle9, Messages.XSDEditFacetAction_DialogTitle9Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
        IInputValidator() {

            public String isValid(String newText) {
                if (newText.trim().isEmpty()) {
                    return null;
                }
                return isValidBoundaryNumber(std, newText);
            }
        });
    }
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    String input = ((InputDialog) dialog).getValue();
    if (!input.trim().isEmpty()) {
        XSDMaxExclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMaxExclusiveFacet();
        if (isDateType) {
            f.setLexicalValue(input.trim());
            std.getFacetContents().add(f);
        } else if (Double.parseDouble(input) >= 0) {
            // $NON-NLS-1$
            f.setLexicalValue("" + getValidBoundaryNumber(std, input));
            std.getFacetContents().add(f);
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)101 InputDialog (org.eclipse.jface.dialogs.InputDialog)88 Composite (org.eclipse.swt.widgets.Composite)20 IStatus (org.eclipse.core.runtime.IStatus)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 ArrayList (java.util.ArrayList)12 Button (org.eclipse.swt.widgets.Button)12 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 List (java.util.List)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Label (org.eclipse.swt.widgets.Label)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Control (org.eclipse.swt.widgets.Control)7 Display (org.eclipse.swt.widgets.Display)7 IResource (org.eclipse.core.resources.IResource)6 CoreException (org.eclipse.core.runtime.CoreException)6 Window (org.eclipse.jface.window.Window)6 Event (org.eclipse.swt.widgets.Event)6