Browse Source

installation node: dropdowns for ios
default values, persistence wip

Martin Kunz 4 years ago
parent
commit
b0d15be941

+ 0 - 2
src/main/java/urgrip/Activator.java

@@ -15,11 +15,9 @@ public class Activator implements BundleActivator {
 	@Override
 	public void start(BundleContext context) throws Exception {
 		System.out.println("Gripper Activator says Hello World!");
-
 		context.registerService(SwingToolbarService.class, new MyToolbarService(), null);
 		context.registerService(SwingProgramNodeService.class, new GripperNodeService(), null);
 		context.registerService(SwingInstallationNodeService.class, new HelloWorldInstallationNodeService(), null);
-
 	}
 
 	@Override

+ 52 - 28
src/main/java/urgrip/installation/HelloWorldInstallationNodeContribution.java

@@ -3,76 +3,100 @@ package urgrip.installation;
 import com.ur.urcap.api.contribution.InstallationNodeContribution;
 import com.ur.urcap.api.contribution.installation.InstallationAPIProvider;
 import com.ur.urcap.api.domain.data.DataModel;
+import com.ur.urcap.api.domain.io.IO;
 import com.ur.urcap.api.domain.script.ScriptWriter;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputCallback;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputFactory;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput;
 
+import java.util.Collection;
+
 public class HelloWorldInstallationNodeContribution implements InstallationNodeContribution {
 
-	private static final String POPUPTITLE_KEY = "popuptitle";
-	private static final String DEFAULT_VALUE = "Hello World";
 	private final HelloWorldInstallationNodeView view;
-	private final KeyboardInputFactory keyboardFactory;
+	private final InstallationAPIProvider apiProvider;
+	public final static String KEY_GRIP="KEY_GRIP";
+	private final static String KEY_GRIP_DEFAULT="digital_out[0]";
+	public final static String KEY_BLOWOUT="KEY_BLOWOUT";
+	private final static String KEY_BLOWOUT_DEFAULT="digital_out[1]";
+	public final static String KEY_WAITFOR="KEY_WAITFOR";
+	private final static String KEY_WAITFOR_DEFAULT="digital_in[0]";
 
 	private DataModel model;
 
 	public HelloWorldInstallationNodeContribution(InstallationAPIProvider apiProvider, DataModel model, HelloWorldInstallationNodeView view) {
-		this.keyboardFactory = apiProvider.getUserInterfaceAPI().getUserInteraction().getKeyboardInputFactory();
 		this.model = model;
 		this.view = view;
+		this.apiProvider=apiProvider;
 	}
 
 	@Override
 	public void openView() {
-		view.setPopupText(getPopupTitle());
+		Collection<IO> ios = apiProvider.getInstallationAPI().getIOModel().getIOs();
+		view.setIO(ios);
 	}
 
 	@Override
 	public void closeView() {
+		setGripIO(getGripIO());
 
 	}
 
 	public boolean isDefined() {
-		return !getPopupTitle().isEmpty();
+		if(getGripIO().isEmpty())
+			return false;
+		if(getBlowoutIO().isEmpty())
+			return false;
+		if(getWaitforIO().isEmpty())
+			return false;
+		return true;
 	}
 
 	@Override
 	public void generateScript(ScriptWriter writer) {
 		// Store the popup title in a global variable so it is globally available to all Hello World program nodes.
-		writer.assign("hello_world_swing_popup_title", "\"" + getPopupTitle() + "\"");
+		// writer.assign("hello_world_swing_popup_title", "\"" + getPopupTitle() + "\"");
+	}
+
+	public String getGripIO() {
+		return model.get(KEY_GRIP, KEY_GRIP_DEFAULT);
 	}
 
-	public String getPopupTitle() {
-		return model.get(POPUPTITLE_KEY, DEFAULT_VALUE);
+	public String getBlowoutIO() {
+		return model.get(KEY_BLOWOUT, KEY_BLOWOUT_DEFAULT);
 	}
 
-	public void setPopupTitle(String message) {
-		if ("".equals(message)) {
-			resetToDefaultValue();
+	public String getWaitforIO() {
+		return model.get(KEY_WAITFOR, KEY_WAITFOR_DEFAULT);
+	}
+
+	public void setGripIO(String ioName) {
+		if ("".equals(ioName)) {
+			model.set(KEY_GRIP, KEY_GRIP_DEFAULT);
 		} else {
-			model.set(POPUPTITLE_KEY, message);
+			model.set(KEY_GRIP, ioName);
 		}
 	}
 
-	private void resetToDefaultValue() {
-		view.setPopupText(DEFAULT_VALUE);
-		model.set(POPUPTITLE_KEY, DEFAULT_VALUE);
+	public void setBlowoutIO(String ioName) {
+		if ("".equals(ioName)) {
+			model.set(KEY_BLOWOUT, KEY_BLOWOUT_DEFAULT);
+		} else {
+			model.set(KEY_BLOWOUT, ioName);
+		}
 	}
 
-	public KeyboardTextInput getInputForTextField() {
-		KeyboardTextInput keyboardInput = keyboardFactory.createStringKeyboardInput();
-		keyboardInput.setInitialValue(getPopupTitle());
-		return keyboardInput;
+	public void setWaitforIO(String ioName) {
+		if ("".equals(ioName)) {
+			model.set(KEY_WAITFOR, KEY_WAITFOR_DEFAULT);
+		} else {
+			model.set(KEY_WAITFOR, ioName);
+		}
 	}
 
-	public KeyboardInputCallback<String> getCallbackForTextField() {
-		return new KeyboardInputCallback<String>() {
-			@Override
-			public void onOk(String value) {
-				setPopupTitle(value);
-				view.setPopupText(value);
-			}
-		};
+	private void resetToDefaultValue() {
+		model.set(KEY_GRIP, KEY_GRIP_DEFAULT);
+		model.set(KEY_BLOWOUT, KEY_BLOWOUT_DEFAULT);
+		model.set(KEY_WAITFOR, KEY_WAITFOR_DEFAULT);
 	}
 }

+ 41 - 36
src/main/java/urgrip/installation/HelloWorldInstallationNodeView.java

@@ -1,27 +1,28 @@
 package urgrip.installation;
 
 import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView;
+import com.ur.urcap.api.domain.io.IO;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput;
 import urgrip.programnodes.Style;
 
-import javax.swing.BorderFactory;
-import javax.swing.Box;
-import javax.swing.BoxLayout;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.JTextPane;
+import javax.swing.*;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyleConstants;
 import java.awt.Component;
 import java.awt.Dimension;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Collection;
+import java.util.Vector;
+
+import static urgrip.installation.HelloWorldInstallationNodeContribution.*;
 
 public class HelloWorldInstallationNodeView implements SwingInstallationNodeView<HelloWorldInstallationNodeContribution> {
 
 	private final Style style;
-	private JTextField jTextField;
+	private JComboBox ddGrip;
+	private JComboBox ddBlow;
+	private JComboBox ddWaitFor;
 
 	public HelloWorldInstallationNodeView(Style style) {
 		this.style = style;
@@ -30,10 +31,32 @@ public class HelloWorldInstallationNodeView implements SwingInstallationNodeView
 	@Override
 	public void buildUI(JPanel jPanel, final HelloWorldInstallationNodeContribution installationNode) {
 		jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
-
 		jPanel.add(createInfo());
 		jPanel.add(createVerticalSpacing());
-		jPanel.add(createInput(installationNode));
+		// jPanel.add(createInput(installationNode));
+		ddGrip = createDropdown(KEY_GRIP);
+		jPanel.add(ddGrip);
+		ddBlow = createDropdown(KEY_BLOWOUT);
+		jPanel.add(ddBlow);
+		ddWaitFor = createDropdown(KEY_WAITFOR);
+		jPanel.add(ddWaitFor);
+	}
+
+	private JComboBox createDropdown(String key) {
+		Box section = Box.createHorizontalBox();
+		section.setAlignmentX(Component.LEFT_ALIGNMENT);
+		JComboBox jcb = new JComboBox();
+		jcb.setPreferredSize(style.getInputfieldSize());
+		jcb.setMaximumSize(style.getInputfieldSize());
+		jcb.setMinimumSize(style.getInputfieldSize());
+		jcb.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent actionEvent) {
+			}
+		});
+		section.add(new JLabel(key));
+		section.add(jcb);
+		return jcb;
 	}
 
 	private Box createInfo() {
@@ -53,28 +76,6 @@ public class HelloWorldInstallationNodeView implements SwingInstallationNodeView
 		return infoBox;
 	}
 
-	private Box createInput(final HelloWorldInstallationNodeContribution installationNode) {
-		Box inputBox = Box.createHorizontalBox();
-		inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
-
-		inputBox.add(new JLabel("Popup title:"));
-		inputBox.add(createHorizontalSpacing());
-
-		jTextField = new JTextField();
-		jTextField.setFocusable(false);
-		jTextField.setPreferredSize(style.getInputfieldSize());
-		jTextField.setMaximumSize(jTextField.getPreferredSize());
-		jTextField.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mousePressed(MouseEvent e) {
-				KeyboardTextInput keyboardInput = installationNode.getInputForTextField();
-				keyboardInput.show(jTextField, installationNode.getCallbackForTextField());
-			}
-		});
-		inputBox.add(jTextField);
-
-		return inputBox;
-	}
 
 	private Component createHorizontalSpacing() {
 		return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
@@ -84,7 +85,11 @@ public class HelloWorldInstallationNodeView implements SwingInstallationNodeView
 		return Box.createRigidArea(new Dimension(0, style.getVerticalSpacing()));
 	}
 
-	public void setPopupText(String t) {
-		jTextField.setText(t);
+	public void setIO(Collection<IO> ios) {
+		Vector<IO> iov=new Vector<>();
+		iov.addAll(ios);
+		ddGrip.setModel(new DefaultComboBoxModel(iov));
+		ddBlow.setModel(new DefaultComboBoxModel(iov));
+		ddWaitFor.setModel(new DefaultComboBoxModel(iov));
 	}
 }