allow marking grouos as seen or unseen, update next unseen appropriatly

This commit is contained in:
jmillman 2015-06-11 15:52:15 -04:00
parent bf1481d685
commit efd19fc56f
4 changed files with 152 additions and 150 deletions

View File

@ -56,14 +56,15 @@ public class NextUnseenGroup extends Action {
});
controller.getGroupManager().getUnSeenGroups().addListener((Observable observable) -> {
updateButton();
Platform.runLater(this::updateButton);
});
setEventHandler((ActionEvent t) -> {
Optional.ofNullable(controller.viewState())
.map(ObjectExpression<GroupViewState>::getValue)
.map(GroupViewState::getGroup)
.ifPresent(controller.getGroupManager()::markGroupSeen);
.ifPresent(group -> controller.getGroupManager().markGroupSeen(group, true));
if (false == controller.getGroupManager().getUnSeenGroups().isEmpty()) {
controller.advance(GroupViewState.tile(controller.getGroupManager().getUnSeenGroups().get(0)));

View File

@ -218,7 +218,7 @@ public final class DrawableDB {
analyzedGroupStmt = prepareStatement("Select obj_id , analyzed from drawable_files where analyzed = ?", DrawableAttribute.ANALYZED);
hashSetGroupStmt = prepareStatement("select drawable_files.obj_id as obj_id, analyzed from drawable_files , hash_sets , hash_set_hits where drawable_files.obj_id = hash_set_hits.obj_id and hash_sets.hash_set_id = hash_set_hits.hash_set_id and hash_sets.hash_set_name = ?", DrawableAttribute.HASHSET);
updateGroupStmt = prepareStatement("update groups set seen = 1 where value = ? and attribute = ?");
updateGroupStmt = prepareStatement("update groups set seen = ? where value = ? and attribute = ?");
insertGroupStmt = prepareStatement("insert or replace into groups (value, attribute) values (?,?)");
groupSeenQueryStmt = prepareStatement("select seen from groups where value = ? and attribute = ?");
@ -515,13 +515,14 @@ public final class DrawableDB {
return false;
}
public void markGroupSeen(GroupKey<?> gk) {
public void markGroupSeen(GroupKey<?> gk, boolean seen) {
dbWriteLock();
try {
//PreparedStatement updateGroup = con.prepareStatement("update groups set seen = 1 where value = ? and attribute = ?");
//PreparedStatement updateGroup = con.prepareStatement("update groups set seen = ? where value = ? and attribute = ?");
updateGroupStmt.clearParameters();
updateGroupStmt.setString(1, gk.getValueDisplayName());
updateGroupStmt.setString(2, gk.getAttribute().attrName.toString());
updateGroupStmt.setBoolean(1, seen);
updateGroupStmt.setString(2, gk.getValueDisplayName());
updateGroupStmt.setString(3, gk.getAttribute().attrName.toString());
updateGroupStmt.execute();
} catch (SQLException ex) {
LOGGER.log(Level.SEVERE, "Error marking group as seen", ex);

View File

@ -138,7 +138,6 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
if (fileIDs.contains(f) == false) {
fileIDs.add(f);
seen.set(false);
}
}
@ -155,8 +154,8 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName());
}
void setSeen() {
this.seen.set(true);
void setSeen(boolean isSeen) {
this.seen.set(isSeen);
}
public ReadOnlyBooleanWrapper seenProperty() {

View File

@ -245,6 +245,9 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
List<Long> newFiles = files == null ? new ArrayList<>() : files;
DrawableGroup g = new DrawableGroup(groupKey, newFiles);
g.seenProperty().addListener((observable, oldSeen, newSeen) -> {
markGroupSeen(g, newSeen);
});
synchronized (groupMap) {
groupMap.put(groupKey, g);
}
@ -258,11 +261,15 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
* @param group the {@link DrawableGroup} to mark as seen
*/
@ThreadConfined(type = ThreadType.JFX)
public void markGroupSeen(DrawableGroup group) {
db.markGroupSeen(group.getGroupKey());
group.setSeen();
unSeenGroups.removeAll(group);
public void markGroupSeen(DrawableGroup group, boolean seen) {
db.markGroupSeen(group.getGroupKey(), seen);
group.setSeen(seen);
if (seen) {
unSeenGroups.removeAll(group);
} else if (unSeenGroups.contains(group) == false) {
unSeenGroups.add(group);
FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder));
}
}
/**
@ -324,19 +331,13 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
if (task == null || (task.isCancelled() == false)) {
final boolean groupSeen = db.isGroupSeen(g.getGroupKey());
if (groupSeen) {
g.setSeen();
}
Platform.runLater(() -> {
if (analyzedGroups.contains(g) == false) {
analyzedGroups.add(g);
}
if (groupSeen) {
unSeenGroups.removeAll(g);
} else if (unSeenGroups.contains(g) == false) {
unSeenGroups.add(g);
FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder));
}
markGroupSeen(g, groupSeen);
});
}
}