svn-gvsig-desktop / 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 / DefaultFeatureAttributeSelectionPanel.java @ 46501
History | View | Annotate | Download (4.83 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.featuretype; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeSelectionPanel; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ComponentAdapter; |
6 |
import java.awt.event.ComponentEvent; |
7 |
import java.net.URL; |
8 |
import java.util.function.Predicate; |
9 |
import javax.swing.ImageIcon; |
10 |
import javax.swing.JComponent; |
11 |
import javax.swing.tree.TreePath; |
12 |
import org.apache.commons.io.FilenameUtils; |
13 |
import org.gvsig.fmap.dal.complements.Search; |
14 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
15 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
17 |
import org.gvsig.fmap.dal.feature.FeatureType; |
18 |
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTreeModel.Node; |
19 |
import org.gvsig.timesupport.DataTypes; |
20 |
import org.gvsig.tools.dispose.Disposable; |
21 |
import org.gvsig.tools.swing.api.FilteredTreeController; |
22 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
23 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
24 |
|
25 |
/**
|
26 |
*
|
27 |
* @author jjdelcerro
|
28 |
*/
|
29 |
public class DefaultFeatureAttributeSelectionPanel |
30 |
extends DefaultFeatureAttributeSelectionPanelView
|
31 |
implements FeatureAttributeSelectionPanel {
|
32 |
|
33 |
private final FeatureStore store; |
34 |
private FilteredTreeController controllerFilter;
|
35 |
private final FeatureType ftype; |
36 |
private FeatureQuery query;
|
37 |
|
38 |
public DefaultFeatureAttributeSelectionPanel(FeatureStore store, FeatureType ftype, FeatureQuery query) {
|
39 |
this.store = store;
|
40 |
this.ftype = ftype;
|
41 |
this.query = query;
|
42 |
this.initComponents();
|
43 |
} |
44 |
|
45 |
public DefaultFeatureAttributeSelectionPanel(FeatureStore store, FeatureType ftype) {
|
46 |
this(store, ftype, null); |
47 |
} |
48 |
|
49 |
private void initComponents() { |
50 |
FeatureAttributeTreeModel treeModel = new FeatureAttributeTreeModel(
|
51 |
this.store,
|
52 |
this.ftype,
|
53 |
true,
|
54 |
Search.BASIC_TYPES_FILTER.or((FeatureAttributeDescriptor t) -> t.getType()==DataTypes.LIST), |
55 |
this.query
|
56 |
); |
57 |
this.treeFields.setCellRenderer(new FeatureAttributeTreeCellRenderer()); |
58 |
this.treeFields.setModel(treeModel);
|
59 |
try {
|
60 |
this.treeFields.setSelectionRow(1); |
61 |
} catch (Throwable th) { |
62 |
} |
63 |
|
64 |
Dimension sz = this.getPreferredSize(); |
65 |
if (sz.width < DEFAULT_WIDTH) {
|
66 |
sz.width = DEFAULT_WIDTH; |
67 |
} |
68 |
if (sz.height < DEFAULT_HEIGHT) {
|
69 |
sz.height = DEFAULT_HEIGHT; |
70 |
} |
71 |
this.controllerFilter = ToolsSwingLocator
|
72 |
.getToolsSwingManager() |
73 |
.createFilteredTreeController(treeFields, txtFilter, btnFilter); |
74 |
|
75 |
this.setPreferredSize(sz);
|
76 |
this.addComponentListener(new ComponentAdapter() { |
77 |
@Override
|
78 |
public void componentHidden(ComponentEvent ce) { |
79 |
super.componentHidden(ce);
|
80 |
if(treeFields instanceof Disposable) { |
81 |
((Disposable)treeFields).dispose(); |
82 |
} |
83 |
} |
84 |
}); |
85 |
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Return a TreePath<FeatureAttributeTreeModel.Node> for the selected
|
90 |
* attribute.
|
91 |
*
|
92 |
* @return
|
93 |
*/
|
94 |
@Override
|
95 |
public FeatureAttributeDescriptor[] getSelectedPath() { |
96 |
TreePath path = this.treeFields.getSelectionPath(); |
97 |
FeatureAttributeDescriptor[] attrs = new FeatureAttributeDescriptor[path.getPathCount()-1]; |
98 |
for (int i = 0; i < attrs.length; i++) { |
99 |
Node node = (Node) path.getPathComponent(i+1); // Saltamos el 0 que es el store |
100 |
attrs[i] = node.getValue(); |
101 |
} |
102 |
return attrs;
|
103 |
} |
104 |
|
105 |
@Override
|
106 |
public FeatureAttributeDescriptor getSelectedAttributeDescriptor() {
|
107 |
Node node = (Node) this.treeFields.getSelectionPath().getLastPathComponent();
|
108 |
FeatureAttributeDescriptor attrdesc = node.getValue(); |
109 |
return attrdesc;
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
public FeatureStore getSelectedStore() {
|
114 |
Node node = (Node) this.treeFields.getSelectionPath().getLastPathComponent();
|
115 |
FeatureStore theStore = node.getFeatureStore(); |
116 |
return theStore;
|
117 |
} |
118 |
|
119 |
@Override
|
120 |
public String getSelectedName() { |
121 |
return this.getSelectedAttributeDescriptor().getName(); |
122 |
} |
123 |
|
124 |
@Override
|
125 |
public JComponent asJComponent() { |
126 |
return this; |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public ImageIcon loadImage(String imageName) { |
131 |
String name = FilenameUtils.getBaseName(imageName);
|
132 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
133 |
if (theme.exists(name)) {
|
134 |
return theme.get(name);
|
135 |
} |
136 |
URL url = this.getClass().getResource(name + ".png"); |
137 |
if (url == null) { |
138 |
return null; |
139 |
} |
140 |
return new ImageIcon(url); |
141 |
} |
142 |
|
143 |
public static void selfRegister() { |
144 |
// String[][] iconNames = new String[][]{
|
145 |
//// new String[]{"dalswing", "common-filter"},
|
146 |
// };
|
147 |
// IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
|
148 |
// for (String[] icon : iconNames) {
|
149 |
// URL url = DefaultFeatureAttributeSelectionPanel.class.getResource(icon[1] + ".png");
|
150 |
// theme.registerDefault("DALSwing", icon[0], icon[1], null, url);
|
151 |
// }
|
152 |
} |
153 |
} |