basic support for multiple cache lists

This commit is contained in:
2014-06-09 22:49:57 +02:00
parent 615d277359
commit 2cc63e28f8
17 changed files with 391 additions and 37 deletions

View File

@@ -31,7 +31,11 @@ import de.geofroggerfx.fx.components.MapPaneWrapper;
import de.geofroggerfx.fx.components.GeocachingIcons;
import de.geofroggerfx.fx.components.IconManager;
import de.geofroggerfx.model.Cache;
import de.geofroggerfx.model.CacheList;
import de.geofroggerfx.service.CacheService;
import javafx.animation.FadeTransition;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
@@ -49,6 +53,7 @@ import javax.inject.Inject;
import java.net.URL;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
/**
@@ -90,6 +95,9 @@ public class CacheDetailsController implements Initializable, SessionContextList
private CheckBox shortDescriptionHtml;
@FXML
private CheckBox longDescriptionHtml;
@FXML
private MenuButton addToListMenuButton;
private ImageView icon;
private FadeTransition ft;
@@ -101,6 +109,9 @@ public class CacheDetailsController implements Initializable, SessionContextList
@Inject
private SessionContext sessionContext;
@Inject
private CacheService cacheService;
/**
* Initializes the controller class.
*
@@ -119,11 +130,11 @@ public class CacheDetailsController implements Initializable, SessionContextList
longDescriptionWebView = new WebView();
shortDescriptionField = new TextArea();
longDescriptionField = new TextArea();
editableForm(false);
initFading();
}
@Override
public void sessionContextChanged() {
Cache currentCache = (Cache) sessionContext.getData("current-cache");
@@ -136,8 +147,35 @@ public class CacheDetailsController implements Initializable, SessionContextList
}
}
@FXML
public void editCache(final ActionEvent actionEvent) {
}
private void setSessionListener() {
sessionContext.addListener("current-cache", this);
sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListMenu));
}
@SuppressWarnings("unchecked")
private void refreshCacheListMenu() {
List<CacheList> cacheLists = (List<CacheList>) sessionContext.getData("cache-lists");
addToListMenuButton.getItems().clear();
cacheLists.stream().forEach(this::addToListMenuItem);
}
private void addToListMenuItem(CacheList cacheList) {
final MenuItem listItem = new MenuItem(cacheList.getName());
addToListMenuButton.getItems().add(listItem);
listItem.setOnAction(actionEvent -> addCacheAction(cacheList)
);
}
private void addCacheAction(CacheList cacheList) {
Cache currentCache = (Cache) sessionContext.getData("current-cache");
cacheList.addCache(currentCache);
cacheService.storeCacheList(cacheList);
}
private void initFading() {

View File

@@ -12,14 +12,21 @@
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="-1.0" styleClass="details-header"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="detailsIconHeader" alignment="CENTER_LEFT" maxWidth="-1.0" text="" textAlignment="LEFT"
wrapText="false" HBox.hgrow="ALWAYS"/>
<Label fx:id="cacheNameHeader" maxWidth="1.7976931348623157E308" text="" textFill="WHITE" underline="false"
HBox.hgrow="ALWAYS">
<font>
<Font size="16.0"/>
</font>
</Label>
<Label fx:id="detailsIconHeader" alignment="CENTER_RIGHT" maxWidth="-1.0" text="" textAlignment="LEFT"
wrapText="false" HBox.hgrow="ALWAYS"/>
<AnchorPane prefHeight="40.0">
<children>
<MenuButton fx:id="addToListMenuButton" mnemonicParsing="false" text="Add to list" AnchorPane.rightAnchor="10.0" />
<Button mnemonicParsing="false" onAction="#editCache" text="Edit coordinates" AnchorPane.rightAnchor="100.0" />
</children>
</AnchorPane>
</children>
<padding>
<Insets left="16.0" right="16.0"/>