|
@@ -7,6 +7,7 @@ import com.ur.urcap.api.domain.script.ScriptWriter;
|
|
|
import com.ur.urcap.api.ui.annotation.Input;
|
|
|
import com.ur.urcap.api.ui.annotation.Label;
|
|
|
import com.ur.urcap.api.ui.component.InputEvent;
|
|
|
+import com.ur.urcap.api.ui.component.InputRadioButton;
|
|
|
import com.ur.urcap.api.ui.component.InputTextField;
|
|
|
import com.ur.urcap.api.ui.component.LabelComponent;
|
|
|
|
|
@@ -15,9 +16,11 @@ import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
|
|
|
public class MyDaemonProgramNodeContribution implements ProgramNodeContribution {
|
|
|
- private static final String NAME = "name";
|
|
|
+ private static final String POS = "pos";
|
|
|
+ private static final String ABSOLUTE = "absolute";
|
|
|
|
|
|
- private final DataModel model;
|
|
|
+
|
|
|
+ private final DataModel model;
|
|
|
private final URCapAPI api;
|
|
|
private Timer uiTimer;
|
|
|
|
|
@@ -26,8 +29,14 @@ public class MyDaemonProgramNodeContribution implements ProgramNodeContribution
|
|
|
this.model = model;
|
|
|
}
|
|
|
|
|
|
- @Input(id = "yourname")
|
|
|
- private InputTextField nameTextField;
|
|
|
+ @Input(id = "pos")
|
|
|
+ private InputTextField posTextField;
|
|
|
+
|
|
|
+ @Input(id = "rbAbs")
|
|
|
+ private InputRadioButton radioAbsButton;
|
|
|
+
|
|
|
+ @Input(id = "rbRel")
|
|
|
+ private InputRadioButton radioRelButton;
|
|
|
|
|
|
@Label(id = "titlePreviewLabel")
|
|
|
private LabelComponent titlePreviewLabel;
|
|
@@ -35,18 +44,21 @@ public class MyDaemonProgramNodeContribution implements ProgramNodeContribution
|
|
|
@Label(id = "messagePreviewLabel")
|
|
|
private LabelComponent messagePreviewLabel;
|
|
|
|
|
|
- @Input(id = "yourname")
|
|
|
+ @Input(id = "pos")
|
|
|
public void onInput(InputEvent event) {
|
|
|
if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
|
|
|
- setName(nameTextField.getText());
|
|
|
+ setPos(posTextField.getText());
|
|
|
updatePreview();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void openView() {
|
|
|
- nameTextField.setText(getName());
|
|
|
-
|
|
|
+ posTextField.setText(getPos());
|
|
|
+ if(isAbsolute())
|
|
|
+ radioAbsButton.setSelected();
|
|
|
+ else
|
|
|
+ radioRelButton.setSelected();
|
|
|
//UI updates from non-GUI threads must use EventQueue.invokeLater (or SwingUtilities.invokeLater)
|
|
|
uiTimer = new Timer(true);
|
|
|
uiTimer.schedule(new TimerTask() {
|
|
@@ -62,63 +74,67 @@ public class MyDaemonProgramNodeContribution implements ProgramNodeContribution
|
|
|
}, 0, 1000);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void closeView() {
|
|
|
uiTimer.cancel();
|
|
|
+ if(radioAbsButton.isSelected())
|
|
|
+ model.set(ABSOLUTE, true);
|
|
|
+ else model.set(ABSOLUTE, false);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getTitle() {
|
|
|
- return "My Daemon: " + (model.isSet(NAME) ? getName() : "");
|
|
|
+ return "My Daemon: " + (model.isSet(POS) ? getPos() : "");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean isDefined() {
|
|
|
// return getInstallation().isDefined() && !getName().isEmpty();
|
|
|
- return !getName().isEmpty();
|
|
|
-
|
|
|
+ return !getPos().isEmpty();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void generateScript(ScriptWriter writer) {
|
|
|
// Interact with the daemon process through XML-RPC calls
|
|
|
// Note, alternatively plain sockets can be used.
|
|
|
- writer.assign("mydaemon_message", getInstallation().getXMLRPCVariable() + ".get_message(\"" + getName() + "\")");
|
|
|
- writer.assign("mydaemon_title", getInstallation().getXMLRPCVariable() + ".get_title()");
|
|
|
- writer.appendLine("popup(mydaemon_message, mydaemon_title, False, False, blocking=True)");
|
|
|
+// if(radioRelButton.isSelected()) {
|
|
|
+// writer.appendLine( getInstallation().getXMLRPCVariable() + ".rel(\"" + getName() + "\")");
|
|
|
+// }
|
|
|
+// else if(radioAbsButton.isSelected()) {
|
|
|
+// writer.appendLine( getInstallation().getXMLRPCVariable() + ".abs(\"" + getName() + "\")");
|
|
|
+// }
|
|
|
+ writer.appendLine( getInstallation().getXMLRPCVariable() + ".rel(\"" + getPos() + "\")");
|
|
|
writer.writeChildren();
|
|
|
}
|
|
|
|
|
|
private void updatePreview() {
|
|
|
- String title = "";
|
|
|
- String message = "";
|
|
|
- try {
|
|
|
- // Provide a real-time preview of the daemon state
|
|
|
- title = getInstallation().getDaemonInterface().getTitle();
|
|
|
- message = getInstallation().getDaemonInterface().getMessage(getName());
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("Could not retrieve essential data from the daemon process for the preview.");
|
|
|
- title = message = "<Daemon disconnected>";
|
|
|
- }
|
|
|
-
|
|
|
- titlePreviewLabel.setText(title);
|
|
|
- messagePreviewLabel.setText(message);
|
|
|
+ titlePreviewLabel.setText("pos: " + (radioAbsButton.isSelected()?"Abs":"Rel"));
|
|
|
+ //messagePreviewLabel.setText(message);
|
|
|
}
|
|
|
|
|
|
- private String getName() {
|
|
|
- return model.get(NAME, "");
|
|
|
+ private String getPos() {
|
|
|
+ return model.get(POS, "");
|
|
|
}
|
|
|
|
|
|
- private void setName(String name) {
|
|
|
+ private void setPos(String name) {
|
|
|
if ("".equals(name)){
|
|
|
- model.remove(NAME);
|
|
|
+ model.remove(POS);
|
|
|
}else{
|
|
|
- model.set(NAME, name);
|
|
|
+ model.set(POS, name);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private MyDaemonInstallationNodeContribution getInstallation(){
|
|
|
+ private boolean isAbsolute() {
|
|
|
+ return model.get(ABSOLUTE, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAbsolute(boolean absolute) {
|
|
|
+ model.set(ABSOLUTE, absolute);
|
|
|
+ }
|
|
|
+
|
|
|
+ private MyDaemonInstallationNodeContribution getInstallation(){
|
|
|
return api.getInstallationNode(MyDaemonInstallationNodeContribution.class);
|
|
|
}
|
|
|
-
|
|
|
}
|