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