Skip to content

Commit 14c8b5d

Browse files
author
Lea Steffen
committed
Make the name of the program tree configurable
1 parent 35524e5 commit 14c8b5d

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

src/main/java/com/fzi/externalcontrol/impl/ExternalControlInstallationNodeContribution.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
public class ExternalControlInstallationNodeContribution implements InstallationNodeContribution {
3737
private static final String HOST_IP = "host_ip";
3838
private static final String PORT_NR = "port_nr";
39+
private static final String NAME = "name";
3940
private String urScriptProgram = "";
4041
private static final String DEFAULT_IP = "192.168.56.1";
4142
private static final String DEFAULT_PORT = "50002";
43+
private static final String DEFAULT_NAME = DEFAULT_IP;
4244
private DataModel model;
4345
private final ExternalControlInstallationNodeView view;
4446
private final KeyboardInputFactory keyboardFactory;
@@ -133,6 +135,39 @@ public void onOk(String value) {
133135
};
134136
}
135137

138+
// name helper functions
139+
public void setName(String name) {
140+
if ("".equals(name)) {
141+
resetToDefaultName();
142+
} else {
143+
model.set(NAME, name);
144+
}
145+
}
146+
147+
public String getName() {
148+
return model.get(NAME, DEFAULT_NAME);
149+
}
150+
151+
private void resetToDefaultName() {
152+
model.set(NAME, DEFAULT_NAME);
153+
}
154+
155+
public KeyboardTextInput getInputForNameTextField() {
156+
KeyboardTextInput keyboInput = keyboardFactory.createStringKeyboardInput();
157+
keyboInput.setInitialValue(getName());
158+
return keyboInput;
159+
}
160+
161+
public KeyboardInputCallback<String> getCallbackForNameTextField() {
162+
return new KeyboardInputCallback<String>() {
163+
@Override
164+
public void onOk(String value) {
165+
setName(value);
166+
view.UpdateNameTextField(value);
167+
}
168+
};
169+
}
170+
136171
public String getUrScriptProgram() {
137172
return urScriptProgram;
138173
}

src/main/java/com/fzi/externalcontrol/impl/ExternalControlInstallationNodeService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.ur.urcap.api.contribution.installation.CreationContext;
3131
import com.ur.urcap.api.contribution.installation.InstallationAPIProvider;
3232
import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeService;
33-
import com.ur.urcap.api.contribution.program.ProgramAPIProvider;
3433
import com.ur.urcap.api.domain.data.DataModel;
3534

3635
import java.util.Locale;

src/main/java/com/fzi/externalcontrol/impl/ExternalControlInstallationNodeView.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ public class ExternalControlInstallationNodeView
4141
implements SwingInstallationNodeView<ExternalControlInstallationNodeContribution> {
4242
private JTextField textFieldIP;
4343
private JTextField textFieldPort;
44+
private JTextField textFieldName;
4445

4546
public ExternalControlInstallationNodeView() {}
4647

4748
@Override
4849
public void buildUI(
4950
JPanel panel, final ExternalControlInstallationNodeContribution contribution) {
5051
panel.add(createIPBox(contribution));
51-
panel.add(createSpacer(60));
52+
panel.add(createSpacer(200));
5253
panel.add(createPortBox(contribution));
54+
panel.add(createSpacer(200));
55+
panel.add(createNameBox(contribution));
5356
}
5457

5558
public void UpdateIPTextField(String value) {
@@ -60,10 +63,14 @@ public void UpdatePortTextField(String value) {
6063
textFieldPort.setText(value);
6164
}
6265

66+
public void UpdateNameTextField(String value) {
67+
textFieldName.setText(value);
68+
}
69+
6370
private Box createIPBox(final ExternalControlInstallationNodeContribution contribution) {
6471
Box box = Box.createVerticalBox();
6572
// create IP Label
66-
JLabel label = new JLabel("Please setup the remote host's IP: ");
73+
JLabel label = new JLabel("Host IP: ");
6774
box.add(label);
6875
// create IP Textfield
6976
textFieldIP = new JTextField(15);
@@ -83,7 +90,7 @@ public void mousePressed(MouseEvent e) {
8390
private Box createPortBox(final ExternalControlInstallationNodeContribution contribution) {
8491
Box box = Box.createVerticalBox();
8592
// create port Label
86-
JLabel label = new JLabel("Please setup the custom port: ");
93+
JLabel label = new JLabel("Custom port: ");
8794
box.add(label);
8895
// create port Textfield
8996
textFieldPort = new JTextField(15);
@@ -100,6 +107,26 @@ public void mousePressed(MouseEvent e) {
100107
return box;
101108
}
102109

110+
private Box createNameBox(final ExternalControlInstallationNodeContribution contribution) {
111+
Box box = Box.createVerticalBox();
112+
// create name Label
113+
JLabel label = new JLabel("Host name");
114+
box.add(label);
115+
// create name Textfield
116+
textFieldName = new JTextField(15);
117+
textFieldName.setText(contribution.getHostIP());
118+
textFieldName.setFocusable(false);
119+
textFieldName.addMouseListener(new MouseAdapter() {
120+
@Override
121+
public void mousePressed(MouseEvent e) {
122+
KeyboardTextInput keyboardInput = contribution.getInputForNameTextField();
123+
keyboardInput.show(textFieldPort, contribution.getCallbackForNameTextField());
124+
}
125+
});
126+
box.add(textFieldName);
127+
return box;
128+
}
129+
103130
private Component createSpacer(int height) {
104131
return Box.createRigidArea(new Dimension(0, height));
105132
}

src/main/java/com/fzi/externalcontrol/impl/ExternalControlProgramNodeContribution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void closeView() {}
6969

7070
@Override
7171
public String getTitle() {
72-
return "ExternalControl";
72+
return "Control by " + getInstallation().getName();
7373
}
7474

7575
@Override

0 commit comments

Comments
 (0)