Search in sources :

Example 71 with ProgressMonitorDialog

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

the class ImportExchangeDialog method okPressed.

@Override
protected void okPressed() {
    //$NON-NLS-1$ //$NON-NLS-2$
    IPath tempPath = new Path(System.getProperty("user.dir")).append("temp");
    File pathFile = tempPath.toFile();
    if (downloadproperty.getFileName() == null || downloadproperty.getFileName() == null) {
        MessageBox box = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
        //$NON-NLS-1$
        box.setText(Messages.getString("ImportExchangeDialog.WARNING"));
        //$NON-NLS-1$
        box.setMessage(Messages.getString("ImportExchangeDialog.NOTSELECTWARNING"));
        box.open();
        return;
    }
    tempFile = new File(pathFile, downloadproperty.getFileName());
    try {
        url = new URL(downloadproperty.getDownloadUrl());
    } catch (MalformedURLException e1) {
        ExceptionHandler.process(e1);
    }
    if (!pathFile.exists()) {
        pathFile.mkdirs();
    }
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell().getShell());
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) {
            //$NON-NLS-1$
            monitor.beginTask(Messages.getString("ImportExchangeDialog.downloadProgressBar"), IProgressMonitor.UNKNOWN);
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        new DownloadHelper().download(url, tempFile);
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                }
            });
            monitor.done();
        }
    };
    try {
        progressDialog.run(true, true, runnable);
    } catch (InvocationTargetException e1) {
        ExceptionHandler.process(e1);
    } catch (InterruptedException e1) {
        ExceptionHandler.process(e1);
    }
    selectFile = tempFile.toString();
    super.okPressed();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) MalformedURLException(java.net.MalformedURLException) IPath(org.eclipse.core.runtime.IPath) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DownloadHelper(org.talend.core.download.DownloadHelper) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) File(java.io.File)

Example 72 with ProgressMonitorDialog

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

the class ImportCompatibleEcoComponentsComposite method findChoiceExchange.

/**
     * 
     * This is a progressBar.when this progressBar run it will download some jobs/templates/routines from net.
     */
