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) -> { controller.getGroupManager().getUnSeenGroups().addListener((Observable observable) -> {
updateButton(); Platform.runLater(this::updateButton);
}); });
setEventHandler((ActionEvent t) -> { setEventHandler((ActionEvent t) -> {
Optional.ofNullable(controller.viewState()) Optional.ofNullable(controller.viewState())
.map(ObjectExpression<GroupViewState>::getValue) .map(ObjectExpression<GroupViewState>::getValue)
.map(GroupViewState::getGroup) .map(GroupViewState::getGroup)
.ifPresent(controller.getGroupManager()::markGroupSeen); .ifPresent(group -> controller.getGroupManager().markGroupSeen(group, true));
if (false == controller.getGroupManager().getUnSeenGroups().isEmpty()) { if (false == controller.getGroupManager().getUnSeenGroups().isEmpty()) {
controller.advance(GroupViewState.tile(controller.getGroupManager().getUnSeenGroups().get(0))); 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); 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); 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 (?,?)"); insertGroupStmt = prepareStatement("insert or replace into groups (value, attribute) values (?,?)");
groupSeenQueryStmt = prepareStatement("select seen from groups where value = ? and attribute = ?"); groupSeenQueryStmt = prepareStatement("select seen from groups where value = ? and attribute = ?");
@ -515,13 +515,14 @@ public final class DrawableDB {
return false; return false;
} }
public void markGroupSeen(GroupKey<?> gk) { public void markGroupSeen(GroupKey<?> gk, boolean seen) {
dbWriteLock(); dbWriteLock();
try { 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.clearParameters();
updateGroupStmt.setString(1, gk.getValueDisplayName()); updateGroupStmt.setBoolean(1, seen);
updateGroupStmt.setString(2, gk.getAttribute().attrName.toString()); updateGroupStmt.setString(2, gk.getValueDisplayName());
updateGroupStmt.setString(3, gk.getAttribute().attrName.toString());
updateGroupStmt.execute(); updateGroupStmt.execute();
} catch (SQLException ex) { } catch (SQLException ex) {
LOGGER.log(Level.SEVERE, "Error marking group as seen", 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) { if (fileIDs.contains(f) == false) {
fileIDs.add(f); fileIDs.add(f);
seen.set(false); seen.set(false);
} }
} }
@ -155,8 +154,8 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName()); return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName());
} }
void setSeen() { void setSeen(boolean isSeen) {
this.seen.set(true); this.seen.set(isSeen);
} }
public ReadOnlyBooleanWrapper seenProperty() { public ReadOnlyBooleanWrapper seenProperty() {

View File

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