Revision 46876 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/featuretype/DefaultFeatureAttributePanel.java
DefaultFeatureAttributePanel.java | ||
---|---|---|
30 | 30 |
import javax.swing.event.ListSelectionEvent; |
31 | 31 |
import javax.swing.text.JTextComponent; |
32 | 32 |
import org.apache.commons.io.FilenameUtils; |
33 |
import org.apache.commons.lang3.ArrayUtils; |
|
33 | 34 |
import org.apache.commons.lang3.StringUtils; |
34 | 35 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
35 | 36 |
import org.apache.commons.lang3.tuple.Pair; |
... | ... | |
55 | 56 |
import org.gvsig.fmap.dal.DataTypes; |
56 | 57 |
import org.gvsig.fmap.dal.SQLBuilder; |
57 | 58 |
import org.gvsig.fmap.dal.StoresRepository; |
59 |
import org.gvsig.fmap.dal.complements.RelatedFeatures; |
|
60 |
import static org.gvsig.fmap.dal.complements.RelatedFeatures.DAL_RELATED_TABLE; |
|
61 |
import static org.gvsig.fmap.dal.complements.RelatedFeatures.DAL_RELATED_UNIQUE_FIELD_NAME; |
|
58 | 62 |
import org.gvsig.fmap.dal.exception.DataException; |
59 | 63 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
60 | 64 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
... | ... | |
95 | 99 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
96 | 100 |
import org.gvsig.tools.dynobject.DynField; |
97 | 101 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
102 |
import org.gvsig.tools.dynobject.Tags; |
|
98 | 103 |
import org.gvsig.tools.i18n.I18nManager; |
99 | 104 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
100 | 105 |
import org.gvsig.tools.swing.api.ListElement; |
... | ... | |
613 | 618 |
doTableChanged(); |
614 | 619 |
this.pickerForeignField.set(fieldsAndTable[2]); |
615 | 620 |
this.pickerExpression.set(expression); |
621 |
} else { |
|
622 |
this.clean(); |
|
616 | 623 |
} |
617 | 624 |
} catch (Throwable t) { |
618 | 625 |
LOGGER.warn("Can't set attribute descriptor in toMany controller",t); |
... | ... | |
632 | 639 |
} else { |
633 | 640 |
descriptor.setFeatureAttributeEmulator(exp); |
634 | 641 |
} |
642 |
Tags tags = descriptor.getTags(); |
|
643 |
if( !tags.has(DAL_RELATED_TABLE) ) { |
|
644 |
String tableName = this.getTableName(); |
|
645 |
if( StringUtils.isNotBlank(tableName) ) { |
|
646 |
tags.set(DAL_RELATED_TABLE, tableName); |
|
647 |
} |
|
648 |
} |
|
649 |
if( !tags.has(DAL_RELATED_UNIQUE_FIELD_NAME) ) { |
|
650 |
String tableName = tags.getString(DAL_RELATED_TABLE, null); |
|
651 |
if( StringUtils.isNotBlank(tableName) ) { |
|
652 |
try { |
|
653 |
StoresRepository repository = DALLocator.getDataManager().getStoresRepository(); |
|
654 |
FeatureType ft = repository.getFeatureType(tableName); |
|
655 |
FeatureAttributeDescriptor[] pk = ft.getPrimaryKey(); |
|
656 |
if( !ArrayUtils.isEmpty(pk) && pk.length==1 ) { |
|
657 |
tags.set(DAL_RELATED_UNIQUE_FIELD_NAME, pk[0].getName()); |
|
658 |
} |
|
659 |
} catch(Throwable t) { |
|
660 |
LOGGER.warn("Can't get primary key of table '"+tableName+"'.",t); |
|
661 |
} |
|
662 |
} |
|
663 |
} |
|
635 | 664 |
} |
636 | 665 |
|
637 | 666 |
public int getRelationType() { |
... | ... | |
1184 | 1213 |
break; |
1185 | 1214 |
} |
1186 | 1215 |
|
1216 |
this.rdbRelationNone.setEnabled(enabled); |
|
1217 |
this.rdbRelationToOne.setEnabled(enabled && !this.isVirtualField()); |
|
1218 |
this.rdbRelationToMany.setEnabled(enabled && (this.isVirtualField() || this.getDataType().getType()==DataTypes.LIST)); |
|
1219 |
|
|
1187 | 1220 |
if( this.rdbRelationNone.isSelected() ) { |
1188 | 1221 |
this.pickerVirtualFieldGetter.setEnabled(enabled); |
1189 | 1222 |
this.toOneController.setEnabled(false); |
1190 | 1223 |
this.toManyController.setEnabled(false); |
1191 |
this.toManyController.setEnabled(false); |
|
1192 | 1224 |
} else if( this.rdbRelationToOne.isSelected() ) { |
1193 | 1225 |
this.pickerVirtualFieldGetter.setEnabled(enabled); |
1194 | 1226 |
this.toManyController.setEnabled(false); |
1195 | 1227 |
if( this.isVirtualField() ) { |
1196 | 1228 |
this.rdbRelationNone.setSelected(true); |
1197 | 1229 |
} else { |
1230 |
this.toOneController.setEditable(enabled); |
|
1198 | 1231 |
this.toOneController.setEnabled(enabled); |
1199 | 1232 |
} |
1200 | 1233 |
} else if( this.rdbRelationToMany.isSelected() ) { |
... | ... | |
1203 | 1236 |
} else { |
1204 | 1237 |
this.pickerVirtualFieldGetter.setEnabled(false); |
1205 | 1238 |
this.toOneController.setEnabled(false); |
1239 |
this.toManyController.setEditable(enabled); |
|
1206 | 1240 |
this.toManyController.setEnabled(enabled); |
1207 | 1241 |
} |
1208 | 1242 |
} |
... | ... | |
1692 | 1726 |
case DynField.RELATION_TYPE_NONE: |
1693 | 1727 |
this.rdbRelationNone.setSelected(true); |
1694 | 1728 |
this.rdbRelationToOne.setSelected(false); |
1695 |
this.rdbRelationToMany.setSelected(false); |
|
1696 |
this.toOneController.clean(); |
|
1697 |
this.toManyController.clean(); |
|
1729 |
this.rdbRelationToMany.setSelected(false); |
|
1730 |
// No los borramos, solo quedan deshabilitados, para no peder la informacion que contengan |
|
1731 |
// this.toOneController.clean(); |
|
1732 |
// this.toManyController.clean(); |
|
1698 | 1733 |
break; |
1699 | 1734 |
case DynField.RELATION_TYPE_IDENTITY: |
1700 | 1735 |
case DynField.RELATION_TYPE_COLLABORATION: |
1701 | 1736 |
this.rdbRelationNone.setSelected(false); |
1702 | 1737 |
this.rdbRelationToOne.setSelected(true); |
1703 | 1738 |
this.rdbRelationToMany.setSelected(false); |
1704 |
this.toManyController.clean(); |
|
1739 |
// this.toManyController.clean();
|
|
1705 | 1740 |
break; |
1706 | 1741 |
case DynField.RELATION_TYPE_COMPOSITION: |
1707 | 1742 |
case DynField.RELATION_TYPE_AGGREGATE: |
... | ... | |
1710 | 1745 |
this.rdbRelationToMany.setSelected(true); |
1711 | 1746 |
this.pickerVirtualFieldGetter.setEnabled(false); |
1712 | 1747 |
// this.pickerVirtualFieldGetter.set(null); |
1713 |
this.toOneController.clean(); |
|
1748 |
// this.toOneController.clean();
|
|
1714 | 1749 |
break; |
1715 | 1750 |
|
1716 | 1751 |
} |
Also available in: Unified diff