use states in cache list
This commit is contained in:
@@ -29,6 +29,7 @@ import de.geofroggerfx.dao.CacheDAO;
|
|||||||
import de.geofroggerfx.dao.UserDAO;
|
import de.geofroggerfx.dao.UserDAO;
|
||||||
import de.geofroggerfx.model.*;
|
import de.geofroggerfx.model.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.w3c.dom.Attr;
|
import org.w3c.dom.Attr;
|
||||||
@@ -130,17 +131,26 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CacheListEntry> getAllCacheEntriesSortBy(String name, String asc) {
|
public List<CacheListEntry> getAllCacheEntriesSortBy(String name, String asc) {
|
||||||
return this.jdbcTemplate.query(
|
try {
|
||||||
"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,
|
return this.jdbcTemplate.query(
|
||||||
(rs, rowNum) -> {
|
"SELECT c.id, c.name AS name, c.name AS code, c.difficulty, c.terrain, c.type, c.available, c.archived, c.found " +
|
||||||
return new CacheListEntry(
|
" FROM " + CACHE_TABLE + " c ORDER BY " + name + " " + asc,
|
||||||
rs.getLong("id"),
|
(rs, rowNum) -> {
|
||||||
rs.getString("name"),
|
return new CacheListEntry(
|
||||||
rs.getString("code"),
|
rs.getLong("id"),
|
||||||
rs.getString("difficulty"),
|
rs.getString("name"),
|
||||||
rs.getString("terrain"),
|
rs.getString("code"),
|
||||||
groundspeakStringToType(rs.getString("type")));
|
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
|
@Override
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ package de.geofroggerfx.model;
|
|||||||
import javafx.beans.property.*;
|
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 {
|
public class CacheListEntry {
|
||||||
|
|
||||||
@@ -38,19 +38,28 @@ public class CacheListEntry {
|
|||||||
private StringProperty terrain = new SimpleStringProperty();
|
private StringProperty terrain = new SimpleStringProperty();
|
||||||
private StringProperty code = new SimpleStringProperty();
|
private StringProperty code = new SimpleStringProperty();
|
||||||
private ObjectProperty<Type> type = new SimpleObjectProperty<>();
|
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,
|
public CacheListEntry(long id,
|
||||||
String name,
|
String name,
|
||||||
String code,
|
String code,
|
||||||
String difficulty,
|
String difficulty,
|
||||||
String terrain,
|
String terrain,
|
||||||
Type type) {
|
Type type,
|
||||||
|
boolean found,
|
||||||
|
boolean archived,
|
||||||
|
boolean available) {
|
||||||
this.id.setValue(id);
|
this.id.setValue(id);
|
||||||
this.name.setValue(name);
|
this.name.setValue(name);
|
||||||
this.code.setValue(code);
|
this.code.setValue(code);
|
||||||
this.difficulty.setValue(difficulty);
|
this.difficulty.setValue(difficulty);
|
||||||
this.terrain.setValue(terrain);
|
this.terrain.setValue(terrain);
|
||||||
this.type.setValue(type);
|
this.type.setValue(type);
|
||||||
|
this.found.setValue(found);
|
||||||
|
this.archived.setValue(archived);
|
||||||
|
this.available.setValue(available);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -101,6 +110,30 @@ public class CacheListEntry {
|
|||||||
return type;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CacheListEntry{" +
|
return "CacheListEntry{" +
|
||||||
|
|||||||
@@ -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 static final String GRAY = ";-fx-fill: linear-gradient(#cccccc 0%, #999999 70%, #888888 85%);";
|
||||||
private final GridPane grid = new GridPane();
|
private final GridPane grid = new GridPane();
|
||||||
private final Text icon = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "20.0");
|
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 Label name = new Label();
|
||||||
private final Text difficultyStars = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "8.0");
|
private final Text difficultyStars = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "8.0");
|
||||||
private final Text terrainStars = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "8.0");
|
private final Text terrainStars = GlyphsDude.createIcon(FontAwesomeIcons.BLANK, "8.0");
|
||||||
|
|
||||||
public CacheListCell() {
|
public CacheListCell() {
|
||||||
|
this.getStyleClass().add("cache-list-cell");
|
||||||
configureGrid();
|
configureGrid();
|
||||||
configureIcon();
|
configureIcon();
|
||||||
configureName();
|
configureName();
|
||||||
@@ -68,6 +70,22 @@ public class CacheListCell extends ListCell<CacheListEntry> {
|
|||||||
clearContent();
|
clearContent();
|
||||||
} else {
|
} else {
|
||||||
addContent(cache);
|
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);
|
ColumnConstraints column5 = new ColumnConstraints(30 , 50 , Double.MAX_VALUE);
|
||||||
column5.setHgrow(Priority.ALWAYS);
|
column5.setHgrow(Priority.ALWAYS);
|
||||||
column5.setFillWidth(true);
|
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() {
|
private void configureIcon() {
|
||||||
@@ -110,6 +131,7 @@ public class CacheListCell extends ListCell<CacheListEntry> {
|
|||||||
private void addControlsToGrid() {
|
private void addControlsToGrid() {
|
||||||
grid.add(icon, 0, 0, 1, 2);
|
grid.add(icon, 0, 0, 1, 2);
|
||||||
grid.add(name, 1, 0, 4, 1);
|
grid.add(name, 1, 0, 4, 1);
|
||||||
|
grid.add(foundIcon, 5, 0);
|
||||||
grid.add(new Label("Difficulty:"), 1, 1);
|
grid.add(new Label("Difficulty:"), 1, 1);
|
||||||
grid.add(difficultyStars, 2, 1);
|
grid.add(difficultyStars, 2, 1);
|
||||||
grid.add(new Label("Terrain:"), 3, 1);
|
grid.add(new Label("Terrain:"), 3, 1);
|
||||||
@@ -123,6 +145,7 @@ public class CacheListCell extends ListCell<CacheListEntry> {
|
|||||||
|
|
||||||
private void addContent(CacheListEntry cache) {
|
private void addContent(CacheListEntry cache) {
|
||||||
setIcon(cache);
|
setIcon(cache);
|
||||||
|
setFoundIcon(cache);
|
||||||
setCacheName(cache);
|
setCacheName(cache);
|
||||||
setDifficulty(cache);
|
setDifficulty(cache);
|
||||||
setTerrain(cache);
|
setTerrain(cache);
|
||||||
@@ -137,6 +160,14 @@ public class CacheListCell extends ListCell<CacheListEntry> {
|
|||||||
icon.setText(GeocachingIcons.getIconAsString(cache.getType()));
|
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) {
|
private void setDifficulty(CacheListEntry cache) {
|
||||||
difficultyStars.setText(GeocachingIcons.getStarsAsString(cache.getDifficulty()));
|
difficultyStars.setText(GeocachingIcons.getStarsAsString(cache.getDifficulty()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,11 @@
|
|||||||
-fx-font-size: 24pt;
|
-fx-font-size: 24pt;
|
||||||
-fx-font-family: "Sofia-Regular";
|
-fx-font-family: "Sofia-Regular";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cache-list-cell.not-available .label .text {
|
||||||
|
-fx-fill: #ff3333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cache-list-cell.archived .label .text {
|
||||||
|
-fx-fill: #aaaaaa;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user