Skip to content

Commit cfa9c34

Browse files
committed
UIEXT-3487: WebUI-Migration Binary Objects to PNGs
UIEXT-3487 (WebUI-Migration Binary Objects to PNGs)
1 parent 1fa1f98 commit cfa9c34

9 files changed

+570
-110
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<config xmlns="http://www.knime.org/2008/09/XMLConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.knime.org/2008/09/XMLConfig http://www.knime.org/XMLConfig_2008_09.xsd" key="settings.xml">
3+
<entry key="node_file" type="xstring" value="settings.xml"/>
4+
<config key="flow_stack"/>
5+
<config key="internal_node_subsettings">
6+
<entry key="memory_policy" type="xstring" value="CacheSmallInMemory"/>
7+
</config>
8+
<config key="model">
9+
<entry key="columnselection" type="xstring" value="Image"/>
10+
<entry key="replace" type="xstring" value="Append"/>
11+
<entry key="columnname" type="xstring" value="PNG"/>
12+
</config>
13+
<config key="variables"/>
14+
<entry key="customDescription" type="xstring" isnull="true" value=""/>
15+
<entry key="state" type="xstring" value="CONFIGURED"/>
16+
<entry key="factory" type="xstring" value="org.knime.base.filehandling.binaryobjectstopngs.BinaryObjectsToPNGsNodeFactory"/>
17+
<entry key="node-name" type="xstring" value="Binary Objects to PNGs"/>
18+
<entry key="node-bundle-name" type="xstring" value="KNIME File Handling Nodes"/>
19+
<entry key="node-bundle-symbolic-name" type="xstring" value="org.knime.base.filehandling"/>
20+
<entry key="node-bundle-vendor" type="xstring" value="KNIME AG, Zurich, Switzerland"/>
21+
<entry key="node-bundle-version" type="xstring" value="5.11.0.qualifier"/>
22+
<entry key="node-feature-name" type="xstring" isnull="true" value=""/>
23+
<entry key="node-feature-symbolic-name" type="xstring" isnull="true" value=""/>
24+
<entry key="node-feature-vendor" type="xstring" isnull="true" value=""/>
25+
<entry key="node-feature-version" type="xstring" value="0.0.0"/>
26+
<config key="factory_settings"/>
27+
<entry key="name" type="xstring" value="Binary Objects to PNGs"/>
28+
<entry key="hasContent" type="xboolean" value="false"/>
29+
<entry key="isInactive" type="xboolean" value="false"/>
30+
<config key="ports">
31+
<config key="port_1">
32+
<entry key="index" type="xint" value="1"/>
33+
<entry key="port_dir_location" type="xstring" isnull="true" value=""/>
34+
</config>
35+
</config>
36+
<config key="filestores">
37+
<entry key="file_store_location" type="xstring" isnull="true" value=""/>
38+
<entry key="file_store_id" type="xstring" isnull="true" value=""/>
39+
</config>
40+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"data" : {
3+
"model" : {
4+
"columnSelection" : "",
5+
"outputMode" : "REPLACE",
6+
"newColumnName" : "PNG"
7+
}
8+
},
9+
"schema" : {
10+
"type" : "object",
11+
"properties" : {
12+
"model" : {
13+
"type" : "object",
14+
"properties" : {
15+
"columnSelection" : {
16+
"type" : "string",
17+
"title" : "Column selection",
18+
"description" : "Column containing the binary objects that will be converted to PNG images.",
19+
"default" : ""
20+
},
21+
"newColumnName" : {
22+
"type" : "string",
23+
"title" : "New column name",
24+
"description" : "Name of the appended column. Only applicable when \"Append\" is selected.",
25+
"default" : "PNG"
26+
},
27+
"outputMode" : {
28+
"oneOf" : [ {
29+
"const" : "REPLACE",
30+
"title" : "Replace"
31+
}, {
32+
"const" : "APPEND",
33+
"title" : "Append"
34+
} ],
35+
"title" : "Output handling",
36+
"description" : "Determines whether to append a new PNG column or to replace the selected binary object column.\n<ul>\n<li><b>Replace</b>: Replaces the selected binary object column with the PNG column.</li>\n<li><b>Append</b>: Appends a new PNG column to the table.</li>\n</ul>",
37+
"default" : "REPLACE"
38+
}
39+
}
40+
}
41+
}
42+
},
43+
"ui_schema" : {
44+
"elements" : [ {
45+
"type" : "Control",
46+
"scope" : "#/properties/model/properties/columnSelection",
47+
"options" : {
48+
"format" : "dropDown"
49+
},
50+
"providedOptions" : [ "possibleValues" ]
51+
}, {
52+
"type" : "Control",
53+
"scope" : "#/properties/model/properties/outputMode",
54+
"options" : {
55+
"format" : "valueSwitch"
56+
}
57+
}, {
58+
"type" : "Control",
59+
"scope" : "#/properties/model/properties/newColumnName",
60+
"rule" : {
61+
"effect" : "SHOW",
62+
"condition" : {
63+
"scope" : "#/properties/model/properties/outputMode",
64+
"schema" : {
65+
"oneOf" : [ {
66+
"const" : "APPEND"
67+
} ]
68+
}
69+
}
70+
}
71+
} ]
72+
},
73+
"persist" : {
74+
"type" : "object",
75+
"properties" : {
76+
"model" : {
77+
"type" : "object",
78+
"properties" : {
79+
"columnSelection" : {
80+
"configKey" : "columnselection"
81+
},
82+
"outputMode" : {
83+
"configPaths" : [ [ "replace" ] ]
84+
},
85+
"newColumnName" : {
86+
"configKey" : "columnname"
87+
}
88+
}
89+
}
90+
}
91+
},
92+
"initialUpdates" : [ {
93+
"scope" : "#/properties/model/properties/columnSelection",
94+
"providedOptionName" : "possibleValues",
95+
"values" : [ {
96+
"indices" : [ ],
97+
"value" : [ {
98+
"id" : "foo",
99+
"text" : "foo",
100+
"type" : {
101+
"id" : "org.knime.core.data.blob.BinaryObjectDataValue",
102+
"text" : "Binary Object"
103+
}
104+
} ]
105+
} ]
106+
} ]
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<config xmlns="http://www.knime.org/2008/09/XMLConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.knime.org/2008/09/XMLConfig http://www.knime.org/XMLConfig_2008_09.xsd" key="test">
3+
<entry key="columnselection" type="xstring" value="Image"/>
4+
<entry key="replace" type="xstring" value="Append"/>
5+
<entry key="columnname" type="xstring" value="PNG"/>
6+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"data" : {
3+
"model" : {
4+
"columnSelection" : "Image",
5+
"outputMode" : "APPEND",
6+
"newColumnName" : "PNG"
7+
}
8+
},
9+
"schema" : {
10+
"type" : "object",
11+
"properties" : {
12+
"model" : {
13+
"type" : "object",
14+
"properties" : {
15+
"columnSelection" : {
16+
"type" : "string",
17+
"title" : "Column selection",
18+
"description" : "Column containing the binary objects that will be converted to PNG images.",
19+
"default" : ""
20+
},
21+
"newColumnName" : {
22+
"type" : "string",
23+
"title" : "New column name",
24+
"description" : "Name of the appended column. Only applicable when \"Append\" is selected.",
25+
"default" : "PNG"
26+
},
27+
"outputMode" : {
28+
"oneOf" : [ {
29+
"const" : "REPLACE",
30+
"title" : "Replace"
31+
}, {
32+
"const" : "APPEND",
33+
"title" : "Append"
34+
} ],
35+
"title" : "Output handling",
36+
"description" : "Determines whether to append a new PNG column or to replace the selected binary object column.\n<ul>\n<li><b>Replace</b>: Replaces the selected binary object column with the PNG column.</li>\n<li><b>Append</b>: Appends a new PNG column to the table.</li>\n</ul>",
37+
"default" : "REPLACE"
38+
}
39+
}
40+
}
41+
}
42+
},
43+
"ui_schema" : {
44+
"elements" : [ {
45+
"type" : "Control",
46+
"scope" : "#/properties/model/properties/columnSelection",
47+
"options" : {
48+
"format" : "dropDown"
49+
},
50+
"providedOptions" : [ "possibleValues" ]
51+
}, {
52+
"type" : "Control",
53+
"scope" : "#/properties/model/properties/outputMode",
54+
"options" : {
55+
"format" : "valueSwitch"
56+
}
57+
}, {
58+
"type" : "Control",
59+
"scope" : "#/properties/model/properties/newColumnName",
60+
"rule" : {
61+
"effect" : "SHOW",
62+
"condition" : {
63+
"scope" : "#/properties/model/properties/outputMode",
64+
"schema" : {
65+
"oneOf" : [ {
66+
"const" : "APPEND"
67+
} ]
68+
}
69+
}
70+
}
71+
} ]
72+
},
73+
"persist" : {
74+
"type" : "object",
75+
"properties" : {
76+
"model" : {
77+
"type" : "object",
78+
"properties" : {
79+
"columnSelection" : {
80+
"configKey" : "columnselection"
81+
},
82+
"outputMode" : {
83+
"configPaths" : [ [ "replace" ] ]
84+
},
85+
"newColumnName" : {
86+
"configKey" : "columnname"
87+
}
88+
}
89+
}
90+
}
91+
},
92+
"initialUpdates" : [ {
93+
"scope" : "#/properties/model/properties/columnSelection",
94+
"providedOptionName" : "possibleValues",
95+
"values" : [ {
96+
"indices" : [ ],
97+
"value" : [ {
98+
"id" : "foo",
99+
"text" : "foo",
100+
"type" : {
101+
"id" : "org.knime.core.data.blob.BinaryObjectDataValue",
102+
"text" : "Binary Object"
103+
}
104+
} ]
105+
} ]
106+
} ]
107+
}

