Search in sources :

Example 26 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class CreateHL7ElementAction method createChildNode.

/**
     * Create the child node of the input node
     *
     * @param node
     */
private boolean createChildNode(final HL7TreeNode node) {
    if (node.getColumn() != null) {
        if (!MessageDialog.openConfirm(xmlViewer.getControl().getShell(), "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element" + node.getLabel() + "\"?")) {
            return false;
        }
        node.setColumn(null);
    }
    String label = "";
    final String nodeLabel = node.getLabel() + "-";
    while (!StringUtil.validateLabelForXML(label)) {
        // add validator
        IInputValidator validator = new IInputValidator() {

            @Override
            public String isValid(String newText) {
                if (newText != null) {
                    String text = newText.trim();
                    for (HL7TreeNode children : node.getChildren()) {
                        if (text.equals(children.getLabel())) {
                            //$NON-NLS-1$
                            return "The name already existed.";
                        }
                    }
                }
                return null;
            }
        };
        InputDialog dialog = new InputDialog(null, "Input element's label", "Input the new element's valid label", nodeLabel, validator) {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
                 */
            @Override
            protected void okPressed() {
                super.okPressed();
            }
        };
        dialog.setErrorMessage("name is error");
        int status = dialog.open();
        if (status == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (status == InputDialog.CANCEL) {
            return false;
        }
    }
    HL7TreeNode child = new Element(label);
    // if the root not have CurSchema
    if (node.getRow() == null || node.getRow().equals("")) {
        if (hl7ui != null && hl7ui.gethl7Manager() instanceof HL7OutputManager) {
            if (label.length() == 3) {
                child.setRow(label);
                IMetadataTable table = null;
                for (IMetadataTable curTable : hl7ui.gethl7Manager().getHl7Component().getMetadataList()) {
                    if (label.equals(curTable.getLabel())) {
                        table = curTable;
                        break;
                    }
                }
                if (table == null) {
                    table = new MetadataTable();
                    table.setLabel(label);
                    table.setTableName(label);
                    hl7ui.gethl7Manager().getHl7Component().getMetadataList().add(table);
                }
                List<Map<String, String>> maps = (List<Map<String, String>>) hl7ui.gethl7Manager().getHl7Component().getElementParameter("SCHEMAS").getValue();
                boolean found = false;
                for (Map<String, String> map : maps) {
                    if (map.get("SCHEMA").equals(table.getTableName())) {
                        found = true;
                    }
                }
                if (!found) {
                    Map<String, String> hl7Schema = new HashMap<String, String>();
                    maps.add(hl7Schema);
                    hl7Schema.put("SCHEMA", table.getTableName());
                }
            }
        } else if (label.length() == 3) {
            child.setRow(label);
        }
    } else {
        child.setRow(node.getRow());
    }
    node.addChild(child);
    this.xmlViewer.refresh();
    return true;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) HashMap(java.util.HashMap) Element(org.talend.designer.hl7.ui.data.Element) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 27 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class MapperUI method openNewOutputCreationDialog.

public String openNewOutputCreationDialog() {
    final IProcess process = mapperManager.getMapperComponent().getProcess();
    //$NON-NLS-1$
    String outputName = process.generateUniqueConnectionName("out");
    InputDialog id = new InputDialog(mapperShell, "Add a output", "New Output :", outputName, new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (!process.checkValidConnectionName(newText)) {
                return "Output is invalid.";
            }
            return null;
        }
    });
    int response = id.open();
    if (response == InputDialog.OK) {
        return id.getValue();
    }
    return null;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IProcess(org.talend.core.model.process.IProcess) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 28 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class RenameAction method getNewName.

/**
     * Gets the new file name.
     * 
     * @return The new file name
     */
private String getNewName() {
    IFileStore fileStore = snapshot.getFileStore();
    List<String> oldNames = new ArrayList<String>();
    try {
        for (String oldName : fileStore.getParent().childNames(EFS.NONE, null)) {
            oldNames.add(removeSuffix(oldName));
        }
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.accessFileFailedMsg, fileStore.getName()), e);
        return null;
    }
    String oldName = fileStore.getName();
    IInputValidator validator = new InputValidator(oldNames, oldName);
    InputDialog dialog = new InputDialog(treeViewer.getControl().getShell(), Messages.renameTitle, Messages.newNameLabel, removeSuffix(oldName), validator);
    if (dialog.open() == Window.OK) {
        return oldName.replace(removeSuffix(oldName), dialog.getValue());
    }
    return null;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) ArrayList(java.util.ArrayList) IFileStore(org.eclipse.core.filesystem.IFileStore) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 29 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class CreateJSONElementAction method createChildNode.

