Search in sources :

Example 96 with ProgressMonitorDialog

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

the class LoginProjectPage method refreshLicenseIfNeeded.

/**
     * 
     * @return if false: user cancel login
     */
private boolean refreshLicenseIfNeeded() {
    ConnectionBean conn = loginHelper.getCurrentSelectedConnBean();
    Project proj = getProject();
    if (LoginHelper.isRemoteConnection(conn)) {
        String url = getAdminURL();
        String projLabel = proj.getLabel();
        String userId = conn.getUser();
        try {
            String key = loginHelper.getLicenseMapKey(url, projLabel, userId);
            String license = loginHelper.getLicense(key);
            if (license == null || license.isEmpty()) {
                Job fetchJob = fetchLicenseJobMap.get(proj);
                if (fetchJob == null || fetchJob.getResult() != null) {
                    // if result is not null, means fetchJob has already finished but no license fetched
                    fetchJob = fetchLicense(proj);
                }
                final Job fJob = fetchJob;
                if (fJob != null) {
                    final AtomicBoolean isInterupted = new AtomicBoolean(false);
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
                    dialog.run(true, true, new IRunnableWithProgress() {

                        @Override
                        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            monitor.setTaskName(fJob.getName());
                            while (true) {
                                if (monitor.isCanceled()) {
                                    /**
                                         * If network is slow, maybe just wait the fetch job finish, but still can click
                                         * the Refresh button to cancel all fetch jobs
                                         */
                                    // fJob.cancel();
                                    isInterupted.set(true);
                                    break;
                                }
                                IStatus result = fJob.getResult();
                                if (result != null) {
                                    break;
                                }
                                try {
                                    Thread.sleep(250);
                                } catch (Exception e) {
                                // nothing to do
                                }
                            }
                        }
                    });
                    if (isInterupted.get()) {
                        return false;
                    }
                }
                license = loginHelper.getLicense(key);
            }
            if (license == null || license.isEmpty()) {
                //$NON-NLS-1$
                throw new Exception(Messages.getString("LoginProjectPage.fetchLicense.error.failed"));
            }
        // will do save in CoreTisService if needed
        // ICoreTisService tisService = (ICoreTisService) GlobalServiceRegister.getDefault()
        // .getService(ICoreTisService.class);
        // File remoteLicense = tisService.getRemoteLicenseFile();
        // tisService.storeLicenseFile(remoteLicense, license);
        } catch (Exception e) {
            //$NON-NLS-1$
            ExceptionMessageDialog.openError(//$NON-NLS-1$
            getShell(), //$NON-NLS-1$
            Messages.getString("LoginProjectPage.fetchLicense.error.title"), Messages.getString("LoginProjectPage.fetchLicense.error.msg"), //$NON-NLS-1$
            e);
            return false;
        }
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) JSONException(org.talend.utils.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Project(org.talend.core.model.general.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConnectionBean(org.talend.core.model.general.ConnectionBean) Job(org.eclipse.core.runtime.jobs.Job)

Example 97 with ProgressMonitorDialog

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

the class ComponentsPreferencePage method performOk.

@Override
public boolean performOk() {
    boolean flag = super.performOk();
    String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
    if ("".equals(oldPath)) {
        //$NON-NLS-1$
        oldPath = null;
    }
    if ("".equals(newPath)) {
        //$NON-NLS-1$
        newPath = null;
    }
    DesignerPlugin.getDefault().getPreferenceStore().setValue(TalendDesignerPrefConstants.COMPONENT_ASSIST, enableComponentAssistCheckBoxField.getBooleanValue());
    TalendEditorComponentCreationUtil.updateAssistListener();
    if (this.oldPath != newPath) {
        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                //$NON-NLS-1$
                monitor.beginTask("Loading user component ......", 100);
                Display display = Display.getCurrent();
                if (display == null) {
                    display = Display.getDefault();
                }
                if (display != null) {
                    display.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            // install the new components via P2
                            ComponentsInstallComponent component = LocalComponentInstallHelper.getComponent();
                            if (component != null) {
                                String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
                                if (newPath != null && StringUtils.isNotEmpty(newPath.trim())) {
                                    File componentFolder = new File(newPath.trim());
                                    if (componentFolder.exists()) {
                                        try {
                                            component.setComponentFolder(componentFolder);
                                            if (component.install()) {
                                                String installedMessages = component.getInstalledMessages();
                                                //$NON-NLS-1$
                                                String title = Messages.getString("ComponentsPreferencePage_SuccessTitle");
                                                if (component.needRelaunch()) {
                                                    String warningMessage = Messages.getString(//$NON-NLS-1$
                                                    "ComponentsPreferencePage_SuccessMessage1") + //$NON-NLS-1$
                                                    Messages.getString("ComponentsPreferencePage_SuccessMessage2");
                                                    boolean confirm = MessageDialog.openConfirm(getShell(), title, installedMessages + '\n' + '\n' + warningMessage);
                                                    if (confirm) {
                                                        PlatformUI.getWorkbench().restart();
                                                    }
                                                } else {
                                                    MessageDialog.openInformation(getShell(), title, installedMessages);
                                                }
                                            }
                                        } finally {
                                            // after install, clear the setting for service.
                                            component.setComponentFolder(null);
                                        }
                                    }
                                }
                            }
                            // components will be reloaded when refreshTemplates;
                            // IComponentsFactory components = ComponentsFactoryProvider.getInstance();
                            // components.loadUserComponentsFromComponentsProviderExtension();
                            CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                            monitor.worked(50);
                            // ComponentUtilities.updatePalette();
                            ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
                            service.refreshTemplates();
                        }
                    });
                }
            }
        };
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
        try {
            dialog.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
            ExceptionHandler.process(e);
        }
        this.oldPath = newPath;
    }
    return flag;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ComponentsInstallComponent(org.talend.commons.runtime.service.ComponentsInstallComponent) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 98 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 99 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 100 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project bndtools by bndtools.

the class GitHubRepoDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    setTitle(title);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    container.setLayout(new GridLayout(2, false));
    Label lblRepo = new Label(container, SWT.NONE);
    lblRepo.setText("Repository Name:");
    txtRepository = new Text(container, SWT.BORDER);
    txtRepository.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    txtRepository.setMessage("username/repository");
    if (repository != null)
        txtRepository.setText(repository);
    new Label(container, SWT.NONE).setText("Branch:");
    txtBranch = new Text(container, SWT.BORDER);
    txtBranch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    txtBranch.setMessage("default branch");
    if (branch != null)
        txtBranch.setText(branch);
    ControlDecoration branchDecor = new ControlDecoration(txtBranch, SWT.LEFT, container);
    branchDecor.setDescriptionText("Specify the branch, tag or commit ID you would like to clone from the\nrepository. We use the default branch specified in GitHub settings.");
    branchDecor.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    branchDecor.setShowHover(true);
    final Button btnValidate = new Button(container, SWT.PUSH);
    btnValidate.setText("Validate");
    btnValidate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1));
    ModifyListener modifyListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            if (!txtRepository.getText().trim().equals(repository)) {
                isValidated = false;
                repository = txtRepository.getText().trim();
            }
            branch = txtBranch.getText().trim();
            updateButtons();
        }
    };
    txtRepository.addModifyListener(modifyListener);
    txtBranch.addModifyListener(modifyListener);
    btnValidate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setMessage(null, IMessageProvider.INFORMATION);
            try {
                if (repository == null || repository.isEmpty())
                    throw new GitHubValidationException("No repository name specified");
                if (repository.contains(":/"))
                    throw new GitHubValidationException("Specify GitHub repositories as username/repository");
                IRunnableWithProgress runnable = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            final GithubRepoDetailsDTO dto = new GitHub(cache, executor).loadRepoDetails(repository).getValue();
                            final URI cloneUri = URI.create(dto.clone_url);
                            btnValidate.getDisplay().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    setMessage(String.format("Validated! Clone URL is '%s'. Default branch 'origin/%s'", cloneUri, dto.default_branch), IMessageProvider.INFORMATION);
                                    isValidated = true;
                                    updateButtons();
                                }
                            });
                        } catch (InvocationTargetException e) {
                            throw e;
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                };
                ProgressRunner.execute(false, runnable, new ProgressMonitorDialog(getParentShell()), btnValidate.getDisplay());
                setErrorMessage(null);
            } catch (InvocationTargetException ex) {
                Throwable t = ex.getCause();
                if (t instanceof FileNotFoundException)
                    setErrorMessage("Could not find the requested repository");
                else
                    setErrorMessage(t.getClass().getSimpleName() + ": " + t.getMessage());
            } catch (GitHubValidationException ex) {
                setErrorMessage(ex.getMessage());
            } catch (Exception ex) {
                setErrorMessage(ex.getClass().getSimpleName() + ": " + ex.getMessage());
            }
        }
    });
    return area;
}
Also used : GitHubValidationException(org.bndtools.templating.jgit.GitHubValidationException) ModifyListener(org.eclipse.swt.events.ModifyListener) GitHub(org.bndtools.templating.jgit.GitHub) Label(org.eclipse.swt.widgets.Label) FileNotFoundException(java.io.FileNotFoundException) URI(java.net.URI) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Text(org.eclipse.swt.widgets.Text) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GitHubValidationException(org.bndtools.templating.jgit.GitHubValidationException) GithubRepoDetailsDTO(org.bndtools.templating.jgit.GithubRepoDetailsDTO) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData)

Aggregations

ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)108 InvocationTargetException (java.lang.reflect.InvocationTargetException)99 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)85 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)83 ArrayList (java.util.ArrayList)31 Display (org.eclipse.swt.widgets.Display)24 CoreException (org.eclipse.core.runtime.CoreException)21 Shell (org.eclipse.swt.widgets.Shell)18 List (java.util.List)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 IFile (org.eclipse.core.resources.IFile)14 PartInitException (org.eclipse.ui.PartInitException)14 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)12 File (java.io.File)10 HashMap (java.util.HashMap)10 IProject (org.eclipse.core.resources.IProject)9 SocketTask (com.cubrid.cubridmanager.core.common.socket.SocketTask)8 SQLException (java.sql.SQLException)8 Status (org.eclipse.core.runtime.Status)8