Allow users to sort 'My' menu items of preference screen

Change-Id: I153da15b5ace9a1aa7ec85f0d11dcb2dccff0260
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2014-03-26 03:44:40 +01:00
parent 95c3addd1a
commit dfe46232d0
7 changed files with 82 additions and 19 deletions

@ -119,4 +119,6 @@ public interface GerritConstants extends Constants {
String stringListPanelAdd();
String stringListPanelDelete();
String stringListPanelUp();
String stringListPanelDown();
}

@ -102,3 +102,5 @@ userCannotVoteToolTip = User cannot vote in this category
stringListPanelAdd = Add
stringListPanelDelete = Delete
stringListPanelUp = Up
stringListPanelDown = Down

@ -28,6 +28,12 @@ public interface GerritResources extends ClientBundle {
@Source("arrowRight.gif")
public ImageResource arrowRight();
@Source("arrowUp.png")
public ImageResource arrowUp();
@Source("arrowDown.png")
public ImageResource arrowDown();
@Source("editText.png")
public ImageResource edit();

@ -44,14 +44,15 @@ public class StringListPanel extends FlowPanel {
private Image info;
private FocusWidget widget;
public StringListPanel(String title, List<String> fieldNames, FocusWidget w) {
public StringListPanel(String title, List<String> fieldNames, FocusWidget w,
boolean autoSort) {
widget = w;
titlePanel = new HorizontalPanel();
SmallHeading titleLabel = new SmallHeading(title);
titlePanel.add(titleLabel);
add(titlePanel);
t = new StringListTable(fieldNames);
t = new StringListTable(fieldNames, autoSort);
add(t);
deleteButton = new Button(Gerrit.C.stringListPanelDelete());
@ -84,8 +85,11 @@ public class StringListPanel extends FlowPanel {
private class StringListTable extends NavigationTable<List<String>> {
private final List<NpTextBox> inputs;
private final boolean autoSort;
StringListTable(List<String> names, boolean autoSort) {
this.autoSort = autoSort;
StringListTable(List<String> names) {
Button addButton =
new Button(new ImageResourceRenderer().render(Gerrit.RESOURCES.listAdd()));
addButton.setTitle(Gerrit.C.stringListPanelAdd());
@ -124,6 +128,13 @@ public class StringListPanel extends FlowPanel {
}
});
table.setWidget(1, 0, addButton);
if (!autoSort) {
fmt.addStyleName(0, names.size() + 1, Gerrit.RESOURCES.css().iconHeader());
fmt.addStyleName(0, names.size() + 2, Gerrit.RESOURCES.css().iconHeader());
fmt.addStyleName(1, names.size() + 1, Gerrit.RESOURCES.css().iconHeader());
fmt.addStyleName(1, names.size() + 2, Gerrit.RESOURCES.css().iconHeader());
}
}
void display(List<List<String>> values) {
@ -132,7 +143,7 @@ public class StringListPanel extends FlowPanel {
}
int row = 2;
for (List<String> v : values) {
populate(row, v);
populate(row, v, row == values.size() + 1);
row++;
}
}
@ -140,16 +151,20 @@ public class StringListPanel extends FlowPanel {
List<List<String>> getValues() {
List<List<String>> values = new ArrayList<>();
for (int row = 2; row < table.getRowCount(); row++) {
List<String> v = new ArrayList<>();
for (int i = 0; i < inputs.size(); i++) {
v.add(table.getText(row, i + 1));
}
values.add(v);
values.add(getValues(row));
}
return values;
}
private void populate(int row, List<String> values) {
List<String> getValues(int row) {
List<String> v = new ArrayList<>();
for (int i = 0; i < inputs.size(); i++) {
v.add(table.getText(row, i + 1));
}
return v;
}
private void populate(final int row, List<String> values, boolean last) {
FlexCellFormatter fmt = table.getFlexCellFormatter();
fmt.addStyleName(row, 0, Gerrit.RESOURCES.css().iconCell());
CheckBox checkBox = new CheckBox();
@ -164,6 +179,41 @@ public class StringListPanel extends FlowPanel {
fmt.addStyleName(row, i + 1, Gerrit.RESOURCES.css().dataCell());
table.setText(row, i + 1, values.get(i));
}
if (!autoSort) {
fmt.addStyleName(row, values.size() + 1, Gerrit.RESOURCES.css().iconCell());
if (!last) {
Image down = new Image(Gerrit.RESOURCES.arrowDown());
down.setTitle(Gerrit.C.stringListPanelDown());
down.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
List<String> value = getValues(row);
List<String> nextValue = getValues(row + 1);
populate(row, nextValue, false);
populate(row + 1, value, row + 1 == table.getRowCount() - 1);
widget.setEnabled(true);
}
});
table.setWidget(row, values.size() + 1, down);
}
if (row > 2) {
Image up = new Image(Gerrit.RESOURCES.arrowUp());
up.setTitle(Gerrit.C.stringListPanelUp());
up.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
List<String> previousValue = getValues(row - 1);
List<String> value = getValues(row);
populate(row - 1, value, false);
populate(row, previousValue, row == table.getRowCount() - 1);
widget.setEnabled(true);
}
});
table.setWidget(row, values.size() + 2, up);
}
}
}
void add() {
@ -180,17 +230,19 @@ public class StringListPanel extends FlowPanel {
void insert(List<String> v) {
int insertPos = table.getRowCount();
for (int row = 1; row < table.getRowCount(); row++) {
int compareResult = v.get(0).compareTo(table.getText(row, 1));
if (compareResult < 0) {
insertPos = row;
break;
} else if (compareResult == 0) {
return;
if (autoSort) {
for (int row = 1; row < table.getRowCount(); row++) {
int compareResult = v.get(0).compareTo(table.getText(row, 1));
if (compareResult < 0) {
insertPos = row;
break;
} else if (compareResult == 0) {
return;
}
}
}
table.insertRow(insertPos);
populate(insertPos, v);
populate(insertPos, v, insertPos == table.getRowCount() - 1);
}
void enableDelete() {

@ -209,7 +209,8 @@ public class MyPreferencesScreen extends SettingsScreen {
});
myMenus = new StringListPanel(Util.C.myMenu(),
Arrays.asList(Util.C.myMenuName(), Util.C.myMenuUrl()), save);
Arrays.asList(Util.C.myMenuName(), Util.C.myMenuUrl()),
save, false);
myMenus.setInfo(Util.C.myMenuInfo());
add(myMenus);

Binary file not shown.

After

(image error) Size: 1.6 KiB

Binary file not shown.

After

(image error) Size: 1.6 KiB