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