From 1e21989d02b348fd530513586799dec717f6ebcb Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Wed, 5 Mar 2014 04:20:26 +0100 Subject: [PATCH] RemoteAgents, new service with input parameters. --- .../main/webapp/WEB-INF/spring-mainapp-servlet.xml | 5 ++ .../remote/agents/clients/app/ClientsMainTest.java | 5 ++ .../agents/clients/app/RemoteGUIExample.java | 60 ++++++++++++++++++++-- .../agents/clients/app/SpringContextLocator.java | 4 +- .../resources/clients-remote-agents-spring.xml | 5 ++ .../agents/services/WriteTextServiceImpl.java | 20 ++++++++ .../src/main/resources/service-spring.xml | 3 ++ .../remote/agents/services/WriteTextService.java | 8 +++ 8 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java create mode 100644 RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java diff --git a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml index 980e6c6..c614c13 100644 --- a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml +++ b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml @@ -23,4 +23,9 @@ + + + + + diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java index 3bbaff9..eadad13 100644 --- a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java +++ b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java @@ -6,6 +6,7 @@ import java.util.TimerTask; import org.apache.log4j.Logger; import de.remote.agents.services.CurrentDateService; +import de.remote.agents.services.WriteTextService; public class ClientsMainTest { private static final Logger logger = Logger.getLogger(ClientsMainTest.class); @@ -61,6 +62,10 @@ public class ClientsMainTest { // GUIThread.setUncaughtExceptionHandler(new DriverHWUncaughtExceptionHandler()); GUIThread.start(); + final WriteTextService remoteWriteText = (WriteTextService) SpringContextLocator + .getInstance().getBean("remoteWriteTextService"); + window.setWriteTextService(remoteWriteText); + final Timer t = new Timer("Timer-Thread", false); t.scheduleAtFixedRate(new TimerTask() { @Override 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 index a413a3b..b13033a 100644 --- 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 @@ -1,16 +1,25 @@ package de.remote.agents.clients.app; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import de.remote.agents.services.WriteTextService; + public class RemoteGUIExample { private Shell shell; private Text textBox; private Display display; + private Label lblTextToSend; + private Text textToSend; + private WriteTextService writeTextService; /** @@ -38,18 +47,61 @@ public class RemoteGUIExample { }); } + public void setWriteTextService(final WriteTextService writeTextService) { + this.writeTextService = writeTextService; + } private void createContents() { this.shell = new Shell(); - this.shell.setSize(450, 300); + this.shell.setSize(526, 419); this.shell.setText("Remote GUI"); this.textBox = new Text(this.shell, SWT.BORDER); - this.textBox.setBounds(111, 95, 181, 58); + this.textBox.setBounds(80, 66, 181, 58); final Label lblRemoteDate = new Label(this.shell, SWT.NONE); - lblRemoteDate.setBounds(111, 63, 113, 26); + lblRemoteDate.setBounds(80, 34, 113, 26); lblRemoteDate.setText("Remote Date:"); - } + this.lblTextToSend = new Label(this.shell, SWT.NONE); + this.lblTextToSend.setText("Text to send:"); + this.lblTextToSend.setBounds(80, 171, 113, 26); + + this.textToSend = new Text(this.shell, SWT.BORDER); + this.textToSend.setBounds(80, 203, 181, 58); + + final Combo comboSendNumber = new Combo(this.shell, SWT.READ_ONLY); + comboSendNumber.setItems(new String[] { "1", "20", "30", "40", "500", + "633", "722", "899" }); + comboSendNumber.setBounds(80, 309, 113, 43); + comboSendNumber.select(0); + + final Label lblNumberToSend = new Label(this.shell, SWT.NONE); + lblNumberToSend.setText("Number to send:"); + lblNumberToSend.setBounds(80, 277, 113, 26); + + final Button btnSendtextAndNumber = new Button(this.shell, SWT.NONE); + btnSendtextAndNumber.setText("SendTextAndNumber"); + btnSendtextAndNumber.setBounds(295, 302, 162, 23); + btnSendtextAndNumber.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(final MouseEvent e) { + final String text = RemoteGUIExample.this.textToSend.getText(); + final String item = comboSendNumber.getItem(comboSendNumber.getSelectionIndex()); + RemoteGUIExample.this.writeTextService.setWriteText(text, + Integer.valueOf(item)); + } + }); + + final Button btnSendtext = new Button(this.shell, SWT.NONE); + btnSendtext.setBounds(295, 225, 162, 23); + btnSendtext.setText("SendText"); + btnSendtext.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(final MouseEvent e) { + final String text = RemoteGUIExample.this.textToSend.getText(); + RemoteGUIExample.this.writeTextService.setWriteText(text); + } + }); + } } diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java index e5e96c2..293d371 100644 --- a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java +++ b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java @@ -30,8 +30,8 @@ public class SpringContextLocator { } /** - * Singleton pattern not thread safety. To use SingletoHolder pattern as the - * best approximation otherwise to use an Enum class (see Effective Java + * Singleton pattern not thread safety. To use SingletonHolder pattern as + * the best approximation otherwise to use an Enum class (see Effective Java * Second Edition and ) if we need serialization. */ public static SpringContextLocator getInstance() { diff --git a/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml b/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml index 502b166..1445d07 100644 --- a/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml +++ b/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml @@ -15,4 +15,9 @@ + + + + + diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java new file mode 100644 index 0000000..7c05f04 --- /dev/null +++ b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java @@ -0,0 +1,20 @@ +package de.remote.agents.services; + +import org.apache.log4j.Logger; + +public class WriteTextServiceImpl implements WriteTextService { + private static final Logger logger = Logger + .getLogger(WriteTextServiceImpl.class); + + @Override + public void setWriteText(final String text, final Integer number) { + logger.info("String received from agent: " + text); + logger.info("Number received from agent: " + number); + } + + @Override + public void setWriteText(final String text) { + logger.info("We have received one string from agent: " + text); + } + +} diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml b/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml index 67b2ed4..397953f 100644 --- a/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml +++ b/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml @@ -14,4 +14,7 @@ + + + diff --git a/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java new file mode 100644 index 0000000..35b0b90 --- /dev/null +++ b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java @@ -0,0 +1,8 @@ +package de.remote.agents.services; + +public interface WriteTextService { + + void setWriteText(final String text); + + void setWriteText(final String text, final Integer number); +} -- 2.1.4