forked from fanruan/demo-tabledata-es
richie
5 years ago
104 changed files with 1865 additions and 35 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1,19 @@
|
||||
# elasticsearch数据集插件 |
||||
# Elasticsearch数据集插件 |
||||
|
||||
## 新建Elasticsearch数据连接 |
||||
|
||||
![connection](screenshots/connection.png) |
||||
|
||||
支持连接集群,以逗号分隔多个主机地址和端口即可,确保主机地址和端口数量一致。 |
||||
|
||||
## 新建Elasticsearch数据集 |
||||
|
||||
![tabledata](screenshots/tabledata.png) |
||||
|
||||
左侧区域是用于测试的,输入Elasticsearch命令后,点击执行按钮,可以在左下角输出区看到输出结果; |
||||
|
||||
右侧区域是用于实际查询的,每一个输入框区域都可以使用${p}的格式带入参数。 |
||||
|
||||
## 预览Elasticsearch数据集 |
||||
|
||||
![preview](screenshots/preview.png) |
After Width: | Height: | Size: 64 KiB |
After Width: | Height: | Size: 306 KiB |
After Width: | Height: | Size: 261 KiB |
@ -0,0 +1,85 @@
|
||||
package com.fr.plugin.db.es.fun; |
||||
|
||||
import com.fanruan.api.conf.BaseUniqueKey; |
||||
import com.fanruan.api.conf.HolderKit; |
||||
import com.fanruan.api.util.AssistKit; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLable; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class ConfigAttribute extends BaseUniqueKey implements XMLable { |
||||
|
||||
public static final String XML_TAG = "ConfigAttribute"; |
||||
private static final long serialVersionUID = -2125057720890342129L; |
||||
|
||||
private Conf<Boolean> sorted = HolderKit.simple(false); |
||||
private Conf<Boolean> prepare = HolderKit.simple(false); |
||||
|
||||
|
||||
public ConfigAttribute() { |
||||
|
||||
} |
||||
|
||||
public boolean isSorted() { |
||||
return sorted.get(); |
||||
} |
||||
|
||||
public void setSorted(boolean sorted) { |
||||
this.sorted.set(sorted); |
||||
} |
||||
|
||||
public boolean isPrepare() { |
||||
return prepare.get(); |
||||
} |
||||
|
||||
public void setPrepare(boolean prepare) { |
||||
this.prepare.set(prepare); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
String tagName = reader.getTagName(); |
||||
if ("Attr".equals(tagName)) { |
||||
sorted.set(reader.getAttrAsBoolean("sorted", false)); |
||||
prepare.set(reader.getAttrAsBoolean("prepare", false)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
writer.startTAG("Attr"); |
||||
writer.attr("sorted", sorted.get()); |
||||
writer.attr("prepare", prepare.get()); |
||||
writer.end(); |
||||
} |
||||
|
||||
@Override |
||||
@SuppressWarnings("unchecked") |
||||
public Object clone() throws CloneNotSupportedException { |
||||
ConfigAttribute cloned = (ConfigAttribute) super.clone(); |
||||
cloned.sorted = (Conf<Boolean>) sorted.clone(); |
||||
cloned.prepare = (Conf<Boolean>) prepare.clone(); |
||||
return cloned; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
return obj instanceof ConfigAttribute |
||||
&& AssistKit.equals(this.sorted, ((ConfigAttribute) obj).sorted) |
||||
&& AssistKit.equals(this.prepare, ((ConfigAttribute) obj).prepare); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return AssistKit.hashCode(sorted.get(), prepare.get()); |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
package com.fr.plugin.db.es.fun.assist; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class SimpleDataModel { |
||||
|
||||
private List<List<Object>> data = new ArrayList<List<Object>>(); |
||||
private String[] columnNames = null; |
||||
private int rowCount; |
||||
|
||||
public SimpleDataModel(String[] columnNames, List<List<Object>> data){ |
||||
this.columnNames = columnNames; |
||||
this.data = data; |
||||
} |
||||
|
||||
public SimpleDataModel(String[] columnNames, List<List<Object>> data, int rowCount){ |
||||
this.columnNames = columnNames; |
||||
this.data = data; |
||||
this.rowCount = rowCount; |
||||
} |
||||
|
||||
public List<List<Object>> getData() { |
||||
return data; |
||||
} |
||||
|
||||
public void setData(List<List<Object>> data) { |
||||
this.data = data; |
||||
} |
||||
|
||||
public String[] getColumnNames() { |
||||
return columnNames; |
||||
} |
||||
|
||||
public void setColumnNames(String[] columnNames) { |
||||
this.columnNames = columnNames; |
||||
} |
||||
|
||||
public int getRowCount() { |
||||
return rowCount; |
||||
} |
||||
|
||||
public void setRowCount(int rowCount) { |
||||
this.rowCount = rowCount; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.db.es.fun.category; |
||||
|
||||
import com.fr.plugin.db.es.fun.ConfigAttribute; |
||||
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public interface ResultStandardize { |
||||
|
||||
SimpleDataModel result(String text, String script, ConfigAttribute configAttribute, int rowCount); |
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin.db.es.fun.category; |
||||
|
||||
import com.fr.plugin.db.es.fun.category.impl.JSONResultStandardize; |
||||
import com.fr.plugin.db.es.fun.category.impl.JSResultStandardize; |
||||
import com.fr.plugin.db.es.fun.type.ConverterType; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class ResultStandardizeSelector { |
||||
|
||||
public static ResultStandardize select(ConverterType converterType) { |
||||
if (converterType == ConverterType.JSON) { |
||||
return new JSONResultStandardize(); |
||||
} else { |
||||
return new JSResultStandardize(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,166 @@
|
||||
package com.fr.plugin.db.es.fun.category.impl; |
||||
|
||||
import com.fr.plugin.db.es.fun.ConfigAttribute; |
||||
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; |
||||
import com.fr.plugin.db.es.fun.category.ResultStandardize; |
||||
import com.jayway.jsonpath.JsonPath; |
||||
import net.minidev.json.JSONArray; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashSet; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.LinkedHashSet; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
import java.util.TreeMap; |
||||
import java.util.TreeSet; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class JSONResultStandardize implements ResultStandardize { |
||||
|
||||
private List<String> columnNames = new ArrayList<>(); |
||||
private List<List<Object>> data = new ArrayList<List<Object>>(); |
||||
|
||||
@Override |
||||
public SimpleDataModel result(String text, String script, ConfigAttribute configAttribute, int rowCount) { |
||||
Object object = JsonPath.read(text, script); |
||||
if (object instanceof LinkedHashMap) { |
||||
initJSONObject(new TreeMap<>((LinkedHashMap<String, Object>) object)); |
||||
} else if (object instanceof JSONArray) { |
||||
initJSONArray((JSONArray) object, configAttribute); |
||||
} else { |
||||
initSingleData(object); |
||||
} |
||||
return new SimpleDataModel(columnNames.toArray(new String[0]), data); |
||||
} |
||||
|
||||
private Map<String, Object> transferMap(Map<String, Object> data, ConfigAttribute attr) { |
||||
if (attr.isSorted()) { |
||||
return new TreeMap<>(data); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
private void initJSONObject(Map<String, Object> map) { |
||||
List<Object> row = new ArrayList<Object>(); |
||||
for (Map.Entry<String, Object> entry : map.entrySet()) { |
||||
columnNames.add(entry.getKey()); |
||||
row.add(entry.getValue()); |
||||
} |
||||
data.add(row); |
||||
} |
||||
|
||||
private void initJSONArray(JSONArray jsonArray, ConfigAttribute attr) { |
||||
if (attr.isPrepare()) { |
||||
iterateAllColumn(jsonArray, attr); |
||||
} else { |
||||
quickAttach(jsonArray, attr); |
||||
} |
||||
} |
||||
|
||||
private int findColumnIndexByName(String columnName) { |
||||
for (int i = 0, len = columnNames.size(); i < len; i++) { |
||||
if (columnName.equals(columnNames.get(i))) { |
||||
return i; |
||||
} |
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
private void quickAttach(JSONArray jsonArray, ConfigAttribute attr) { |
||||
boolean findMap = false; |
||||
boolean colGet = false; |
||||
Set<String> extraColumns = new LinkedHashSet<String>(); |
||||
for (Object obj : jsonArray) { |
||||
List<Object> row = new ArrayList<Object>(); |
||||
if (obj instanceof LinkedHashMap) { |
||||
findMap = true; |
||||
Map<String, Object> map = transferMap((LinkedHashMap<String, Object>) obj, attr); |
||||
|
||||
Map<String, Object> lazy = new LinkedHashMap<String, Object>(); |
||||
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) { |
||||
String key = entry.getKey(); |
||||
if (!colGet) { |
||||
columnNames.add(key); |
||||
} |
||||
if (findColumnIndexByName(key) != -1) { |
||||
row.add(entry.getValue()); |
||||
} else { |
||||
lazy.put(key, entry.getValue()); |
||||
} |
||||
} |
||||
for (Map.Entry<String, Object> entry : lazy.entrySet()) { |
||||
row.add(entry.getValue()); |
||||
extraColumns.add(entry.getKey()); |
||||
} |
||||
colGet = true; |
||||
data.add(row); |
||||
} else if (obj instanceof JSONArray) { |
||||
findMap = true; |
||||
JSONArray array = (JSONArray) obj; |
||||
for (int i = 0, len = array.size(); i < len; i++) { |
||||
if (!colGet) { |
||||
columnNames.add("value" + (i + 1)); |
||||
} |
||||
row.add(array.get(i)); |
||||
} |
||||
colGet = true; |
||||
data.add(row); |
||||
|
||||
} |
||||
} |
||||
columnNames.addAll(extraColumns); |
||||
if (!findMap) { |
||||
columnNames.add("value"); |
||||
for (Object obj : jsonArray) { |
||||
List<Object> row = new ArrayList<Object>(); |
||||
row.add(obj); |
||||
data.add(row); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void iterateAllColumn(JSONArray jsonArray, ConfigAttribute attr) { |
||||
Set<String> columnString = transferColumnSet(attr); |
||||
for (Object obj : jsonArray) { |
||||
if (obj instanceof LinkedHashMap) { |
||||
Map<String, Object> map = transferMap((LinkedHashMap<String, Object>) obj, attr); |
||||
columnString.addAll(map.keySet()); |
||||
} else { |
||||
throw new RuntimeException("Illegal format, data must be JSONObject!"); |
||||
} |
||||
} |
||||
columnNames = new ArrayList<>(columnString); |
||||
for (Object obj : jsonArray) { |
||||
List<Object> row = new ArrayList<Object>(); |
||||
if (obj instanceof LinkedHashMap) { |
||||
Map<String, Object> map = (LinkedHashMap<String, Object>) obj; |
||||
for (String key : columnNames) { |
||||
row.add(map.get(key)); |
||||
} |
||||
} |
||||
data.add(row); |
||||
} |
||||
} |
||||
|
||||
private Set<String> transferColumnSet(ConfigAttribute attr) { |
||||
if (attr.isSorted()) { |
||||
return new TreeSet<>(); |
||||
} |
||||
return new HashSet<>(); |
||||
} |
||||
|
||||
private void initSingleData(Object obj) { |
||||
columnNames.add("value"); |
||||
List<Object> row = new ArrayList<>(); |
||||
row.add(obj); |
||||
data.add(row); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.db.es.fun.category.impl; |
||||
|
||||
import com.fr.plugin.db.es.fun.ConfigAttribute; |
||||
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; |
||||
import com.fr.plugin.db.es.fun.category.ResultStandardize; |
||||
import com.fr.plugin.db.es.fun.category.script.ScriptClientSelector; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class JSResultStandardize implements ResultStandardize { |
||||
@Override |
||||
public SimpleDataModel result(String text, String script, ConfigAttribute configAttribute, int rowCount) { |
||||
return ScriptClientSelector.auto().build(text, script, rowCount); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.fr.plugin.db.es.fun.category.script; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
public enum EngineType { |
||||
|
||||
V8(0), JAVA(1); |
||||
|
||||
private int index; |
||||
|
||||
EngineType(int index) { |
||||
this.index = index; |
||||
} |
||||
|
||||
public int getType() { |
||||
return index; |
||||
} |
||||
|
||||
public static EngineType parse(int type) { |
||||
for (EngineType engineType : values()) { |
||||
if (engineType.index == type) { |
||||
return engineType; |
||||
} |
||||
} |
||||
return V8; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.db.es.fun.category.script; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Inherited |
||||
public @interface ScriptBridge { |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.plugin.db.es.fun.category.script; |
||||
|
||||
import com.eclipsesource.v8.V8; |
||||
import com.fr.plugin.db.es.fun.category.script.client.ScriptClient; |
||||
import com.fr.plugin.db.es.fun.category.script.client.impl.NashornClient; |
||||
import com.fr.plugin.db.es.fun.category.script.client.impl.V8Client; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
* JS客户端选择器 |
||||
*/ |
||||
public class ScriptClientSelector { |
||||
|
||||
private final static boolean SUPPORT_J2V8 = isSupportJ2v8(); |
||||
|
||||
public static boolean isSupportJ2v8() { |
||||
V8 v8; |
||||
try { |
||||
v8 = V8.createV8Runtime(); |
||||
} catch (IllegalStateException ex) { |
||||
return false; |
||||
} |
||||
v8.release(); |
||||
return true; |
||||
} |
||||
|
||||
public static ScriptClient auto() { |
||||
if (SUPPORT_J2V8) { |
||||
return new V8Client(); |
||||
} else { |
||||
return new NashornClient(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.fr.plugin.db.es.fun.category.script.client; |
||||
|
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.macro.EncodeConstants; |
||||
import com.fanruan.api.util.IOKit; |
||||
import com.fr.plugin.db.es.fun.category.script.ScriptBridge; |
||||
|
||||
import javax.script.ScriptEngine; |
||||
import java.io.InputStream; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
public class NashornFiles { |
||||
|
||||
private ScriptEngine scriptEngine; |
||||
|
||||
public NashornFiles(ScriptEngine scriptEngine) { |
||||
this.scriptEngine = scriptEngine; |
||||
} |
||||
|
||||
@ScriptBridge |
||||
public void require(String filePath) { |
||||
InputStream in = IOKit.readResource(filePath); |
||||
if (in != null) { |
||||
try { |
||||
String text = IOKit.inputStream2String(in, EncodeConstants.ENCODING_UTF_8); |
||||
scriptEngine.eval(text); |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.db.es.fun.category.script.client; |
||||
|
||||
|
||||
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
public interface ScriptClient { |
||||
|
||||
SimpleDataModel build(String text, String query, int limit); |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.plugin.db.es.fun.category.script.client; |
||||
|
||||
|
||||
import com.eclipsesource.v8.V8; |
||||
import com.fanruan.api.macro.EncodeConstants; |
||||
import com.fanruan.api.util.IOKit; |
||||
import com.fr.plugin.db.es.fun.category.script.ScriptBridge; |
||||
|
||||
import java.io.InputStream; |
||||
import java.io.UnsupportedEncodingException; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
public class V8Files { |
||||
|
||||
private V8 v8; |
||||
|
||||
public V8Files(V8 v8) { |
||||
this.v8 = v8; |
||||
} |
||||
|
||||
@ScriptBridge |
||||
public void require(String filePath) { |
||||
InputStream in = IOKit.readResource(filePath); |
||||
if (in != null) { |
||||
try { |
||||
v8.executeVoidScript(IOKit.inputStream2String(in, EncodeConstants.ENCODING_UTF_8)); |
||||
} catch (UnsupportedEncodingException ignore) { |
||||
|
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.fr.plugin.db.es.fun.category.script.client.impl; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; |
||||
import com.fr.plugin.db.es.fun.category.script.client.NashornFiles; |
||||
import com.fr.plugin.db.es.fun.category.script.client.ScriptClient; |
||||
import com.fr.plugin.db.es.fun.help.Console; |
||||
|
||||
import javax.script.ScriptEngine; |
||||
import javax.script.ScriptEngineFactory; |
||||
import javax.script.ScriptEngineManager; |
||||
import javax.script.ScriptException; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
public class NashornClient implements ScriptClient { |
||||
|
||||
private static final String PREPARE_SCRIPT = |
||||
"function unique(array) {var res = [];for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {for (var j = 0, resLen = res.length; j < resLen; j++ ) {if (array[i] === res[j]) {break;}} if (j === resLen) {res.push(array[i])}} return res;}\n" + |
||||
"function merge(table, column) {return {content:table, column:column}};"; |
||||
|
||||
private ScriptEngine scriptEngine; |
||||
|
||||
public NashornClient() { |
||||
this.scriptEngine = findScriptEngine(); |
||||
} |
||||
|
||||
@Override |
||||
public SimpleDataModel build(String text, String query, int limit) { |
||||
scriptEngine.put("console", new Console()); |
||||
scriptEngine.put("Files", new NashornFiles(scriptEngine)); |
||||
try { |
||||
scriptEngine.eval(PREPARE_SCRIPT); |
||||
Map<String, Map<String, Object>> r = (Map<String, Map<String, Object>>) scriptEngine.eval(String.format( |
||||
"(function($){var $data = $; %s})(%s);", query, text)); |
||||
|
||||
Map<String, Object> columns = r.get("column"); |
||||
int columnCount = columns.size(); |
||||
String[] columnNames = new String[columnCount]; |
||||
int k = 0; |
||||
for (Map.Entry<String, Object> entry : columns.entrySet()) { |
||||
columnNames[k] = String.valueOf(entry.getValue()); |
||||
k++; |
||||
} |
||||
|
||||
Map<String, Object> content = r.get("content"); |
||||
int returnRowCount = content.size(); |
||||
int realCount = limit == TableData.RESULT_ALL ? returnRowCount : Math.min(returnRowCount, limit); |
||||
|
||||
List<List<Object>> data = new ArrayList<List<Object>>(); |
||||
int i = 0; |
||||
for (Map.Entry<String, Object> entry : content.entrySet()) { |
||||
if (i >= realCount) { |
||||
break; |
||||
} |
||||
List<Object> row = new ArrayList<Object>(); |
||||
|
||||
Object el = entry.getValue(); |
||||
if (el instanceof Map) { |
||||
Map<String, Object> rowCollection = (Map<String, Object>) entry.getValue(); |
||||
for (Map.Entry<String, Object> rowEntry : rowCollection.entrySet()) { |
||||
row.add(rowEntry.getValue()); |
||||
} |
||||
} else if (el instanceof Object[]) { |
||||
Object[] array = (Object[]) el; |
||||
row.addAll(Arrays.asList(array)); |
||||
} |
||||
|
||||
data.add(row); |
||||
i++; |
||||
} |
||||
return new SimpleDataModel(columnNames, data, realCount); |
||||
} catch (ScriptException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private static ScriptEngine findScriptEngine() { |
||||
ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); |
||||
ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn"); |
||||
if (engine == null) { |
||||
List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories(); |
||||
for (ScriptEngineFactory factory : factories) { |
||||
ScriptEngine current = factory.getScriptEngine(); |
||||
if (current != null) { |
||||
engine = current; |
||||
} |
||||
} |
||||
} |
||||
return engine; |
||||
} |
||||
} |
@ -0,0 +1,82 @@
|
||||
package com.fr.plugin.db.es.fun.category.script.client.impl; |
||||
|
||||
import com.eclipsesource.v8.V8; |
||||
import com.eclipsesource.v8.V8Array; |
||||
import com.eclipsesource.v8.V8Object; |
||||
import com.fr.base.TableData; |
||||
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; |
||||
import com.fr.plugin.db.es.fun.category.script.client.ScriptClient; |
||||
import com.fr.plugin.db.es.fun.category.script.client.V8Files; |
||||
import com.fr.plugin.db.es.fun.help.Console; |
||||
import com.fr.plugin.db.es.fun.help.RegisterUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/30 |
||||
*/ |
||||
public class V8Client implements ScriptClient { |
||||
|
||||
private V8 v8; |
||||
|
||||
public V8Client() { |
||||
this.v8 = V8.createV8Runtime(); |
||||
} |
||||
|
||||
@Override |
||||
public SimpleDataModel build(String text, String query, int limit) { |
||||
V8Object v8Console = initConsole(v8); |
||||
V8Object v8Require = initRequire(v8); |
||||
v8.executeVoidScript( |
||||
"function unique(array) {return Array.from(new Set(array));};" + |
||||
"function merge(table, column) {return {content:table, column:column}};"); |
||||
V8Object returnObj = v8.executeObjectScript(String.format( |
||||
"(function($){var $data = $; %s})(%s);", query, text)); |
||||
|
||||
V8Array v8Column = returnObj.getArray("column"); |
||||
V8Array v8Table = returnObj.getArray("content"); |
||||
int columnCount = v8Column.length(); |
||||
String[] columnNames = new String[columnCount]; |
||||
for (int i = 0; i < columnCount; i++) { |
||||
columnNames[i] = String.valueOf(v8Column.get(i)); |
||||
} |
||||
int returnRowCount = v8Table.length(); |
||||
int realCount = limit == TableData.RESULT_ALL ? returnRowCount : Math.min(returnRowCount, limit); |
||||
List<List<Object>> data = new ArrayList<List<Object>>(); |
||||
for (int i = 0; i < realCount; i++) { |
||||
V8Array v8Row = v8Table.getArray(i); |
||||
List<Object> row = new ArrayList<Object>(); |
||||
for (int j = 0, col = v8Row.length(); j < col; j++) { |
||||
row.add(v8Row.get(j)); |
||||
} |
||||
v8Row.release(); |
||||
data.add(row); |
||||
} |
||||
v8Require.release(); |
||||
v8Console.release(); |
||||
v8Table.release(); |
||||
v8Column.release(); |
||||
returnObj.release(); |
||||
v8.release(true); |
||||
return new SimpleDataModel(columnNames, data, realCount); |
||||
} |
||||
|
||||
private V8Object initConsole(V8 v8) { |
||||
V8Object v8Console = new V8Object(v8); |
||||
v8.add("console", v8Console); |
||||
Console console = new Console(); |
||||
RegisterUtils.registerJavaMethods(v8Console, console); |
||||
return v8Console; |
||||
} |
||||
|
||||
private V8Object initRequire(V8 v8) { |
||||
V8Object v8Files = new V8Object(v8); |
||||
v8.add("Files", v8Files); |
||||
V8Files files = new V8Files(v8); |
||||
RegisterUtils.registerJavaMethods(v8Files, files); |
||||
return v8Files; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.plugin.db.es.fun.help; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.plugin.db.es.fun.category.script.ScriptBridge; |
||||
import com.fr.plugin.db.es.fun.category.script.ScriptClientSelector; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class Console { |
||||
|
||||
@ScriptBridge |
||||
public void log(Object message) { |
||||
LogKit.info(message == null ? null : message.toString()); |
||||
} |
||||
|
||||
@ScriptBridge |
||||
public void error(Object message) { |
||||
LogKit.error(message == null ? null : message.toString()); |
||||
} |
||||
|
||||
@ScriptBridge |
||||
public String engine() { |
||||
return ScriptClientSelector.isSupportJ2v8() ? "V8" : "Nashorn"; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.fr.plugin.db.es.fun.help; |
||||
|
||||
import com.fanruan.api.util.ArrayKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import org.apache.http.HttpHost; |
||||
import org.apache.http.auth.AuthScope; |
||||
import org.apache.http.auth.UsernamePasswordCredentials; |
||||
import org.apache.http.client.CredentialsProvider; |
||||
import org.apache.http.impl.client.BasicCredentialsProvider; |
||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; |
||||
import org.elasticsearch.client.RestClient; |
||||
import org.elasticsearch.client.RestClientBuilder; |
||||
import org.elasticsearch.client.RestHighLevelClient; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/31 |
||||
*/ |
||||
public class ElasticsearchClientFactory { |
||||
|
||||
public static RestHighLevelClient buildHighLevelClient(String[] hosts, Integer[] ports, String username, String password) { |
||||
return new RestHighLevelClient(build(hosts, ports, username, password)); |
||||
} |
||||
|
||||
public static RestClient buildClient(String[] hosts, Integer[] ports, String username, String password) { |
||||
return build(hosts, ports, username, password).build(); |
||||
} |
||||
|
||||
private static RestClientBuilder build(String[] hosts, Integer[] ports, String username, String password) { |
||||
int hostCount = ArrayKit.getLength(hosts); |
||||
int portCount = ArrayKit.getLength(ports); |
||||
if (portCount != hostCount) { |
||||
throw new IllegalArgumentException("Hosts and ports must be matched!"); |
||||
} |
||||
HttpHost[] httpHosts = new HttpHost[hostCount]; |
||||
for (int i = 0; i < hostCount; i++) { |
||||
httpHosts[i] = new HttpHost(hosts[i], ports[i], "http"); |
||||
} |
||||
RestClientBuilder builder = RestClient.builder(httpHosts); |
||||
if (StringKit.isNotEmpty(username)) { |
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
||||
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); |
||||
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() { |
||||
@Override |
||||
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) { |
||||
return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider); |
||||
} |
||||
}); |
||||
} |
||||
return builder; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.db.es.fun.help; |
||||
|
||||
import com.eclipsesource.v8.V8Object; |
||||
import com.fr.plugin.db.es.fun.category.script.ScriptBridge; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class RegisterUtils { |
||||
|
||||
public static void registerJavaMethods(V8Object v8Object, Object target) { |
||||
Method[] methods = target.getClass().getMethods(); |
||||
for (Method m : methods) { |
||||
if (m.getAnnotation(ScriptBridge.class) != null) { |
||||
v8Object.registerJavaMethod(target, m.getName(), m.getName(), m.getParameterTypes()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,33 @@
|
||||
package com.fr.plugin.db.es.fun.help; |
||||
|
||||
import com.fanruan.api.util.RenderKit; |
||||
import com.fr.base.Parameter; |
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.ParameterProvider; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/31 |
||||
*/ |
||||
public class RenderUtils { |
||||
|
||||
public static String calculateQuery(String query, ParameterProvider[] ps) { |
||||
if (ArrayUtils.isEmpty(ps)) { |
||||
return query; |
||||
} |
||||
Map<String, Object> map = new HashMap<>(); |
||||
for (ParameterProvider p : ps) { |
||||
map.put(p.getName(), p.getValue()); |
||||
} |
||||
try { |
||||
return RenderKit.renderParameter4Tpl(query, map); |
||||
} catch (Exception e) { |
||||
return query; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.fr.plugin.db.es.fun.type; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/12/31 |
||||
*/ |
||||
public enum ConverterType { |
||||
JSON(0), JS(1); |
||||
|
||||
private int i; |
||||
|
||||
ConverterType(int i) { |
||||
this.i = i; |
||||
} |
||||
|
||||
public int toInt() { |
||||
return i; |
||||
} |
||||
|
||||
public static ConverterType parse(int i) { |
||||
for (ConverterType type : values()) { |
||||
if (i == type.i) { |
||||
return type; |
||||
} |
||||
} |
||||
return JSON; |
||||
} |
||||
} |
@ -0,0 +1,141 @@
|
||||
package com.fr.plugin.db.es.ui; |
||||
|
||||
import com.fanruan.api.data.ConnectionKit; |
||||
import com.fanruan.api.design.macro.UIConstants; |
||||
import com.fanruan.api.design.ui.component.UIButton; |
||||
import com.fanruan.api.design.ui.component.UIDictionaryComboBox; |
||||
import com.fanruan.api.design.ui.component.UIPlaceholderTextField; |
||||
import com.fanruan.api.design.ui.component.UIRoundedBorder; |
||||
import com.fanruan.api.design.ui.component.code.SyntaxConstants; |
||||
import com.fanruan.api.design.ui.component.code.UISyntaxTextArea; |
||||
import com.fanruan.api.design.ui.component.code.UISyntaxTextScrollPane; |
||||
import com.fanruan.api.design.util.GUICoreKit; |
||||
import com.fanruan.api.design.work.ConnectionComboBoxPanel; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.ArrayKit; |
||||
import com.fanruan.api.util.IOKit; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.plugin.db.es.fun.ElasticsearchConnection; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class ElasticsearchConnectionChosePane extends BasicPane { |
||||
|
||||
private ConnectionComboBoxPanel connectionComboBoxPanel; |
||||
private UIDictionaryComboBox<String> typeComboBox; |
||||
private UIPlaceholderTextField queryAllTextField; |
||||
private UISyntaxTextArea consoleTextPane; |
||||
private UISyntaxTextArea outputTextPane; |
||||
|
||||
public ElasticsearchConnectionChosePane() { |
||||
setLayout(new BorderLayout(4, 4)); |
||||
connectionComboBoxPanel = new ConnectionComboBoxPanel(Connection.class) { |
||||
|
||||
protected void filterConnection(Connection connection, String conName, List<String> nameList) { |
||||
connection.addConnection(nameList, conName, new Class[]{ElasticsearchConnection.class}); |
||||
} |
||||
}; |
||||
|
||||
add(connectionComboBoxPanel, BorderLayout.NORTH); |
||||
connectionComboBoxPanel.addComboBoxActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
|
||||
} |
||||
}); |
||||
JPanel centerPane = new JPanel(new BorderLayout()); |
||||
add(centerPane, BorderLayout.CENTER); |
||||
|
||||
typeComboBox = new UIDictionaryComboBox<>(new String[]{ |
||||
"GET", "POST", "PUT" |
||||
}, new String[]{ |
||||
"GET", "POST", "PUT" |
||||
}); |
||||
typeComboBox.setSelectedItem("GET"); |
||||
queryAllTextField = new UIPlaceholderTextField(); |
||||
queryAllTextField.setText("/_search?pretty=true"); |
||||
UIButton execButton = new UIButton(IOKit.readIcon("/com/fr/plugin/db/es/images/run.png")); |
||||
execButton.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
run(); |
||||
} |
||||
}); |
||||
centerPane.add(GUICoreKit.createBorderLayoutPane( |
||||
typeComboBox, BorderLayout.WEST, |
||||
queryAllTextField, BorderLayout.CENTER, |
||||
execButton, BorderLayout.EAST |
||||
), BorderLayout.NORTH); |
||||
GridLayout gridLayout = new GridLayout(2, 1); |
||||
JPanel interactivePane = new JPanel(gridLayout); |
||||
centerPane.add(interactivePane, BorderLayout.CENTER); |
||||
|
||||
consoleTextPane = new UISyntaxTextArea(); |
||||
consoleTextPane.setEditable(false); |
||||
consoleTextPane.setText("{\n" + |
||||
" \"query\": {\n" + |
||||
" \"match_all\": {}\n" + |
||||
" }\n" + |
||||
"}"); |
||||
interactivePane.add(createShowTextPane(consoleTextPane)); |
||||
outputTextPane = new UISyntaxTextArea(); |
||||
interactivePane.add(createShowTextPane(outputTextPane)); |
||||
} |
||||
|
||||
private void run() { |
||||
String connectionName = getSelectConnectionName(); |
||||
final ElasticsearchConnection connection = ConnectionKit.getConnection(connectionName, ElasticsearchConnection.class); |
||||
if (connection != null) { |
||||
new SwingWorker<String, Void>() { |
||||
@Override |
||||
protected String doInBackground() { |
||||
String[] array = connection.summary(typeComboBox.getSelectedItem(), queryAllTextField.getText(), consoleTextPane.getText()); |
||||
return ArrayKit.isEmpty(array) ? null : array[0]; |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
try { |
||||
String text = get(); |
||||
outputTextPane.setText(text); |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
}.execute(); |
||||
} |
||||
} |
||||
|
||||
private UISyntaxTextScrollPane createShowTextPane(UISyntaxTextArea consoleTextPane) { |
||||
consoleTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); |
||||
UISyntaxTextScrollPane sqlTextScrollPane = new UISyntaxTextScrollPane(consoleTextPane); |
||||
sqlTextScrollPane.setLineNumbersEnabled(false); |
||||
sqlTextScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); |
||||
sqlTextScrollPane.setPreferredSize(new Dimension(300, 120)); |
||||
return sqlTextScrollPane; |
||||
} |
||||
|
||||
|
||||
public String getSelectConnectionName() { |
||||
return connectionComboBoxPanel.getSelectedItem(); |
||||
} |
||||
|
||||
public void populateConnection(Connection connection) { |
||||
connectionComboBoxPanel.populate(connection); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Choose"; |
||||
} |
||||
} |
@ -0,0 +1,149 @@
|
||||
package com.fr.plugin.db.es.ui; |
||||
|
||||
import com.fanruan.api.design.DesignKit; |
||||
import com.fanruan.api.design.macro.UIConstants; |
||||
import com.fanruan.api.design.ui.component.UIDictionaryComboBox; |
||||
import com.fanruan.api.design.ui.component.UILabel; |
||||
import com.fanruan.api.design.ui.component.UIRoundedBorder; |
||||
import com.fanruan.api.design.ui.component.UITextField; |
||||
import com.fanruan.api.design.ui.component.code.SyntaxConstants; |
||||
import com.fanruan.api.design.ui.component.code.UISyntaxTextArea; |
||||
import com.fanruan.api.design.ui.component.code.UISyntaxTextScrollPane; |
||||
import com.fanruan.api.design.ui.layout.TableLayoutKit; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.plugin.db.es.fun.ConfigAttribute; |
||||
import com.fr.plugin.db.es.fun.type.ConverterType; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2020/1/2 |
||||
*/ |
||||
public class ElasticsearchQueryPane extends BasicPane { |
||||
|
||||
private UITextField endPointTextField; |
||||
private UIDictionaryComboBox<ConverterType> converterTypeComboBox; |
||||
private UISyntaxTextArea queryTextPane; |
||||
private UISyntaxTextArea scriptTextPane; |
||||
private UIDictionaryComboBox<Boolean> sortedComboBox; |
||||
private UIDictionaryComboBox<Boolean> prepareComboBox; |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "JSON Query"; |
||||
} |
||||
|
||||
public ElasticsearchQueryPane() { |
||||
setLayout(new BorderLayout()); |
||||
|
||||
double p = TableLayoutKit.PREFERRED; |
||||
double f = TableLayoutKit.FILL; |
||||
|
||||
double[] rowSize = {p, p, p, p, p, p}; |
||||
double[] columnSize = {p, f}; |
||||
|
||||
endPointTextField = new UITextField(); |
||||
|
||||
queryTextPane = new UISyntaxTextArea(); |
||||
|
||||
converterTypeComboBox = new UIDictionaryComboBox<>(new ConverterType[]{ |
||||
ConverterType.JSON, |
||||
ConverterType.JS |
||||
}, new String[]{ |
||||
DesignKit.i18nText("Plugin-Elasticsearch_Auto"), |
||||
DesignKit.i18nText("Plugin-Elasticsearch_Program") |
||||
}); |
||||
converterTypeComboBox.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
checkEnabled(); |
||||
} |
||||
}); |
||||
|
||||
scriptTextPane = new UISyntaxTextArea(); |
||||
|
||||
sortedComboBox = new UIDictionaryComboBox<>( |
||||
new Boolean[]{false, true}, |
||||
new String[]{DesignKit.i18nText("Plugin-Elasticsearch_Sort_Default"), com.fr.design.i18n.Toolkit.i18nText("Plugin-JSON_Sort_Open")}); |
||||
prepareComboBox = new UIDictionaryComboBox<>( |
||||
new Boolean[]{false, true}, |
||||
new String[]{DesignKit.i18nText("Plugin-Elasticsearch_Prepare_Keys_Default"), com.fr.design.i18n.Toolkit.i18nText("Plugin-JSON_Prepare_Keys_Open")} |
||||
); |
||||
Component[][] coms = new Component[][]{ |
||||
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Endpoint") + ":"), endPointTextField}, |
||||
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Query") + ":"), createConditionTextPane(queryTextPane)}, |
||||
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Type")+ ":"), converterTypeComboBox}, |
||||
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Script")+ ":"), createConditionTextPane(scriptTextPane)}, |
||||
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Sort_Key") + ":"), sortedComboBox}, |
||||
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Key_Prepare") + ":"), prepareComboBox} |
||||
}; |
||||
JPanel panel = TableLayoutKit.createTableLayoutPane(coms, rowSize, columnSize); |
||||
add(panel, BorderLayout.CENTER); |
||||
} |
||||
|
||||
private UISyntaxTextScrollPane createConditionTextPane(UISyntaxTextArea sqlTextPane) { |
||||
sqlTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); |
||||
UISyntaxTextScrollPane sqlTextScrollPane = new UISyntaxTextScrollPane(sqlTextPane); |
||||
sqlTextScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); |
||||
sqlTextScrollPane.setPreferredSize(new Dimension(680, 120)); |
||||
return sqlTextScrollPane; |
||||
} |
||||
|
||||
private void checkEnabled() { |
||||
ConverterType converterType = getConverterType(); |
||||
sortedComboBox.setEnabled(converterType == ConverterType.JSON); |
||||
prepareComboBox.setEnabled(converterType == ConverterType.JSON); |
||||
} |
||||
|
||||
public String getEndPoint() { |
||||
return endPointTextField.getText(); |
||||
} |
||||
|
||||
public void setEndPoint(String endPoint) { |
||||
endPointTextField.setText(endPoint); |
||||
} |
||||
|
||||
public ConverterType getConverterType() { |
||||
return converterTypeComboBox.getSelectedItem(); |
||||
} |
||||
|
||||
public void setConverterTypeComboBox(ConverterType converterType) { |
||||
converterTypeComboBox.setSelectedItem(converterType); |
||||
} |
||||
|
||||
public String getQuery() { |
||||
return queryTextPane.getText(); |
||||
} |
||||
|
||||
public void setQuery(String query) { |
||||
queryTextPane.setText(query); |
||||
} |
||||
|
||||
public String getScript() { |
||||
return scriptTextPane.getText(); |
||||
} |
||||
|
||||
public void setScript(String script) { |
||||
scriptTextPane.setText(script); |
||||
} |
||||
|
||||
public ConfigAttribute getConfigAttr() { |
||||
ConfigAttribute attr = new ConfigAttribute(); |
||||
attr.setSorted(sortedComboBox.getSelectedItem()); |
||||
attr.setPrepare(prepareComboBox.getSelectedItem()); |
||||
return attr; |
||||
} |
||||
|
||||
public void setConfigAttr(ConfigAttribute attr) { |
||||
if (attr == null) { |
||||
return; |
||||
} |
||||
sortedComboBox.setSelectedItem(attr.isSorted()); |
||||
prepareComboBox.setSelectedItem(attr.isPrepare()); |
||||
} |
||||
} |
After Width: | Height: | Size: 817 B |
After Width: | Height: | Size: 361 B |
After Width: | Height: | Size: 345 B |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue