Search in sources :

Example 21 with IInputValidator

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

the class XSDEditConceptAction method doAction.

@Override
public IStatus doAction() {
    try {
        ISelection selection = page.getTreeViewer().getSelection();
        XSDElementDeclaration decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer().getContentProvider();
        String oldName = decl.getName();
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditConceptAction_Text, Messages.XSDEditConceptAction_DialogTip, oldName, new IInputValidator() {

            public String isValid(String newText) {
                if ((newText == null) || "".equals(newText)) {
                    return Messages.XSDEditConceptAction_NameCannotBeEmpty;
                }
                if (// $NON-NLS-1$
                Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches() || newText.trim().replaceAll("\\s", "").length() != newText.trim().length()) {
                    return Messages.XSDEditConceptAction_NameCannotContainEmpty;
                }
                if (!XSDUtil.isValidatedXSDName(newText)) {
                    return Messages.InvalidName_Message;
                }
                EList list = schema.getElementDeclarations();
                for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                    XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
                    if (d.getName().equalsIgnoreCase(newText.trim())) {
                        return Messages.XSDEditConceptAction_EntityAlreadyExist;
                    }
                }
                return null;
            }
        });
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        Object[] objs = Util.getAllObject(page.getSite(), objList, provider);
        Object[] allForeignKeyRelatedInfos = Util.getAllForeignKeyRelatedInfos(page.getSite(), new ArrayList<Object>(), provider, new HashSet<Object>());
        String newName = id.getValue().trim();
        decl.setName(newName);
        decl.updateElement();
        Util.updateReference(decl, objs, allForeignKeyRelatedInfos, oldName, newName);
        EntitySyncProcessor.syncNameForAnnotation(decl, oldName, newName);
        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameEntityMapinfo(oldName, newName);
        }
        if (elementExAdapter != null) {
            elementExAdapter.renameEntityName(decl.getSchema(), oldName, newName);
        }
        // change unique key with new name of concept
        EList list = decl.getIdentityConstraintDefinitions();
        XSDIdentityConstraintDefinition toUpdate = null;
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getName().equals(oldName)) {
                toUpdate = icd;
                break;
            }
        }
        if (toUpdate != null) {
            toUpdate.setName(newName);
            toUpdate.updateElement();
        }
        page.refresh();
        page.markDirty();
    // page.refreshPage();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditConceptAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 22 with IInputValidator

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

the class XSDEditFacetAction method editMinExclusive.

private void editMinExclusive() {
    XSDMinExclusiveFacet currentValue = std.getMinExclusiveFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    boolean isDateType = true;
    dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle11, Messages.XSDEditFacetAction_DialogTitle11Tip, stringValue);
    if (dialog == null) {
        isDateType = false;
        dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle11, Messages.XSDEditFacetAction_DialogTitle11Tip, 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()) {
        XSDMinExclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinExclusiveFacet();
        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) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 23 with IInputValidator

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

the class XSDEditFacetAction method editLength.

// EditEnumeration
private void editLength() {
    XSDLengthFacet currentValue = std.getLengthFacet();
    // $NON-NLS-1$
    String stringValue = "0";
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle3, Messages.XSDEditFacetAction_DialogTitle3Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
    IInputValidator() {

        public String isValid(String newText) {
            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);
    }
    int intValue = Integer.parseInt(((InputDialog) dialog).getValue());
    if (intValue > 0) {
        XSDLengthFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDLengthFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + intValue);
        std.getFacetContents().add(f);
    }
}
Also used : XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 24 with IInputValidator

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

the class XSDSetAnnotationSourceSystemAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.ExceptionInfo, xSDCom.getClass().getName()));
        }
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle1, Messages.XSDSetAnnoXX_DialogTip, struc.getSourceSystem(), 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.setSourceSystem("".equals(id.getValue()) ? null : id.getValue());
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnoXX_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 25 with IInputValidator

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

