svn-gvsig-desktop / tags / v2_0_0_Build_2020 / extensions / org.gvsig.hyperlink.app / org.gvsig.hyperlink.app.extension / src / main / java / org / gvsig / hyperlink / app / extension / config / LayerLinkConfig.java @ 33968
History | View | Annotate | Download (4.01 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.hyperlink.app.extension.config; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
27 |
|
28 |
import org.gvsig.tools.ToolsLocator; |
29 |
import org.gvsig.tools.dynobject.DynStruct; |
30 |
import org.gvsig.tools.persistence.PersistenceManager; |
31 |
import org.gvsig.tools.persistence.Persistent; |
32 |
import org.gvsig.tools.persistence.PersistentState; |
33 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
34 |
import org.gvsig.tools.util.Callable; |
35 |
|
36 |
public class LayerLinkConfig implements Persistent { |
37 |
|
38 |
protected List<LinkConfig> linkList; |
39 |
protected boolean enabled; |
40 |
public static final String LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME = "LayerLinkConfig"; |
41 |
|
42 |
public LayerLinkConfig() {
|
43 |
linkList = new ArrayList<LinkConfig>(); |
44 |
} |
45 |
|
46 |
public void addLink(LinkConfig config) { |
47 |
linkList.add(config); |
48 |
} |
49 |
|
50 |
public void addLink(int position, LinkConfig config) { |
51 |
linkList.add(position, config); |
52 |
} |
53 |
|
54 |
public void addLink(String actionCode, String fieldName) { |
55 |
linkList.add(new LinkConfig(actionCode, fieldName));
|
56 |
} |
57 |
|
58 |
public void addLink(String actionCode, String fieldName, String extension) { |
59 |
linkList.add(new LinkConfig(actionCode, fieldName, extension));
|
60 |
} |
61 |
|
62 |
public LinkConfig removeLink(int linkIndex) { |
63 |
try {
|
64 |
return linkList.remove(linkIndex);
|
65 |
} catch (IndexOutOfBoundsException ex) { |
66 |
return null; |
67 |
} |
68 |
} |
69 |
|
70 |
public LinkConfig getLink(int index) { |
71 |
return linkList.get(index);
|
72 |
} |
73 |
|
74 |
public int linkCount() { |
75 |
return linkList.size();
|
76 |
} |
77 |
|
78 |
public String getClassName() { |
79 |
return this.getClass().getName(); |
80 |
} |
81 |
|
82 |
public boolean isEnabled() { |
83 |
return enabled;
|
84 |
} |
85 |
|
86 |
public void setEnabled(boolean enabled) { |
87 |
this.enabled = enabled;
|
88 |
} |
89 |
|
90 |
public void saveToState(PersistentState state) throws PersistenceException { |
91 |
state.set("enabled", this.enabled); |
92 |
state.set("linkList", this.linkList); |
93 |
} |
94 |
|
95 |
@SuppressWarnings("unchecked") |
96 |
public void loadFromState(PersistentState state) throws PersistenceException { |
97 |
this.enabled = state.getBoolean("enabled"); |
98 |
this.linkList = new ArrayList<LinkConfig>(); |
99 |
this.linkList.addAll(state.getList("linkList")); |
100 |
} |
101 |
|
102 |
public static class RegisterPersistence implements Callable { |
103 |
|
104 |
public Object call() throws Exception { |
105 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
106 |
if( manager.getDefinition(LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME)==null ) { |
107 |
DynStruct definition = manager.addDefinition( |
108 |
LayerLinkConfig.class, |
109 |
LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME, |
110 |
LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
111 |
null,
|
112 |
null
|
113 |
); |
114 |
|
115 |
definition.addDynFieldBoolean("enabled").setMandatory(true); |
116 |
definition.addDynFieldList("linkList").setMandatory(false).setClassOfItems(LinkConfig.class); |
117 |
} |
118 |
return Boolean.TRUE; |
119 |
} |
120 |
|
121 |
} |
122 |
|
123 |
} |