refactor MindmapFilter to accept Label Filters

This commit is contained in:
Ezequiel Bergamaschi 2014-01-29 03:59:42 -03:00 committed by Ezequiel Bergamaschi
parent 684c412e95
commit 148b56aecb
2 changed files with 36 additions and 19 deletions

View File

@ -25,57 +25,73 @@ import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public enum MindmapFilter {
ALL("all") {
public abstract class MindmapFilter {
public static MindmapFilter ALL = new MindmapFilter("all") {
@Override
public boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
return true;
}
},
MY_MAPS("my_maps") {
};
public static MindmapFilter MY_MAPS = new MindmapFilter("my_maps") {
@Override
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
return mindmap.getCreator().identityEquality(user);
}
},
STARRED("starred") {
};
public static MindmapFilter STARRED = new MindmapFilter("starred") {
@Override
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
return mindmap.isStarred(user);
}
},
SHARED_WITH_ME("shared_with_me") {
};
public static MindmapFilter SHARED_WITH_ME = new MindmapFilter("shared_with_me") {
@Override
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
return !MY_MAPS.accept(mindmap, user);
}
},
PUBLIC("public") {
};
public static MindmapFilter PUBLIC = new MindmapFilter("public") {
@Override
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
return mindmap.isPublic();
}
};
private String id;
protected String id;
private static MindmapFilter[] values = {ALL, MY_MAPS, PUBLIC, STARRED, SHARED_WITH_ME};
MindmapFilter(@NotNull String id) {
private MindmapFilter(@NotNull String id) {
this.id = id;
}
static public MindmapFilter parse(@Nullable String valueStr) {
MindmapFilter result = ALL;
final MindmapFilter[] values = MindmapFilter.values();
for (MindmapFilter value : values) {
static public MindmapFilter parse(@Nullable final String valueStr) {
MindmapFilter result = valueStr == null ? ALL : null;
for (MindmapFilter value : MindmapFilter.values) {
if (value.id.equals(valueStr)) {
result = value;
break;
}
}
if (result == null) {
assert valueStr != null;
result = new LabelFilter(valueStr);
}
return result;
}
abstract boolean accept(@NotNull Mindmap mindmap, @NotNull User user);
private static final class LabelFilter extends MindmapFilter {
private LabelFilter(@NotNull String id) {
super(id);
}
@Override
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
return mindmap.hasLabel(this.id);
}
}
}

View File

@ -171,7 +171,8 @@ $(function () {
}
};
$('#foldersContainer li').click(function (event) {
//live method is deprecated?
$('#foldersContainer li').live('click', function (event) {
// Deselect previous option ...
$('#foldersContainer li').removeClass('active');
$('#foldersContainer i').removeClass('icon-white');