use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.
the class AbstractHistoryCommandHandler method getRefNodes.
/**
* Utility to get a list of Refs from a commit in order to handle ambiguous
* selections when a Ref is preferred over a commit.
*
* @param commit
* @param repo
* @param refPrefixes
* e.g. "refs/heads/" or ""
* @return a list of RefNodes
*/
protected List<RefNode> getRefNodes(ObjectId commit, Repository repo, String... refPrefixes) {
List<Ref> availableBranches = new ArrayList<>();
List<RefNode> nodes = new ArrayList<>();
try {
Map<String, Ref> branches = new HashMap<>();
for (String refPrefix : refPrefixes) {
branches.putAll(repo.getRefDatabase().getRefs(refPrefix));
}
for (Ref branch : branches.values()) {
ObjectId objectId = branch.getLeaf().getObjectId();
if (objectId != null && objectId.equals(commit)) {
availableBranches.add(branch);
}
}
RepositoryNode repoNode = new RepositoryNode(null, repo);
for (Ref ref : availableBranches) {
nodes.add(new RefNode(repoNode, repo, ref));
}
} catch (IOException e) {
// ignore here
}
return nodes;
}
use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.
the class DeleteBranchDialog method refNameFromDialog.
@Override
protected String refNameFromDialog() {
selectedRefs.clear();
Set<String> selected = new HashSet<>();
IStructuredSelection selection = (IStructuredSelection) branchTree.getSelection();
for (Object sel : selection.toArray()) {
if (!(sel instanceof RefNode))
continue;
RefNode node = (RefNode) sel;
Ref ref = node.getObject();
selectedRefs.add(ref);
selected.add(ref.getName());
}
boolean enabled = !selected.isEmpty() && !selected.contains(currentBranch);
getButton(Window.OK).setEnabled(enabled);
return null;
}
use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.
the class DeleteBranchDialog method buttonPressed.
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == Window.OK) {
try {
int result = deleteBranch(selectedRefs, false);
if (result == DeleteBranchOperation.REJECTED_UNMERGED) {
List<RefNode> nodes = extractSelectedRefNodes();
MessageDialog messageDialog = new UnmergedBranchDialog<>(getShell(), nodes);
if (messageDialog.open() == Window.OK)
deleteBranch(selectedRefs, true);
else
return;
} else if (result == DeleteBranchOperation.REJECTED_CURRENT)
Activator.handleError(UIText.DeleteBranchCommand_CannotDeleteCheckedOutBranch, null, true);
} catch (CoreException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
super.buttonPressed(buttonId);
}
use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.
the class AbstractBranchSelectionDialog method createRefNode.
private RefNode createRefNode(RepositoryTreeNode<?> root, Repository repository, Ref ref) {
IContentProvider cp = branchTree.getContentProvider();
if (cp instanceof RepositoriesViewContentProvider && ((RepositoriesViewContentProvider) cp).isHierarchical()) {
// Create intermediary BranchHierarchyNodes
String fullName = ref.getName();
int i = 0;
if (fullName.startsWith(Constants.R_HEADS)) {
i = Constants.R_HEADS.length();
} else if (fullName.startsWith(Constants.R_REMOTES)) {
i = Constants.R_REMOTES.length();
}
RepositoryTreeNode<?> top = root;
int l = fullName.length();
while (i < l) {
int j = fullName.indexOf('/', i);
if (j > i) {
top = new BranchHierarchyNode(top, repository, new Path(fullName.substring(0, j)));
i = j + 1;
} else {
break;
}
}
return new RefNode(top, repository, ref);
} else {
return new RefNode(root, repository, ref);
}
}
use of org.eclipse.egit.ui.internal.repository.tree.RefNode 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;
}
Aggregations