org.knime.base.filehandling/src/org/knime/base/filehandling/binaryobjectstopngs/BinaryObjectsToPNGsNodeDialog.java renamed to org.knime.base.filehandling.tests/src/org/knime/base/filehandling/binaryobjectstopngs/BinaryObjectsToPNGsNodeParametersTest.java

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* ------------------------------------------------------------------------
3+
*
34
* Copyright by KNIME AG, Zurich, Switzerland
45
* Website: http://www.knime.com; Email: contact@knime.com
56
*
@@ -41,61 +42,64 @@
4142
* may freely choose the license terms applicable to such Node, including
4243
* when such Node is propagated with or for interoperation with KNIME.
4344
* ------------------------------------------------------------------------
44-
*
45-
* History
46-
* Oct 30, 2012 (Patrick Winter): created
4745
*/
4846
package org.knime.base.filehandling.binaryobjectstopngs;
4947

50-
import javax.swing.event.ChangeEvent;
51-
import javax.swing.event.ChangeListener;
48+
import java.io.FileInputStream;
49+
import java.io.IOException;
5250

53-
import org.knime.core.data.blob.BinaryObjectDataValue;
54-
import org.knime.core.node.defaultnodesettings.DefaultNodeSettingsPane;
55-
import org.knime.core.node.defaultnodesettings.DialogComponentButtonGroup;
56-
import org.knime.core.node.defaultnodesettings.DialogComponentColumnNameSelection;
57-
import org.knime.core.node.defaultnodesettings.DialogComponentString;
58-
import org.knime.core.node.defaultnodesettings.SettingsModelString;
51+
import org.knime.core.data.DataTableSpec;
52+
import org.knime.core.data.DataType;
53+
import org.knime.core.data.blob.BinaryObjectDataCell;
54+
import org.knime.core.node.InvalidSettingsException;
55+
import org.knime.core.node.NodeSettings;
56+
import org.knime.core.node.port.PortObjectSpec;
57+
import org.knime.core.webui.node.dialog.SettingsType;
58+
import org.knime.core.webui.node.dialog.defaultdialog.NodeParametersUtil;
59+
import org.knime.testing.node.dialog.DefaultNodeSettingsSnapshotTest;
60+
import org.knime.testing.node.dialog.SnapshotTestConfiguration;
5961

