Search in sources :

Example 41 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project tdi-studio-se by Talend.

the class LoginProjectPage method fillUIBranches.

private void fillUIBranches(final Project project, boolean lastUsedBranch) throws JSONException {
    final String storage = getStorage(project);
    if (LoginHelper.isRemoteConnection(getConnection())) {
        currentProjectSettings = project;
        final List<String> projectBranches = new ArrayList<String>();
        if ("svn".equals(storage)) {
            //$NON-NLS-1$
            projectBranches.add("trunk");
            branchesViewer.setInput(projectBranches);
            //$NON-NLS-1$
            branchesViewer.setSelection(new StructuredSelection(new Object[] { "trunk" }));
        } else if ("git".equals(storage)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            String master = "master";
            projectBranches.add(master);
            branchesViewer.setInput(projectBranches);
            if (projectBranches.size() != 0) {
                branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.contains(master) ? master : projectBranches.get(0) }));
            }
        }
        branchesViewer.getCombo().setEnabled(false);
        if (backgroundGUIUpdate == null) /* || (backgroundGUIUpdate.getState() == Job.NONE) */
        {
            backgroundGUIUpdate = new //$NON-NLS-1$
            Job(//$NON-NLS-1$
            "List Branches") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    projectBranches.clear();
                    try {
                        projectBranches.addAll(loginHelper.getProjectBranches(currentProjectSettings));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        ExceptionHandler.process(e);
                    }
                    return org.eclipse.core.runtime.Status.OK_STATUS;
                }
            };
            Job.getJobManager().addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (event.getJob().equals(backgroundGUIUpdate)) {
                        if (branchesViewer != null && !branchesViewer.getCombo().isDisposed()) {
                            branchesViewer.getCombo().getDisplay().syncExec(new Runnable() {

                                @Override
                                public void run() {
                                    if (branchesViewer == null || branchesViewer.getControl() == null || branchesViewer.getControl().isDisposed()) {
                                        return;
                                    }
                                    branchesViewer.setInput(projectBranches);
                                    //branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.get(0) })); //$NON-NLS-1$ 
                                    if ("svn".equals(storage) && projectBranches.size() != 0) {
                                        branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.contains("trunk") ? "trunk" : projectBranches.get(0) }));
                                    } else if ("git".equals(storage) && projectBranches.size() != 0) {
                                        branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.contains("master") ? "master" : projectBranches.get(0) }));
                                    }
                                    // svnBranchCombo.getCombo().setFont(originalFont);
                                    branchesViewer.getCombo().setEnabled(projectViewer.getControl().isEnabled());
                                }
                            });
                        }
                    }
                }
            });
            branchesViewer.getCombo().addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent e) {
                    backgroundGUIUpdate = null;
                }
            });
        }
        backgroundGUIUpdate.schedule();
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JSONException(org.talend.utils.json.JSONException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JSONObject(org.talend.utils.json.JSONObject)

Example 42 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.

the class RunRequirementsPart method doResolve.

private void doResolve() {
    // Make sure all the parts of this editor page have committed their
    // dirty state to the model
    IFormPart[] parts = getManagedForm().getParts();
    for (IFormPart part : parts) {
        if (part.isDirty())
            part.commit(false);
    }
    final IFormPage page = (IFormPage) getManagedForm().getContainer();
    final IEditorInput input = page.getEditorInput();
    final IEditorPart editor = page.getEditor();
    final IFile file = ResourceUtil.getFile(input);
    final Shell parentShell = page.getEditor().getSite().getShell();
    // Create the wizard and pre-validate
    final ResolveJob job = new ResolveJob(model);
    IStatus validation = job.validateBeforeRun();
    if (!validation.isOK()) {
        ErrorDialog errorDialog = new ErrorDialog(parentShell, "Validation Problem", null, validation, IStatus.ERROR | IStatus.WARNING) {

            @Override
            protected void createButtonsForButtonBar(Composite parent) {
                // create OK, Cancel and Details buttons
                createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
                createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
                createDetailsButton(parent);
            }
        };
        int response = errorDialog.open();
        if (Window.CANCEL == response || validation.getSeverity() >= IStatus.ERROR) {
            btnResolveNow.setEnabled(true);
            return;
        }
    }
    // Add the operation to perform at the end of the resolution job (i.e.,
    // showing the result)
    final Runnable showResult = new Runnable() {

        @Override
        public void run() {
            ResolutionWizard wizard = new ResolutionWizard(model, file, job.getResolutionResult());
            WizardDialog dialog = new WizardDialog(parentShell, wizard);
            boolean dirtyBeforeResolve = editor.isDirty();
            if (dialog.open() == Dialog.OK && !dirtyBeforeResolve) {
                // only save the editor, when no unsaved changes happened before resolution
                editor.getEditorSite().getPage().saveEditor(editor, false);
            }
            btnResolveNow.setEnabled(true);
        }
    };
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            Outcome outcome = job.getResolutionResult().getOutcome();
            if (outcome != Outcome.Cancelled)
                parentShell.getDisplay().asyncExec(showResult);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ResolutionWizard(org.bndtools.core.resolve.ui.ResolutionWizard) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) IFormPage(org.eclipse.ui.forms.editor.IFormPage) IEditorPart(org.eclipse.ui.IEditorPart) ResolveJob(org.bndtools.core.resolve.ResolveJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Shell(org.eclipse.swt.widgets.Shell) Outcome(org.bndtools.core.resolve.ResolutionResult.Outcome) IFormPart(org.eclipse.ui.forms.IFormPart) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 43 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.

the class BndEditor method doAutoResolveOnSave.

private void doAutoResolveOnSave(IProgressMonitor monitor) {
    final Shell shell = getEditorSite().getShell();
    final IFile file = ResourceUtil.getFile(getEditorInput());
    if (file == null) {
        MessageDialog.openError(shell, "Resolution Error", "Unable to run resolution because the file is not in the workspace. NB.: the file will still be saved.");
        reallySave(monitor);
        return;
    }
    // Create resolver job and pre-validate
    final ResolveJob job = new ResolveJob(model);
    IStatus validation = job.validateBeforeRun();
    if (!validation.isOK()) {
        String message = "Unable to run the resolver. NB.: the file will still be saved.";
        ErrorDialog.openError(shell, "Resolution Validation Problem", message, validation, IStatus.ERROR | IStatus.WARNING);
        reallySave(monitor);
        return;
    }
    // Add operation to perform at the end of resolution (i.e. display
    // results and actually save the file)
    final UIJob completionJob = new UIJob(shell.getDisplay(), "Display Resolution Results") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            ResolutionResult result = job.getResolutionResult();
            ResolutionWizard wizard = new ResolutionWizard(model, file, result);
            if (result.getOutcome() != ResolutionResult.Outcome.Resolved) /*|| !result.getResolve().getOptionalResources().isEmpty() */
            {
                WizardDialog dialog = new WizardDialog(shell, wizard);
                if (dialog.open() != Window.OK) {
                    if (!wizard.performFinish()) {
                        MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
                    }
                }
            } else {
                if (!wizard.performFinish()) {
                    MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
                }
            }
            reallySave(monitor);
            return Status.OK_STATUS;
        }
    };
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            completionJob.schedule();
        }
    });
    // Start job
    job.setUser(true);
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ResolutionWizard(org.bndtools.core.resolve.ui.ResolutionWizard) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ResolveJob(org.bndtools.core.resolve.ResolveJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 44 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.

the class BundleCalculatedImportsPart method refresh.

@Override
public void refresh() {
    super.refresh();
    IFile file = getEditorFile();
    if (file == null)
        return;
    IPath location = file.getLocation();
    if (location == null)
        return;
    Set<BndFileCapReqLoader> loaders = Collections.singleton(new BndFileCapReqLoader(location.toFile()));
    final AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob(Messages.BundleCalculatedImportsPart_jobAnalyse, loaders);
    final Display display = tree.getDisplay();
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (job.getResult().isOK()) {
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (tree != null && !tree.isDisposed())
                            viewer.setInput(job.getRequirements());
                    }
                });
            }
        }
    });
    job.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) AnalyseBundleResolutionJob(bndtools.tasks.AnalyseBundleResolutionJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) BndFileCapReqLoader(bndtools.tasks.BndFileCapReqLoader) Display(org.eclipse.swt.widgets.Display)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)44 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)44 Job (org.eclipse.core.runtime.jobs.Job)17 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)16 IStatus (org.eclipse.core.runtime.IStatus)11 IFile (org.eclipse.core.resources.IFile)7 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IOException (java.io.IOException)3 QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)3 Status (org.eclipse.core.runtime.Status)3 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)3 AnalyseBundleResolutionJob (bndtools.tasks.AnalyseBundleResolutionJob)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExportDatabaseBean (net.heartsome.cat.database.bean.ExportDatabaseBean)2 ExportFilterBean (net.heartsome.cat.database.bean.ExportFilterBean)2