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 / featureform / swing / impl / dynformset / FeatureTableJDynFormSet.java @ 44253

History | View | Annotate | Download (9.89 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.featureform.swing.impl.dynformset;
24

    
25
import java.awt.Dimension;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ActionEvent;
29
import java.util.List;
30
import javax.swing.Action;
31
import javax.swing.Box.Filler;
32
import javax.swing.JButton;
33

    
34
import javax.swing.JComponent;
35
import javax.swing.JPanel;
36
import org.gvsig.fmap.dal.swing.DALSwingLocator;
37
import org.gvsig.fmap.dal.swing.FeatureTableModel;
38
import org.gvsig.fmap.dal.swing.JFeatureTable;
39
import org.gvsig.tools.dynform.DynFormDefinition;
40
import org.gvsig.tools.dynform.JDynForm.DynFormContext;
41
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
42
import org.gvsig.tools.dynform.spi.dynformset.AbstractJDynFormSet;
43
import org.gvsig.tools.dynform.spi.dynformset.JDynFormSetFactory;
44
import org.gvsig.tools.dynobject.DynObjectSet;
45
import org.gvsig.tools.dynobject.Tags;
46
import org.gvsig.tools.service.ServiceException;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

    
50
public class FeatureTableJDynFormSet extends AbstractJDynFormSet  {
51

    
52
    private static final Logger logger = LoggerFactory.getLogger(FeatureTableJDynFormSet.class);
53

    
54
    private int current = 0;
55
    
56
    private JButton btnModify;
57
    private JButton btnNew;
58
    private JButton btnRemove;
59
    private JButton btnSelect;
60
    private JButton btnShow;
61
    private Filler filler1;
62
    private Filler filler2;
63
    private JFeatureTable table = null;
64
    private FeatureTableModel tableModel = null;
65

    
66
    public FeatureTableJDynFormSet(
67
            DynFormSPIManager manager, 
68
            JDynFormSetFactory factory,
69
            DynFormContext context,
70
            DynFormDefinition definition,
71
            Tags contextTags
72
        ) {
73
        super(manager, factory, context, definition, contextTags);
74
    }
75

    
76
    @Override
77
    public JComponent asJComponent() {
78
        if (this.contents == null) {
79
            try {
80
                this.initComponents();
81
            } catch (ServiceException e) {
82
                throw new RuntimeException(e.getLocalizedMessage(), e);
83
            }
84
        }
85
        this.fireFormMovedToEvent(current);
86
        return this.contents;
87
    }
88

    
89
    private void initComponents() throws ServiceException {
90
        JPanel panel = new JPanel();
91
        GridBagConstraints gridBagConstraints;
92

    
93
        filler1 = new Filler(new Dimension(5, 5), new Dimension(5, 5), new Dimension(5, 5));
94
        this.tableModel = DALSwingLocator.getSwingManager().createEmptyFeatureTableModel(this.getDefinition().getElementsType());
95
        this.table = DALSwingLocator.getSwingManager().createJFeatureTable(tableModel);
96
        btnNew = new JButton();
97
        btnShow = new JButton();
98
        btnModify = new JButton();
99
        btnRemove = new JButton();
100
        btnSelect = new JButton();
101
        filler2 = new Filler(new Dimension(5, 5), new Dimension(5, 5), new Dimension(5, 5));
102
        
103

    
104
        GridBagLayout layout = new GridBagLayout();
105
        layout.columnWidths = new int[] {0, 5, 0, 5, 0, 5, 0};
106
        layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0};
107
        panel.setLayout(layout);
108

    
109
        gridBagConstraints = new GridBagConstraints();
110
        gridBagConstraints.gridx = 2;
111
        gridBagConstraints.gridy = 2;
112
        gridBagConstraints.gridheight = 11;
113
        gridBagConstraints.fill = GridBagConstraints.BOTH;
114
        gridBagConstraints.weightx = 1.0;
115
        gridBagConstraints.weighty = 1.0;
116
        panel.add(table.asJComponent(), gridBagConstraints);
117

    
118
        btnNew.setText("_nuevo");
119
        btnNew.addActionListener(new java.awt.event.ActionListener() {
120
            @Override
121
            public void actionPerformed(ActionEvent evt) {
122
                btnNewActionPerformed(evt);
123
            }
124
        });
125
        gridBagConstraints = new GridBagConstraints();
126
        gridBagConstraints.gridx = 4;
127
        gridBagConstraints.gridy = 2;
128
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
129
        panel.add(btnNew, gridBagConstraints);
130

    
131
        btnShow.setText("_mostrar");
132
        btnShow.addActionListener(new java.awt.event.ActionListener() {
133
            @Override
134
            public void actionPerformed(ActionEvent evt) {
135
                btnShowActionPerformed(evt);
136
            }
137
        });
138
        gridBagConstraints = new GridBagConstraints();
139
        gridBagConstraints.gridx = 4;
140
        gridBagConstraints.gridy = 4;
141
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
142
        panel.add(btnShow, gridBagConstraints);
143

    
144
        btnModify.setText("_modificar");
145
        btnModify.addActionListener(new java.awt.event.ActionListener() {
146
            @Override
147
            public void actionPerformed(ActionEvent evt) {
148
                btnModifyActionPerformed(evt);
149
            }
150
        });
151
        gridBagConstraints = new GridBagConstraints();
152
        gridBagConstraints.gridx = 4;
153
        gridBagConstraints.gridy = 6;
154
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
155
        panel.add(btnModify, gridBagConstraints);
156

    
157
        btnRemove.setText("_eliminar");
158
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
159
            @Override
160
            public void actionPerformed(ActionEvent evt) {
161
                btnRemoveActionPerformed(evt);
162
            }
163
        });
