Revision 44753 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttributes.java
DefaultExportAttributes.java | ||
---|---|---|
16 | 16 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
17 | 17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
18 | 18 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
19 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
19 | 20 |
import org.gvsig.fmap.dal.feature.FeatureType; |
20 | 21 |
import org.gvsig.tools.ToolsLocator; |
22 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
23 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
21 | 24 |
import org.gvsig.tools.dynobject.DynStruct; |
22 | 25 |
import org.gvsig.tools.persistence.PersistenceManager; |
23 | 26 |
import org.gvsig.tools.persistence.PersistentState; |
... | ... | |
32 | 35 |
private FeatureType sourceFeatureType; |
33 | 36 |
static final Logger LOGGER = LoggerFactory.getLogger(DefaultExportAttributes.class); |
34 | 37 |
private boolean active; |
38 |
private FeatureQuery query = null; |
|
35 | 39 |
|
36 | 40 |
public DefaultExportAttributes() { |
37 | 41 |
this.namesTranslator = new DummyAttributeNamesTranslator(); |
38 | 42 |
this.active = false; |
39 | 43 |
} |
40 | 44 |
|
41 |
public void fillExportAttributes(FeatureType ftype) { |
|
45 |
public void fillExportAttributes(FeatureType ftype, FeatureQuery query) {
|
|
42 | 46 |
ArrayList attrs = new ArrayList(); |
43 | 47 |
if (ftype != null) { |
44 | 48 |
for (FeatureAttributeDescriptor fad : ftype) { |
... | ... | |
47 | 51 |
exportAttribute.setNewName(newName); |
48 | 52 |
exportAttribute.setNewType(fad.getDataType().getType()); |
49 | 53 |
exportAttribute.setSize(fad.getSize()); |
50 |
exportAttribute.setExported(true); |
|
54 |
if (query == null || (query != null && query.getGroupByColumns().isEmpty())) { |
|
55 |
exportAttribute.setExported(isShowableDataType(fad.getDataType().getType())); |
|
56 |
} else { |
|
57 |
if (query.getAggregate(fad.getName()) != null || query.getGroupByColumns().contains(fad.getName())) { |
|
58 |
exportAttribute.setExported(isShowableDataType(fad.getDataType().getType())); |
|
59 |
} else { |
|
60 |
exportAttribute.setExported(false); |
|
61 |
} |
|
62 |
} |
|
51 | 63 |
attrs.add(exportAttribute); |
52 | 64 |
} |
53 | 65 |
} |
66 |
|
|
67 |
if (query!=null && query.getExtraColumn().getColumns()!=null && !query.getExtraColumn().getColumns().isEmpty() ) { |
|
68 |
for (FeatureAttributeDescriptor fad : query.getExtraColumn().getColumns()) { |
|
69 |
DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad); |
|
70 |
String newName = this.getNamesTranslator().getNameSuggestion(fad.getName()); |
|
71 |
exportAttribute.setNewName(newName); |
|
72 |
exportAttribute.setNewType(fad.getDataType().getType()); |
|
73 |
exportAttribute.setSize(fad.getSize()); |
|
74 |
exportAttribute.setExported(isShowableDataType(fad.getDataType().getType())); |
|
75 |
attrs.add(exportAttribute); |
|
76 |
} |
|
77 |
} |
|
54 | 78 |
this.setExportAttributes(attrs); |
55 | 79 |
this.fixAttributeNames(); |
56 | 80 |
|
57 | 81 |
} |
82 |
|
|
83 |
protected boolean isShowableDataType(int dataType) { |
|
84 |
DataTypesManager dataTypemanager = ToolsLocator.getDataTypesManager(); |
|
85 |
if (dataTypemanager.isContainer(dataType) |
|
86 |
|| dataTypemanager.isObject(dataType) |
|
87 |
|| dataType == DataTypes.ARRAY) { |
|
88 |
return false; |
|
58 | 89 |
|
90 |
} else { |
|
91 |
return true; |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
59 | 95 |
@Override |
60 | 96 |
public void setNamesTranslator(AttributeNamesTranslator namesTranslator) { |
61 | 97 |
if (this.namesTranslator != namesTranslator) { |
62 | 98 |
this.namesTranslator = namesTranslator; |
63 | 99 |
if (this.sourceFeatureType != null) { |
64 |
this.fillExportAttributes(sourceFeatureType); |
|
100 |
this.fillExportAttributes(sourceFeatureType, this.query);
|
|
65 | 101 |
} |
66 | 102 |
} |
67 | 103 |
} |
... | ... | |
136 | 172 |
int size = exportAttr.getSize(); |
137 | 173 |
eAttr.setSize(size); |
138 | 174 |
} |
175 |
if (this.query!=null && this.query.getExtraColumn().getColumns()!=null && !this.query.getExtraColumn().getColumns().isEmpty()) { |
|
176 |
for (EditableFeatureAttributeDescriptor attrExtra : this.query.getExtraColumn().getColumns()) { |
|
177 |
//FeatureAttributeDescriptor attr = targetFeatureType.getAttributeDescriptor(attrSource.getName()); |
|
178 |
String name = attrExtra.getName(); |
|
179 |
ExportAttribute exportAttr = this.getExportAttribute(name); |
|
180 |
if (!exportAttr.isExported()) { |
|
181 |
//targetFeatureType.remove(name); |
|
182 |
continue; |
|
183 |
} |
|
184 |
//EditableFeatureAttributeDescriptor eAttr = targetFeatureType.getEditableAttributeDescriptor(name); |
|
185 |
// if( eAttr.isComputed() && !exportAttr.isComputed() ) { |
|
186 |
// eAttr.setFeatureAttributeEmulator((FeatureAttributeEmulator)null); |
|
187 |
// } |
|
188 |
if (this.getTargetName(name) == null && name != null && !this.getTargetName(name).equals(name)) { |
|
189 |
attrExtra.setName(this.getTargetName(name)); |
|
190 |
} |
|
191 |
int type = attrExtra.getDataType().getType(); |
|
192 |
if (type != this.getTargetType(name)) { |
|
193 |
attrExtra.setDataType(this.getTargetType(name)); |
|
194 |
attrExtra.setDefaultValue(null); // TODO: delete default value |
|
195 |
} |
|
196 |
int size = exportAttr.getSize(); |
|
197 |
attrExtra.setSize(size); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
139 | 201 |
return targetFeatureType.getNotEditableCopy(); |
140 | 202 |
} |
141 | 203 |
|
142 | 204 |
@Override |
143 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
|
205 |
public void setSourceFeatureType(FeatureType sourceFeatureType, FeatureQuery query) { |
|
206 |
this.query = query; |
|
144 | 207 |
if (!sourceFeatureType.equals(this.sourceFeatureType)) { |
145 | 208 |
this.sourceFeatureType = sourceFeatureType; |
146 |
this.fillExportAttributes(this.sourceFeatureType); |
|
209 |
this.fillExportAttributes(this.sourceFeatureType, query);
|
|
147 | 210 |
} |
148 | 211 |
} |
149 | 212 |
|
Also available in: Unified diff