public void findChoiceExchange() {
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell().getShell());
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) {
            monitor.beginTask(progressBarMessage, IProgressMonitor.UNKNOWN);
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    compatible = ComponentSearcher.getImportComponentExtensions(version, ExchangeUtils.getCurrentLanguage(), categoryCombo.getSelectionIndex() >= 0 ? fCategorys.get(categoryCombo.getSelectionIndex()).getCategoryId() : "");
                    updateTable(compatible);
                }
            });
            monitor.done();
            if (monitor.isCanceled()) {
                try {
                    //$NON-NLS-1$
                    throw new InterruptedException(Messages.getString("ImportExchangeDialog.OPERATION_CANCELLED"));
                } catch (InterruptedException e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    };
    try {
        progressDialog.run(true, true, runnable);
    } catch (InvocationTargetException e1) {
        ExceptionHandler.process(e1);
    } catch (InterruptedException e1) {
        ExceptionHandler.process(e1);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 73 with ProgressMonitorDialog

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

the class GuessSchemaController method runShadowProcessForPerl.

private void runShadowProcessForPerl() {
    final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
    try {
        pmd.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (columns != null) {
                    columns.clear();
                }
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("GuessSchemaController.waitOpenDatabase"), IProgressMonitor.UNKNOWN);
                if (connParameters == null) {
                    initConnectionParameters();
                }
                ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
                DatabaseConnection connt = service.createConnection(connParameters);
                IMetadataConnection iMetadataConnection = null;
                boolean isStatus = false;
                ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
                if (connt != null) {
                    iMetadataConnection = ConvertionHelper.convert(connt);
                    isStatus = checkConnection(iMetadataConnection);
                }
                if (!monitor.isCanceled()) {
                    try {
                        if (isStatus) {
                            extractMeta.getConnection(iMetadataConnection.getDbType(), iMetadataConnection.getUrl(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDatabase(), iMetadataConnection.getSchema(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getAdditionalParams());
                            if (extractMeta.getConn() != null) {
                                Statement smst = extractMeta.getConn().createStatement();
                                extractMeta.setQueryStatementTimeout(smst);
                                ResultSet rs = smst.executeQuery(memoSQL);
                                ResultSetMetaData rsmd = rs.getMetaData();
                                int numbOfColumn = rsmd.getColumnCount();
                                int count = 0;
                                List<String[]> cvsArrays = new ArrayList<String[]>();
                                while (rs.next() && count < 50) {
                                    String[] dataOneRow = new String[numbOfColumn];
                                    for (int i = 1; i <= numbOfColumn; i++) {
                                        String tempStr = rs.getString(i);
                                        dataOneRow[i - 1] = tempStr;
                                    }
                                    cvsArrays.add(dataOneRow);
                                    count++;
                                }
                                refreshMetaDataTable(rsmd, cvsArrays);
                                extractMeta.closeConnection();
                            }
                        } 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(composite.getShell(), part.getProcess().getContextManager());
                                    }
                                }
                            });
                        }
                    } catch (Exception e) {
                        extractMeta.closeConnection();
                        ExceptionHandler.process(e);
                        final String strExcepton = "Connect to DB error ,or some errors in SQL query string, or 'Guess Schema' not compatible with current SQL query string." + System.getProperty("line.separator");
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connError"), //$NON-NLS-1$
                                strExcepton);
                            }
                        });
                    }
                }
            }
        });
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ResultSetMetaData(java.sql.ResultSetMetaData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 74 with ProgressMonitorDialog

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

the class I18nPreferencePage method runProgressMonitorDialog.

/**
     * 
     * DOC wzhang Comment method "runProgressMonitorDialog".
     * 
     * @param validated
     */
public void runProgressMonitorDialog(final String zipFileName) {
    updateCompleted = false;
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getFieldEditorParent().getShell());
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) {
            try {
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("I18nPreferencePage.wait_process"), IProgressMonitor.UNKNOWN);
                applyBabiliResource(zipFileName);
            } catch (Exception e1) {
                ExceptionHandler.process(e1);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        progressDialog.run(true, true, runnable);
    } catch (InvocationTargetException e1) {
        ExceptionHandler.process(e1);
    } catch (InterruptedException e1) {
        ExceptionHandler.process(e1);
    }
    if (updateCompleted) {
    } else {
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 75 with ProgressMonitorDialog

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

the class UpdateManagerUtils method doExecuteUpdates.

private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
    if (results == null || results.isEmpty()) {
        return false;
    }
    try {
        IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                monitor.setCanceled(false);
                int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                // first list by job we need to update
                Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
                Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
                for (UpdateResult result : results) {
                    // if (!result.isChecked()) {
                    // continue;
                    // }
                    String id = result.getObjectId();
                    String version = result.getObjectVersion();
                    if (id == null) {
                        if (result.getJob() != null && result.getJob() instanceof IProcess) {
                            IProcess process = (IProcess) result.getJob();
                            if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
                                // file.
                                continue;
                            }
                            id = process.getId();
                            version = process.getVersion();
                            result.setObjectId(id);
                            result.setObjectVersion(version);
                        } else {
                            continue;
                        }
                    }
                    Set<String> versionList;
                    if (!jobIdToVersion.containsKey(id)) {
                        versionList = new HashSet<String>();
                        jobIdToVersion.put(id, versionList);
                    } else {
                        versionList = jobIdToVersion.get(id);
                    }
                    versionList.add(version);
                    //$NON-NLS-1$
                    jobIdClosed.put(id + " - " + version, result.isFromItem());
                }
                // now will execute updates only for the job selected depends this list.
                for (String currentId : jobIdToVersion.keySet()) {
                    for (String version : jobIdToVersion.get(currentId)) {
                        IRepositoryViewObject currentObj = null;
                        //$NON-NLS-1$
                        boolean closedItem = jobIdClosed.get(currentId + " - " + version);
                        IProcess process = null;
                        Item item = null;
                        if (closedItem) {
                            // if item is closed, then just load it.
                            boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
                            "checkOnlyLastVersion"));
                            try {
                                if (checkOnlyLastVersion || version == null) {
                                    currentObj = factory.getLastVersion(currentId);
                                } else {
                                    List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
                                    for (IRepositoryViewObject obj : allVersion) {
                                        if (obj.getVersion().equals(version)) {
                                            currentObj = obj;
                                        }
                                    }
                                }
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                            if (currentObj == null) {
                                // item not found, don't do anything
                                continue;
                            }
                            item = currentObj.getProperty().getItem();
                            IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
                            if (item instanceof ProcessItem) {
                                process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                            } else if (item instanceof JobletProcessItem) {
                                process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
                            }
                        }
                        for (UpdateResult result : results) {
                            // }
                            if (!StringUtils.equals(currentId, result.getObjectId())) {
                                // not the current job we need to update
                                continue;
                            }
                            if (closedItem) {
                                if (result.getJob() == null) {
                                    result.setJob(process);
                                } else {
                                    process = (IProcess) result.getJob();
                                }
                                IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
                                if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
                                    if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
                                        process.getContextManager().setListContext((List<IContext>) result.getParameter());
                                    }
                                }
                            }
                            // execute
                            executeUpdate(result, monitor, updateAllJobs);
                            if (closedItem) {
                                result.setJob(null);
                            }
                        }
                        boolean isTestContainer = false;
                        ITestContainerProviderService testContainerService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                            testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                            if (testContainerService != null) {
                                isTestContainer = testContainerService.isTestContainerItem(item);
                            }
                        }
                        if (closedItem && process instanceof IProcess2) {
                            IProcess2 process2 = (IProcess2) process;
                            ProcessType processType;
                            try {
                                processType = process2.saveXmlFile(false);
                                if (isTestContainer) {
                                    testContainerService.setTestContainerProcess(processType, item);
                                } else if (item instanceof JobletProcessItem) {
                                    ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                                } else {
                                    ((ProcessItem) item).setProcess(processType);
                                }
                                factory.save(item);
                            } catch (IOException e) {
                                ExceptionHandler.process(e);
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
                            // unload item from memory, but only if this one is not locked by current user.
                            try {
                                factory.unloadResources(item.getProperty());
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    }
                }
                UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
                // update joblet reference
                upadateJobletReferenceInfor();
                final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
                // refresh
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refreshRelatedViewers(tempResults);
                        // hyWang add method checkandRefreshProcess for bug7248
                        checkandRefreshProcess(tempResults);
                    }
                });
                monitor.worked(1 * UpdatesConstants.SCALE);
                monitor.done();
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        }
        return !results.isEmpty();
    } finally {
        results.clear();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobletProcess(org.talend.designer.joblet.model.JobletProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) UpdateResult(org.talend.core.model.update.UpdateResult) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)88 InvocationTargetException (java.lang.reflect.InvocationTargetException)81 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)74 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)74 ArrayList (java.util.ArrayList)27 Display (org.eclipse.swt.widgets.Display)22 CoreException (org.eclipse.core.runtime.CoreException)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 List (java.util.List)15 Shell (org.eclipse.swt.widgets.Shell)12 PartInitException (org.eclipse.ui.PartInitException)12 IFile (org.eclipse.core.resources.IFile)11 SQLException (java.sql.SQLException)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 SocketTask (com.cubrid.cubridmanager.core.common.socket.SocketTask)8 File (java.io.File)8 Item (org.talend.core.model.properties.Item)8 IProject (org.eclipse.core.resources.IProject)7 TableItem (org.eclipse.swt.widgets.TableItem)7