forked from hugh/demo-connection-provider
hugh
4 years ago
19 changed files with 818 additions and 1 deletions
@ -1,3 +1,7 @@
|
||||
# demo-connection-provider |
||||
|
||||
创建数据源连接的demo |
||||
创建数据源连接的demo\ |
||||
demo生效后在设计器/决策平台的数据源管理页面会增加一个名为Demo Conn的数据源类型。\ |
||||
添加后设置一个key值,注:只有key1 key2 key3这三个key值可以链接成功。\ |
||||
添加完数据源连接,在模板数据集【注意不是服务器数据集】处可添加Demo Conn Data数据集\ |
||||
可以选择对应的数据源后预览得到对应的数据结果。 |
@ -0,0 +1,124 @@
|
||||
|
||||
apply plugin: 'java' |
||||
|
||||
[compileJava,compileTestJava]*.options*.encoding = 'UTF-8' |
||||
|
||||
ext { |
||||
/** |
||||
* 项目中依赖的jar的路径 |
||||
* 1.如果依赖的jar需要打包到zip中,放置在lib根目录下 |
||||
* 2.如果依赖的jar仅仅是编译时需要,防止在lib下子目录下即可 |
||||
*/ |
||||
libPath = "$projectDir/../webroot/WEB-INF/lib" |
||||
|
||||
/** |
||||
* 是否对插件的class进行加密保护,防止反编译 |
||||
*/ |
||||
guard = false |
||||
|
||||
def pluginInfo = getPluginInfo() |
||||
pluginPre = "fine-plugin" |
||||
pluginName = pluginInfo.id |
||||
pluginVersion = pluginInfo.version |
||||
|
||||
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes" |
||||
} |
||||
|
||||
group = 'com.fr.plugin' |
||||
version = '10.0' |
||||
sourceCompatibility = '8' |
||||
|
||||
sourceSets { |
||||
main { |
||||
java.outputDir = file(outputPath) |
||||
output.resourcesDir = file(outputPath) |
||||
} |
||||
} |
||||
|
||||
ant.importBuild("encrypt.xml") |
||||
//定义ant变量 |
||||
ant.projectDir = projectDir |
||||
ant.references["compile.classpath"] = ant.path { |
||||
fileset(dir: libPath, includes: '**/*.jar') |
||||
fileset(dir: ".",includes:"**/*.jar" ) |
||||
} |
||||
|
||||
classes.dependsOn('clean') |
||||
|
||||
task copyFiles(type: Copy,dependsOn: 'classes'){ |
||||
from outputPath |
||||
into "$projectDir/classes" |
||||
} |
||||
|
||||
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){ |
||||
from "$projectDir/classes" |
||||
into "$projectDir/transform-classes" |
||||
include "**/*.*" |
||||
} |
||||
jar.dependsOn("preJar") |
||||
|
||||
task makeJar(type: Jar,dependsOn: preJar){ |
||||
from fileTree(dir: "$projectDir/transform-classes") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
destinationDir = file("$buildDir/libs") |
||||
|
||||
doLast(){ |
||||
delete file("$projectDir/classes") |
||||
delete file("$projectDir/transform-classes") |
||||
} |
||||
} |
||||
|
||||
task copyFile(type: Copy,dependsOn: ["makeJar"]){ |
||||
from "$buildDir/libs" |
||||
from("$projectDir/lib") { |
||||
include "*.jar" |
||||
} |
||||
from "$projectDir/plugin.xml" |
||||
into file("$buildDir/temp/plugin") |
||||
} |
||||
|
||||
task zip(type:Zip,dependsOn:["copyFile"]){ |
||||
from "$buildDir/temp/plugin" |
||||
destinationDir file("$buildDir/install") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
} |
||||
|
||||
//控制build时包含哪些文件,排除哪些文件 |
||||
processResources { |
||||
// exclude everything |
||||
// 用*.css没效果 |
||||
// exclude '**/*.css' |
||||
// except this file |
||||
// include 'xx.xml' |
||||
} |
||||
|
||||
/*读取plugin.xml中的version*/ |
||||
def getPluginInfo(){ |
||||
def xmlFile = file("plugin.xml") |
||||
if (!xmlFile.exists()) { |
||||
return ["id":"none", "version":"1.0.0"] |
||||
} |
||||
def plugin = new XmlParser().parse(xmlFile) |
||||
def version = plugin.version[0].text() |
||||
def id = plugin.id[0].text() |
||||
return ["id":id,"version":version] |
||||
} |
||||
|
||||
repositories { |
||||
mavenLocal() |
||||
maven { |
||||
url = uri('http://mvn.finedevelop.com/repository/maven-public/') |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
//使用本地jar |
||||
implementation fileTree(dir: 'lib', include: ['**/*.jar']) |
||||
implementation fileTree(dir: libPath, include: ['**/*.jar']) |
||||
} |
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<project> |
||||
<target name="compile_encrypt_javas" depends="copyFiles"> |
||||
<echo message="加密文件"/> |
||||
<echo message="${projectDir}"/> |
||||
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||
<classpath refid="compile.classpath"/> |
||||
</taskdef> |
||||
<pretreatment baseDir="${projectDir}"/> |
||||
</target> |
||||
<target name="compile_plain_javas" depends="copyFiles"> |
||||
</target> |
||||
</project> |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.tptj.demo.hg.connection.v10</id> |
||||
<name><![CDATA[ connection demo ]]></name> |
||||
<active>yes</active> |
||||
<version>1.0</version> |
||||
<env-version>10.0</env-version> |
||||
<vendor>tptj</vendor> |
||||
<jartime>2019-07-18</jartime> |
||||
<description><![CDATA[ ]]></description> |
||||
<change-notes><![CDATA[]]></change-notes> |
||||
<main-package>com.tptj.demo.hg.connection</main-package> |
||||
<function-recorder class="com.tptj.demo.hg.connection.data.DemoData"/> |
||||
<extra-designer> |
||||
<ConnectionProvider class="com.tptj.demo.hg.connection.Demo"/> |
||||
<TableDataDefineProvider class="com.tptj.demo.hg.connection.DemoTableDataDefine"/> |
||||
</extra-designer> |
||||
<extra-decision> |
||||
<UniversalConnectionProvider class="com.tptj.demo.hg.connection.decision.Demo"/> |
||||
</extra-decision> |
||||
</plugin> |
@ -0,0 +1,34 @@
|
||||
package com.tptj.demo.hg.connection; |
||||
|
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.fun.impl.AbstractConnectionProvider; |
||||
import com.tptj.demo.hg.connection.conn.DemoConnection; |
||||
import com.tptj.demo.hg.connection.conn.DemoConnectionPane; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class Demo extends AbstractConnectionProvider { |
||||
@Override |
||||
public String nameForConnection() { |
||||
return "Demo Conn"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForConnection() { |
||||
return "com/tptj/demo/hg/connection/images/icon.png"; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends Connection> classForConnection() { |
||||
return DemoConnection.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BasicBeanPane<? extends Connection>> appearanceForConnection() { |
||||
return DemoConnectionPane.class; |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.tptj.demo.hg.connection; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||
import com.fr.design.fun.impl.AbstractTableDataDefineProvider; |
||||
import com.tptj.demo.hg.connection.data.DemoData; |
||||
import com.tptj.demo.hg.connection.data.DemoDataPane; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class DemoTableDataDefine extends AbstractTableDataDefineProvider { |
||||
@Override |
||||
public Class<? extends TableData> classForTableData() { |
||||
return DemoData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForInitTableData() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends AbstractTableDataPane> appearanceForTableData() { |
||||
return DemoDataPane.class; |
||||
} |
||||
|
||||
@Override |
||||
public String nameForTableData() { |
||||
return "Demo Conn Data"; |
||||
} |
||||
|
||||
@Override |
||||
public String prefixForTableData() { |
||||
return "dcd"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForTableData() { |
||||
return "com/tptj/demo/hg/connection/images/icon.png"; |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
package com.tptj.demo.hg.connection.conn; |
||||
|
||||
import com.fanruan.api.conf.HolderKit; |
||||
import com.fanruan.api.data.open.BaseConnection; |
||||
import com.fanruan.api.i18n.I18nKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
import com.fr.third.ibm.icu.impl.Assert; |
||||
import com.tptj.demo.hg.connection.store.Store; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class DemoConnection extends BaseConnection { |
||||
|
||||
private Conf<String> key = HolderKit.simple(StringKit.EMPTY); |
||||
|
||||
public String getKey() { |
||||
return key.get(); |
||||
} |
||||
|
||||
public void setKey(String key) { |
||||
this.key.set(key); |
||||
} |
||||
|
||||
@Override |
||||
public void testConnection() throws Exception { |
||||
Assert.assrt( Store.getInstance().contains(getKey()) ); |
||||
} |
||||
|
||||
@Override |
||||
public String connectMessage(boolean status) { |
||||
return I18nKit.getLocText(status?"Fine-Core_Datasource_Connection_Successfully":"Fine-Design_Database_Connection_Failed"); |
||||
} |
||||
|
||||
@Override |
||||
public String getDriver() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
super.readXML(reader); |
||||
if (reader.isChildNode()) { |
||||
String tagName = reader.getTagName(); |
||||
if ("Attr".equals(tagName)) { |
||||
setKey(reader.getAttrAsString("key", StringKit.EMPTY)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
super.writeXML(writer); |
||||
writer.startTAG("Attr").attr("key", getKey()).end(); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
DemoConnection cloned = (DemoConnection) super.clone(); |
||||
cloned.key = (Conf<String>) key.clone(); |
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.tptj.demo.hg.connection.conn; |
||||
|
||||
import com.fanruan.api.design.ui.component.UITextField; |
||||
import com.fanruan.api.design.work.DatabaseConnectionPane; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class DemoConnectionPane extends DatabaseConnectionPane<DemoConnection> { |
||||
//hugh:因为mainPanel是在父类的构造中先调用的,所以我们定义的控件一定不要在这里赋值!切记
|
||||
private UITextField w_key; |
||||
|
||||
@Override |
||||
protected JPanel mainPanel() { |
||||
JPanel pane = new JPanel(); |
||||
w_key = new UITextField(); |
||||
pane.setLayout( new BorderLayout(4,4) ); |
||||
pane.add(w_key,BorderLayout.NORTH); |
||||
return pane; |
||||
} |
||||
|
||||
@Override |
||||
protected void populateSubDatabaseConnectionBean( DemoConnection conn ) { |
||||
if( null != conn ){ |
||||
w_key.setText(conn.getKey()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected DemoConnection updateSubDatabaseConnectionBean() { |
||||
DemoConnection conn = new DemoConnection(); |
||||
conn.setKey( w_key.getText() ); |
||||
return conn; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Demo Conn"; |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
package com.tptj.demo.hg.connection.data; |
||||
|
||||
import com.fanruan.api.conf.HolderKit; |
||||
import com.fanruan.api.data.ConnectionKit; |
||||
import com.fanruan.api.data.open.BaseTableData; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
import com.tptj.demo.hg.connection.conn.DemoConnection; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
@EnableMetrics |
||||
public class DemoData extends BaseTableData { |
||||
private Conf<String> database = HolderKit.simple(StringKit.EMPTY); |
||||
|
||||
public String getDatabase() { |
||||
return database.get(); |
||||
} |
||||
|
||||
public void setDatabase( String database) { |
||||
this.database.set(database); |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = "com.tptj.demo.hg.connection.v10",text = "connection demo") |
||||
public DataModel createDataModel(Calculator calculator) { |
||||
DemoConnection conn = ConnectionKit.getConnection(getDatabase(),DemoConnection.class); |
||||
try { |
||||
conn.testConnection(); |
||||
}catch (Exception e){ |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
return DataModel.EMPTY_DATAMODEL; |
||||
} |
||||
return new DemoModel(conn); |
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
super.readXML(reader); |
||||
if (reader.isChildNode()) { |
||||
String tagName = reader.getTagName(); |
||||
if ("Attr".equals(tagName)) { |
||||
setDatabase(reader.getAttrAsString("source", StringKit.EMPTY)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
super.writeXML(writer); |
||||
writer.startTAG("Attr").attr("source", getDatabase()).end(); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
DemoData cloned = (DemoData) super.clone(); |
||||
cloned.database = (Conf<String>) database.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
package com.tptj.demo.hg.connection.data; |
||||
|
||||
import com.fanruan.api.design.work.BaseTableDataPane; |
||||
import com.fanruan.api.design.work.ConnectionComboBoxPanel; |
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.data.datapane.preview.PreviewTablePane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.tptj.demo.hg.connection.conn.DemoConnection; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class DemoDataPane extends BaseTableDataPane<DemoData> { |
||||
private ConnectionComboBoxPanel w_connections; |
||||
public DemoDataPane(){ |
||||
setLayout(new BorderLayout(4, 4)); |
||||
w_connections = new ConnectionComboBoxPanel(DemoConnection.class); |
||||
add(w_connections, BorderLayout.NORTH); |
||||
UIButton preview = new UIButton(BaseUtils.readIcon("/com/fr/design/images/m_file/preview.png")); |
||||
preview.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
SwingUtilities.invokeLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
PreviewTablePane.previewTableData(DemoDataPane.this.updateBean()); |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
add(TableLayoutHelper.createTableLayoutPane( |
||||
new Component[][] {{ |
||||
w_connections,preview |
||||
}}, |
||||
new double[] { TableLayout.PREFERRED }, |
||||
new double[] { TableLayout.FILL,TableLayout.PREFERRED } |
||||
),BorderLayout.NORTH); |
||||
} |
||||
@Override |
||||
public void populateBean(DemoData data) { |
||||
if( null != data ){ |
||||
w_connections.setSelectedItem( data.getDatabase() ); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public DemoData updateBean() { |
||||
DemoData data = new DemoData(); |
||||
data.setDatabase( w_connections.getSelectedItem() ); |
||||
return data; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Demo Conn Data"; |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.tptj.demo.hg.connection.data; |
||||
|
||||
import com.fanruan.api.data.open.BaseDataModel; |
||||
import com.fanruan.api.err.TableDataException; |
||||
import com.tptj.demo.hg.connection.store.Data; |
||||
import com.tptj.demo.hg.connection.conn.DemoConnection; |
||||
import com.tptj.demo.hg.connection.store.Store; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class DemoModel extends BaseDataModel { |
||||
private Data data = Data.EMPTY; |
||||
public DemoModel( DemoConnection conn ){ |
||||
data = Store.getInstance().get( conn.getKey() ); |
||||
} |
||||
@Override |
||||
public int getColumnCount() throws TableDataException { |
||||
return data.getKey().length; |
||||
} |
||||
|
||||
@Override |
||||
public String getColumnName(int cIdx) throws TableDataException { |
||||
return data.getKey()[cIdx]; |
||||
} |
||||
|
||||
@Override |
||||
public int getRowCount() throws TableDataException { |
||||
return data.getRow().length; |
||||
} |
||||
|
||||
@Override |
||||
public Object getValueAt(int rIdx, int cIdx) throws TableDataException { |
||||
return data.getRow()[rIdx][cIdx]; |
||||
} |
||||
|
||||
@Override |
||||
public void release() throws Exception { |
||||
data = Data.EMPTY; |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.tptj.demo.hg.connection.decision; |
||||
|
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.decision.fun.impl.AbstractUniversalConnectionProvider; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.web.struct.Atom; |
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.browser.RequestClient; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.tptj.demo.hg.connection.conn.DemoConnection; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class WebDemo extends AbstractUniversalConnectionProvider<DemoConnection> { |
||||
|
||||
@Override |
||||
public String nameForConnection() { |
||||
return "demo_con"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForConnection() { |
||||
return "/com/tptj/demo/hg/connection/images/icon.png"; |
||||
} |
||||
|
||||
@Override |
||||
public Class<DemoConnection> classForConnection() { |
||||
return DemoConnection.class; |
||||
} |
||||
|
||||
@Override |
||||
public Atom client() { |
||||
return new Component() { |
||||
@Override |
||||
public ScriptPath script(RequestClient client) { |
||||
return ScriptPath.build("com/tptj/demo/hg/connection/js/main.js"); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject serialize(DemoConnection connection) { |
||||
return JSONObject.create().put("key",connection.getKey()); |
||||
} |
||||
|
||||
@Override |
||||
public DemoConnection deserialize(DemoConnection old, JSONObject config ){ |
||||
DemoConnection conn = new DemoConnection(); |
||||
conn.setKey(config.optString("key", StringKit.EMPTY)); |
||||
if( null != old ){ |
||||
conn.setId( old.getId() ); |
||||
conn.setCreator( old.getCreator() ); |
||||
} |
||||
return conn; |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.tptj.demo.hg.connection.store; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
**/ |
||||
public class Data { |
||||
private String[] key = new String[0]; |
||||
private String[][] row = new String[0][0]; |
||||
public static final Data EMPTY = new Data(); |
||||
private Data(){} |
||||
public Data(String[] key, String[][] row) { |
||||
this.key = key; |
||||
this.row = row; |
||||
} |
||||
|
||||
public String[] getKey() { |
||||
return key; |
||||
} |
||||
|
||||
public void setKey(String[] key) { |
||||
this.key = key; |
||||
} |
||||
|
||||
public String[][] getRow() { |
||||
return row; |
||||
} |
||||
|
||||
public void setRow(String[][] row) { |
||||
this.row = row; |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.tptj.demo.hg.connection.store; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-31 |
||||
* 模拟数据源 |
||||
**/ |
||||
public class Store { |
||||
private Map<String, Data> store = new HashMap<String,Data>(3); |
||||
private static Store instance = null; |
||||
private Store(){ } |
||||
|
||||
public boolean contains(String key){ |
||||
return store.containsKey(key); |
||||
} |
||||
|
||||
public Data get(String key){ |
||||
return store.get(key); |
||||
} |
||||
|
||||
private void load(){ |
||||
store.put("key1",new Data(new String[]{"k1","k2","k3"}, |
||||
new String[][]{ |
||||
{"v11","v12","v13"}, |
||||
{"v21","v22","v23"}, |
||||
{"v31","v32","v33"} |
||||
} )); |
||||
store.put("key2",new Data(new String[]{"k4","k5"}, |
||||
new String[][]{ |
||||
{"n11","n12"}, |
||||
{"n21","n22"}, |
||||
{"n31","n32"} |
||||
} )); |
||||
store.put("key3",new Data(new String[]{"k6","k7","k3","k8"}, |
||||
new String[][]{ |
||||
{"x11","x12","x13","x14"}, |
||||
{"x21","x22","x23","x24"}, |
||||
{"x31","x32","x33","x34"} |
||||
} )); |
||||
} |
||||
|
||||
public static Store getInstance(){ |
||||
if( null == instance ){ |
||||
synchronized (Store.class){ |
||||
if( null == instance ){ |
||||
instance = new Store(); |
||||
instance.load(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
} |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 382 B |
@ -0,0 +1,133 @@
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-03-29 |
||||
**/ |
||||
!(function () { |
||||
|
||||
//编辑配置
|
||||
var createEditLine = function(label,value,ref,action){ |
||||
return { |
||||
type: 'bi.left', |
||||
items: [ |
||||
{ |
||||
type: 'bi.label', |
||||
cls: 'bi-font-bold', |
||||
width: 100, |
||||
textAlign: 'left', |
||||
text: label |
||||
}, |
||||
{ |
||||
type: 'bi.text_editor', |
||||
width: 300, |
||||
allowBlank: true, |
||||
ref: ref, |
||||
value:value, |
||||
listeners: [{ |
||||
eventName: BI.FormulaEditor.EVENT_CHANGE, |
||||
action: action |
||||
}] |
||||
} |
||||
] |
||||
}; |
||||
} |
||||
var DemoEditName = 'dec.dcm.connection.plugin.demo.edit'; |
||||
var DemoEdit = BI.inherit(BI.Widget, { |
||||
props: { |
||||
value:{ |
||||
key: '' |
||||
}, |
||||
connectionName:'' |
||||
}, |
||||
render() { |
||||
var self = this; |
||||
var o = this.options; |
||||
return { |
||||
type: 'bi.vertical', |
||||
hgap: 15, |
||||
vgap: 10, |
||||
items: [ |
||||
createEditLine( |
||||
'数据源名称', |
||||
o.connectionName,//self._parent.options.formData.connectionName,
|
||||
function(_ref) { |
||||
self.name = _ref; |
||||
}, |
||||
//hugh:2021-04-02,截止目前的所有发布版本均不支持getName方法修改数据源连接名称,需要使用下面这种非常不友好的方式修改
|
||||
function () { |
||||
self._parent.options.formData.connectionName = this.getValue(); |
||||
} |
||||
), |
||||
createEditLine( |
||||
'key值', |
||||
o.value.key, |
||||
function(_ref) { |
||||
self.key = _ref; |
||||
}, |
||||
function () {} |
||||
) |
||||
] |
||||
}; |
||||
}, |
||||
getValue() { |
||||
return { |
||||
key: this.key.getValue() |
||||
}; |
||||
}, |
||||
//hugh:2021-04-02下个小版本应该就支持直接使用getName来返回要修改的数据源链接名称了
|
||||
getName(){ |
||||
return this.name.getValue(); |
||||
} |
||||
}); |
||||
BI.shortcut(DemoEditName, DemoEdit); |
||||
BI.constant('dec.constant.database.conf.connect.form.demo.edit', DemoEditName); |
||||
|
||||
//显示配置
|
||||
var DemoShowName = 'dec.dcm.connection.plugin.demo.show'; |
||||
var DemoShow = BI.inherit(BI.Widget, { |
||||
props: { |
||||
value: { |
||||
key: '' |
||||
} |
||||
}, |
||||
render() { |
||||
var o = this.options; |
||||
return { |
||||
type: 'bi.vertical', |
||||
hgap: 15, |
||||
vgap: 10, |
||||
items: [ |
||||
{ |
||||
type: 'bi.left', |
||||
items: [ |
||||
{ |
||||
type: 'bi.label', |
||||
cls: 'bi-font-bold', |
||||
width: 100, |
||||
textAlign: 'left', |
||||
text: 'Key值' |
||||
}, |
||||
{ |
||||
type: 'bi.label', |
||||
text: o.value.key |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}; |
||||
} |
||||
}); |
||||
|
||||
BI.shortcut(DemoShowName, DemoShow); |
||||
BI.constant('dec.constant.database.conf.connect.form.demo.show', DemoShowName); |
||||
//注册
|
||||
BI.config('dec.connection.provider.datebase', function(provider){ |
||||
provider.registerDatabaseType({ |
||||
text: 'Demo Conn', |
||||
databaseType: 'demo_con', |
||||
iconUrl: 'com/tptj/demo/hg/connection/images/demo.jpg', |
||||
edit: 'dec.dcm.connection.plugin.demo.edit', |
||||
show: 'dec.dcm.connection.plugin.demo.show', |
||||
}); |
||||
}); |
||||
})(); |
Loading…
Reference in new issue