diff --git a/src/main/java/de/geofroggerfx/dao/jdbc/JdbcCacheDAO.java b/src/main/java/de/geofroggerfx/dao/jdbc/JdbcCacheDAO.java index 9d4ce59..1af18ea 100644 --- a/src/main/java/de/geofroggerfx/dao/jdbc/JdbcCacheDAO.java +++ b/src/main/java/de/geofroggerfx/dao/jdbc/JdbcCacheDAO.java @@ -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,17 +131,26 @@ public class JdbcCacheDAO implements CacheDAO { @Override public List getAllCacheEntriesSortBy(String name, String asc) { - 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, - (rs, rowNum) -> { - return new CacheListEntry( - rs.getLong("id"), - rs.getString("name"), - rs.getString("code"), - rs.getString("difficulty"), - rs.getString("terrain"), - groundspeakStringToType(rs.getString("type"))); - }); + try { + return this.jdbcTemplate.query( + "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"), + rs.getString("name"), + rs.getString("code"), + rs.getString("difficulty"), + rs.getString("terrain"), + 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 diff --git a/src/main/java/de/geofroggerfx/model/CacheListEntry.java b/src/main/java/de/geofroggerfx/model/CacheListEntry.java index cd17648..4f2aaaf 100644 --- a/src/main/java/de/geofroggerfx/model/CacheListEntry.java +++ b/src/main/java/de/geofroggerfx/model/CacheListEntry.java @@ -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 = 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{" + diff --git a/src/main/java/de/geofroggerfx/ui/list/CacheListCell.java b/src/main/java/de/geofroggerfx/ui/list/CacheListCell.java index b01da0c..63d9763 100644 --- a/src/main/java/de/geofroggerfx/ui/list/CacheListCell.java +++ b/src/main/java/de/geofroggerfx/ui/list/CacheListCell.java @@ -48,11 +48,13 @@ public class CacheListCell extends ListCell { 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 { 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 { 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 { 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 { private void addContent(CacheListEntry cache) { setIcon(cache); + setFoundIcon(cache); setCacheName(cache); setDifficulty(cache); setTerrain(cache); @@ -137,6 +160,14 @@ public class CacheListCell extends ListCell { 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())); } diff --git a/src/main/resources/de/geofroggerfx/ui/geofroggerfx.css b/src/main/resources/de/geofroggerfx/ui/geofroggerfx.css index ad78d49..3143e30 100644 --- a/src/main/resources/de/geofroggerfx/ui/geofroggerfx.css +++ b/src/main/resources/de/geofroggerfx/ui/geofroggerfx.css @@ -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; +} \ No newline at end of file