Search in sources :

Example 46 with IInputValidator

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

the class TOPRepositoryService method getInputDialog.

/**
 * Comment method "getInputDialog".
 *
 * @param get input dialog
 * @return inputDialog
 */
public InputDialog getInputDialog(final Item newItem) {
    Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    // $NON-NLS-1$
    String dialogTitle = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Title");
    // $NON-NLS-1$
    String dialogMessage = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Message");
    final InputDialog inputDialog = new InputDialog(parentShell, dialogTitle, dialogMessage, newItem.getProperty().getLabel() + DateUtils.formatTimeStamp(DateUtils.PATTERN_6, System.currentTimeMillis()), new IInputValidator() {

        public String isValid(String newText) {
            String returnStr = null;
            Item item = newItem;
            ERepositoryObjectType type = ERepositoryObjectType.getItemType(item);
            // String pattern = RepositoryConstants.getPattern(type);
            // $NON-NLS-1$
            String pattern = "[_A-Za-z0-9-][a-zA-Z0-9\\\\.\\\\-_(), ]*";
            boolean matches = Pattern.matches(pattern, newText);
            boolean nameAvailable = false;
            try {
                List<IRepositoryViewObject> listExistingObjects = ProxyRepositoryFactory.getInstance().getAll(type, true, false);
                nameAvailable = ProxyRepositoryFactory.getInstance().isNameAvailable(item, newText, listExistingObjects);
            } catch (PersistenceException e) {
                log.error(e, e);
                return e.getMessage();
            }
            if (!matches) {
                returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
                "TOPRepositoryService.InputDialog.ErrorMessage1");
            } else if (!nameAvailable) {
                returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
                "TOPRepositoryService.InputDialog.ErrorMessage2");
            }
            return returnStr;
        }
    });
    return inputDialog;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Shell(org.eclipse.swt.widgets.Shell) InputDialog(org.eclipse.jface.dialogs.InputDialog) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 47 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project usbdm-eclipse-plugins by podonoghue.

the class OpenGdbConsoleHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    InputDialog dialog = new InputDialog(window.getShell(), "TTY Port Number", "Port number for TTY console", portNum, new IInputValidator() {

        @Override
        public String isValid(String arg0) {
            try {
                int num = Integer.parseInt(arg0);
                if (num <= 0) {
                    return "Must not be zero";
                }
                if (num >= 65536) {
                    return "Too large";
                }
            } catch (Exception e) {
                return "Invalid integer";
            }
            return null;
        }
    });
    int rc = dialog.open();
    if (rc != InputDialog.OK) {
        return null;
    }
    portNum = dialog.getValue();
    try {
        MyConsoleInterface.startServer(Integer.parseInt(portNum));
    } catch (Exception e) {
        MessageBox mb = new MessageBox(window.getShell());
        mb.setMessage(e.getMessage());
        mb.setText("Error opening TTY");
        mb.open();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InputDialog(org.eclipse.jface.dialogs.InputDialog) ExecutionException(org.eclipse.core.commands.ExecutionException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 48 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 49 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 50 with IInputValidator

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

the class XSDEditFacetAction method editMinLength.

// EditLength
private void editMinLength() {
    XSDMinLengthFacet currentValue = std.getMinLengthFacet();
    // $NON-NLS-1$
    String stringValue = "0";
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle4, Messages.XSDEditFacetAction_DialogTitle4Tip, 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) {
        XSDMinLengthFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinLengthFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + intValue);
        std.getFacetContents().add(f);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)60 InputDialog (org.eclipse.jface.dialogs.InputDialog)51 Composite (org.eclipse.swt.widgets.Composite)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 Button (org.eclipse.swt.widgets.Button)9 ArrayList (java.util.ArrayList)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 IStatus (org.eclipse.core.runtime.IStatus)7 GridData (org.eclipse.swt.layout.GridData)7 Label (org.eclipse.swt.widgets.Label)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 SelectionListener (org.eclipse.swt.events.SelectionListener)6 Event (org.eclipse.swt.widgets.Event)6 FillLayout (org.eclipse.swt.layout.FillLayout)5 Control (org.eclipse.swt.widgets.Control)5 Group (org.eclipse.swt.widgets.Group)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5 ISelection (org.eclipse.jface.viewers.ISelection)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4