private boolean createChildNode(FOXTreeNode node) {
    if (node.getColumn() != null) {
        if (!MessageDialog.openConfirm(jsonViewer.getControl().getShell(), "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element " + node.getLabel() + " \"?")) {
            return false;
        }
        node.setColumn(null);
    }
    String label = "";
    while (!JSONUtil.validateLabelForJSON(label)) {
        InputDialog dialog = new InputDialog(null, "Input element's label", "Input the new element's valid label", "", null);
        int status = dialog.open();
        if (status == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (status == InputDialog.CANCEL) {
            return false;
        }
    }
    FOXTreeNode child = new Element(label);
    // child.setRow(node.getRow());
    node.addChild(child);
    // fix for TDI-18802
    if (node.getParent() == null && node.isLoop()) {
        node.setLoop(false);
    }
    this.jsonViewer.refresh();
    this.jsonViewer.expandAll();
    return true;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) InputDialog(org.eclipse.jface.dialogs.InputDialog) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 30 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class CreateElementAction method run.

@Override
public void run() {
    TreeNode treeNode = null;
    boolean needWarning = false;
    if (input) {
        treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
        if (!parent.getOutgoingConnections().isEmpty()) {
            needWarning = true;
        }
    } else {
        treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
        OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
        EList<Connection> incomingConnections = parent.getIncomingConnections();
        if (!incomingConnections.isEmpty()) {
            needWarning = true;
        }
    }
    boolean canContinue = true;
    // Shell shell = this.part.getSite().getShell();
    if (needWarning) {
        canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element ?");
    }
    if (canContinue) {
        // IInputValidator validataor = new IInputValidator() {
        //
        // public String isValid(String newText) {
        // String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ELEMENT);
        // EList<TreeNode> children = parent.getChildren();
        // boolean exist = false;
        // for (TreeNode child : children) {
        // if (child.getXpath() != null && child.getXpath().equals(xpath)) {
        // exist = true;
        // break;
        // }
        // }
        //
        // if (exist) {
        // return "Element '" + newText + "' already exist !";
        // } else {
        // return null;
        // }
        // }
        //
        // };
        InputDialog dialog = new InputDialog(null, "Create New Element", "Input the new element's valid label", "", null);
        int open = -1;
        String label = "";
        while (!StringUtil.validateLabelForXML(label)) {
            open = dialog.open();
            if (open == InputDialog.OK) {
                label = dialog.getValue().trim();
            }
            if (open == InputDialog.CANCEL) {
                return;
            }
        }
        if (open == Window.OK) {
            XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
            treeNode.setName(label);
            treeNode.setNodeType(NodeType.ELEMENT);
            String parentXpath = parent.getXpath();
            if (parent.isChoice() || parent.isSubstitution()) {
                TreeNode realPrant = XmlMapUtil.getRealParentNode(parent);
                if (realPrant != null) {
                    parentXpath = realPrant.getXpath();
                }
            }
            treeNode.setXpath(XmlMapUtil.getXPath(parentXpath, treeNode.getName(), treeNode.getNodeType()));
            treeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            parent.getChildren().add(treeNode);
            parent.setExpression("");
            if (!input) {
                OutputTreeNode output = (OutputTreeNode) parent;
                if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
                    output.setAggregate(false);
                }
            }
        }
        if (open == Window.OK && mapperManager != null) {
            // if (input) {
            // mapperManager.inputTreeSchemaBeanListModified();
            // } else {
            // mapperManager.outputTreeSchemaBeanListModified();
            // }
            Object object = graphicViewer.getEditPartRegistry().get(treeNode);
            if (object instanceof TreeNodeEditPart) {
                graphicViewer.select((TreeNodeEditPart) object);
            }
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Aggregations

InputDialog (org.eclipse.jface.dialogs.InputDialog)31 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)12 Composite (org.eclipse.swt.widgets.Composite)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 Group (org.eclipse.swt.widgets.Group)5 Label (org.eclipse.swt.widgets.Label)5 IStatus (org.eclipse.core.runtime.IStatus)4 Control (org.eclipse.swt.widgets.Control)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 ArrayList (java.util.ArrayList)3 Status (org.eclipse.core.runtime.Status)3 ErrorDialog (org.eclipse.jface.dialogs.ErrorDialog)3 SashForm (org.eclipse.swt.custom.SashForm)3 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3