the class SelectImportedModulesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 2;
    SashForm form = new SashForm(composite, SWT.HORIZONTAL);
    GridData data = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
    data.widthHint = 400;
    data.heightHint = 300;
    form.setLayoutData(data);
    entityViewer = createTableViewer(form, "Entities", entityprovider, new XSDTreeLabelProvider());
    typeViewer = createTableViewer(form, "Types", typeprovider, new TypesLabelProvider());
    form.setWeights(new int[] { 3, 5 });
    Composite compositeBtn = new Composite(composite, SWT.FILL);
    compositeBtn.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    compositeBtn.setLayout(new GridLayout(1, false));
    Button addXSDFromLocal = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
    addXSDFromLocal.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    addXSDFromLocal.setText(Messages.AddXsdFromlocal);
    addXSDFromLocal.setToolTipText(Messages.AddXsdSchemaFromlocal);
    addXSDFromLocal.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            FileDialog fd = new FileDialog(shell.getShell(), SWT.SAVE);
            // $NON-NLS-1$
            fd.setFilterExtensions(new String[] { "*.xsd" });
            fd.setText(Messages.ImportXSDSchema);
            String filename = fd.open();
            if (filename == null) {
                return;
            }
            URL url = getSourceURL("file:///" + filename);
            addSchema(url, true);
        }
    });
    if (exAdapter != null) {
        exAdapter.createDialogArea(compositeBtn);
    }
    Button impXSDFromExchange = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
    impXSDFromExchange.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    impXSDFromExchange.setText(Messages.ImportFromExchangeServer);
    impXSDFromExchange.setToolTipText(Messages.ImportSchemaFromServer);
    impXSDFromExchange.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            StringBuffer repository = new StringBuffer();
            ImportExchangeOptionsDialog dlg = new ImportExchangeOptionsDialog(shell.getShell(), null, false, repository);
            dlg.setBlockOnOpen(true);
            int ret = dlg.open();
            if (ret == Window.OK) {
                File dir = new File(repository.toString());
                File[] fs = dir.listFiles(new FileFilter() {

                    @Override
                    public boolean accept(File pathname) {
                        return pathname.getName().endsWith(".xsd");
                    }
                });
                if (null == fs || fs.length == 0) {
                    MessageDialog.openWarning(getShell(), Messages.import_schema_failed, Messages.no_schema_available);
                    return;
                }
                for (File file : fs) {
                    URL url = getSourceURL("file:///" + file.getPath());
                    addSchema(url, true);
                }
            }
        }
    });
    Button addXSDFromInputDlg = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
    addXSDFromInputDlg.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    addXSDFromInputDlg.setText(Messages.AddXsdFromOther);
    addXSDFromInputDlg.setToolTipText(Messages.AddFromOtherSite);
    addXSDFromInputDlg.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            InputDialog id = new InputDialog(shell.getShell(), Messages.AddXsdFromOther, Messages.EnterTextUrl, "", new // $NON-NLS-1$
            IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if ((newText == null) || "".equals(newText)) {
                        return Messages.NameNotEmpty;
                    }
                    return null;
                }
            });
            id.setBlockOnOpen(true);
            int ret = id.open();
            if (ret == Window.CANCEL) {
                return;
            }
            URL url = getSourceURL(id.getValue());
            addSchema(url, true);
        }
    });
    entityViewer.setInput(addContent);
    typeViewer.setInput(addContent);
    return composite;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) XSDTreeLabelProvider(com.amalto.workbench.providers.XSDTreeLabelProvider) TypesLabelProvider(com.amalto.workbench.providers.TypesLabelProvider) URL(java.net.URL) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileFilter(java.io.FileFilter) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)85 InputDialog (org.eclipse.jface.dialogs.InputDialog)74 Composite (org.eclipse.swt.widgets.Composite)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 IStatus (org.eclipse.core.runtime.IStatus)12 GridData (org.eclipse.swt.layout.GridData)11 Button (org.eclipse.swt.widgets.Button)11 ArrayList (java.util.ArrayList)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Label (org.eclipse.swt.widgets.Label)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Display (org.eclipse.swt.widgets.Display)6 Event (org.eclipse.swt.widgets.Event)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 List (java.util.List)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 File (java.io.File)4 Iterator (java.util.Iterator)4