HadoopIntellijPlugin插件文件系统配置设计和实现1

  HDFS文件系统浏览器的配置设置分为两部分,一个是配置的基础类,涉及到对象的持久化写入,该部分定义相关的接口和抽象类的实现;另一部分是具体的对象持久化配置,包括HDFS连接配置持久化和整个系统的通用配置(国际化多语言的支持和文件树展现方式)持久化。本节讲解配置的基础类。
配置的基础类,定义在core 包中。整个的类的关系图如下:

定义持久化配置接口PersistentConfiguration

  该接口定义读取和写入持久化配置方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* 定义持久化配置接口
* Created by fangyuzhong on 17-7-21.
*/
public interface PersistentConfiguration
{
/**
* 读取持久化配置 config
* @param paramElement
*/
void readConfiguration(Element paramElement);
/**
* 写入持久化配置 config
* @param paramElement
*/
void writeConfiguration(Element paramElement);
}

定义Boolean、Enum、Int、String类型的对象持久化

  这些对象,继承了抽象类Setting,并且实现了PersistentConfiguration接口。抽象类Setting,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* 定义抽象设置类
* Created by fangyuzhong on 17-7-21.
*/
public abstract class Setting<T, E>
{
private T value;
private String name;
protected Setting(String configName, T value)
{
this.name = configName;
this.value = value;
}
/**
* 配置项名称
* @return
*/
public String getName()
{
return this.name;
}
/*
* 配置项的值
* @return
*/
public T value()
{
return this.value;
}
/**
* 设置配置项的值
* @param value
* @return
*/
public boolean setValue(T value)
{
boolean response = !CommonUtil.safeEqual(this.value, value);
this.value = value;
return response;
}
/**
* 获取配置项的值
* @return
*/
public T getValue()
{
return this.value;
}
/**
* 获取Setting的返回值
* @return
*/
public String toString()
{
return "[" + getClass().getSimpleName() + "] " + this.name + " = " + this.value;
}
/**
*
* @param paramE
* @return
* @throws ConfigurationException
*/
public abstract boolean to(E paramE)
throws ConfigurationException;
/**
*
* @param paramE
*/
public abstract void from(E paramE);
}

定义抽象配置类Configuration

  抽象类Configuration是一个抽象的泛型类,创建和读取配置的主窗体UI对象:ConfigurationEditorForm,同时也继承了ConfigurationUtil类。
ConfigurationEditorForm类是配置的UI对象的抽象类,所有配置的UI对象都需要实现该类。该类继承了通用窗体类FileSystemBaseFormImpl。

工程配置持久化ProjectConfiguration和配置集合类CompositeConfigurationEditorForm

  ProjectConfiguration 为工程配置抽象类,继承了配置Configuration,泛型类,定义了获取当前的工程Project。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* 定义工程配置类
* Created by fangyuzhong on 17-7-21.
*/
public abstract class ProjectConfiguration<T extends ConfigurationEditorForm>
extends Configuration<T>
implements ProjectSupplier
{

private Project project;
/**
* 初始化工程配置
* @param project
*/
public ProjectConfiguration(Project project)
{
this.project = project;
}
/**
*获取工程Project
* @return
*/
public Project getProject()
{
return this.project;
}
}

  CompositeConfigurationEditorForm 类为配置集合类,插件的配置分为多个项,因此需要将多个配置组合到一起。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
*定义配置集合类
* Created by fangyuzhong on 17-7-21.
*/
public abstract class CompositeConfiguration<T extends CompositeConfigurationEditorForm>
extends Configuration<T>
{
private Configuration[] configurations;
/**
* 获取配置集合类
* @return
*/
public final Configuration[] getConfigurations()
{
if (this.configurations == null)
{
this.configurations = createConfigurations();
}
return this.configurations;
}
/**
* 创建配置集合
* @return
*/
protected abstract Configuration[] createConfigurations();
/**
* 是否修改
* @return
*/
public final boolean isModified()
{
for (Configuration configuration : getConfigurations())
{
if (configuration.isModified())
{
return true;
}
}
return super.isModified();
}
/**
* 应用程序
* @throws ConfigurationException
*/
public void apply()
throws ConfigurationException
{
T settingsEditor = (T) getSettingsEditor();
if (((this instanceof TopLevelConfig)) && (settingsEditor != null))
{
GUIUtil.stopTableCellEditing(settingsEditor.getComponent());
}
for (Configuration configuration : getConfigurations())
{
configuration.apply();
}
super.apply();
onApply();
}
/**
* 重置
*/
public final void reset()
{
for (Configuration configuration : getConfigurations())
{
configuration.reset();
}
super.reset();
}
/**
* 释放UI资源
*/
public void disposeUIResources()
{
for (Configuration configuration : getConfigurations())
{
configuration.disposeUIResources();
}
super.disposeUIResources();
}
/**
* 读取配置
* @param element
*/
public void readConfiguration(Element element)
{
Configuration[] configurations = getConfigurations();
for (Configuration configuration : configurations)
{
readConfiguration(element,configuration);
}
}
/**
* 写入配置
* @param element
*/
public void writeConfiguration(Element element)
{
Configuration[] configurations = getConfigurations();
for (Configuration configuration : configurations)
{

writeConfiguration(element,configuration);
}
}
}

基础配置部分大致就这么多了,下一节,具体分析一下各个配置项。