Search in sources :

Example 36 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class GitModelSynchronize method fireSynchronizeAction.

private static void fireSynchronizeAction(final IWorkbenchWindow window, final GitSynchronizeDataSet gsdSet, final ResourceMapping[] mappings) {
    final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsdSet);
    Job syncJob = new WorkspaceJob(UIText.GitModelSynchronize_fetchGitDataJobName) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            subscriber.init(monitor);
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.SYNCHRONIZE_READ_DATA.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    syncJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            RemoteResourceMappingContext remoteContext = new GitSubscriberResourceMappingContext(subscriber, gsdSet);
            SubscriberScopeManager manager = new SubscriberScopeManager(subscriber.getName(), mappings, subscriber, remoteContext, true);
            GitSubscriberMergeContext context = new GitSubscriberMergeContext(subscriber, manager, gsdSet);
            final GitModelSynchronizeParticipant participant = new GitModelSynchronizeParticipant(context);
            TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] { participant });
            IWorkbenchPart activePart = null;
            if (window != null)
                activePart = window.getActivePage().getActivePart();
            participant.run(activePart);
        }
    });
    syncJob.setUser(true);
    syncJob.schedule();
}
Also used : GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ISynchronizeParticipant(org.eclipse.team.ui.synchronize.ISynchronizeParticipant) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)

Example 37 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class FilteredCheckboxTree method doCreateRefreshJob.

/*
	 * Overridden to hook a listener on the job and set the deferred content
	 * provider to synchronous mode before a filter is done.
	 *
	 */
@Override
protected WorkbenchJob doCreateRefreshJob() {
    WorkbenchJob filterJob = super.doCreateRefreshJob();
    filterJob.addJobChangeListener(new JobChangeAdapter() {

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

                    @Override
                    public void run() {
                        if (checkboxViewer.getTree().isDisposed())
                            return;
                        checkboxViewer.restoreLeafCheckState();
                    }
                });
            }
        }
    });
    return filterJob;
}
Also used : WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 38 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class CommitViewerComparator method createFileSection.

private Section createFileSection(Composite container) {
    Section filesSection = toolkit.createSection(container, ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(filesSection);
    Composite filesArea = toolkit.createComposite(filesSection);
    filesSection.setClient(filesArea);
    toolkit.paintBordersFor(filesArea);
    GridLayoutFactory.fillDefaults().extendedMargins(2, 2, 2, 2).applyTo(filesArea);
    ToolBar filesToolbar = new ToolBar(filesSection, SWT.FLAT);
    filesSection.setTextClient(filesToolbar);
    PatternFilter patternFilter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(Viewer viewer, Object element) {
            if (element instanceof CommitItem) {
                CommitItem commitItem = (CommitItem) element;
                return wordMatches(commitItem.path);
            }
            return super.isLeafMatch(viewer, element);
        }
    };
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredCheckboxTree resourcesTreeComposite = new FilteredCheckboxTree(filesArea, toolkit, SWT.FULL_SELECTION, patternFilter) {

        @Override
        protected WorkbenchJob doCreateRefreshJob() {
            // workaround for file filter not having an explicit change
            // listener
            WorkbenchJob filterJob = super.doCreateRefreshJob();
            filterJob.addJobChangeListener(new JobChangeAdapter() {

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

                            @Override
                            public void run() {
                                updateFileSectionText();
                            }
                        });
                    }
                }
            });
            return filterJob;
        }
    };
    Tree resourcesTree = resourcesTreeComposite.getViewer().getTree();
    resourcesTree.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
    resourcesTreeComposite.setLayoutData(GridDataFactory.fillDefaults().hint(600, 200).grab(true, true).create());
    resourcesTree.addSelectionListener(new CommitItemSelectionListener());
    resourcesTree.setHeaderVisible(true);
    if (getPreferenceStore().getBoolean(UIPreferences.WARN_BEFORE_COMMITTING) && getPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT)) {
        ignoreErrors = new Button(resourcesTreeComposite, SWT.CHECK);
        ignoreErrors.setText(UIText.CommitDialog_IgnoreErrors);
        ignoreErrors.setSelection(false);
        ignoreErrors.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Button button = (Button) e.getSource();
                boolean enable = button.getSelection();
                updateMessage();
                updateCommitButtons(enable);
            }
        });
    }
    TreeColumn statCol = new TreeColumn(resourcesTree, SWT.LEFT);
    statCol.setText(UIText.CommitDialog_Status);
    statCol.setWidth(150);
    statCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByStatus));
    TreeColumn resourceCol = new TreeColumn(resourcesTree, SWT.LEFT);
    resourceCol.setText(UIText.CommitDialog_Path);
    resourceCol.setWidth(415);
    resourceCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByFile));
    filesViewer = resourcesTreeComposite.getCheckboxTreeViewer();
    new TreeViewerColumn(filesViewer, statCol).setLabelProvider(createStatusLabelProvider());
    new TreeViewerColumn(filesViewer, resourceCol).setLabelProvider(new CommitPathLabelProvider());
    ColumnViewerToolTipSupport.enableFor(filesViewer);
    filesViewer.setContentProvider(new CommitFileContentProvider());
    filesViewer.setUseHashlookup(true);
    IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
    if (settings.get(SHOW_UNTRACKED_PREF) != null) {
        // note, no matter how the dialog settings are, if
        // the preferences force us to include untracked files
        // we must show them
        showUntracked = Boolean.valueOf(settings.get(SHOW_UNTRACKED_PREF)).booleanValue() || getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
    }
    filesViewer.addFilter(new CommitItemFilter());
    filesViewer.setInput(items.toArray());
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(createContextMenuListener());
    filesViewer.getTree().setMenu(menuManager.createContextMenu(filesViewer.getTree()));
    filesViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateFileSectionText();
        }
    });
    showUntrackedItem = new ToolItem(filesToolbar, SWT.CHECK);
    Image showUntrackedImage = UIIcons.UNTRACKED_FILE.createImage();
    UIUtils.hookDisposal(showUntrackedItem, showUntrackedImage);
    showUntrackedItem.setImage(showUntrackedImage);
    showUntrackedItem.setToolTipText(UIText.CommitDialog_ShowUntrackedFiles);
    showUntrackedItem.setSelection(showUntracked);
    showUntrackedItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showUntracked = showUntrackedItem.getSelection();
            filesViewer.refresh(true);
            updateFileSectionText();
            updateMessage();
        }
    });
    ToolItem checkAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image checkImage = UIIcons.CHECK_ALL.createImage();
    UIUtils.hookDisposal(checkAllItem, checkImage);
    checkAllItem.setImage(checkImage);
    checkAllItem.setToolTipText(UIText.CommitDialog_SelectAll);
    checkAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(true);
            updateFileSectionText();
            updateMessage();
        }
    });
    ToolItem uncheckAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
    UIUtils.hookDisposal(uncheckAllItem, uncheckImage);
    uncheckAllItem.setImage(uncheckImage);
    uncheckAllItem.setToolTipText(UIText.CommitDialog_DeselectAll);
    uncheckAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(false);
            updateFileSectionText();
            updateMessage();
        }
    });
    if (!allowToChangeSelection) {
        amendingItem.setSelection(false);
        amendingItem.setEnabled(false);
        showUntrackedItem.setSelection(false);
        showUntrackedItem.setEnabled(false);
        checkAllItem.setEnabled(false);
        uncheckAllItem.setEnabled(false);
        filesViewer.addCheckStateListener(new ICheckStateListener() {

            @Override
            public void checkStateChanged(CheckStateChangedEvent event) {
                if (!event.getChecked())
                    filesViewer.setAllChecked(true);
                updateFileSectionText();
            }
        });
        filesViewer.setAllChecked(true);
    } else {
        final boolean includeUntracked = getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
        for (CommitItem item : items) {
            if (!preselectAll && !preselectedFiles.contains(item.path))
                continue;
            if (item.status == Status.ASSUME_UNCHANGED)
                continue;
            if (!includeUntracked && item.status == Status.UNTRACKED)
                continue;
            filesViewer.setChecked(item, true);
        }
    }
    statCol.pack();
    resourceCol.pack();
    return filesSection;
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) Tree(org.eclipse.swt.widgets.Tree) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Section(org.eclipse.ui.forms.widgets.Section) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ToolBar(org.eclipse.swt.widgets.ToolBar) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 39 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class CancelableFuture method start.

