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