-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#7330: add spark configuration widget
- Loading branch information
1 parent
e952466
commit 97c3e08
Showing
13 changed files
with
314 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
const widgets = require('./widgets'); | ||
|
||
|
||
class SparkConfigurationModel extends widgets.VBoxModel { | ||
|
||
defaults() { | ||
return { | ||
...super.defaults(), | ||
_view_name: "SparkConfigurationView", | ||
_model_name: "SparkConfigurationModel", | ||
_model_module: 'beakerx', | ||
_view_module: 'beakerx', | ||
_model_module_version: BEAKERX_MODULE_VERSION, | ||
_view_module_version: BEAKERX_MODULE_VERSION, | ||
}; | ||
} | ||
} | ||
|
||
class SparkConfigurationView extends widgets.VBoxView { | ||
|
||
} | ||
|
||
export default { | ||
SparkConfigurationModel, | ||
SparkConfigurationView | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
kernel/sparkex/src/main/java/com/twosigma/beakerx/widget/Properties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.twosigma.beakerx.widget; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Properties { | ||
|
||
private final VBox widget; | ||
|
||
public Properties(List<PropertyItem> children) { | ||
this.widget = new VBox(children.stream().map(x -> (Widget) x).collect(Collectors.toList())); | ||
} | ||
|
||
public List<PropertyItem> getItems() { | ||
return this.widget.getChildren().stream() | ||
.map(x -> (PropertyItem) x) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public VBox getWidget() { | ||
return widget; | ||
} | ||
|
||
public void add(PropertyItem propertyItem) { | ||
this.widget.add(propertyItem); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
kernel/sparkex/src/main/java/com/twosigma/beakerx/widget/PropertyItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.twosigma.beakerx.widget; | ||
|
||
import static com.twosigma.beakerx.util.Preconditions.checkNotNull; | ||
import static java.util.Arrays.asList; | ||
|
||
public class PropertyItem extends HBox { | ||
|
||
private Text name; | ||
private Text value; | ||
private Button remove; | ||
|
||
public PropertyItem(Text name, Text value, Button remove) { | ||
super(asList(checkNotNull(name), checkNotNull(value), checkNotNull(remove))); | ||
this.name = name; | ||
this.value = value; | ||
this.remove = remove; | ||
} | ||
|
||
public String getNameAsString() { | ||
return name.getValue(); | ||
} | ||
|
||
public String getValueAsString() { | ||
return value.getValue(); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
kernel/sparkex/src/main/java/com/twosigma/beakerx/widget/SparkConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.twosigma.beakerx.widget; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Collections.EMPTY_LIST; | ||
import static java.util.Collections.singletonList; | ||
|
||
public class SparkConfiguration extends VBox { | ||
|
||
public static final String VIEW_NAME_VALUE = "SparkConfigurationView"; | ||
public static final String MODEL_NAME_VALUE = "SparkConfigurationModel"; | ||
|
||
private Button add; | ||
private HBox header; | ||
private Properties properties; | ||
|
||
public SparkConfiguration() { | ||
super(new ArrayList<>()); | ||
this.add = createAddButton(); | ||
this.header = new HBox(singletonList(this.add)); | ||
add(this.header); | ||
this.properties = new Properties(new ArrayList<>()); | ||
add(this.properties.getWidget()); | ||
} | ||
|
||
private Button createAddButton() { | ||
Button add = new Button(); | ||
add.setDescription("+"); | ||
add.registerOnClick((content, message) -> addProperty()); | ||
return add; | ||
} | ||
|
||
private void addProperty() { | ||
Text name = new Text(); | ||
name.setPlaceholder("name"); | ||
Text value = new Text(); | ||
value.setPlaceholder("value"); | ||
Button remove = new Button(); | ||
remove.setDescription("-"); | ||
PropertyItem propertyItem = new PropertyItem(name, value, remove); | ||
remove.registerOnClick((content, message) -> this.properties.getWidget().removeDOMWidget(propertyItem)); | ||
this.properties.add(propertyItem); | ||
} | ||
|
||
@Override | ||
public String getModelNameValue() { | ||
return MODEL_NAME_VALUE; | ||
} | ||
|
||
@Override | ||
public String getViewNameValue() { | ||
return VIEW_NAME_VALUE; | ||
} | ||
|
||
@Override | ||
public String getModelModuleValue() { | ||
return BeakerxWidget.MODEL_MODULE_VALUE; | ||
} | ||
|
||
@Override | ||
public String getViewModuleValue() { | ||
return BeakerxWidget.VIEW_MODULE_VALUE; | ||
} | ||
|
||
public List<Configuration> getConfiguration() { | ||
if (this.properties == null) { | ||
return EMPTY_LIST; | ||
} | ||
List<PropertyItem> children = this.properties.getItems(); | ||
return children.stream() | ||
.map(x -> new Configuration(x.getNameAsString(), x.getValueAsString())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static class Configuration { | ||
|
||
private String name; | ||
private String value; | ||
|
||
public Configuration(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.