Statistics
| Revision:

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 @ 44744

History | View | Annotate | Download (3.98 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 java.util.function.Predicate;
7
import javax.swing.ImageIcon;
8
import javax.swing.JComponent;
9
import javax.swing.tree.TreePath;
10
import org.apache.commons.io.FilenameUtils;
11
import org.gvsig.fmap.dal.complements.Search;
12
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
13
import org.gvsig.fmap.dal.feature.FeatureStore;
14
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTreeModel.Node;
15
import org.gvsig.timesupport.DataTypes;
16
import org.gvsig.tools.swing.api.FilteredTreeController;
17
import org.gvsig.tools.swing.api.ToolsSwingLocator;
18
import org.gvsig.tools.swing.icontheme.IconTheme;
19

    
20
/**
21
 *
22
 * @author jjdelcerro
23
 */
24
public class DefaultFeatureAttributeSelectionPanel
25
        extends DefaultFeatureAttributeSelectionPanelView
26
        implements FeatureAttributeSelectionPanel {
27

    
28
  private final FeatureStore store;
29
    private FilteredTreeController controllerFilter;
30

    
31
  public DefaultFeatureAttributeSelectionPanel(FeatureStore store) {
32
    this.store = store;
33
    this.initComponents();
34
  }
35

    
36
  private void initComponents() {
37
    FeatureAttributeTreeModel treeModel = new FeatureAttributeTreeModel(
38
            this.store,
39
            true,
40
            Search.BASIC_TYPES_FILTER.or((FeatureAttributeDescriptor t) -> t.getType()==DataTypes.LIST)
41
    );
42
    this.treeFields.setCellRenderer(new FeatureAttributeTreeCellRenderer());
43
    this.treeFields.setModel(treeModel);
44
    try {
45
      this.treeFields.setSelectionRow(1);
46
    } catch (Throwable th) {
47
    }
48

    
49
    Dimension sz = this.getPreferredSize();
50
    if (sz.width < DEFAULT_WIDTH) {
51
      sz.width = DEFAULT_WIDTH;
52
    }
53
    if (sz.height < DEFAULT_HEIGHT) {
54
      sz.height = DEFAULT_HEIGHT;
55
    }
56
    this.controllerFilter = ToolsSwingLocator
57
              .getToolsSwingManager()
58
              .createFilteredTreeController(treeFields, txtFilter, btnFilter);
59
    
60
    this.setPreferredSize(sz);
61
    
62
  }
63

    
64
  /**
65
   * Return a TreePath<FeatureAttributeTreeModel.Node> for the selected
66
   * attribute.
67
   *
68
   * @return
69
   */
70
  @Override
71
  public FeatureAttributeDescriptor[] getSelectedPath() {
72
    TreePath path = this.treeFields.getSelectionPath();
73
    FeatureAttributeDescriptor[] attrs = new FeatureAttributeDescriptor[path.getPathCount()-1];
74
    for (int i = 0; i < attrs.length; i++) {
75
      Node node = (Node) path.getPathComponent(i+1); // Saltamos el 0 que es el store
76
      attrs[i] = node.getValue();
77
    }
78
    return attrs;
79
  }
80

    
81
  @Override
82
  public FeatureAttributeDescriptor getSelectedAttributeDescriptor() {
83
    Node node = (Node) this.treeFields.getSelectionPath().getLastPathComponent();
84
    FeatureAttributeDescriptor attrdesc = node.getValue();
85
    return attrdesc;
86
  }
87

    
88
  @Override
89
  public FeatureStore getSelectedStore() {
90
    Node node = (Node) this.treeFields.getSelectionPath().getLastPathComponent();
91
    FeatureStore theStore = node.getFeatureStore();
92
    return theStore;
93
  }
94

    
95
  @Override
96
  public String getSelectedName() {
97
    return this.getSelectedAttributeDescriptor().getName();
98
  }
99
  
100
  @Override
101
  public JComponent asJComponent() {
102
    return this;
103
  }
104

    
105
  @Override
106
  public ImageIcon loadImage(String imageName) {
107
    String name = FilenameUtils.getBaseName(imageName);
108
    IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault();
109
    if (theme.exists(name)) {
110
      return theme.get(name);
111
    }
112
    URL url = this.getClass().getResource(name + ".png");
113
    if (url == null) {
114
      return null;
115
    }
116
    return new ImageIcon(url);
117
  }
118

    
119
  public static void selfRegister() {
120
    String[][] iconNames = new String[][]{
121
      new String[]{"dalswing", "common-filter"},};
122
    IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
123
    for (String[] icon : iconNames) {
124
      URL url = DefaultFeatureAttributeSelectionPanel.class.getResource(icon[1] + ".png");
125
      theme.registerDefault("DALSwing", icon[0], icon[1], null, url);
126
    }
127
  }
128
}