forked from p81075629/datagear
[analysis]完善看板基础API
This commit is contained in:
parent
d26664a71d
commit
a597c583ea
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.analysis;
|
||||
|
||||
/**
|
||||
* 看板部件。
|
||||
* <p>
|
||||
* 它可在{@linkplain RenderContext}中渲染自己所描述的{@linkplain Dashboard}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public abstract class DashboardWidget<T extends RenderContext> extends AbstractIdentifiable
|
||||
{
|
||||
/** 名称 */
|
||||
private String name;
|
||||
|
||||
public DashboardWidget()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public DashboardWidget(String id, String name)
|
||||
{
|
||||
super(id);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染{@linkplain Dashboard}。
|
||||
*
|
||||
* @param renderContext
|
||||
* @return
|
||||
* @throws RenderException
|
||||
*/
|
||||
public abstract Dashboard render(T renderContext) throws RenderException;
|
||||
}
|
|
@ -3,13 +3,6 @@
|
|||
*/
|
||||
package org.datagear.analysis;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.datagear.analysis.support.LocationResource;
|
||||
import org.datagear.util.IOUtil;
|
||||
|
||||
/**
|
||||
* 模板看板部件。
|
||||
* <p>
|
||||
|
@ -19,20 +12,18 @@ import org.datagear.util.IOUtil;
|
|||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public abstract class TemplateDashboardWidget<T extends RenderContext> extends AbstractIdentifiable
|
||||
public abstract class TemplateDashboardWidget<T extends RenderContext> extends DashboardWidget<T>
|
||||
{
|
||||
private String template;
|
||||
|
||||
private String templateEncoding = "UTF-8";
|
||||
|
||||
public TemplateDashboardWidget()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public TemplateDashboardWidget(String id, String template)
|
||||
public TemplateDashboardWidget(String id, String name, String template)
|
||||
{
|
||||
super(id);
|
||||
super(id, name);
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
|
@ -45,47 +36,4 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
|
|||
{
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public String getTemplateEncoding()
|
||||
{
|
||||
return templateEncoding;
|
||||
}
|
||||
|
||||
public void setTemplateEncoding(String templateEncoding)
|
||||
{
|
||||
this.templateEncoding = templateEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染{@linkplain Dashboard}。
|
||||
*
|
||||
* @param renderContext
|
||||
* @return
|
||||
* @throws RenderException
|
||||
*/
|
||||
public abstract Dashboard render(T renderContext) throws RenderException;
|
||||
|
||||
/**
|
||||
* 获取{@linkplain #getTemplate()}的输入流。
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
protected BufferedReader getTemplateReader() throws IOException
|
||||
{
|
||||
BufferedReader reader = null;
|
||||
|
||||
if (LocationResource.isFileLocation(this.template)
|
||||
|| LocationResource.isClasspathLocation(this.template))
|
||||
{
|
||||
LocationResource resource = new LocationResource(this.template);
|
||||
reader = IOUtil.getReader(resource.getInputStream(), this.templateEncoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader = new BufferedReader(new StringReader(this.template));
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.datagear.analysis.RenderException;
|
|||
*/
|
||||
public class ChartWidget<T extends RenderContext> extends AbstractIdentifiable
|
||||
{
|
||||
private String name;
|
||||
|
||||
private ChartPlugin<T> chartPlugin;
|
||||
|
||||
private ChartPropertyValues chartPropertyValues;
|
||||
|
@ -34,15 +36,26 @@ public class ChartWidget<T extends RenderContext> extends AbstractIdentifiable
|
|||
super();
|
||||
}
|
||||
|
||||
public ChartWidget(String id, ChartPlugin<T> chartPlugin, ChartPropertyValues chartPropertyValues,
|
||||
public ChartWidget(String id, String name, ChartPlugin<T> chartPlugin, ChartPropertyValues chartPropertyValues,
|
||||
DataSetFactory... dataSetFactories)
|
||||
{
|
||||
super(id);
|
||||
this.name = name;
|
||||
this.chartPlugin = chartPlugin;
|
||||
this.chartPropertyValues = chartPropertyValues;
|
||||
this.dataSetFactories = dataSetFactories;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ChartPlugin<T> getChartPlugin()
|
||||
{
|
||||
return chartPlugin;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package org.datagear.analysis.support;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.datagear.analysis.DashboardWidget;
|
||||
|
||||
/**
|
||||
* {@linkplain DashboardWidget}文件资源管理器。
|
||||
* <p>
|
||||
* 此类用于通过{@linkplain DashboardWidget#getId()}来管理{@linkplain DashboardWidget}文件资源。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class DashboardWidgetResManager
|
||||
{
|
||||
private static final String PATH_SEPARATOR = File.separator;
|
||||
|
||||
private File rootDirectory;
|
||||
|
||||
public DashboardWidgetResManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public DashboardWidgetResManager(File rootDirectory)
|
||||
{
|
||||
super();
|
||||
this.rootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
public DashboardWidgetResManager(String rootDirectory)
|
||||
{
|
||||
super();
|
||||
this.rootDirectory = new File(rootDirectory);
|
||||
}
|
||||
|
||||
public File getRootDirectory()
|
||||
{
|
||||
return rootDirectory;
|
||||
}
|
||||
|
||||
public void setRootDirectory(File rootDirectory)
|
||||
{
|
||||
this.rootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
protected String trimPath(String path)
|
||||
{
|
||||
if (path == null)
|
||||
return null;
|
||||
|
||||
if (PATH_SEPARATOR.equals("\\"))
|
||||
return path.replace("/", PATH_SEPARATOR);
|
||||
else
|
||||
return path.replace("\\", PATH_SEPARATOR);
|
||||
}
|
||||
}
|
|
@ -28,9 +28,9 @@ public class HtmlTemplateDashboardWidget<T extends HtmlRenderContext> extends Te
|
|||
super();
|
||||
}
|
||||
|
||||
public HtmlTemplateDashboardWidget(String id, String template, ChartWidgetSource chartWidgetSource)
|
||||
public HtmlTemplateDashboardWidget(String id, String name, String template, ChartWidgetSource chartWidgetSource)
|
||||
{
|
||||
super(id, template);
|
||||
super(id, name, template);
|
||||
this.chartWidgetSource = chartWidgetSource;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue