Permalink
Browse files

Decorate branch with tag decoration of its last revision

  • Loading branch information...
1 parent 5e83465 commit fe6661a50e3c09df2ccd0f306a6e5185e84ac606 @angvoz committed Jan 13, 2016
View
@@ -74,6 +74,7 @@ CVS Version Tree will connect with arrows merged versions provided they are tagg
== What's new ==
=== New features in development version ("unstable" build) ===
+* Decorate branch with tag decoration of its last revision
* Improved reporting errors from CVS server
=== New features in release 1.7.2 ===
@@ -13,6 +13,11 @@
import net.sf.versiontree.VersionTreePlugin;
import net.sf.versiontree.data.IBranch;
+import net.sf.versiontree.data.IRevision;
+import net.sf.versiontree.data.ITreeElement;
+
+import java.util.Collections;
+import java.util.List;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.events.DisposeEvent;
@@ -47,7 +52,10 @@
private Color background;
private Image versionImage;
- private int stringXPosition = 0;
+ private Image lockedWithTagImage;
+ private Image requestImage;
+ private Image closedImage;
+ private Image completedImage;
/**
* Creates a widget representing a branch.
@@ -88,6 +96,11 @@ public void widgetDisposed(DisposeEvent e) {
*/
private void initializeImages() {
versionImage = VersionTreeImages.getImage(VersionTreeImages.IMG_BRANCH);
+
+ lockedWithTagImage = VersionTreeImages.getImage(VersionTreeImages.IMG_LOCKED);
+ requestImage = VersionTreeImages.getImage(VersionTreeImages.IMG_REQUEST);
+ closedImage = VersionTreeImages.getImage(VersionTreeImages.IMG_CLOSED);
+ completedImage = VersionTreeImages.getImage(VersionTreeImages.IMG_COMPLETED);
}
/**
@@ -101,18 +114,78 @@ protected void paintControl(PaintEvent e) {
gc.setBackground(background);
gc.fillRoundRectangle(0, 0, size.width, size.height, 20, 20);
+ Image tagImage = getTagImage();
+ if (tagImage != null) {
+ gc.drawImage(tagImage, INSET, INSET);
+ }
+
int yOffset = inset;
+ int stringXPosition = versionImage.getBounds().width + 2 * INSET;
Point extent = gc.stringExtent(branchData.getName());
- gc.drawString(branchData.getName(), INSET + versionImage.getBounds().width, yOffset);
+ gc.drawString(branchData.getName(), stringXPosition, yOffset);
yOffset += offsetBetweenStrings + extent.y;
gc.drawImage(versionImage, INSET, yOffset);
+
extent = gc.stringExtent(branchData.getBranchPrefix());
- stringXPosition = versionImage.getBounds().width + 2 * INSET;
gc.drawString(branchData.getBranchPrefix(), stringXPosition, yOffset);
gc.drawRoundRectangle(0, 0, size.width - 1, size.height - 1, 20, 20);
}
+ private Image getTagImage() {
+ Image tagImage = null;
+ List<IRevision> revisions = branchData.getRevisions();
+ String branchName = branchData.getName();
+ if (!branchName.equals(IBranch.HEAD_NAME)/* && !revisions.isEmpty()*/) {
+ IRevision lastRevision = null;
+ if (revisions.isEmpty()) {
+ ITreeElement par = branchData.getParent();
+ if (!(par instanceof IRevision)) {
+ return null;
+ }
+ lastRevision = (IRevision) par;
+ } else {
+ Collections.sort(revisions);
+ lastRevision = revisions.get(revisions.size()-1);
+ }
+
+ IPreferenceStore prefs = VersionTreePlugin.getDefault().getPreferenceStore();
+ boolean isLockedWithTag = false;
+ boolean isMerged = false;
+ boolean isBeingMerged = false;
+ boolean isClosed = false;
+ List<String> tags = lastRevision.getTags();
+ for (String tag : tags) {
+ if (tag.contains(branchName)) {
+ if (tag.matches(prefs.getString(VersionTreePlugin.PREF_REGEX_LOCKED))) {
+ isLockedWithTag = true;
+ // "locked" has preference over other icons
+ break;
+ }
+ if (tag.matches(prefs.getString(VersionTreePlugin.PREF_REGEX_REQUEST))) {
+ isBeingMerged = true;
+ }
+ if (tag.matches(prefs.getString(VersionTreePlugin.PREF_REGEX_CLOSED))) {
+ isClosed = true;
+ }
+ if (tag.matches(prefs.getString(VersionTreePlugin.PREF_REGEX_MERGE_TO))) {
+ isMerged = true;
+ }
+ }
+ }
+ if (isLockedWithTag) {
+ tagImage = lockedWithTagImage;
+ } else if (isBeingMerged) {
+ tagImage = requestImage;
+ } else if (isClosed && isMerged) {
+ tagImage = completedImage;
+ } else if (isClosed) {
+ tagImage = closedImage;
+ }
+ }
+ return tagImage;
+ }
+
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(width, height);
@@ -48,8 +48,6 @@
private static final int STRING_OFFSET = 2;
private static final int INSET = 3;
- private int stringXPosition = 0;
-
private IRevision revisionData;
private int width;
@@ -118,8 +116,6 @@ private void initializeImages() {
completedImage = VersionTreeImages.getImage(VersionTreeImages.IMG_COMPLETED);
lockedByMeImage = VersionTreeImages.getImage(VersionTreeImages.IMG_LOCKED_BY_ME);
lockedBySomebodyElseImage = VersionTreeImages.getImage(VersionTreeImages.IMG_LOCKED_BY_SOMEBODY_ELSE);
-
- stringXPosition = versionImage.getBounds().width + 2 * INSET;
}
/**
@@ -177,18 +173,19 @@ protected void paintControl(PaintEvent e) {
gc.drawImage(image, INSET, INSET);
}
+ int xOffset = versionImage.getBounds().width + 2 * INSET;
int yOffset = INSET;
Point extent = gc.stringExtent(getRevisionString());
// draw revision string
Color rememberColor = gc.getForeground();
if (revisionData.getLogEntry().isDeletion()) {
gc.setForeground(new Color(Display.getDefault(),128,128,128));
}
- gc.drawString(getRevisionString(), stringXPosition, yOffset);
+ gc.drawString(getRevisionString(), xOffset, yOffset);
yOffset += STRING_OFFSET + extent.y;
// draw author string
extent = gc.stringExtent(revisionData.getAuthor());
- gc.drawString(revisionData.getAuthor(), stringXPosition, yOffset);
+ gc.drawString(revisionData.getAuthor(), xOffset, yOffset);
// draw rectangle (or focus border if selected)
if (isSelected()) {
gc.drawFocus(0, 0, size.width, size.height);

0 comments on commit fe6661a

Please sign in to comment.