diff --git a/README.md b/README.md
index 6b24b48..ca092d3 100644
--- a/README.md
+++ b/README.md
@@ -16,10 +16,10 @@ To start with, please make sure you have the following prerequisites:
The command line steps to get this up and running are:
- cd client
+ cd server
mvn jetty:run
cd ..
- cd server
+ cd client
mvn compile exec:java
If it doesn't work, make sure that maven is running the right version of java by calling "mvn -version". If you are still having trouble, check out the blogs mentioned above, and post if your issue is not resolved.
\ No newline at end of file
diff --git a/jsr330client/pom.xml b/jsr330client/pom.xml
new file mode 100644
index 0000000..b851778
--- /dev/null
+++ b/jsr330client/pom.xml
@@ -0,0 +1,156 @@
+
+
+ 4.0.0
+ steveonjava
+ javafx-spring-client
+ Spring client for JavaFX/Spring sample application.
+ jar
+ 1.0.0
+
+
+ 1.6
+ 3.1.0.RELEASE
+
+
+
+ com.oracle
+ javafx
+ 2.2
+ system
+ ${java.home}/lib/jfxrt.jar
+
+
+ org.slf4j
+ slf4j-api
+ 1.5.6
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.5.6
+ compile
+
+
+ org.codehaus.jackson
+ jackson-mapper-asl
+ 1.9.9
+
+
+ cglib
+ cglib
+ 2.2.2
+
+
+ org.springframework.security
+ spring-security-core
+ ${org.springframework-version}
+
+
+ org.springframework.security
+ spring-security-config
+ ${org.springframework-version}
+
+
+ org.springframework
+ spring-web
+ ${org.springframework-version}
+
+
+ org.springframework
+ spring-core
+ ${org.springframework-version}
+
+
+ org.springframework
+ spring-context
+ ${org.springframework-version}
+
+
+ org.springframework
+ spring-beans
+ ${org.springframework-version}
+
+
+ org.springframework
+ spring-expression
+ ${org.springframework-version}
+
+
+ javax.inject
+ javax.inject
+ 1
+
+
+
+
+
+ org.springframework.maven.snapshot
+ Spring Maven Snapshot Repository
+ http://maven.springframework.org/snapshot
+
+ false
+
+
+ true
+
+
+
+
+ org.springframework.maven.milestone
+ Spring Maven Milestone Repository
+ http://maven.springframework.org/milestone
+
+ false
+
+
+
+
+ JBoss Repo
+ https://repository.jboss.org/nexus/content/repositories/releases
+ JBoss Repo
+
+
+
+
+ repository.springframework.maven.milestone
+ Spring Framework Maven Milestone Repository
+ http://maven.springframework.org/milestone
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.7
+ 1.7
+ true
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+
+ compile
+ steveonjava.client.CustomerApp
+
+
+
+ maven-assembly-plugin
+
+
+
+ steveonjava.client.CustomerApp
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jsr330client/src/main/java/steveonjava/client/AddCustomerController.java b/jsr330client/src/main/java/steveonjava/client/AddCustomerController.java
new file mode 100644
index 0000000..b011d73
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/AddCustomerController.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.TextField;
+import javafx.stage.Stage;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Named
+public class AddCustomerController {
+ @Inject
+ private CustomerModel model;
+
+ @FXML
+ TextField firstName;
+ @FXML
+ TextField lastName;
+
+ @FXML
+ public void add() {
+ model.addCustomer(firstName.getText(), lastName.getText());
+ ((Stage) firstName.getScene().getWindow()).close();
+ }
+
+ @FXML
+ public void cancel() {
+ ((Stage) firstName.getScene().getWindow()).close();
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/AddCustomerDialogProvider.java b/jsr330client/src/main/java/steveonjava/client/AddCustomerDialogProvider.java
new file mode 100644
index 0000000..b8f7196
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/AddCustomerDialogProvider.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.stage.StageStyle;
+import javax.inject.Named;
+
+@Named
+public class AddCustomerDialogProvider extends FXMLDialogProvider {
+ public AddCustomerDialogProvider() {
+ super(AddCustomerDialogProvider.class.getResource("AddCustomer.fxml"), StageStyle.DECORATED);
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/CustomerApp.java b/jsr330client/src/main/java/steveonjava/client/CustomerApp.java
new file mode 100644
index 0000000..dbcfcd4
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/CustomerApp.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.application.Application;
+import javafx.stage.Stage;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+public class CustomerApp extends Application {
+ private static Stage primaryStage;
+
+ public static Stage getPrimaryStage() {
+ return primaryStage;
+ }
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage stage) throws Exception {
+ primaryStage = stage;
+ ApplicationContext context = new AnnotationConfigApplicationContext(CustomerAppConfiguration.class);
+ context.getBean(LoginDialogProvider.class).get().show();
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/CustomerAppConfiguration.java b/jsr330client/src/main/java/steveonjava/client/CustomerAppConfiguration.java
new file mode 100644
index 0000000..e6324c2
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/CustomerAppConfiguration.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import java.util.Collections;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+@ComponentScan(basePackages="steveonjava.client")
+@ImportResource("classpath:applicationContext-security.xml")
+public class CustomerAppConfiguration {
+ @Bean
+ RestTemplate restTemplate() {
+ RestTemplate restTemplate = new RestTemplate();
+ restTemplate.setMessageConverters(Collections.>singletonList(new MappingJacksonHttpMessageConverter()));
+ return restTemplate;
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/CustomerDataScreen.java b/jsr330client/src/main/java/steveonjava/client/CustomerDataScreen.java
new file mode 100644
index 0000000..77d206f
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/CustomerDataScreen.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.geometry.Insets;
+import javafx.scene.Node;
+import javafx.scene.control.*;
+import javafx.scene.control.cell.PropertyValueFactory;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBoxBuilder;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.springframework.security.access.AccessDeniedException;
+import steveonjava.server.Customer;
+
+@Named
+public class CustomerDataScreen extends StackPane {
+ @Inject
+ CustomerDataScreenController controller;
+ private TableView tableView = new TableView();
+
+ @PostConstruct
+ private void createScreen() {
+ getChildren().add(VBoxBuilder.create()
+ .children(
+ createHeader(),
+ createToolbar(),
+ createDataTable())
+ .build());
+ }
+
+ private Node createHeader() {
+ return new ImageView(getClass().getResource("header.jpg").toString());
+ }
+
+ private Node createToolbar() {
+ Button removeButton;
+ ToolBar toolBar = ToolBarBuilder.create()
+ .items(
+ ButtonBuilder.create()
+ .text("Add Customer")
+ .onAction(new EventHandler() {
+ public void handle(ActionEvent actionEvent) {
+ controller.addCustomer();
+ }
+ })
+ .build(),
+ removeButton = ButtonBuilder.create()
+ .text("Remove Customer")
+ .onAction(new EventHandler() {
+ public void handle(ActionEvent actionEvent) {
+ try {
+ controller.removeCustomer(tableView.getSelectionModel().getSelectedItem());
+ tableView.getSelectionModel().select(Math.min(tableView.getSelectionModel().getSelectedIndex(),
+ tableView.getItems().size() - 1));
+ } catch (AccessDeniedException e) {
+ controller.showErrorDialog();
+ }
+ }
+ })
+ .build()
+ )
+ .build();
+ removeButton.disableProperty().bind(tableView.getSelectionModel().selectedItemProperty().isNull());
+ return toolBar;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Node createDataTable() {
+ StackPane dataTableBorder = new StackPane();
+ dataTableBorder.getChildren().add(tableView);
+ dataTableBorder.setPadding(new Insets(8));
+ dataTableBorder.setStyle("-fx-background-color: lightgray");
+ tableView.setItems(controller.getCustomers());
+ tableView.getColumns().setAll(
+ TableColumnBuilder.create()
+ .text("First Name")
+ .cellValueFactory(new PropertyValueFactory("firstName"))
+ .prefWidth(204)
+ .build(),
+ TableColumnBuilder.create()
+ .text("Last Name")
+ .cellValueFactory(new PropertyValueFactory("lastName"))
+ .prefWidth(204)
+ .build(),
+ TableColumnBuilder.create()
+ .text("Sign-up Date")
+ .cellValueFactory(new PropertyValueFactory("signupDate"))
+ .prefWidth(351)
+ .build()
+ );
+ tableView.setPrefHeight(500);
+ return dataTableBorder;
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/CustomerDataScreenController.java b/jsr330client/src/main/java/steveonjava/client/CustomerDataScreenController.java
new file mode 100644
index 0000000..7a04998
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/CustomerDataScreenController.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.collections.ObservableList;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.springframework.security.access.annotation.Secured;
+import steveonjava.server.Customer;
+
+@Named
+public class CustomerDataScreenController {
+
+ @Inject
+ private CustomerModel customerModel;
+
+ @Inject
+ private ErrorDialogProvider errorDialogProvider;
+
+ @Inject
+ private AddCustomerDialogProvider addCustomerDialogProvider;
+
+ public CustomerDataScreenController() {
+ }
+
+ public void showErrorDialog() {
+ errorDialogProvider.get().show();
+ }
+
+ public ObservableList getCustomers() {
+ return customerModel.getCustomers();
+ }
+
+ @Secured({"ROLE_MANAGER", "ROLE_EMPLOYEE"})
+ public void addCustomer() {
+ addCustomerDialogProvider.get().show();
+ }
+
+ public void removeCustomer(Customer customer) {
+ customerModel.remove(customer);
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/CustomerModel.java b/jsr330client/src/main/java/steveonjava/client/CustomerModel.java
new file mode 100644
index 0000000..bf884d2
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/CustomerModel.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import java.util.Date;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.springframework.security.access.annotation.Secured;
+import org.springframework.web.client.RestTemplate;
+import steveonjava.server.Customer;
+
+@Named
+public class CustomerModel {
+ private ObservableList customers = FXCollections.observableArrayList();
+
+ public ObservableList getCustomers() {
+ return customers;
+ }
+
+ private RestTemplate restTemplate;
+
+ public CustomerModel() {}
+
+ @Inject
+ public CustomerModel(RestTemplate restTemplate) {
+ this.restTemplate = restTemplate;
+ loadData();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void loadData() {
+ Customer[] customers = restTemplate.getForObject("http://localhost:8080/crm/customers", Customer[].class);
+ this.customers.setAll(customers);
+ }
+
+ @Secured("ROLE_MANAGER")
+ public void remove(Customer customer) {
+ restTemplate.delete("http://localhost:8080/crm/customer/" + customer.getId());
+ customers.remove(customer);
+ }
+
+ public void addCustomer(String firstName, String lastName) {
+ Customer customer = new Customer();
+ customer.setFirstName(firstName);
+ customer.setLastName(lastName);
+ customer.setSignupDate(new Date());
+ Integer id = restTemplate.postForObject("http://localhost:8080/crm/customers", customer, Integer.class);
+ customer.setId(id);
+ customers.add(customer);
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/ErrorController.java b/jsr330client/src/main/java/steveonjava/client/ErrorController.java
new file mode 100644
index 0000000..1811baf
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/ErrorController.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.fxml.FXML;
+import javafx.scene.layout.AnchorPane;
+import javafx.stage.Stage;
+import javax.inject.Named;
+
+@Named
+public class ErrorController {
+ @FXML
+ AnchorPane root;
+
+ @FXML
+ public void close() {
+ ((Stage) root.getScene().getWindow()).close();
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/ErrorDialogProvider.java b/jsr330client/src/main/java/steveonjava/client/ErrorDialogProvider.java
new file mode 100644
index 0000000..3ec9497
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/ErrorDialogProvider.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.stage.StageStyle;
+import javax.inject.Named;
+
+@Named
+public class ErrorDialogProvider extends FXMLDialogProvider {
+ public ErrorDialogProvider() {
+ super(ErrorDialogProvider.class.getResource("Error.fxml"), StageStyle.UNDECORATED);
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/FXMLDialogProvider.java b/jsr330client/src/main/java/steveonjava/client/FXMLDialogProvider.java
new file mode 100644
index 0000000..4e63e88
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/FXMLDialogProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Modality;
+import javafx.stage.Stage;
+import javafx.stage.StageStyle;
+import javafx.util.Callback;
+import java.io.IOException;
+import java.net.URL;
+import javax.inject.Inject;
+import javax.inject.Provider;
+import org.springframework.context.ApplicationContext;
+
+public class FXMLDialogProvider implements Provider {
+ @Inject
+ private ApplicationContext applicationContext;
+ private final StageStyle style;
+ private final URL fxml;
+
+ public FXMLDialogProvider(URL fxml, StageStyle style) {
+ this.style = style;
+ this.fxml = fxml;
+ }
+
+ @Override
+ public Stage get() {
+ Stage dialog = new Stage(style);
+ dialog.initModality(Modality.WINDOW_MODAL);
+ dialog.initOwner(CustomerApp.getPrimaryStage());
+ try {
+ FXMLLoader loader = new FXMLLoader(fxml);
+ loader.setControllerFactory(new Callback, Object>() {
+ @Override
+ public Object call(Class> aClass) {
+ return applicationContext.getBean(aClass);
+ }
+ });
+ dialog.setScene(new Scene((Parent) loader.load()));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return dialog;
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/LoginController.java b/jsr330client/src/main/java/steveonjava/client/LoginController.java
new file mode 100644
index 0000000..c85dd19
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/LoginController.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.paint.Color;
+import javafx.stage.Stage;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+@Named
+public class LoginController {
+ @Inject
+ private AuthenticationManager authenticationManager;
+ @Inject
+ private CustomerDataScreen customerDataScreen;
+
+ @FXML
+ Label header;
+ @FXML
+ TextField username;
+ @FXML
+ TextField password;
+
+ @FXML
+ public void login() {
+ Authentication authToken = new UsernamePasswordAuthenticationToken(username.getText(), password.getText());
+ try {
+ authToken = authenticationManager.authenticate(authToken);
+ SecurityContextHolder.getContext().setAuthentication(authToken);
+ } catch (AuthenticationException e) {
+ header.setText("Login failure, please try again:");
+ header.setTextFill(Color.DARKRED);
+ return;
+ }
+ ((Stage) header.getScene().getWindow()).close();
+ Stage primaryStage = CustomerApp.getPrimaryStage();
+ primaryStage.setScene(new Scene(customerDataScreen, 777, 500));
+ primaryStage.show();
+ }
+
+ @FXML
+ public void employee() {
+ username.setText("employee");
+ password.setText("lol");
+ }
+
+ @FXML
+ public void manager() {
+ username.setText("manager");
+ password.setText("password");
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/client/LoginDialogProvider.java b/jsr330client/src/main/java/steveonjava/client/LoginDialogProvider.java
new file mode 100644
index 0000000..744ec50
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/client/LoginDialogProvider.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package steveonjava.client;
+
+import javafx.stage.StageStyle;
+import javax.inject.Named;
+
+@Named
+public class LoginDialogProvider extends FXMLDialogProvider {
+ public LoginDialogProvider() {
+ super(LoginDialogProvider.class.getResource("Login.fxml"), StageStyle.UNDECORATED);
+ }
+}
diff --git a/jsr330client/src/main/java/steveonjava/server/Customer.java b/jsr330client/src/main/java/steveonjava/server/Customer.java
new file mode 100644
index 0000000..3100d75
--- /dev/null
+++ b/jsr330client/src/main/java/steveonjava/server/Customer.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2012, Stephen Chin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL STEPHEN CHIN OR ORACLE CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package steveonjava.server;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class Customer implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private Integer id;
+
+ private Date signupDate;
+
+ private String firstName;
+
+ private String lastName;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Date getSignupDate() {
+ return signupDate;
+ }
+
+ public void setSignupDate(Date signupDate) {
+ this.signupDate = signupDate;
+ }
+}
diff --git a/jsr330client/src/main/resources/applicationContext-security.xml b/jsr330client/src/main/resources/applicationContext-security.xml
new file mode 100644
index 0000000..a1e278d
--- /dev/null
+++ b/jsr330client/src/main/resources/applicationContext-security.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jsr330client/src/main/resources/steveonjava/client/AddCustomer.fxml b/jsr330client/src/main/resources/steveonjava/client/AddCustomer.fxml
new file mode 100644
index 0000000..fa741bb
--- /dev/null
+++ b/jsr330client/src/main/resources/steveonjava/client/AddCustomer.fxml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jsr330client/src/main/resources/steveonjava/client/Error.fxml b/jsr330client/src/main/resources/steveonjava/client/Error.fxml
new file mode 100644
index 0000000..30a7f18
--- /dev/null
+++ b/jsr330client/src/main/resources/steveonjava/client/Error.fxml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jsr330client/src/main/resources/steveonjava/client/Login.fxml b/jsr330client/src/main/resources/steveonjava/client/Login.fxml
new file mode 100644
index 0000000..b0ad485
--- /dev/null
+++ b/jsr330client/src/main/resources/steveonjava/client/Login.fxml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jsr330client/src/main/resources/steveonjava/client/header.jpg b/jsr330client/src/main/resources/steveonjava/client/header.jpg
new file mode 100644
index 0000000..4200b43
Binary files /dev/null and b/jsr330client/src/main/resources/steveonjava/client/header.jpg differ
diff --git a/jsr330client/src/main/resources/steveonjava/client/logo.png b/jsr330client/src/main/resources/steveonjava/client/logo.png
new file mode 100644
index 0000000..c320d25
Binary files /dev/null and b/jsr330client/src/main/resources/steveonjava/client/logo.png differ