}
@Override
public void viewMenuOptions(final UserActionSet options) {
final UserActionSet sortOptions = options.addNewActionSet("Sort");
sortOptions.add(new UserActionAbstract("Clear") {
@Override
public Consent disabled(final View component) {
return ConsentAbstract.allowIf(order != null);
}
@Override
public void execute(final Workspace workspace, final View view, final Location at) {
order = null;
view.invalidateContent();
}
});
if (reverse) {
sortOptions.add(new UserActionAbstract("Normal sort order") {
@Override
public Consent disabled(final View component) {
return ConsentAbstract.allowIf(order != null);
}
@Override
public void execute(final Workspace workspace, final View view, final Location at) {
reverse = false;
view.invalidateContent();
}
});
} else {
sortOptions.add(new UserActionAbstract("Reverse sort order") {
@Override
public Consent disabled(final View component) {
return ConsentAbstract.allowIf(order != null);
}
@Override
public void execute(final Workspace workspace, final View view, final Location at) {
reverse = true;
view.invalidateContent();
}
});
}
sortOptions.add(new UserActionAbstract("Sort by title") {
@Override
public Consent disabled(final View component) {
return ConsentAbstract.allowIf(order != TITLE_COMPARATOR);
}
@Override
public void execute(final Workspace workspace, final View view, final Location at) {
order = TITLE_COMPARATOR;
view.invalidateContent();
}
});
sortOptions.add(new UserActionAbstract("Sort by type") {
@Override
public Consent disabled(final View component) {
return ConsentAbstract.allowIf(order != TYPE_COMPARATOR);
}
@Override
public void execute(final Workspace workspace, final View view, final Location at) {
order = TYPE_COMPARATOR;
view.invalidateContent();
}
});
final List<ObjectAssociation> fields = getElementSpecification().getAssociations(Contributed.EXCLUDED);
for (int i = 0; i < fields.size(); i++) {
final ObjectAssociation field = fields.get(i);
sortOptions.add(new UserActionAbstract("Sort by " + field.getName()) {
@Override
public void execute(final Workspace workspace, final View view, final Location at) {
order = new FieldComparator(field);
view.invalidateContent();
}