root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / fieldmanagers / AbstractFieldManager.java @ 6212
History | View | Annotate | Download (3.56 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.edition.fieldmanagers; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
|
45 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
46 |
import com.iver.cit.gvsig.fmap.edition.IFieldManager; |
47 |
|
48 |
public abstract class AbstractFieldManager implements IFieldManager { |
49 |
|
50 |
protected ArrayList fieldCommands = new ArrayList(); |
51 |
|
52 |
protected FieldDescription[] originalFields; |
53 |
|
54 |
public FieldDescription[] getOriginalFields() { |
55 |
return originalFields;
|
56 |
} |
57 |
|
58 |
public void setOriginalFields(FieldDescription[] fields) { |
59 |
originalFields = fields; |
60 |
|
61 |
} |
62 |
|
63 |
public void addField(FieldDescription fieldDesc) { |
64 |
AddFieldCommand c = new AddFieldCommand(fieldDesc);
|
65 |
fieldCommands.add(c); |
66 |
} |
67 |
|
68 |
public FieldDescription removeField(String fieldName) { |
69 |
RemoveFieldCommand c = new RemoveFieldCommand(fieldName);
|
70 |
FieldDescription[] act = getFields();
|
71 |
FieldDescription found = null;
|
72 |
for (int i=0; i < act.length; i++) |
73 |
{ |
74 |
if (act[i].getFieldAlias().compareToIgnoreCase(fieldName) == 0) |
75 |
{ |
76 |
found = act[i]; |
77 |
break;
|
78 |
} |
79 |
} |
80 |
fieldCommands.add(c); |
81 |
return found;
|
82 |
} |
83 |
|
84 |
public void renameField(String antName, String newName) { |
85 |
RenameFieldCommand c = new RenameFieldCommand(antName, newName);
|
86 |
fieldCommands.add(c); |
87 |
} |
88 |
|
89 |
public FieldDescription[] getFields() |
90 |
{ |
91 |
ArrayList aux = new ArrayList(); |
92 |
for (int i=0; i < aux.size(); i++) |
93 |
{ |
94 |
aux.add(getOriginalFields()[i]); |
95 |
} |
96 |
// procesamos comandos para devolver los campos reales.
|
97 |
for (int j=0; j < fieldCommands.size(); j++) |
98 |
{ |
99 |
FieldCommand fc = (FieldCommand) fieldCommands.get(j); |
100 |
if (fc instanceof AddFieldCommand) |
101 |
{ |
102 |
AddFieldCommand ac = (AddFieldCommand) fc; |
103 |
aux.add(ac.getFieldDesc()); |
104 |
} |
105 |
if (fc instanceof RemoveFieldCommand) |
106 |
{ |
107 |
RemoveFieldCommand rc = (RemoveFieldCommand) fc; |
108 |
for (int k = 0; k < aux.size(); k++) { |
109 |
FieldDescription fAux = (FieldDescription) aux.get(k); |
110 |
if (fAux.getFieldAlias().compareTo(rc.getFieldName()) == 0) { |
111 |
aux.remove(k); |
112 |
break;
|
113 |
} |
114 |
} |
115 |
} |
116 |
if (fc instanceof RenameFieldCommand) |
117 |
{ |
118 |
RenameFieldCommand renc = (RenameFieldCommand) fc; |
119 |
for (int k = 0; k < aux.size(); k++) { |
120 |
FieldDescription fAux = (FieldDescription) aux.get(k); |
121 |
if (fAux.getFieldAlias().compareTo(renc.getAntName()) == 0) { |
122 |
fAux.setFieldAlias(renc.getNewName()); |
123 |
break;
|
124 |
} |
125 |
} |
126 |
|
127 |
} |
128 |
|
129 |
} |
130 |
return (FieldDescription[]) aux.toArray(new FieldDescription[0]); |
131 |
} |
132 |
|
133 |
} |