/**
 * On the first call, starts a background job to fetch the result.
 * Subsequent calls do nothing and return immediately. Before creating and
 * scheduling the job, {@link #prepareRun()} is called.
 *
 * @throws InvocationTargetException
 *             propagated from {@link #prepareRun()}
 */
public synchronized void start() throws InvocationTargetException {
    if (job != null || state != State.PRISTINE) {
        return;
    }
    try {
        prepareRun();
    } catch (InvocationTargetException e) {
        finish(false);
        throw e;
    }
    job = new InterruptibleJob(getJobTitle()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                CancelableFuture.this.run(monitor);
                return Status.OK_STATUS;
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            } catch (InvocationTargetException e) {
                synchronized (CancelableFuture.this) {
                    if (state == State.CANCELING || state == State.INTERRUPT) {
                        return Status.CANCEL_STATUS;
                    }
                }
                return Activator.createErrorStatus(e.getLocalizedMessage(), e);
            } catch (RuntimeException e) {
                return Activator.createErrorStatus(e.getLocalizedMessage(), e);
            }
        }
    };
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            IStatus status = event.getResult();
            finish(status != null && status.isOK());
        }
    });
    job.setUser(false);
    job.setSystem(true);
    state = State.SCHEDULED;
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 40 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class StashDropHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final RevCommit commit = getSelectedItem(RevCommit.class, event);
    if (commit == null)
        return null;
    Repository repo = getSelectedItem(Repository.class, event);
    if (repo == null)
        return null;
    final Shell parent = getPart(event).getSite().getShell();
    final int stashIndex = getStashIndex(repo, commit.getId());
    if (!confirmStashDrop(parent, stashIndex))
        return null;
    final StashDropOperation op = new StashDropOperation(repo, stashIndex);
    Job job = new WorkspaceJob(MessageFormat.format(UIText.StashDropCommand_jobTitle, commit.name())) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (CoreException e) {
                Activator.logError(MessageFormat.format(UIText.StashDropCommand_dropFailed, // $NON-NLS-1$
                "stash@{" + stashIndex + "}"), // $NON-NLS-1$
                e);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.STASH.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    final IWorkbenchPart part = getPart(event);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()) {
                if (part instanceof CommitEditor) {
                    ((CommitEditor) part).close(false);
                }
            }
        }
    });
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.schedule();
    return null;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) StashDropOperation(org.eclipse.egit.core.op.StashDropOperation) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)166 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)157 Job (org.eclipse.core.runtime.jobs.Job)44 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)43 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 File (java.io.File)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)8 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7 IProject (org.eclipse.core.resources.IProject)6