svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / select / SelectRowPanel.java @ 38032
History | View | Annotate | Download (8.07 KB)
1 |
package org.gvsig.editing.gui.cad.tools.select; |
---|---|
2 |
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government
|
4 |
*
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
6 |
* of the Valencian Government (CIT)
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
21 |
* MA 02110-1301, USA.
|
22 |
*
|
23 |
*/
|
24 |
|
25 |
/*
|
26 |
* AUTHORS (In addition to CIT):
|
27 |
* 2009 IVER T.I. S.A. {{Task}}
|
28 |
*/
|
29 |
|
30 |
import java.awt.BorderLayout; |
31 |
import java.awt.Color; |
32 |
import java.awt.Dimension; |
33 |
import java.awt.FlowLayout; |
34 |
import java.awt.event.ActionEvent; |
35 |
import java.awt.event.ActionListener; |
36 |
import java.util.ArrayList; |
37 |
|
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JScrollPane; |
42 |
import javax.swing.ListSelectionModel; |
43 |
import javax.swing.table.AbstractTableModel; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
47 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
48 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
49 |
import org.gvsig.fmap.dal.exception.DataException; |
50 |
import org.gvsig.fmap.dal.exception.ReadException; |
51 |
import org.gvsig.fmap.dal.feature.Feature; |
52 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
53 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
54 |
import org.gvsig.fmap.dal.feature.FeatureType; |
55 |
import org.gvsig.tools.dispose.DisposableIterator; |
56 |
import org.gvsig.tools.dispose.DisposeUtils; |
57 |
import org.gvsig.utils.swing.jtable.JTable; |
58 |
/**
|
59 |
*
|
60 |
* @author Vicente Caballero Navarro
|
61 |
*
|
62 |
*/
|
63 |
public class SelectRowPanel extends JPanel implements IWindow { |
64 |
|
65 |
private static final long serialVersionUID = 1L; |
66 |
|
67 |
private JPanel jTablePanel; |
68 |
private JPanel buttonsPanel; |
69 |
private JScrollPane scrollPane; |
70 |
private JButton accept, cancel; |
71 |
private JTable jTable; |
72 |
private MyTableModel tableModel;
|
73 |
private MyActionListener action;
|
74 |
|
75 |
private ArrayList<Feature> features=new ArrayList<Feature>(); |
76 |
|
77 |
private VectorialLayerEdited vle;
|
78 |
private FeatureType featureType;
|
79 |
|
80 |
public SelectRowPanel(FeatureSet featureSet, VectorialLayerEdited vle) throws ReadException, DataException { |
81 |
super();
|
82 |
this.vle = vle;
|
83 |
featureType = featureSet.getDefaultFeatureType(); |
84 |
DisposableIterator iterator = null;
|
85 |
try {
|
86 |
iterator = featureSet.iterator(); |
87 |
while (iterator.hasNext()) {
|
88 |
Feature feature = (Feature) iterator.next(); |
89 |
features.add(feature); |
90 |
} |
91 |
} finally {
|
92 |
DisposeUtils.dispose(iterator); |
93 |
} |
94 |
action = new MyActionListener();
|
95 |
initialize(); |
96 |
} |
97 |
|
98 |
private void initialize() { |
99 |
Dimension preferred = new Dimension(400, 150); |
100 |
this.setSize(preferred);
|
101 |
this.setPreferredSize(preferred);
|
102 |
this.setLayout(new BorderLayout()); |
103 |
this.add(getScrollPane(), BorderLayout.CENTER); |
104 |
this.add(getButtonsPanel(), BorderLayout.SOUTH); |
105 |
} |
106 |
|
107 |
private JPanel getTablePanel() { |
108 |
if (jTablePanel == null) { |
109 |
jTablePanel = new JPanel(new BorderLayout()); |
110 |
jTablePanel.setSize(new Dimension(400, 150)); |
111 |
jTablePanel.add(getTable().getTableHeader(), BorderLayout.NORTH);
|
112 |
jTablePanel.add(getTable(), BorderLayout.CENTER);
|
113 |
} |
114 |
return jTablePanel;
|
115 |
} |
116 |
|
117 |
private JScrollPane getScrollPane() { |
118 |
if (scrollPane == null) { |
119 |
scrollPane = new JScrollPane(); |
120 |
scrollPane.setViewportView(getTablePanel()); |
121 |
} |
122 |
return scrollPane;
|
123 |
} |
124 |
|
125 |
private JPanel getButtonsPanel() { |
126 |
if (buttonsPanel == null) { |
127 |
buttonsPanel = new JPanel(new FlowLayout()); |
128 |
buttonsPanel.add(getButtonAceptar()); |
129 |
buttonsPanel.add(getButtonCancelar()); |
130 |
} |
131 |
return buttonsPanel;
|
132 |
} |
133 |
|
134 |
private JButton getButtonAceptar() { |
135 |
if (accept == null) { |
136 |
accept = new JButton(); |
137 |
accept.setText(PluginServices.getText(this, "accept")); |
138 |
accept.addActionListener(action); |
139 |
} |
140 |
return accept;
|
141 |
} |
142 |
|
143 |
private JButton getButtonCancelar() { |
144 |
if (cancel == null) { |
145 |
cancel = new JButton(); |
146 |
cancel.setText(PluginServices.getText(this, "cancel")); |
147 |
cancel.addActionListener(action); |
148 |
} |
149 |
return cancel;
|
150 |
} |
151 |
|
152 |
@SuppressWarnings("unchecked") |
153 |
private JTable getTable() { |
154 |
if (jTable == null) { |
155 |
|
156 |
jTable = new JTable(); |
157 |
tableModel = new MyTableModel(features);
|
158 |
jTable.setModel(tableModel); |
159 |
jTable.setSelectionBackground(Color.yellow);
|
160 |
jTable.setSelectionForeground(Color.blue);
|
161 |
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
162 |
|
163 |
jTable.setCellSelectionEnabled(false);
|
164 |
jTable.setRowSelectionAllowed(true);
|
165 |
jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
166 |
} |
167 |
return jTable;
|
168 |
} |
169 |
|
170 |
/** ******************************************************* */
|
171 |
/** ******************** IWindow ************************** */
|
172 |
/** ******************************************************* */
|
173 |
|
174 |
public WindowInfo getWindowInfo() {
|
175 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG);
|
176 |
wi.setTitle(PluginServices.getText(this, "select_rows")); |
177 |
wi.setWidth(this.getWidth());
|
178 |
wi.setHeight(this.getHeight());
|
179 |
return wi;
|
180 |
} |
181 |
|
182 |
/** ******************************************************* */
|
183 |
/** ***************** ActionListener ********************** */
|
184 |
/** ******************************************************* */
|
185 |
private class MyActionListener implements ActionListener { |
186 |
|
187 |
public void actionPerformed(ActionEvent e) { |
188 |
FeatureSelection rowSelecteds; |
189 |
try {
|
190 |
|
191 |
if (e.getSource().equals(accept)) {
|
192 |
rowSelecteds = vle.getFeatureStore().getFeatureSelection(); |
193 |
rowSelecteds.deselectAll(); |
194 |
int[] index = jTable.getSelectedRows(); |
195 |
if (index.length > 0) { |
196 |
for (int i = 0; i < index.length; i++) { |
197 |
Feature sl = features.get(index[i]); |
198 |
rowSelecteds.select(sl); |
199 |
} |
200 |
// vle.getFeatureStore().setSelection(rowSelecteds);
|
201 |
PluginServices.getMDIManager().closeWindow( |
202 |
SelectRowPanel.this); |
203 |
} else {
|
204 |
JOptionPane.showMessageDialog(null, PluginServices.getText( |
205 |
this, "select_one_row"), PluginServices.getText( |
206 |
this, "attention"), JOptionPane.WARNING_MESSAGE); |
207 |
} |
208 |
} |
209 |
} catch (ReadException e1) {
|
210 |
e1.printStackTrace(); |
211 |
} catch (DataException e1) {
|
212 |
e1.printStackTrace(); |
213 |
} |
214 |
if (e.getSource().equals(cancel)) {
|
215 |
PluginServices.getMDIManager().closeWindow(SelectRowPanel.this); |
216 |
} |
217 |
} |
218 |
} |
219 |
|
220 |
/** ******************************************************* */
|
221 |
/** ******************* TableModel ************************ */
|
222 |
/** ******************************************************* */
|
223 |
private class MyTableModel extends AbstractTableModel { |
224 |
|
225 |
private static final long serialVersionUID = 1L; |
226 |
|
227 |
private ArrayList<Feature> features; |
228 |
|
229 |
public void setSelectedSymbols(ArrayList<Feature> rs) { |
230 |
features = rs; |
231 |
fireTableDataChanged(); |
232 |
} |
233 |
|
234 |
public MyTableModel(ArrayList<Feature> rs) { |
235 |
features = rs; |
236 |
} |
237 |
|
238 |
public ArrayList<Feature> getSymbolsList() { |
239 |
return features;
|
240 |
} |
241 |
|
242 |
public int getRowCount() { |
243 |
return features.size();
|
244 |
} |
245 |
|
246 |
public int getColumnCount() { |
247 |
return featureType.size();
|
248 |
} |
249 |
|
250 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
251 |
return false; |
252 |
} |
253 |
|
254 |
public Object getValueAt(int rowIndex, int columnIndex) { |
255 |
Feature r = (Feature) features.get(rowIndex); |
256 |
String s = r.get(columnIndex).toString();
|
257 |
return s;
|
258 |
} |
259 |
|
260 |
@SuppressWarnings("unchecked") |
261 |
public Class getColumnClass(int columnIndex) { |
262 |
return String.class; |
263 |
} |
264 |
|
265 |
public String getColumnName(int columnIndex) { |
266 |
return featureType.getAttributeDescriptor(columnIndex).getName();
|
267 |
} |
268 |
} |
269 |
|
270 |
public Object getWindowProfile() { |
271 |
return WindowInfo.DIALOG_PROFILE;
|
272 |
} |
273 |
} |