RemoteAgents: SWT GUI
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Wed, 5 Feb 2014 00:47:19 +0000 (01:47 +0100)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Wed, 5 Feb 2014 00:47:19 +0000 (01:47 +0100)
RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml
RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java
RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java [new file with mode: 0644]
RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml
RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java [new file with mode: 0644]
RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml
RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java [new file with mode: 0644]

index b24b1b5..980e6c6 100644 (file)
         <property name="service" ref="userService"/>
         <property name="serviceInterface" value="de.remote.agents.services.UserService"/>
     </bean>
+    
+    <bean name="/CurrentDateService.json" class="com.googlecode.jsonrpc4j.spring.JsonServiceExporter">
+        <property name="service" ref="currentDateService"/>
+        <property name="serviceInterface" value="de.remote.agents.services.CurrentDateService"/>
+    </bean>
 
 </beans>
index 983958c..3bbaff9 100644 (file)
@@ -1,27 +1,25 @@
 package de.remote.agents.clients.app;
 
-import java.net.URL;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import org.apache.log4j.Logger;
 
-import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
-
-import de.remote.agents.SnakeEyes;
-import de.remote.agents.SnakeEyesImpl;
+import de.remote.agents.services.CurrentDateService;
 
 public class ClientsMainTest {
     private static final Logger logger = Logger.getLogger(ClientsMainTest.class);
 
     public static void main(final String[] args) throws Throwable {
 
-        final JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(
-                "http://127.0.0.1:8080/spring-mainapp/UserService.json"));
-
-        final SnakeEyes user = client.invoke("createUser", new Object[] {
-                "Shana M. O'Hara", "Snake Eyes" }, SnakeEyesImpl.class);
-
-        logger.info("Canon: " + user.getCanon());
-        logger.info("Name: " + user.getName());
+        // final JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(
+        // "http://127.0.0.1:8080/spring-mainapp/UserService.json"));
+        //
+        // final SnakeEyes user = client.invoke("createUser", new Object[] {
+        // "Shana M. O'Hara", "Snake Eyes" }, SnakeEyesImpl.class);
+        //
+        // logger.info("Canon: " + user.getCanon());
+        // logger.info("Name: " + user.getName());
 
 
         // I need a way to set the return type parameter, otherwise I am not
@@ -39,6 +37,48 @@ public class ClientsMainTest {
         // logger.info("Canon: " + snakeEyes.getCanon());
         // logger.info("Name: " + snakeEyes.getName());
 
+        // I need a way to set the return type parameter, otherwise I am not
+        // going to be able to use this JSON-RPC plugin :(
+
+        logger.info("Starting application");
+        SpringContextLocator.getInstance();
+
+        final CurrentDateService remoteCurrentDate = (CurrentDateService) SpringContextLocator
+                .getInstance().getBean("remoteCurrentDateService");
+
+
+        final RemoteGUIExample window = new RemoteGUIExample();
+        final Runnable task = new Runnable() {
+
+            @Override
+            public void run() {
+                window.open();
+            }
+
+        };
+
+        final Thread GUIThread = new Thread(task, "GUI-Thread");
+        // GUIThread.setUncaughtExceptionHandler(new DriverHWUncaughtExceptionHandler());
+        GUIThread.start();
+
+        final Timer t = new Timer("Timer-Thread", false);
+        t.scheduleAtFixedRate(new TimerTask() {
+            @Override
+            public void run() {
+                final String remoteDate = remoteCurrentDate.getCurrentDate();
+                window.updateTextBox(remoteDate);
+            }
+        }, 1000, 1000);
+
     }
 
+    //    private class DriverHWUncaughtExceptionHandler implements UncaughtExceptionHandler {
+    //
+    //        @Override
+    //        public void uncaughtException(final Thread t, final Throwable e) {
+    //            logger.warn(
+    //                    "Exception not expected while running thread " + t.getName(), e);
+    //        }
+    //    }
+
 }
diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java
new file mode 100644 (file)
index 0000000..a413a3b
--- /dev/null
@@ -0,0 +1,55 @@
+package de.remote.agents.clients.app;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class RemoteGUIExample {
+
+    private Shell shell;
+    private Text textBox;
+    private Display display;
+
+
+    /**
+     * @wbp.parser.entryPoint
+     */
+    public void open() {
+        this.display = Display.getDefault();
+        this.createContents();
+        this.shell.open();
+        this.shell.layout();
+        while (!this.shell.isDisposed()) {
+            if (!this.display.readAndDispatch()) {
+                this.display.sleep();
+            }
+        }
+    }
+
+    public void updateTextBox(final String text) {
+        this.display.asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                if (!RemoteGUIExample.this.textBox.isDisposed())
+                    RemoteGUIExample.this.textBox.setText(text);
+            }
+        });
+    }
+
+
+    private void createContents() {
+        this.shell = new Shell();
+        this.shell.setSize(450, 300);
+        this.shell.setText("Remote GUI");
+
+        this.textBox = new Text(this.shell, SWT.BORDER);
+        this.textBox.setBounds(111, 95, 181, 58);
+
+        final Label lblRemoteDate = new Label(this.shell, SWT.NONE);
+        lblRemoteDate.setBounds(111, 63, 113, 26);
+        lblRemoteDate.setText("Remote Date:");
+    }
+
+}
index b917a91..502b166 100644 (file)
@@ -9,5 +9,10 @@
         <property name="serviceUrl" value="http://127.0.0.1:8080/spring-mainapp/UserService.json"/>
         <property name="serviceInterface" value="de.remote.agents.services.UserService"/>
     </bean>  
+    
+    <bean id="remoteCurrentDateService" class="com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean">
+        <property name="serviceUrl" value="http://127.0.0.1:8080/spring-mainapp/CurrentDateService.json"/>
+        <property name="serviceInterface" value="de.remote.agents.services.CurrentDateService"/>
+    </bean>
 
 </beans>
diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java
new file mode 100644 (file)
index 0000000..64391a6
--- /dev/null
@@ -0,0 +1,19 @@
+package de.remote.agents.services;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class CurrentDateServiceImpl implements CurrentDateService {
+
+    @Override
+    public String getCurrentDate() {
+        final DateFormat dateFormat = new SimpleDateFormat(
+                "yyyy/MM/dd HH:mm:ss");
+
+        final Date date = new Date();
+
+        return dateFormat.format(date);
+    }
+
+}
index 5d57305..67b2ed4 100644 (file)
@@ -10,5 +10,8 @@
 
     <bean id="userService" class="de.remote.agents.services.UserServiceImpl">
     </bean>
+    
+    <bean id="currentDateService" class="de.remote.agents.services.CurrentDateServiceImpl">
+    </bean>
 
 </beans>
diff --git a/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java
new file mode 100644 (file)
index 0000000..0bb11c5
--- /dev/null
@@ -0,0 +1,7 @@
+package de.remote.agents.services;
+
+public interface CurrentDateService {
+
+    String getCurrentDate();
+
+}