2016-05-30 20:07:26 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
from py4j.java_gateway import JavaGateway
|
|
|
|
|
from py4j.java_gateway import java_import, JavaGateway, GatewayClient
|
|
|
|
|
|
|
|
|
|
client = GatewayClient(port=%PORT%)
|
|
|
|
|
gateway = JavaGateway(client)
|
|
|
|
|
java_import(gateway.jvm, "org.apache.zeppelin.display.Input")
|
|
|
|
|
|
|
|
|
|
class PyZeppelinContext():
|
|
|
|
|
paramOption = gateway.jvm.org.apache.zeppelin.display.Input.ParamOption
|
|
|
|
|
javaList = gateway.jvm.java.util.ArrayList
|
2016-06-16 15:50:06 +00:00
|
|
|
|
2016-05-30 20:07:26 +00:00
|
|
|
def __init__(self, zc):
|
|
|
|
|
self.z = zc
|
2016-06-16 15:50:06 +00:00
|
|
|
|
2016-05-30 20:07:26 +00:00
|
|
|
def input(self, name, defaultValue=""):
|
|
|
|
|
return self.z.getGui().input(name, defaultValue)
|
2016-06-16 15:50:06 +00:00
|
|
|
|
2016-05-30 20:07:26 +00:00
|
|
|
def select(self, name, options, defaultValue=""):
|
|
|
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
|
|
|
i = 0
|
|
|
|
|
for tuple in options:
|
|
|
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
|
|
|
i += 1
|
|
|
|
|
return self.z.getGui().select(name, defaultValue, javaOptions)
|
2016-06-16 15:50:06 +00:00
|
|
|
|
2016-05-30 20:07:26 +00:00
|
|
|
def checkbox(self, name, options, defaultChecked=[]):
|
|
|
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
|
|
|
i = 0
|
|
|
|
|
for tuple in options:
|
|
|
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
|
|
|
i += 1
|
|
|
|
|
javaDefaultCheck = self.javaList()
|
|
|
|
|
for check in defaultChecked:
|
|
|
|
|
javaDefaultCheck.append(check)
|
|
|
|
|
return self.z.getGui().checkbox(name, javaDefaultCheck, javaOptions)
|
|
|
|
|
|
|
|
|
|
z = PyZeppelinContext(gateway.entry_point)
|