Skip to content

Commit 16f3b5c

Browse files
authored
[UI] Update SML Process Gui
Process Admin Panel - This addition allows user to configure the process xml within the admin interface.
2 parents 4facec8 + f9af559 commit 16f3b5c

9 files changed

Lines changed: 1095 additions & 247 deletions

File tree

sensorhub-webui-core/src/main/java/org/sensorhub/ui/AdminUIModule.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.sensorhub.api.comm.CommProviderConfig;
2626
import org.sensorhub.api.comm.NetworkConfig;
2727
import org.sensorhub.api.common.SensorHubException;
28-
import org.sensorhub.api.database.DatabaseConfig;
2928
import org.sensorhub.api.database.IObsSystemDatabase;
3029
import org.sensorhub.api.datastore.command.CommandFilter;
3130
import org.sensorhub.api.datastore.command.CommandStreamFilter;
@@ -34,7 +33,6 @@
3433
import org.sensorhub.api.datastore.system.SystemFilter;
3534
import org.sensorhub.api.event.IEventListener;
3635
import org.sensorhub.api.module.IModule;
37-
import org.sensorhub.api.module.ModuleConfig;
3836
import org.sensorhub.api.module.ModuleEvent.ModuleState;
3937
import org.sensorhub.api.processing.ProcessConfig;
4038
import org.sensorhub.api.sensor.SensorConfig;
@@ -101,7 +99,7 @@ public void setConfiguration(AdminUIConfig config)
10199
customForms.put(CommandStreamFilter.class.getCanonicalName(), DatabaseFilterConfigForm.class);
102100
customForms.put(ObsFilter.class.getCanonicalName(), DatabaseFilterConfigForm.class);
103101
customForms.put(CommandFilter.class.getCanonicalName(), DatabaseFilterConfigForm.class);
104-
102+
105103
// custom form builders defined in config
106104
for (CustomUIConfig customForm: config.customForms)
107105
{

sensorhub-webui-core/src/main/java/org/sensorhub/ui/ProcessAdminPanel.java

Lines changed: 762 additions & 162 deletions
Large diffs are not rendered by default.

sensorhub-webui-core/src/main/java/org/sensorhub/ui/ProcessFlowDiagram.java

Lines changed: 94 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.vast.process.ProcessInfo;
2929
import org.vast.sensorML.AbstractProcessImpl;
3030
import org.vast.sensorML.AggregateProcessImpl;
31+
import org.vast.sensorML.LinkImpl;
3132
import org.vast.sensorML.SMLUtils;
3233
import org.vast.swe.SWEHelper;
3334
import com.rits.cloning.Cloner;
@@ -178,27 +179,28 @@ protected void setupCallbacks()
178179
{
179180
addFunction("onChangeLink", new JavaScriptFunction() {
180181
@Override
181-
public void call(JsonArray args)
182-
{
182+
public void call(JsonArray args) {
183183
Connection conn = new Connection();
184184
conn.id = args.getString(0);
185185
conn.src = args.getString(1);
186186
conn.dest = args.getString(2);
187-
addConnection(conn);
187+
addConnection(conn); // updates UI state
188+
upsertProcessChainLink(conn); // <-- persist to processChain
188189
notifyListeners();
189-
}
190+
}
190191
});
191-
192+
192193
addFunction("onRemoveLink", new JavaScriptFunction() {
193194
@Override
194-
public void call(JsonArray args)
195-
{
195+
public void call(JsonArray args) {
196196
String id = args.getString(0);
197197
getState().connections.remove(id);
198+
removeProcessChainLink(id); // <-- mirror removal
198199
notifyListeners();
199-
}
200+
}
200201
});
201-
202+
203+
202204
addFunction("onChangeElement", new JavaScriptFunction() {
203205
@Override
204206
public void call(JsonArray args)
@@ -226,34 +228,86 @@ public void call(JsonArray args)
226228
notifyListeners();
227229
}
228230
});
229-
231+
230232
addFunction("onContextMenu", new JavaScriptFunction() {
231233
@Override
232-
public void call(JsonArray args)
233-
{
234+
public void call(JsonArray args) {
234235
String action = args.getString(0);
235236
String blockName = args.getString(1);
236237
String portName = args.getString(2);
237-
if ("addInput".equals(action))
238-
addExternalInput(blockName, portName);
239-
else if ("setInput".equals(action))
240-
setInputValues(blockName, portName);
241-
else if ("setParam".equals(action))
242-
setParamValues(blockName, portName);
238+
239+
// normalize action names coming from the UI
240+
switch (action) {
241+
case "addInput":
242+
case "exposeInput":
243+
case "exposeAsInput":
244+
case "Expose as input":
245+
addExternalInput(blockName, portName);
246+
break;
247+
248+
case "setInput":
249+
case "setValue":
250+
case "Set value":
251+
setInputValues(blockName, portName);
252+
break;
253+
254+
case "setParam":
255+
case "setParameter":
256+
setParamValues(blockName, portName);
257+
break;
258+
259+
default:
260+
// ignore unknowns to avoid NPEs
261+
return;
262+
}
243263
notifyListeners();
244-
}
264+
}
245265
});
266+
246267
}
247-
248-
249-
protected void addExternalInput(String blockName, String portName)
250-
{
268+
269+
protected void upsertProcessChainLink(Connection conn) {
270+
// replace if same id exists
271+
for (int i = 0; i < processChain.getConnectionList().size(); i++) {
272+
Link l = processChain.getConnectionList().get(i);
273+
if (conn.id != null && conn.id.equals(l.getId())) {
274+
l.setSource(conn.src);
275+
l.setDestination(conn.dest);
276+
return;
277+
}
278+
}
279+
// otherwise add a new link
280+
Link l = new LinkImpl();
281+
l.setId(conn.id != null ? conn.id : UUID.randomUUID().toString());
282+
l.setSource(conn.src);
283+
l.setDestination(conn.dest);
284+
processChain.getConnectionList().add(l);
285+
}
286+
287+
protected void removeProcessChainLink(String id) {
288+
if (id == null) return;
289+
List<Link> links = processChain.getConnectionList();
290+
for (int i = links.size() - 1; i >= 0; i--) {
291+
Link l = links.get(i);
292+
if (id.equals(l.getId())) {
293+
links.remove(i);
294+
}
295+
}
296+
}
297+
298+
299+
300+
protected void addExternalInput(String blockName, String portName) {
301+
for (Port p : getState().inputs) {
302+
if (p.path.equals(portName)) return; // already exposed
303+
}
251304
Port port = new Port();
252305
port.path = portName;
253306
getState().inputs.add(port);
254307
}
255-
256-
308+
309+
310+
257311
protected void addExternalParam(String blockName, String portName)
258312
{
259313

@@ -264,40 +318,33 @@ protected void addExternalOutput(String blockName, String portName)
264318
{
265319

266320
}
267-
268-
269-
protected void setInputValues(String blockName, String portName)
270-
{
321+
322+
323+
protected void setInputValues(String blockName, String portName) {
271324
AbstractProcess process = processChain.getComponent(blockName);
272-
DataComponent paramPort = process.getParameterComponent(portName);
273-
editValues(paramPort);
325+
DataComponent inputPort = process.getInputComponent(portName); // <-- FIXED
326+
editValues("Set Input", inputPort);
274327
}
275-
276-
277-
protected void setParamValues(String blockName, String portName)
278-
{
328+
329+
protected void setParamValues(String blockName, String portName) {
279330
AbstractProcess process = processChain.getComponent(blockName);
280331
DataComponent paramPort = process.getParameterComponent(portName);
281-
editValues(paramPort);
332+
editValues("Set Parameter", paramPort);
282333
}
283-
284-
285-
protected void editValues(DataComponent component)
286-
{
287-
Window popup = new Window("Set Parameter");
334+
335+
protected void editValues(String title, DataComponent component) {
336+
Window popup = new Window(title); // <-- dynamic title
288337
VerticalLayout content = new VerticalLayout();
289338
popup.setContent(content);
290339
popup.center();
291-
292-
// retrieve param component
340+
293341
SWEParamForm form = new SWEParamForm(component);
294342
content.addComponent(form);
295-
296-
// Open it in the UI
297343
getUI().addWindow(popup);
298344
}
299-
300-
345+
346+
347+
301348
protected void addDataSource(ProcessBlock b)
302349
{
303350
getState().dataSources.put(b.name, b);

sensorhub-webui-core/src/main/java/org/sensorhub/ui/ProcessSelectionPopup.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@
1818
import java.util.HashMap;
1919
import java.util.Map;
2020
import java.util.regex.Pattern;
21+
22+
import com.vaadin.ui.*;
2123
import org.sensorhub.api.processing.IProcessProvider;
2224
import org.sensorhub.api.processing.ProcessingException;
25+
import org.sensorhub.impl.processing.StreamDataSource;
2326
import org.sensorhub.ui.api.UIConstants;
2427
import org.vast.process.ProcessInfo;
25-
import com.vaadin.ui.Alignment;
26-
import com.vaadin.ui.Button;
2728
import com.vaadin.v7.ui.TreeTable;
28-
import com.vaadin.ui.VerticalLayout;
29-
import com.vaadin.ui.Window;
3029
import com.vaadin.ui.Button.ClickEvent;
3130
import com.vaadin.ui.Button.ClickListener;
32-
import com.vaadin.ui.HorizontalLayout;
33-
import com.vaadin.ui.Label;
34-
import com.vaadin.ui.TextField;
3531

3632

3733
/**
@@ -65,7 +61,7 @@ public ProcessSelectionPopup(Collection<IProcessProvider> providers, final Proce
6561
setWidth(1000.0f, Unit.PIXELS);
6662
buildDialog(providers, callback);
6763
}
68-
64+
6965

7066
protected void buildDialog(Collection<IProcessProvider> providers, final ProcessSelectionCallback callback)
7167
{
@@ -81,7 +77,7 @@ protected void buildDialog(Collection<IProcessProvider> providers, final Process
8177
table.addContainerProperty(PROP_DESC, String.class, null);
8278
table.addContainerProperty(PROP_VERSION, String.class, null);
8379
table.addContainerProperty(PROP_AUTHOR, String.class, null);
84-
table.setColumnHeaders(new String[] {"Name", "Description", "Version", "Author"});
80+
table.setColumnHeaders("Name", "Description", "Version", "Author");
8581
table.setColumnWidth(PROP_NAME, 250);
8682
table.setPageLength(10);
8783
table.setMultiSelect(false);
@@ -97,8 +93,8 @@ protected void buildDialog(Collection<IProcessProvider> providers, final Process
9793

9894
for (ProcessInfo info: provider.getProcessMap().values())
9995
{
100-
// skip data sources as they are inserted separately
101-
if (info.getUri().contains(":datasource:"))
96+
// For simplicity, don't let users choose this one
97+
if (info == StreamDataSource.INFO)
10298
continue;
10399

104100
Object id = table.addItem(new Object[] {
@@ -111,21 +107,23 @@ protected void buildDialog(Collection<IProcessProvider> providers, final Process
111107
}
112108
}
113109
layout.addComponent(table);
114-
115-
// link to more modules
116-
Button installNew = new Button("Install More Packages...");
117-
installNew.setStyleName(STYLE_LINK);
118-
layout.addComponent(installNew);
119-
layout.setComponentAlignment(installNew, Alignment.MIDDLE_RIGHT);
120-
installNew.addClickListener(new ClickListener()
121-
{
122-
@Override
123-
public void buttonClick(ClickEvent event)
124-
{
125-
//close();
126-
getUI().addWindow(new DownloadModulesPopup());
127-
}
128-
});
110+
111+
var osgiCtx = ((AdminUI) UI.getCurrent()).getParentHub().getOsgiContext();
112+
if (osgiCtx != null) {
113+
// link to more modules
114+
Button installNew = new Button("Install More Packages...");
115+
installNew.setStyleName(STYLE_LINK);
116+
layout.addComponent(installNew);
117+
layout.setComponentAlignment(installNew, Alignment.MIDDLE_RIGHT);
118+
119+
installNew.addClickListener(new ClickListener() {
120+
@Override
121+
public void buttonClick(ClickEvent event) {
122+
//close();
123+
getUI().addWindow(new DownloadModulesPopup());
124+
}
125+
});
126+
}
129127

130128
// buttons bar
131129
HorizontalLayout buttons = new HorizontalLayout();

sensorhub-webui-core/src/main/java/org/sensorhub/ui/SWEControlForm.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,27 @@ public class SWEControlForm extends SWEEditForm
3838
transient Random random = new SecureRandom();
3939

4040

41-
public SWEControlForm(final IStreamingControlInterface controlInput)
41+
public SWEControlForm(final IStreamingControlInterface controlInput) { this(controlInput, null); }
42+
43+
public SWEControlForm(final IStreamingControlInterface controlInput, final ClickListener submitListener)
4244
{
4345
super(controlInput.getCommandDescription().copy());
4446
this.controlInput = controlInput;
4547
this.component.assignNewDataBlock();
46-
buildForm();
48+
buildForm(submitListener);
4749
}
4850

49-
50-
public SWEControlForm(final DataComponent params)
51+
public SWEControlForm(final DataComponent params) { this(params, null); }
52+
53+
public SWEControlForm(final DataComponent params, ClickListener submitListener)
5154
{
5255
super(params.copy());
5356
this.addSpacing = true;
5457
this.controlSink = params;
5558
this.component.setData(params.getData());
56-
buildForm();
59+
buildForm(submitListener);
5760
}
5861

59-
6062
@Override
6163
public void attach()
6264
{
@@ -77,8 +79,12 @@ public void attach()
7779
}
7880
}
7981

82+
@Override
83+
protected void buildForm() {
84+
buildForm(null);
85+
}
8086

81-
protected void buildForm()
87+
protected void buildForm(ClickListener submitListener)
8288
{
8389
super.buildForm();
8490

@@ -116,5 +122,8 @@ public void buttonClick(ClickEvent event)
116122
}
117123
}
118124
});
125+
126+
if (submitListener != null)
127+
sendBtn.addClickListener(submitListener);
119128
}
120129
}

0 commit comments

Comments
 (0)