From af4138b9657ca978138ca56b89380e94e7e75ab1 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Thu, 13 Sep 2012 16:11:14 +0200 Subject: [PATCH] Allow users of ChangeTable to control styling of change rows Currently it is hard-coded in the ChangeTable that outdated and abandoned changes should be highlighted. With this change users of the ChangeTable can now control from outside which changes should be highlighted and how the highlighting should be done. The ChangeTable which shows the dependencies on the ChangeScreen is using the new ability so that outdated and abandoned changes are now only highlighted in the 'Depends On' section, but not anymore in the 'Needed By' section. Change-Id: If3140a3ad0a47d4c6813fc3aef06adb1c959f49b Signed-off-by: Edwin Kempin --- .../gerrit/client/changes/ChangeScreen.java | 17 +++++++ .../gerrit/client/changes/ChangeTable.java | 46 +++++++++++++++---- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java index 5fde797d49..e016149e40 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java @@ -183,6 +183,23 @@ public class ChangeScreen extends Screen } }; dependsOn = new ChangeTable.Section(Util.C.changeScreenDependsOn()); + dependsOn.setChangeRowFormatter(new ChangeTable.ChangeRowFormatter() { + @Override + public String getRowStyle(ChangeInfo c) { + if (! c.isLatest() || Change.Status.ABANDONED.equals(c.getStatus())) { + return Gerrit.RESOURCES.css().outdated(); + } + return null; + } + + @Override + public String getDisplayText(final ChangeInfo c, final String displayText) { + if (! c.isLatest()) { + return displayText + " [OUTDATED]"; + } + return displayText; + } + }); neededBy = new ChangeTable.Section(Util.C.changeScreenNeededBy()); dependencies.addSection(dependsOn); dependencies.addSection(neededBy); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeTable.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeTable.java index 3a13297756..0d6820d886 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeTable.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeTable.java @@ -191,7 +191,8 @@ public class ChangeTable extends NavigationTable { } } - private void populateChangeRow(final int row, final ChangeInfo c) { + private void populateChangeRow(final int row, final ChangeInfo c, + final ChangeRowFormatter changeRowFormatter) { ChangeCache cache = ChangeCache.get(c.getId()); cache.getChangeInfoCache().set(c); @@ -206,13 +207,12 @@ public class ChangeTable extends NavigationTable { if (c.getStatus() != null && c.getStatus() != Change.Status.NEW) { s += " (" + c.getStatus().name() + ")"; } - if (! c.isLatest()) { - s += " [OUTDATED]"; - table.getRowFormatter().addStyleName(row, Gerrit.RESOURCES.css().outdated()); - } else if (Change.Status.ABANDONED.equals(c.getStatus())) { - table.getRowFormatter().addStyleName(row, Gerrit.RESOURCES.css().outdated()); - } else { - table.getRowFormatter().removeStyleName(row, Gerrit.RESOURCES.css().outdated()); + if (changeRowFormatter != null) { + final String rowStyle = changeRowFormatter.getRowStyle(c); + if (rowStyle != null) { + table.getRowFormatter().addStyleName(row, rowStyle); + } + s = changeRowFormatter.getDisplayText(c, s); } table.setWidget(row, C_SUBJECT, new TableChangeLink(s, c)); @@ -222,6 +222,7 @@ public class ChangeTable extends NavigationTable { table.setWidget(row, C_BRANCH, new BranchLink(c.getProject().getKey(), c .getStatus(), c.getBranch(), c.getTopic())); table.setText(row, C_LAST_UPDATE, shortFormat(c.getLastUpdatedOn())); + setRowItem(row, c); } @@ -418,6 +419,8 @@ public class ChangeTable extends NavigationTable { int dataBegin; int rows; + private ChangeRowFormatter changeRowFormatter; + public Section() { this(null, ApprovalViewType.NONE, null); } @@ -440,6 +443,10 @@ public class ChangeTable extends NavigationTable { } } + public void setChangeRowFormatter(final ChangeRowFormatter changeRowFormatter) { + this.changeRowFormatter = changeRowFormatter; + } + public void display(final List changeList) { final int sz = changeList != null ? changeList.size() : 0; final boolean hadData = rows > 0; @@ -469,7 +476,7 @@ public class ChangeTable extends NavigationTable { for (int i = 0; i < sz; i++) { ChangeInfo c = changeList.get(i); - parent.populateChangeRow(dataBegin + i, c); + parent.populateChangeRow(dataBegin + i, c, changeRowFormatter); cids.add(c.getId()); } @@ -488,4 +495,25 @@ public class ChangeTable extends NavigationTable { } } } + + public static interface ChangeRowFormatter { + /** + * Returns the name of the CSS style that should be applied to the change + * row. + * + * @param c the change for which the styling should be returned + * @return the name of the CSS style that should be applied to the change + * row + */ + String getRowStyle(ChangeInfo c); + + /** + * Returns the text that should be displayed for the change. + * + * @param c the change for which the display text should be returned + * @param displayText the current display text + * @return the new display text + */ + String getDisplayText(ChangeInfo c, String displayText); + } }