Search in sources :

Example 6 with IMetadataProvider

use of org.talend.repository.nosql.metadata.IMetadataProvider in project tbd-studio-se by Talend.

the class AbstractNoSQLConnForm method addUtilsButtonListeners.

/*
     * (non-Javadoc)
     *
     * @see org.talend.repository.ui.swt.utils.AbstractForm#addUtilsButtonListeners()
     */
@Override
protected void addUtilsButtonListeners() {
    if (checkBtn != null) {
        checkBtn.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 *
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                try {
                    if (getConnection() != null) {
                        final AtomicBoolean checkedResult = new AtomicBoolean(true);
                        final Thread[] t = new Thread[1];
                        final Exception[] exception = new Exception[1];
                        IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                t[0] = Thread.currentThread();
                                IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(getConnection().getDbType());
                                if (metadataProvider != null) {
                                    try {
                                        checkedResult.set(metadataProvider.checkConnection(getConnection()));
                                    } catch (NoSQLServerException e) {
                                        exception[0] = e;
                                        checkedResult.set(false);
                                        ExceptionHandler.process(e);
                                    }
                                }
                            }
                        };
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {

                            protected void cancelPressed() {
                                super.cancelPressed();
                                t[0].interrupt();
                            }
                        };
                        dialog.run(true, true, runnableWithProgress);
                        if (!checkedResult.get() && exception[0] != null) {
                            new ErrorDialogWidthDetailArea(getShell(), RepositoryNoSQLPlugin.PLUGIN_ID, // $NON-NLS-1$
                            Messages.getString("AbstractNoSQLConnForm.checkFailed"), ExceptionUtils.getFullStackTrace(exception[0]));
                        } else {
                            MessageDialog.openInformation(getShell(), Messages.getString("AbstractNoSQLConnForm.checkConn"), // $NON-NLS-1$ //$NON-NLS-2$
                            Messages.getString("AbstractNoSQLConnForm.checkSuccessful"));
                        }
                    }
                } catch (Exception exception) {
                    new ErrorDialogWidthDetailArea(getShell(), RepositoryNoSQLPlugin.PLUGIN_ID, Messages.getString(// $NON-NLS-1$
                    "AbstractNoSQLConnForm.checkFailed"), ExceptionUtils.getFullStackTrace(exception));
                    ExceptionHandler.process(exception);
                }
            }
        });
    }
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea)

Aggregations

IMetadataProvider (org.talend.repository.nosql.metadata.IMetadataProvider)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ErrorDialogWidthDetailArea (org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea)3 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)3 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Display (org.eclipse.swt.widgets.Display)1 Test (org.junit.Test)1 NoSQLExtractSchemaException (org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)1 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)1