Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / dal / expresionPanel / ExpresionPanel.java @ 41665

History | View | Annotate | Download (5.14 KB)

1

    
2
package org.gvsig.fmap.mapcontrol.dal.expresionPanel;
3

    
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6
import java.util.Map;
7
import javax.swing.ListModel;
8
import javax.swing.event.ListDataListener;
9
import javax.swing.event.ListSelectionEvent;
10
import javax.swing.event.ListSelectionListener;
11
import org.apache.commons.lang3.StringUtils;
12
import org.gvsig.fmap.dal.exception.DataException;
13
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
14
import org.gvsig.fmap.dal.feature.FeatureStore;
15
import org.gvsig.fmap.dal.feature.FeatureType;
16
import org.gvsig.tools.swing.api.ToolsSwingLocator;
17
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

    
21

    
22
public class ExpresionPanel extends ExpresionPanelLayout {
23
    
24
    private static final Logger logger = LoggerFactory.getLogger(ExpresionPanel.class);
25
            
26
    private FeatureStore store;
27
    private Map values;
28
    private boolean okCancelVisible = true;
29
    private boolean isCanceled;
30

    
31
    private static class FeatureTypeListModel implements ListModel {
32
        private final FeatureType featureType;
33

    
34
        public FeatureTypeListModel(FeatureType featureType) {
35
            this.featureType = featureType;
36
        }
37
        public int getSize() {
38
            return this.featureType.size();
39
        }
40

    
41
        public Object getElementAt(int index) {
42
            return this.featureType.get(index);
43
        }
44

    
45
        public void addListDataListener(ListDataListener l) {
46
            
47
        }
48

    
49
        public void removeListDataListener(ListDataListener l) {
50
            
51
        }
52
        
53
    }
54
    
55
    public ExpresionPanel(FeatureStore store) {
56
        this.isCanceled = false;
57
        this.initComponents();
58
    }
59
    
60
    public void setFeatureStore(FeatureStore store) {
61
        this.store = store;
62
        try {
63
            this.lstFields.setModel(new FeatureTypeListModel(this.store.getDefaultFeatureType()));
64
        } catch (DataException ex) {
65
            logger.warn("Can't create model for field list.",ex);
66
        }
67
    }
68
    
69
    public void setOkCancelVisible(boolean acceptVisible) {
70
        this.okCancelVisible = acceptVisible;
71
    }
72
    
73
    public boolean getOkCancelVisible() {
74
        return this.okCancelVisible;
75
    }
76
    
77
    private void initComponents() {
78
        this.butAccept.setVisible(this.okCancelVisible);
79
        
80
        this.lstFields.addListSelectionListener(new ListSelectionListener() {
81
            public void valueChanged(ListSelectionEvent e) {
82
                doSelectField();
83
            }
84
        });
85
        this.lstValues.addListSelectionListener(new ListSelectionListener() {
86
            public void valueChanged(ListSelectionEvent e) {
87
                doSelectValue();
88
            }
89
        });
90
        ActionListener action = new ActionListener() {
91
            public void actionPerformed(ActionEvent e) {
92
                doInsert(e.getActionCommand()+" ");
93
            }
94
        };
95
        this.butAnd.addActionListener(action);
96
        this.butOr.addActionListener(action);
97
        this.butNot.addActionListener(action);
98
        this.butEq.addActionListener(action);
99
        this.butNe.addActionListener(action);
100
        this.butGt.addActionListener(action);
101
        this.butLt.addActionListener(action);
102
        this.butGe.addActionListener(action);
103
        this.butLe.addActionListener(action);
104
        
105
        this.butClear.addActionListener(new ActionListener() {
106
            public void actionPerformed(ActionEvent e) {
107
                doClear();
108
            }
109
        });
110
    
111
        this.butAccept.addActionListener(new ActionListener() {
112
            public void actionPerformed(ActionEvent e) {
113
                doAcept();
114
            }
115
        });
116

    
117
        this.butCancel.addActionListener(new ActionListener() {
118
            public void actionPerformed(ActionEvent e) {
119
                doCancel();
120
            }
121
        });
122

    
123
    }
124

    
125
    public boolean isCanceled() {
126
        return this.isCanceled;
127
    }
128
    
129
    public String getExpresion() {
130
        return StringUtils.defaultIfBlank(this.txtExpresion.getText(), null);
131
    }
132
    
133
    public void showAsDialog(String title) {
134
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
135
        winmgr.showWindow(this, title, WindowManager.MODE.DIALOG);
136
    }
137
    
138
    private void doAcept() {
139
        this.isCanceled=false;
140
        this.setVisible(false);
141
    }
142

    
143
    private void doCancel() {
144
        this.isCanceled=true;
145
        this.setVisible(false);
146
    }
147

    
148
    private void doSelectField() {
149
        FeatureAttributeDescriptor x = (FeatureAttributeDescriptor) this.lstFields.getSelectedValue();
150
        if( x == null ) {
151
            return;
152
        }
153
        this.doInsert(x.getName());
154
        this.doInsert(" ");
155
        this.fillValuesList(x.getName());
156
    }
157

    
158
    private void doClear() {
159
        this.txtExpresion.setText("");
160
    }
161

    
162
    private void doSelectValue() {
163
        // TODO: falta por implemetar doSelectValue
164
    }
165

    
166
    private void doInsert(String s) {
167
        this.txtExpresion.insert(s, this.txtExpresion.getCaretPosition());
168
    }
169

    
170
    private void fillValuesList(String name) {
171
        // TODO: falta por implemetar fillValuesList
172
    }
173
    
174

    
175
}