Search in sources :

Example 1 with TnsParser

use of org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsParser in project tdi-studio-se by Talend.

the class TNSEditorController method createCommand.

public Command createCommand(Button button) {
    IElementParameter elementParameter = this.curParameter.getElement().getElementParameter("TNS_FILE");
    Command command = null;
    if (elementParameter != null) {
        String filePath = new Path(PathExtractor.extractPath(elementParameter.getValue().toString())).toOSString();
        if (filePath != null && new File(filePath).exists()) {
            boolean flag = false;
            try {
                TnsParser tnsparser = new TnsParser(new File(filePath));
                if (tnsparser.getTree().getChildren().size() == 0) {
                    flag = true;
                }
            } catch (Exception e) {
                flag = true;
            }
            if (flag) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openInformation(composite.getShell(), "WARNING", "this file is invalid,please recheck!");
                    }
                });
            } else {
                TnsEditorDialog tnsDialog = new TnsEditorDialog(composite.getShell(), new File(filePath));
                if (tnsDialog.open() == Window.OK) {
                    TnsInfo tnsInfo = tnsDialog.getTnsInfo();
                    command = new TnsPropertyCommand(tnsInfo, this.elem);
                }
            }
        } else {
            MessageBox mBox = new MessageBox(composite.getShell(), SWT.ICON_ERROR);
            //$NON-NLS-1$
            mBox.setText("Error");
            //$NON-NLS-1$
            mBox.setMessage("TNS File Not Found");
            mBox.open();
        }
    }
    return command;
}
Also used : Path(org.eclipse.core.runtime.Path) TnsPropertyCommand(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsPropertyCommand) TnsEditorDialog(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsEditorDialog) TnsParser(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsParser) MessageBox(org.eclipse.swt.widgets.MessageBox) TnsInfo(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsInfo) TnsPropertyCommand(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsPropertyCommand) Command(org.eclipse.gef.commands.Command) IElementParameter(org.talend.core.model.process.IElementParameter) File(java.io.File)

Aggregations

File (java.io.File)1 Path (org.eclipse.core.runtime.Path)1 Command (org.eclipse.gef.commands.Command)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 TnsEditorDialog (org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsEditorDialog)1 TnsInfo (org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsInfo)1 TnsParser (org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsParser)1 TnsPropertyCommand (org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsPropertyCommand)1