164
        gridBagConstraints = new GridBagConstraints();
165
        gridBagConstraints.gridx = 4;
166
        gridBagConstraints.gridy = 8;
167
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
168
        panel.add(btnRemove, gridBagConstraints);
169
        gridBagConstraints = new GridBagConstraints();
170
        gridBagConstraints.gridx = 6;
171
        gridBagConstraints.gridy = 14;
172
        panel.add(filler1, gridBagConstraints);
173

    
174
        btnSelect.setText("_seleccionar");
175
        btnSelect.addActionListener(new java.awt.event.ActionListener() {
176
            @Override
177
            public void actionPerformed(ActionEvent evt) {
178
                btnSelectActionPerformed(evt);
179
            }
180
        });
181
        gridBagConstraints = new GridBagConstraints();
182
        gridBagConstraints.gridx = 4;
183
        gridBagConstraints.gridy = 10;
184
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
185
        panel.add(btnSelect, gridBagConstraints);
186
        gridBagConstraints = new GridBagConstraints();
187
        gridBagConstraints.gridx = 0;
188
        gridBagConstraints.gridy = 0;
189
        panel.add(filler2, gridBagConstraints);
190
    }
191

    
192
    private void btnShowActionPerformed(ActionEvent evt) {                                        
193

    
194
    }                                       
195

    
196
    private void btnNewActionPerformed(ActionEvent evt) {                                       
197

    
198
    }                                      
199

    
200
    private void btnModifyActionPerformed(ActionEvent evt) {                                          
201

    
202
    }                                         
203

    
204
    private void btnRemoveActionPerformed(ActionEvent evt) {                                          
205

    
206
    }                                         
207

    
208
    private void btnSelectActionPerformed(ActionEvent evt) {                                          
209

    
210
    }    
211
    
212
    @Override
213
    public void setValues(List values) {
214
        super.setValues(values);
215
        if (this.contents != null) {
216
            doChangeValues();
217
        }
218
    }
219

    
220
    @Override
221
    public void setValues(DynObjectSet values) {
222
        super.setValues(values);
223
        if (this.contents != null) {
224
            doChangeValues();
225
        }
226
    }
227

    
228
    @Override
229
    public void setReadOnly(boolean readOnly) {
230
        super.setReadOnly(readOnly);
231
    }
232

    
233
    
234
    @Override
235
    public void setFormSize(int width, int height) {
236
        super.setFormSize(width, height);
237
    }
238

    
239
    @Override
240
    public int getCurrentIndex() {
241
        return this.current;
242
    }
243

    
244
    @Override
245
    public void setCurrentIndex(int index) {
246
        if (index < 0 || index > countValues()) {
247
            throw new IllegalArgumentException("Index (" + index + ") out of range [0.." + countValues() + "].");
248
        }
249
        this.table.setCurrent(this.current);
250
    }
251

    
252

    
253
    @Override
254
    public void addAction(Action action) {
255

    
256
    }
257

    
258
    @Override
259
    public void setActionEnabled(String action, boolean enabled) {
260
        logger.info("setActionEnabled not implemented over SimpleTableJDynFormSet.");
261
    }
262

    
263
    @Override
264
    public void setActionVisible(String action, boolean visible) {
265
        logger.info("setActionVisible not implemented over SimpleTableJDynFormSet.");
266
    }
267

    
268
    @Override
269
    public boolean isActionEnabled(String action) {
270
        logger.info("isActionEnabled not implemented over SimpleTableJDynFormSet.");
271
        return true;
272
    }
273

    
274
    @Override
275
    public boolean isActionVisible(String action) {
276
        logger.info("isActionVisible not implemented over SimpleTableJDynFormSet.");
277
        return true;
278
    }
279
    
280

    
281
    private void doChangeValues() {
282

    
283
    }
284

    
285
    @Override
286
    public boolean hasValidValues() {
287
        return true;
288
    }
289

    
290
    @Override
291
    public boolean hasValidValues(List<String> fieldsName) {
292
        return true;
293
    }
294

    
295
    @Override
296
    public List getValues() {
297
        return this.values;
298
    }
299

    
300

    
301
}