Search in sources :

Example 1 with IWorkbenchSiteProgressService

use of org.eclipse.ui.progress.IWorkbenchSiteProgressService in project tdi-studio-se by Talend.

the class DbTableController method openDbTableSelectorJob.

/**
     * qzhang Comment method "openDbTableSelectorJob".
     * 
     * @param openListTable
     */
private void openDbTableSelectorJob(final Button openListTable) {
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("DbTableController.openSelectionDialog")) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            //$NON-NLS-1$
            monitor.beginTask(Messages.getString("DbTableController.waitingForOpen"), IProgressMonitor.UNKNOWN);
            DatabaseConnection existConnection = getExistConnection();
            if (existConnection == null) {
                if (connParameters == null) {
                    initConnectionParameters();
                }
                existConnection = TracesConnectionUtils.createConnection(connParameters);
            }
            final DatabaseConnection con = existConnection;
            IMetadataConnection iMetadataConnection = null;
            final IMetadataConnection[] iMetadata = new IMetadataConnection[1];
            boolean isStatus = false;
            if (existConnection != null) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        IMetadataConnection convert = ConvertionHelper.convert(con);
                        iMetadata[0] = convert;
                    }
                });
                iMetadataConnection = iMetadata[0];
                // Added by Marvin Wang for bug TDI-24288.
                if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
                    if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
                        try {
                            HiveConnectionManager.getInstance().checkConnection(iMetadataConnection);
                            isStatus = true;
                        } catch (ClassNotFoundException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (InstantiationException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (IllegalAccessException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (SQLException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        }
                    }
                } else {
                    isStatus = checkConnection(iMetadataConnection);
                }
            }
            String type = null;
            if (iMetadataConnection != null) {
                type = iMetadataConnection.getDbType();
            }
            final String dbType = type;
            if (!monitor.isCanceled()) {
                try {
                    if (isStatus) {
                        // Added by Marvin Wang for bug TDI-24288.
                        if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
                            if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
                                JavaSqlFactory.doHivePreSetup((DatabaseConnection) iMetadataConnection.getCurrentConnection());
                                returnTablesFormConnection = ExtractMetaDataFromDataBase.fetchAllTablesForHiveEmbeddedModel(iMetadataConnection);
                                JavaSqlFactory.doHiveConfigurationClear();
                            }
                        } else {
                            returnTablesFormConnection = ExtractMetaDataFromDataBase.returnTablesFormConnection(iMetadataConnection);
                        }
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                final DbTableSelectorObject object = new DbTableSelectorObject();
                                DbTableSelectorObject connO = new DbTableSelectorObject();
                                if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
                                    connO.setLabel(connParameters.getLocalServiceName());
                                } else if ("".equals(connParameters.getDbName())) {
                                    //$NON-NLS-1$
                                    connO.setLabel(connParameters.getDatasource());
                                } else {
                                    connO.setLabel(connParameters.getDbName());
                                }
                                // ...
                                if (connO.getLabel() == null || connO.getLabel().equals("")) {
                                    //$NON-NLS-1$
                                    if (elem instanceof INode) {
                                        connO.setLabel(elem.getElementName());
                                    } else {
                                        connO.setLabel("tJDBCConnection");
                                    }
                                }
                                connO.setType(ObjectType.DB);
                                if (monitor.isCanceled()) {
                                    monitor.done();
                                    return;
                                }
                                for (String string : returnTablesFormConnection) {
                                    DbTableSelectorObject tableO = new DbTableSelectorObject();
                                    tableO.setLabel(string);
                                    tableO.setType(ObjectType.TABLE);
                                    connO.addChildren(tableO);
                                }
                                object.addChildren(connO);
                                String propertyName = (String) openListTable.getData(PARAMETER_NAME);
                                DbTableSelectorDialog selectorDialog = new DbTableSelectorDialog(composite.getShell(), object);
                                if (selectorDialog.open() == DbTableSelectorDialog.OK) {
                                    String name = selectorDialog.getSelectName();
                                    if (name != null) {
                                        Command dbSelectorCommand = new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(name));
                                        executeCommand(dbSelectorCommand);
                                        Text labelText = (Text) hashCurControls.get(propertyName);
                                        labelText.setText(TalendTextUtils.addQuotes(name));
                                    }
                                }
                            }
                        });
                    } else {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                //$NON-NLS-1$
                                String pid = "org.talend.sqlbuilder";
                                //$NON-NLS-1$
                                String mainMsg = "Database connection is failed. ";
                                ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
                                if (dialog.getCodeOfButton() == Window.OK) {
                                    openParamemerDialog(openListTable, part.getProcess().getContextManager());
                                }
                            }
                        });
                    }
                } catch (SQLException e) {
                    // Added by Marvin Wang for bug TDI-24288.
                    JavaSqlFactory.doHiveConfigurationClear();
                    ExceptionHandler.process(e);
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialog.openError(openListTable.getShell(), //$NON-NLS-1$
                            Messages.getString("DbTableController.dialog.title"), //$NON-NLS-1$
                            Messages.getString("DbTableController.dialog.contents.fetchTableFailed"));
                        }
                    });
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    if (part != null) {
        IWorkbenchSiteProgressService siteps = (IWorkbenchSiteProgressService) part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
        siteps.showInDialog(composite.getShell(), job);
    } else {
        PlatformUI.getWorkbench().getProgressService().showInDialog(composite.getShell(), job);
    }
    job.setUser(true);
    job.schedule();
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) INode(org.talend.core.model.process.INode) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Text(org.eclipse.swt.widgets.Text) DbTableSelectorDialog(org.talend.core.ui.metadata.dialog.DbTableSelectorDialog) DbTableSelectorObject(org.talend.core.ui.metadata.dialog.DbTableSelectorObject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with IWorkbenchSiteProgressService

use of org.eclipse.ui.progress.IWorkbenchSiteProgressService in project tdi-studio-se by Talend.

the class SQLBuilderService method openSQLBuilderDialog.

public void openSQLBuilderDialog(ConnectionParameters connParameters, Composite composite, IElement elem, String propertyName, CommandStack commandStack, Object abstractElementPropertySectionController, Object abstractMultiPageTalendEditor) {
    OpenSQLBuilderDialogJob openDialogJob = new OpenSQLBuilderDialogJob(connParameters, composite, elem, propertyName, commandStack, (AbstractElementPropertySectionController) abstractElementPropertySectionController);
    IWorkbenchSiteProgressService siteps = (IWorkbenchSiteProgressService) ((AbstractMultiPageTalendEditor) abstractMultiPageTalendEditor).getSite().getAdapter(IWorkbenchSiteProgressService.class);
    siteps.showInDialog(composite.getShell(), openDialogJob);
    openDialogJob.schedule();
}
Also used : IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) OpenSQLBuilderDialogJob(org.talend.sqlbuilder.ui.OpenSQLBuilderDialogJob) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor)

Aggregations

IWorkbenchSiteProgressService (org.eclipse.ui.progress.IWorkbenchSiteProgressService)2 SQLException (java.sql.SQLException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 Command (org.eclipse.gef.commands.Command)1 Text (org.eclipse.swt.widgets.Text)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 INode (org.talend.core.model.process.INode)1 DbTableSelectorDialog (org.talend.core.ui.metadata.dialog.DbTableSelectorDialog)1 DbTableSelectorObject (org.talend.core.ui.metadata.dialog.DbTableSelectorObject)1 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)1 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)1 OpenSQLBuilderDialogJob (org.talend.sqlbuilder.ui.OpenSQLBuilderDialogJob)1