Revision 44263 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/searchpanel/AdvancedAttributeSelectionTreeModel.java

View differences:

AdvancedAttributeSelectionTreeModel.java
5 5
import java.util.HashSet;
6 6
import java.util.List;
7 7
import java.util.Set;
8
import java.util.function.Predicate;
8 9
import javax.swing.event.TreeModelListener;
9 10
import javax.swing.tree.TreeModel;
10 11
import javax.swing.tree.TreePath;
......
23 24
 *
24 25
 * @author jjdelcerro
25 26
 */
27
@SuppressWarnings("UseSpecificCatch")
26 28
public class AdvancedAttributeSelectionTreeModel
27 29
        implements TreeModel {
28 30

  
......
31 33
        public FeatureStore getFeatureStore();
32 34
        public boolean isRoot();
33 35
        public boolean isLeaf();
34
        public List<Node> getChilds();
36
        public List<Node> getChildren();
35 37
    }
36 38

  
37 39
    private class DefaultNode
......
57 59
        }
58 60

  
59 61
        @Override
62
        public String getLabel() {
63
            FeatureAttributeDescriptor attrdesc = this.getValue();
64
            if( attrdesc!=null && attrdesc.isForeingKey() ) {
65
                ForeingKey foreingKey = attrdesc.getForeingKey();
66
                return String.format("%s [%s]", super.getLabel(), foreingKey.getTableName());
67
            }
68
            return super.getLabel();
69
        }
70

  
71
        @Override
60 72
        public FeatureStore getFeatureStore() {
61 73
            return this.store;
62 74
        }
......
67 79
        }
68 80

  
69 81
        @Override
70
        public List<Node> getChilds() {
82
        public List<Node> getChildren() {
71 83
            if (this.childs == null) {
72 84
                if (this.getValue().isForeingKey()) {
73 85
                    ForeingKey foreingKey = this.getValue().getForeingKey();
......
84 96
                                Search.COMPLEMENT_MANE, featureType
85 97
                        );
86 98
                        List<FeatureAttributeDescriptor> attributes = featureTypeSearch.getOrderedAttributes(
87
                                Search.BASIC_TYPES_FILTER,
99
                                filterByDataType,
88 100
                                Search.LABEL_ORDER,
89 101
                                -1
90 102
                        );
......
102 114

  
103 115
        @Override
104 116
        public boolean isLeaf() {
105
            return this.getChilds().isEmpty();
117
            return this.getChildren().isEmpty();
106 118
        }
107 119
    }
108 120

  
109 121
    private final Set<String> stores;
110 122
    private final DefaultNode root;
123
    private final Predicate<FeatureAttributeDescriptor> filterByDataType;
111 124

  
112
    public AdvancedAttributeSelectionTreeModel(FeatureStore store, List<FeatureAttributeDescriptor> attributes) {
125
    public AdvancedAttributeSelectionTreeModel(FeatureStore store, Predicate<FeatureAttributeDescriptor> filterByDataType) {
126
        if( filterByDataType == null ) {
127
            this.filterByDataType = Search.ALL_FILTER;
128
        } else {
129
            this.filterByDataType = filterByDataType;
130
        }
131
        FeatureType featureType;
132
        try {
133
            featureType = store.getDefaultFeatureType();
134
        } catch (Exception ex) {
135
            throw new RuntimeException("Can't access attributes of store", ex);
136
        }
137
        Search featureTypeSearch = (Search) ToolsLocator.getComplementsManager().get(
138
                Search.COMPLEMENT_MANE, featureType
139
        );
140
        List<FeatureAttributeDescriptor> attributes = featureTypeSearch.getOrderedAttributes(
141
                filterByDataType,
142
                Search.LABEL_ORDER,
143
                -1
144
        );
113 145
        this.root = new DefaultNode(store, attributes);
114 146
        this.stores = new HashSet<>();
115 147
    }
......
122 154
    @Override
123 155
    public int getChildCount(Object parent) {
124 156
        DefaultNode node = (DefaultNode) parent;
125
        return node.getChilds().size();
157
        return node.getChildren().size();
126 158
    }
127 159

  
128 160
    @Override
129 161
    public Object getChild(Object parent, int index) {
130 162
        DefaultNode node = (DefaultNode) parent;
131
        return node.getChilds().get(index);
163
        return node.getChildren().get(index);
132 164
    }
133 165

  
134 166
    @Override
......
142 174
            DefaultNode parantNode = (DefaultNode) parent;
143 175
            DefaultNode childNode = (DefaultNode) child;
144 176
            int index = 0;
145
            for (Node node : parantNode.getChilds()) {
177
            for (Node node : parantNode.getChildren()) {
146 178
                if (StringUtils.equalsIgnoreCase(childNode.getValue().getName(), node.getValue().getName())) {
147 179
                    return index;
148 180
                }

Also available in: Unified diff