use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class RepositoriesView method selectAndReveal.
private void selectAndReveal(Map<Repository, Collection<String>> pathsByRepo) {
final List<RepositoryTreeNode> nodesToShow = new ArrayList<>();
for (Map.Entry<Repository, Collection<String>> entry : pathsByRepo.entrySet()) {
Repository repository = entry.getKey();
for (String repoPath : entry.getValue()) {
final RepositoryTreeNode node = getNodeForPath(repository, repoPath);
if (node != null) {
nodesToShow.add(node);
}
}
}
selectReveal(new StructuredSelection(nodesToShow));
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class RepositoriesViewContentProvider method getTagsChildren.
private Object[] getTagsChildren(RepositoryTreeNode parentNode, Repository repo) {
List<RepositoryTreeNode<Ref>> nodes = new ArrayList<>();
try (RevWalk walk = new RevWalk(repo)) {
walk.setRetainBody(true);
Map<String, Ref> tagRefs = getRefs(repo, Constants.R_TAGS);
for (Ref tagRef : tagRefs.values()) {
ObjectId objectId = tagRef.getLeaf().getObjectId();
RevObject revObject = walk.parseAny(objectId);
RevObject peeledObject = walk.peel(revObject);
TagNode tagNode = createTagNode(parentNode, repo, tagRef, revObject, peeledObject);
nodes.add(tagNode);
}
} catch (IOException e) {
return handleException(e, parentNode);
}
return nodes.toArray();
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class RepositoriesViewLabelProvider method getStyledText.
@Override
public StyledString getStyledText(Object element) {
if (!(element instanceof RepositoryTreeNode))
return null;
RepositoryTreeNode node = (RepositoryTreeNode) element;
switch(node.getType()) {
case REPO:
if (node.getParent() != null && node.getParent().getType() == RepositoryTreeNodeType.SUBMODULES)
return getStyledTextForSubmodule(node);
return GitLabels.getStyledLabelExtendedSafe(node.getObject());
case ADDITIONALREF:
Ref ref = (Ref) node.getObject();
// shorten the name
StyledString refName = new StyledString(Repository.shortenRefName(ref.getName()));
ObjectId refId;
if (ref.isSymbolic()) {
refName.append(' ');
refName.append('[', StyledString.DECORATIONS_STYLER);
refName.append(ref.getLeaf().getName(), StyledString.DECORATIONS_STYLER);
refName.append(']', StyledString.DECORATIONS_STYLER);
refId = ref.getLeaf().getObjectId();
} else
refId = ref.getObjectId();
refName.append(' ');
RevCommit commit = getLatestCommit(node);
if (commit != null)
refName.append(abbreviate(commit), StyledString.QUALIFIER_STYLER).append(' ').append(commit.getShortMessage(), StyledString.QUALIFIER_STYLER);
else
refName.append(abbreviate(refId), StyledString.QUALIFIER_STYLER);
return refName;
case WORKINGDIR:
StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode);
// $NON-NLS-1$
dirString.append(" - ", StyledString.QUALIFIER_STYLER);
dirString.append(node.getRepository().getWorkTree().getAbsolutePath(), StyledString.QUALIFIER_STYLER);
return dirString;
case REF:
StyledString styled = null;
String nodeText = getSimpleText(node);
if (nodeText != null) {
styled = new StyledString(nodeText);
if (verboseBranchMode) {
RevCommit latest = getLatestCommit(node);
if (latest != null)
styled.append(' ').append(abbreviate(latest), StyledString.QUALIFIER_STYLER).append(' ').append(latest.getShortMessage(), StyledString.QUALIFIER_STYLER);
}
}
return styled;
case TAG:
return getStyledTextForTag((TagNode) node);
case STASHED_COMMIT:
return getStyledTextForCommit((StashedCommitNode) node);
case SUBMODULES:
return getStyledTextForSubmodules((SubmodulesNode) node);
case PUSH:
// fall through
case FETCH:
// fall through
case FILE:
// fall through
case FOLDER:
// fall through
case BRANCHES:
// fall through
case LOCAL:
// fall through
case REMOTETRACKING:
// fall through
case BRANCHHIERARCHY:
// fall through
case TAGS:
// fall through;
case ADDITIONALREFS:
// fall through
case REMOTES:
// fall through
case REMOTE:
// fall through
case STASH:
// fall through
case ERROR:
{
String label = getSimpleText(node);
if (label != null)
return new StyledString(label);
}
}
return null;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class RepositoriesViewLabelProvider method decorateImage.
private Image decorateImage(final Image image, Object element) {
RepositoryTreeNode node = (RepositoryTreeNode) element;
switch(node.getType()) {
case TAG:
// fall through
case ADDITIONALREF:
// fall through
case REF:
// if the branch or tag is checked out,
// we want to decorate the corresponding
// node with a little check indicator
String refName = ((Ref) node.getObject()).getName();
Ref leaf = ((Ref) node.getObject()).getLeaf();
String branchName;
String compareString;
try {
branchName = node.getRepository().getFullBranch();
if (branchName == null)
return image;
if (refName.startsWith(Constants.R_HEADS)) {
// local branch: HEAD would be on the branch
compareString = refName;
} else if (refName.startsWith(Constants.R_TAGS)) {
// tag: HEAD would be on the commit id to which the tag is
// pointing
TagNode tagNode = (TagNode) node;
compareString = tagNode.getCommitId();
} else if (refName.startsWith(Constants.R_REMOTES)) {
// remote branch: HEAD would be on the commit id to which
// the branch is pointing
ObjectId id = node.getRepository().resolve(refName);
if (id == null)
return image;
try (RevWalk rw = new RevWalk(node.getRepository())) {
RevCommit commit = rw.parseCommit(id);
compareString = commit.getId().name();
}
} else if (refName.equals(Constants.HEAD)) {
return getDecoratedImage(image);
} else {
String leafname = leaf.getName();
if (leafname.startsWith(Constants.R_REFS) && leafname.equals(node.getRepository().getFullBranch())) {
return getDecoratedImage(image);
}
ObjectId objectId = leaf.getObjectId();
if (objectId != null && objectId.equals(node.getRepository().resolve(Constants.HEAD))) {
return getDecoratedImage(image);
}
// some other symbolic reference
return image;
}
} catch (IOException e1) {
return image;
}
if (compareString != null && compareString.equals(branchName)) {
return getDecoratedImage(image);
}
return image;
default:
return image;
}
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class RepositoryPropertySourceProvider method getPropertySource.
@Override
public IPropertySource getPropertySource(Object object) {
if (object == lastObject)
return lastRepositorySource;
if (!(object instanceof RepositoryTreeNode))
return null;
registerDisposal();
removeListener();
RepositoryTreeNode node = (RepositoryTreeNode) object;
listenerHandle = node.getRepository().getListenerList().addConfigChangedListener(new ConfigChangedListener() {
@Override
public void onConfigChanged(ConfigChangedEvent event) {
// force a refresh of the page
lastObject = null;
myPage.getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
myPage.setPropertySourceProvider(RepositoryPropertySourceProvider.this);
}
});
}
});
if (node.getType() == RepositoryTreeNodeType.REPO) {
lastObject = object;
checkChangeType(SourceType.REPOSITORY);
lastRepositorySource = new RepositoryPropertySource((Repository) node.getObject(), myPage);
return lastRepositorySource;
} else if (node.getType() == RepositoryTreeNodeType.REMOTE) {
lastObject = object;
checkChangeType(SourceType.REMOTE);
lastRepositorySource = new RepositoryRemotePropertySource(node.getRepository().getConfig(), (String) node.getObject(), myPage);
return lastRepositorySource;
} else if (node.getType() == RepositoryTreeNodeType.FETCH || node.getType() == RepositoryTreeNodeType.PUSH)
return getPropertySource(node.getParent());
else if (node.getType() == RepositoryTreeNodeType.REF) {
lastObject = object;
Ref ref = (Ref) node.getObject();
if (ref.getName().startsWith(Constants.R_HEADS) || ref.getName().startsWith(Constants.R_REMOTES)) {
checkChangeType(SourceType.BRANCH);
Repository repository = AdapterUtils.adapt(node, Repository.class);
lastRepositorySource = new BranchPropertySource(repository, ref.getName(), myPage);
return lastRepositorySource;
}
return null;
} else
return null;
}
Aggregations