org.apache.zeppelin.display.GUI Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.zeppelin.display;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.zeppelin.display.ui.CheckBox;
import org.apache.zeppelin.display.ui.OptionInput.ParamOption;
import org.apache.zeppelin.display.ui.Password;
import org.apache.zeppelin.display.ui.Select;
import org.apache.zeppelin.display.ui.TextBox;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Settings of a form.
*/
public class GUI implements Serializable {
private static Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(Input.TypeAdapterFactory)
.create();
Map params = new HashMap<>(); // form parameters from client
Map forms = new LinkedHashMap<>(); // form configuration
public GUI() {
}
public void setParams(Map values) {
this.params = values;
}
public Map getParams() {
return params;
}
public Map getForms() {
return forms;
}
public void setForms(Map forms) {
this.forms = forms;
}
@Deprecated
public Object input(String id) {
return textbox(id, "");
}
@Deprecated
public Object input(String id, Object defaultValue) {
return textbox(id, defaultValue.toString());
}
public Object textbox(String id, String defaultValue) {
// first find values from client and then use default
Object value = params.get(id);
if (value == null) {
value = defaultValue;
}
forms.put(id, new TextBox(id, defaultValue));
params.put(id, value);
return value;
}
public Object textbox(String id) {
return textbox(id, "");
}
public Object password(String id) {
forms.put(id, new Password(id));
return params.get(id);
}
public Object select(String id, ParamOption[] options, Object defaultValue) {
if (defaultValue == null && options != null && options.length > 0) {
defaultValue = options[0].getValue();
}
forms.put(id, new Select(id, defaultValue, options));
Object value = params.get(id);
if (value == null) {
value = defaultValue;
}
params.put(id, value);
return value;
}
public List