use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.
the class MergeCommand method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
RepositoryTreeNode node = getSelectedNodes(event).get(0);
final Repository repository = node.getRepository();
if (!MergeActionHandler.checkMergeIsPossible(repository, getShell(event)) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
return null;
}
BasicConfigurationDialog.show(repository);
String targetRef;
if (node instanceof RefNode) {
String refName = ((RefNode) node).getObject().getName();
try {
if (refName.equals(repository.getFullBranch()))
targetRef = null;
else
targetRef = refName;
} catch (IOException e) {
targetRef = null;
}
} else if (node instanceof TagNode)
targetRef = ((TagNode) node).getObject().getName();
else
targetRef = null;
final String refName;
final MergeOperation op;
if (targetRef != null) {
refName = targetRef;
op = new MergeOperation(repository, refName);
} else {
MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(getShell(event), repository);
if (mergeTargetSelectionDialog.open() != IDialogConstants.OK_ID)
return null;
refName = mergeTargetSelectionDialog.getRefName();
op = new MergeOperation(repository, refName);
op.setSquash(mergeTargetSelectionDialog.isMergeSquash());
op.setFastForwardMode(mergeTargetSelectionDialog.getFastForwardMode());
op.setCommit(mergeTargetSelectionDialog.isCommit());
}
String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName);
Job job = new WorkspaceJob(jobname) {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
try {
op.execute(monitor);
} catch (final CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.setRule(op.getSchedulingRule());
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent jobEvent) {
IStatus result = jobEvent.getJob().getResult();
if (result.getSeverity() == IStatus.CANCEL)
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
// don't use getShell(event) here since
// the active shell has changed since the
// execution has been triggered.
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.openInformation(shell, UIText.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage);
}
});
else if (!result.isOK())
Activator.handleError(result.getMessage(), result.getException(), true);
else
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MergeResultDialog.getDialog(shell, repository, op.getResult()).open();
}
});
}
});
job.schedule();
return null;
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.
the class FeatureFinishHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
if (gfRepo == null) {
return error(UIText.Handlers_noGitflowRepositoryFound);
}
final String featureBranch;
Repository repo = gfRepo.getRepository();
try {
featureBranch = repo.getBranch();
} catch (IOException e) {
return error(e.getMessage(), e);
}
Shell activeShell = HandlerUtil.getActiveShell(event);
FinishFeatureDialog dialog = new FinishFeatureDialog(activeShell, featureBranch);
if (dialog.open() != Window.OK) {
return null;
}
final boolean squash = dialog.isSquash();
boolean keepBranch = dialog.isKeepBranch();
try {
try {
if (squash && !UIRepositoryUtils.handleUncommittedFiles(repo, activeShell))
return null;
} catch (GitAPIException e) {
Activator.logError(e.getMessage(), e);
return null;
}
final FeatureFinishOperation operation = new FeatureFinishOperation(gfRepo);
operation.setSquash(squash);
operation.setKeepBranch(keepBranch);
JobUtil.scheduleUserWorkspaceJob(operation, UIText.FeatureFinishHandler_finishingFeature, JobFamilies.GITFLOW_FAMILY, new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent jobChangeEvent) {
if (jobChangeEvent.getResult().isOK()) {
postMerge(gfRepo, featureBranch, squash, operation.getMergeResult());
}
}
});
} catch (WrongGitFlowStateException | CoreException | IOException | OperationCanceledException e) {
return error(e.getMessage(), e);
}
return null;
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.
the class MergeActionHandler method doMerge.
/**
* Run a {@link MergeOperation} in a {@link WorkspaceJob} and report the
* result in a dialog.
*
* @param repository
* the merge operates on
* @param op
* performing the merge
* @param refName
* the merge is for; used in the job's name
*/
public static void doMerge(Repository repository, MergeOperation op, String refName) {
JobUtil.scheduleUserWorkspaceJob(op, NLS.bind(UIText.MergeAction_JobNameMerge, refName), JobFamilies.MERGE, new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
IStatus result = event.getJob().getResult();
if (result.getSeverity() == IStatus.CANCEL) {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.openInformation(shell, UIText.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage);
});
} else if (!result.isOK()) {
Activator.handleError(result.getMessage(), result.getException(), true);
} else {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MergeResultDialog.getDialog(shell, repository, op.getResult()).open();
});
}
}
});
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.
the class BranchOperationUI method start.
/**
* Starts the operation asynchronously
*/
public void start() {
target = confirmTarget(new NullProgressMonitor());
if (target == null) {
return;
}
String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
String jobname = NLS.bind(UIText.BranchAction_checkingOut, repoName, target);
boolean restore = Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.CHECKOUT_PROJECT_RESTORE);
final CheckoutJob job = new CheckoutJob(jobname, restore);
job.setUser(true);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent cevent) {
show(job.getCheckoutResult());
}
});
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.
the class PullOperationUI method handleUncommittedChanges.
/**
* @param repository
* @param files
* uncommitted files that were in the way for the rebase
* @param shell
*/
private void handleUncommittedChanges(final Repository repository, final List<String> files, Shell shell) {
String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
CleanupUncomittedChangesDialog cleanupUncomittedChangesDialog = new CleanupUncomittedChangesDialog(shell, MessageFormat.format(UIText.AbstractRebaseCommandHandler_cleanupDialog_title, repoName), UIText.AbstractRebaseCommandHandler_cleanupDialog_text, repository, files);
cleanupUncomittedChangesDialog.open();
if (cleanupUncomittedChangesDialog.shouldContinue()) {
final PullOperationUI parentOperation = this;
final PullOperationUI pullOperationUI = new PullOperationUI(Collections.singleton(repository));
pullOperationUI.checkForLaunches = false;
tasksToWaitFor.incrementAndGet();
pullOperationUI.start(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
// put the result from this subtask into the result map of
// the outer PullOperationUI and display the results if all
// subtasks have reported back
parentOperation.results.putAll(pullOperationUI.results);
int missing = parentOperation.tasksToWaitFor.decrementAndGet();
if (missing == 0)
parentOperation.showResults();
}
});
}
}
Aggregations