6062
/**
61-
* <code>NodeDialog</code> for the node.
62-
*
63-
*
64-
* @author Patrick Winter, KNIME AG, Zurich, Switzerland
63+
* Snapshot test for {@link BinaryObjectsToPNGsNodeParameters}.
64+
*
65+
* @author Tim Crundall, TNG Technology Consulting GmbH
6566
*/
66-
public class BinaryObjectsToPNGsNodeDialog extends DefaultNodeSettingsPane {
67+
@SuppressWarnings("restriction")
68+
final class BinaryObjectsToPNGsNodeParametersTest extends DefaultNodeSettingsSnapshotTest {
6769

68-
private SettingsModelString m_columnselection;
69-
70-
private SettingsModelString m_columnname;
70+
BinaryObjectsToPNGsNodeParametersTest() {
71+
super(getConfig());
72+
}
7173

72-
private SettingsModelString m_replace;
74+
private static SnapshotTestConfiguration getConfig() {
75+
return SnapshotTestConfiguration.builder() //
76+
.withInputPortObjectSpecs(createInputPortSpecs()) //
77+
.testJsonFormsForModel(BinaryObjectsToPNGsNodeParameters.class) //
78+
.testJsonFormsWithInstance(SettingsType.MODEL, () -> readSettings()) //
79+
.testNodeSettingsStructure(() -> readSettings()) //
80+
.build();
81+
}
7382

74-
/**
75-
* New pane for configuring the node dialog.
76-
*/
77-
@SuppressWarnings("unchecked")
78-
protected BinaryObjectsToPNGsNodeDialog() {
79-
super();
80-
m_columnselection = SettingsFactory.createColumnSelectionSettings();
81-
m_replace = SettingsFactory.createReplacePolicySettings();
82-
m_columnname = SettingsFactory.createColumnNameSettings(m_replace);
83-
m_replace.addChangeListener(new ChangeListener() {
84-
@Override
85-
public void stateChanged(final ChangeEvent e) {
86-
boolean append = m_replace.getStringValue().equals(ReplacePolicy.APPEND.getName());
87-
m_columnname.setEnabled(append);
83+
private static BinaryObjectsToPNGsNodeParameters readSettings() {
84+
try {
85+
var path = getSnapshotPath(BinaryObjectsToPNGsNodeParameters.class).getParent().resolve("node_settings")
86+
.resolve("BinaryObjectsToPNGsNodeParameters.xml");
87+
try (var fis = new FileInputStream(path.toFile())) {
88+
var nodeSettings = NodeSettings.loadFromXML(fis);
89+
return NodeParametersUtil.loadSettings(nodeSettings.getNodeSettings(SettingsType.MODEL.getConfigKey()),
90+
BinaryObjectsToPNGsNodeParameters.class);
8891
}
89-
});
90-
// Column selection
91-
addDialogComponent(new DialogComponentColumnNameSelection(m_columnselection, "Column selection", 0,
92-
BinaryObjectDataValue.class));
93-
createNewGroup("New column...");
94-
// Replace
95-
addDialogComponent(new DialogComponentButtonGroup(m_replace, false, "", ReplacePolicy.getAllSettings()));
96-
// Column name
97-
addDialogComponent(new DialogComponentString(m_columnname, "Name", true, 20));
98-
closeCurrentGroup();
92+
} catch (IOException | InvalidSettingsException e) {
93+
throw new IllegalStateException(e);
94+
}
95+
}
96+
97+
private static PortObjectSpec[] createInputPortSpecs() {
98+
return new PortObjectSpec[]{createDefaultTestTableSpec()};
9999
}
100100

101+
private static DataTableSpec createDefaultTestTableSpec() {
102+
return new DataTableSpec(new String[]{"foo"},
103+
new DataType[]{DataType.getType(BinaryObjectDataCell.class), });
104+
}
101105
}

0 commit comments

Comments
 (0)