Revision 6212 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/fieldmanagers/AbstractFieldManager.java
AbstractFieldManager.java | ||
---|---|---|
46 | 46 |
import com.iver.cit.gvsig.fmap.edition.IFieldManager; |
47 | 47 |
|
48 | 48 |
public abstract class AbstractFieldManager implements IFieldManager { |
49 |
|
|
49 |
|
|
50 | 50 |
protected ArrayList fieldCommands = new ArrayList(); |
51 |
|
|
51 | 52 |
protected FieldDescription[] originalFields; |
52 | 53 |
|
53 |
public void addFieldCommand(FieldCommand fieldCommand) { |
|
54 |
fieldCommands.add(fieldCommand); |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 | 54 |
public FieldDescription[] getOriginalFields() { |
59 | 55 |
return originalFields; |
60 | 56 |
} |
61 | 57 |
|
62 | 58 |
public void setOriginalFields(FieldDescription[] fields) { |
63 | 59 |
originalFields = fields; |
64 |
|
|
60 |
|
|
65 | 61 |
} |
66 | 62 |
|
63 |
public void addField(FieldDescription fieldDesc) { |
|
64 |
AddFieldCommand c = new AddFieldCommand(fieldDesc); |
|
65 |
fieldCommands.add(c); |
|
66 |
} |
|
67 | 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 |
} |
|
68 | 83 |
|
69 |
} |
|
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 |
} |
|
70 | 126 |
|
127 |
} |
|
128 |
|
|
129 |
} |
|
130 |
return (FieldDescription[]) aux.toArray(new FieldDescription[0]); |
|
131 |
} |
|
71 | 132 |
|
133 |
} |
Also available in: Unified diff