svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultFeatureExtraColumns.java @ 44871
History | View | Annotate | Download (5.43 KB)
1 | 44753 | omartinez | /*
|
---|---|---|---|
2 | * To change this license header, choose License Headers in Project Properties.
|
||
3 | * To change this template file, choose Tools | Templates
|
||
4 | * and open the template in the editor.
|
||
5 | */
|
||
6 | package org.gvsig.fmap.dal.feature.impl; |
||
7 | |||
8 | import java.util.ArrayList; |
||
9 | import java.util.List; |
||
10 | import org.apache.commons.lang3.StringUtils; |
||
11 | import org.gvsig.fmap.dal.DALLocator; |
||
12 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
13 | 44829 | omartinez | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
14 | import org.gvsig.tools.ToolsLocator; |
||
15 | import org.gvsig.tools.dynobject.DynStruct; |
||
16 | import org.gvsig.tools.persistence.PersistentState; |
||
17 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
18 | import org.gvsig.fmap.dal.feature.FeatureExtraColumns; |
||
19 | 44753 | omartinez | |
20 | /**
|
||
21 | *
|
||
22 | * @author osc
|
||
23 | */
|
||
24 | 44829 | omartinez | public class DefaultFeatureExtraColumns implements FeatureExtraColumns { |
25 | 44753 | omartinez | |
26 | 44801 | omartinez | private List<EditableFeatureAttributeDescriptor> extraColumns; |
27 | 44764 | jjdelcerro | |
28 | 44829 | omartinez | public DefaultFeatureExtraColumns() {
|
29 | 44753 | omartinez | this.extraColumns = new ArrayList(); |
30 | } |
||
31 | 44764 | jjdelcerro | |
32 | 44753 | omartinez | @Override
|
33 | 44764 | jjdelcerro | public boolean isEmpty() { |
34 | return this.extraColumns.isEmpty(); |
||
35 | } |
||
36 | |||
37 | @Override
|
||
38 | 44753 | omartinez | public EditableFeatureAttributeDescriptor get(String columnName) { |
39 | for (EditableFeatureAttributeDescriptor extraColumn : this.extraColumns) { |
||
40 | if (StringUtils.equals(extraColumn.getName(), columnName)) {
|
||
41 | return extraColumn;
|
||
42 | } |
||
43 | } |
||
44 | return null; |
||
45 | } |
||
46 | |||
47 | @Override
|
||
48 | public EditableFeatureAttributeDescriptor add(String name) { |
||
49 | //TODO que no hayan dos columnas iguales
|
||
50 | // exi.addExtraColumn()
|
||
51 | 44764 | jjdelcerro | EditableFeatureAttributeDescriptor newAttr = new DefaultEditableFeatureAttributeDescriptor(null, false); |
52 | 44753 | omartinez | newAttr.setName(name); |
53 | extraColumns.add(newAttr); |
||
54 | return newAttr;
|
||
55 | } |
||
56 | |||
57 | @Override
|
||
58 | public List<EditableFeatureAttributeDescriptor> getColumns() { |
||
59 | return this.extraColumns; |
||
60 | } |
||
61 | |||
62 | @Override
|
||
63 | 44829 | omartinez | public void merge(FeatureExtraColumns other) { |
64 | 44753 | omartinez | this.extraColumns.addAll(other.getColumns());
|
65 | } |
||
66 | |||
67 | 44778 | omartinez | @Override
|
68 | public int getIndexOf(String name) { |
||
69 | for (int i = 0; i < extraColumns.size(); i++) { |
||
70 | EditableFeatureAttributeDescriptor extraColumn = extraColumns.get(i); |
||
71 | if (StringUtils.equals(extraColumn.getName(), name)) {
|
||
72 | return i;
|
||
73 | } |
||
74 | } |
||
75 | return -1; |
||
76 | } |
||
77 | |||
78 | @Override
|
||
79 | public EditableFeatureAttributeDescriptor get(int index) { |
||
80 | return extraColumns.get(index);
|
||
81 | } |
||
82 | |||
83 | 44779 | omartinez | @Override
|
84 | public int size() { |
||
85 | return extraColumns.size();
|
||
86 | } |
||
87 | |||
88 | 44791 | omartinez | @Override
|
89 | 44829 | omartinez | public void copyFrom(FeatureExtraColumns extraColumn) { |
90 | 44791 | omartinez | this.extraColumns.clear();
|
91 | for (EditableFeatureAttributeDescriptor col : extraColumn.getColumns()) {
|
||
92 | this.extraColumns.add(col);
|
||
93 | } |
||
94 | } |
||
95 | |||
96 | @Override
|
||
97 | public void clear() { |
||
98 | this.extraColumns.clear();
|
||
99 | } |
||
100 | 44801 | omartinez | |
101 | 44829 | omartinez | public FeatureExtraColumns getDeepCopy() {
|
102 | DefaultFeatureExtraColumns other = new DefaultFeatureExtraColumns();
|
||
103 | 44801 | omartinez | ArrayList otherCols = new ArrayList(); |
104 | for (EditableFeatureAttributeDescriptor extraColumn : this.extraColumns) { |
||
105 | EditableFeatureAttributeDescriptor newAttr = DALLocator.getDataManager().createFeatureAttributeDescriptor(); |
||
106 | newAttr.copyFrom(extraColumn); |
||
107 | otherCols.add(newAttr); |
||
108 | } |
||
109 | other.extraColumns = otherCols; |
||
110 | return other;
|
||
111 | } |
||
112 | 44791 | omartinez | |
113 | 44801 | omartinez | @Override
|
114 | 44829 | omartinez | public FeatureExtraColumns getCopy() {
|
115 | DefaultFeatureExtraColumns other = new DefaultFeatureExtraColumns();
|
||
116 | 44801 | omartinez | ArrayList otherCols = new ArrayList(); |
117 | otherCols.addAll(extraColumns); |
||
118 | other.extraColumns = otherCols; |
||
119 | return other;
|
||
120 | } |
||
121 | |||
122 | 44829 | omartinez | @Override
|
123 | public void saveToState(PersistentState state) throws PersistenceException { |
||
124 | |||
125 | // ArrayList<DefaultFeatureAttributeDescriptor> extraListCols = new ArrayList<>();
|
||
126 | // for (EditableFeatureAttributeDescriptor extraColumn : extraColumns) {
|
||
127 | // DefaultEditableFeatureAttributeDescriptor mycol = (DefaultEditableFeatureAttributeDescriptor) extraColumn;
|
||
128 | // DefaultFeatureAttributeDescriptor fad = new DefaultFeatureAttributeDescriptor();
|
||
129 | // fad.copyFrom(mycol);
|
||
130 | // extraListCols.add(fad);
|
||
131 | // }
|
||
132 | state.set("extraColumns", extraColumns);
|
||
133 | } |
||
134 | |||
135 | @Override
|
||
136 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
137 | List<DefaultFeatureAttributeDescriptor> extraColumnsDescriptors = (List) state.getList("extraColumns"); |
||
138 | ArrayList<EditableFeatureAttributeDescriptor> cols = new ArrayList<EditableFeatureAttributeDescriptor>(); |
||
139 | for (DefaultFeatureAttributeDescriptor extraColumnsDescriptor : extraColumnsDescriptors) {
|
||
140 | DefaultEditableFeatureAttributeDescriptor myEditableDescriptor = new DefaultEditableFeatureAttributeDescriptor(extraColumnsDescriptor);
|
||
141 | cols.add(myEditableDescriptor); |
||
142 | } |
||
143 | this.extraColumns = cols;
|
||
144 | } |
||
145 | |||
146 | public static void registerPersistent() { |
||
147 | DynStruct definition = |
||
148 | ToolsLocator.getPersistenceManager() |
||
149 | .addDefinition(DefaultFeatureExtraColumns.class, |
||
150 | "DefaultFeatureExtraColumn",
|
||
151 | "DefaultFeatureExtraColumn Persistent definition",
|
||
152 | null,
|
||
153 | null);
|
||
154 | |||
155 | definition.addDynFieldArray("extraColumns")
|
||
156 | .setClassOfItems(FeatureAttributeDescriptor.class) |
||
157 | .setMandatory(false);
|
||
158 | |||
159 | } |
||
160 | 44753 | omartinez | } |