Search in sources :

Example 1 with OpenContextChooseComboDialog

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

the class GuessSchemaController method useMockJob.

private void useMockJob() {
    /*
         * get the select node,it's the input node of the process. then transfer selected context varriable to
         * openContextChooseDialog, added by hyWang
         */
    final IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    final Shell parentShell = this.composite.getShell();
    final Node inputNode = (Node) this.curParameter.getElement();
    if (connParameters == null) {
        initConnectionParameters();
    }
    final String tmpMemoSql = this.memoSQL;
    final DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
    IMetadataConnection iMetadataConnection = null;
    boolean isStatus = false;
    try {
        if (connt != null) {
            iMetadataConnection = ConvertionHelper.convert(connt);
            isStatus = checkConnection(iMetadataConnection);
        }
        if (isStatus) {
            if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(iMetadataConnection.getDbType())) {
                info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getAdditionalParams());
            } else if (EDatabaseTypeName.HIVE.getDisplayName().equals(iMetadataConnection.getDbType())) {
                String jobTracker = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL)));
                String nameNode = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL)));
                String thrifturi = null;
                if (HiveModeInfo.get(iMetadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
                    thrifturi = "thrift://" + iMetadataConnection.getServerName() + ":" + iMetadataConnection.getPort();
                }
                info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), jobTracker, nameNode, thrifturi, iMetadataConnection.getDriverJarPath());
                String hiveServerVersion = String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.HIVE_SERVER_VERSION));
                //$NON-NLS-1$
                String driverClass = "";
                if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
                    driverClass = EDatabase4DriverClassName.HIVE2.getDriverClass();
                } else {
                    driverClass = EDatabase4DriverClassName.HIVE.getDriverClass();
                }
                info.setDriverClassName(driverClass);
            } else {
                info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverJarPath());
            }
            final Property property = GuessSchemaProcess.getNewmockProperty();
            List<IContext> allcontexts = inputNode.getProcess().getContextManager().getListContext();
            OpenContextChooseComboDialog dialog = new OpenContextChooseComboDialog(parentShell, allcontexts);
            dialog.create();
            dialog.getShell().setText(CONTEXT_CHOOSE_DIALOG_TITLE);
            IContext selectContext = null;
            // job only have defoult context,or the query isn't context mode
            if (allcontexts.size() == 1 || TalendTextUtils.isCommonString(tmpMemoSql)) {
                selectContext = inputNode.getProcess().getContextManager().getDefaultContext();
            } else if (Window.OK == dialog.open()) {
                selectContext = dialog.getSelectedContext();
            }
            final IContext context = selectContext;
            if (context != null) {
                //
                final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
                pmd.run(true, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                runShadowProcess(property, inputNode, context, switchParam);
                            }
                        });
                    }
                });
            }
        } else {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    //$NON-NLS-1$
                    String pid = "org.talend.sqlbuilder";
                    //$NON-NLS-1$
                    String mainMsg = Messages.getString("GuessSchemaController.connectionFailed");
                    ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
                    if (dialog.getCodeOfButton() == Window.OK) {
                        openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
                    }
                }
            });
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
// else {
// try {
// pmd2.run(true, true, new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Display.getDefault().asyncExec(new Runnable() {
//
// public void run() {
// String pid = SqlBuilderPlugin.PLUGIN_ID;
//                    String mainMsg = Messages.getString("GuessSchemaController.connectionFailed"); //$NON-NLS-1$
// ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite
// .getShell(), pid, mainMsg, connParameters.getConnectionComment());
// if (dialog.getCodeOfButton() == Window.OK) {
// openParamemerDialog(composite.getShell(), part.getTalendEditor().getProcess().getContextManager());
// }
// }
// });
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) IContext(org.talend.core.model.process.IContext) Node(org.talend.designer.core.ui.editor.nodes.Node) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) OpenContextChooseComboDialog(org.talend.designer.core.ui.editor.properties.controllers.uidialog.OpenContextChooseComboDialog) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 Shell (org.eclipse.swt.widgets.Shell)1 ErrorDialogWithDetailAreaAndContinueButton (org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton)1 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 IContext (org.talend.core.model.process.IContext)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 Property (org.talend.core.model.properties.Property)1 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1 OpenContextChooseComboDialog (org.talend.designer.core.ui.editor.properties.controllers.uidialog.OpenContextChooseComboDialog)1 ProcessorException (org.talend.designer.runprocess.ProcessorException)1