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();
}
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;
}
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;
}
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();
}
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;
}
Aggregations