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 <edwin.kempin@sap.com>
This commit is contained in:
@@ -183,6 +183,23 @@ public class ChangeScreen extends Screen
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
dependsOn = new ChangeTable.Section(Util.C.changeScreenDependsOn());
|
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());
|
neededBy = new ChangeTable.Section(Util.C.changeScreenNeededBy());
|
||||||
dependencies.addSection(dependsOn);
|
dependencies.addSection(dependsOn);
|
||||||
dependencies.addSection(neededBy);
|
dependencies.addSection(neededBy);
|
||||||
|
@@ -191,7 +191,8 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
ChangeCache cache = ChangeCache.get(c.getId());
|
||||||
cache.getChangeInfoCache().set(c);
|
cache.getChangeInfoCache().set(c);
|
||||||
|
|
||||||
@@ -206,13 +207,12 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
if (c.getStatus() != null && c.getStatus() != Change.Status.NEW) {
|
if (c.getStatus() != null && c.getStatus() != Change.Status.NEW) {
|
||||||
s += " (" + c.getStatus().name() + ")";
|
s += " (" + c.getStatus().name() + ")";
|
||||||
}
|
}
|
||||||
if (! c.isLatest()) {
|
if (changeRowFormatter != null) {
|
||||||
s += " [OUTDATED]";
|
final String rowStyle = changeRowFormatter.getRowStyle(c);
|
||||||
table.getRowFormatter().addStyleName(row, Gerrit.RESOURCES.css().outdated());
|
if (rowStyle != null) {
|
||||||
} else if (Change.Status.ABANDONED.equals(c.getStatus())) {
|
table.getRowFormatter().addStyleName(row, rowStyle);
|
||||||
table.getRowFormatter().addStyleName(row, Gerrit.RESOURCES.css().outdated());
|
}
|
||||||
} else {
|
s = changeRowFormatter.getDisplayText(c, s);
|
||||||
table.getRowFormatter().removeStyleName(row, Gerrit.RESOURCES.css().outdated());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table.setWidget(row, C_SUBJECT, new TableChangeLink(s, c));
|
table.setWidget(row, C_SUBJECT, new TableChangeLink(s, c));
|
||||||
@@ -222,6 +222,7 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
table.setWidget(row, C_BRANCH, new BranchLink(c.getProject().getKey(), c
|
table.setWidget(row, C_BRANCH, new BranchLink(c.getProject().getKey(), c
|
||||||
.getStatus(), c.getBranch(), c.getTopic()));
|
.getStatus(), c.getBranch(), c.getTopic()));
|
||||||
table.setText(row, C_LAST_UPDATE, shortFormat(c.getLastUpdatedOn()));
|
table.setText(row, C_LAST_UPDATE, shortFormat(c.getLastUpdatedOn()));
|
||||||
|
|
||||||
setRowItem(row, c);
|
setRowItem(row, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,6 +419,8 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
int dataBegin;
|
int dataBegin;
|
||||||
int rows;
|
int rows;
|
||||||
|
|
||||||
|
private ChangeRowFormatter changeRowFormatter;
|
||||||
|
|
||||||
public Section() {
|
public Section() {
|
||||||
this(null, ApprovalViewType.NONE, null);
|
this(null, ApprovalViewType.NONE, null);
|
||||||
}
|
}
|
||||||
@@ -440,6 +443,10 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChangeRowFormatter(final ChangeRowFormatter changeRowFormatter) {
|
||||||
|
this.changeRowFormatter = changeRowFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
public void display(final List<ChangeInfo> changeList) {
|
public void display(final List<ChangeInfo> changeList) {
|
||||||
final int sz = changeList != null ? changeList.size() : 0;
|
final int sz = changeList != null ? changeList.size() : 0;
|
||||||
final boolean hadData = rows > 0;
|
final boolean hadData = rows > 0;
|
||||||
@@ -469,7 +476,7 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
|
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int i = 0; i < sz; i++) {
|
||||||
ChangeInfo c = changeList.get(i);
|
ChangeInfo c = changeList.get(i);
|
||||||
parent.populateChangeRow(dataBegin + i, c);
|
parent.populateChangeRow(dataBegin + i, c, changeRowFormatter);
|
||||||
cids.add(c.getId());
|
cids.add(c.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,4 +495,25 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user