use states in cache list

This commit is contained in:
Andreas Billmann
2015-03-29 20:27:11 +02:00
parent 488ead53f8
commit 36e4248f95
4 changed files with 96 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ import de.geofroggerfx.dao.CacheDAO;
import de.geofroggerfx.dao.UserDAO;
import de.geofroggerfx.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.w3c.dom.Attr;
@@ -130,8 +131,10 @@ public class JdbcCacheDAO implements CacheDAO {
@Override
public List<CacheListEntry> getAllCacheEntriesSortBy(String name, String asc) {
try {
return this.jdbcTemplate.query(
"SELECT c.id, c.name AS name, c.name AS code, c.difficulty, c.terrain, c.type FROM " + CACHE_TABLE + " c ORDER BY " + name + " " + asc,
"SELECT c.id, c.name AS name, c.name AS code, c.difficulty, c.terrain, c.type, c.available, c.archived, c.found " +
" FROM " + CACHE_TABLE + " c ORDER BY " + name + " " + asc,
(rs, rowNum) -> {
return new CacheListEntry(
rs.getLong("id"),
@@ -139,8 +142,15 @@ public class JdbcCacheDAO implements CacheDAO {
rs.getString("code"),
rs.getString("difficulty"),
rs.getString("terrain"),
groundspeakStringToType(rs.getString("type")));
groundspeakStringToType(rs.getString("type")),
rs.getBoolean("found"),
rs.getBoolean("archived"),
rs.getBoolean("available"));
});
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "error", e);
return null;
}
}
@Override

View File

@@ -28,7 +28,7 @@ package de.geofroggerfx.model;
import javafx.beans.property.*;
/**
* Created by Andreas on 10.03.2015.
* This class represents a list entry. It is a reduced version of cache.
*/
public class CacheListEntry {
@@ -38,19 +38,28 @@ public class CacheListEntry {
private StringProperty terrain = new SimpleStringProperty();
private StringProperty code = new SimpleStringProperty();
private ObjectProperty<Type> type = new SimpleObjectProperty<>();
private BooleanProperty found = new SimpleBooleanProperty();
private BooleanProperty archived = new SimpleBooleanProperty();
private BooleanProperty available = new SimpleBooleanProperty();
public CacheListEntry(long id,
String name,
String code,
String difficulty,
String terrain,
Type type) {
Type type,
boolean found,
boolean archived,
boolean available) {
this.id.setValue(id);
this.name.setValue(name);
this.code.setValue(code);
this.difficulty.setValue(difficulty);
this.terrain.setValue(terrain);
this.type.setValue(type);
this.found.setValue(found);
this.archived.setValue(archived);
this.available.setValue(available);
}
public String getName() {
@@ -101,6 +110,30 @@ public class CacheListEntry {
return type;
}
public boolean getFound() {
return found.get();
}
public ReadOnlyBooleanProperty foundProperty() {
return found;
}
public boolean getArchived() {
return archived.get();
}
public ReadOnlyBooleanProperty archivedProperty() {
return archived;
}
public boolean getAvailable() {
return available.get();
}
public ReadOnlyBooleanProperty availableProperty() {
return available;
}
@Override
public String toString() {
return "CacheListEntry{" +

View File

@@ -48,11 +48,13 @@ public class CacheListCell extends ListCell<CacheListEntry> {
private static final String GRAY = ";-fx-fill: linear-gradient(#cccccc 0%, #999999 70%, #888888 85%);";
private final GridPane grid = new GridPane();
private final Text icon = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "20.0");
private final Text foundIcon = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "10.0");
private final Label name = new Label();
private final Text difficultyStars = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "8.0");
private final Text terrainStars = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "8.0");
public CacheListCell() {
this.getStyleClass().add("cache-list-cell");
configureGrid();
configureIcon();
configureName();
@@ -68,6 +70,22 @@ public class CacheListCell extends ListCell<CacheListEntry> {
clearContent();
} else {
addContent(cache);
updateCellState(cache);
}
}
private void updateCellState(CacheListEntry cache) {
if (cache.getArchived()) {
this.getStyleClass().add("archived");
} else {
this.getStyleClass().remove("archived");
}
if (cache.getAvailable()) {
this.getStyleClass().remove("not-available");
} else {
this.getStyleClass().add("not-available");
}
}
@@ -87,7 +105,10 @@ public class CacheListCell extends ListCell<CacheListEntry> {
ColumnConstraints column5 = new ColumnConstraints(30 , 50 , Double.MAX_VALUE);
column5.setHgrow(Priority.ALWAYS);
column5.setFillWidth(true);
grid.getColumnConstraints().addAll(column1, column2, column3, column4, column5);
ColumnConstraints column6 = new ColumnConstraints(10, 12, 16);
column6.setHgrow(Priority.NEVER);
column6.setFillWidth(false);
grid.getColumnConstraints().addAll(column1, column2, column3, column4, column5, column6);
}
private void configureIcon() {
@@ -110,6 +131,7 @@ public class CacheListCell extends ListCell<CacheListEntry> {
private void addControlsToGrid() {
grid.add(icon, 0, 0, 1, 2);
grid.add(name, 1, 0, 4, 1);
grid.add(foundIcon, 5, 0);
grid.add(new Label("Difficulty:"), 1, 1);
grid.add(difficultyStars, 2, 1);
grid.add(new Label("Terrain:"), 3, 1);
@@ -123,6 +145,7 @@ public class CacheListCell extends ListCell<CacheListEntry> {
private void addContent(CacheListEntry cache) {
setIcon(cache);
setFoundIcon(cache);
setCacheName(cache);
setDifficulty(cache);
setTerrain(cache);
@@ -137,6 +160,14 @@ public class CacheListCell extends ListCell<CacheListEntry> {
icon.setText(GeocachingIcons.getIconAsString(cache.getType()));
}
private void setFoundIcon(CacheListEntry cache) {
if (cache.getFound()) {
foundIcon.setText(FontAwesomeIcons.CHECK.characterToString());
} else {
foundIcon.setText(FontAwesomeIcons.BLANK.characterToString());
}
}
private void setDifficulty(CacheListEntry cache) {
difficultyStars.setText(GeocachingIcons.getStarsAsString(cache.getDifficulty()));
}

View File

@@ -2,3 +2,11 @@
-fx-font-size: 24pt;
-fx-font-family: "Sofia-Regular";
}
.cache-list-cell.not-available .label .text {
-fx-fill: #ff3333;
}
.cache-list-cell.archived .label .text {
-fx-fill: #aaaaaa;
}