root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectableDataSource.java @ 884
History | View | Annotate | Download (5.32 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import com.hardcode.gdbms.engine.data.DataSource; |
4 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
5 |
import com.hardcode.gdbms.engine.data.DriverException; |
6 |
import com.hardcode.gdbms.engine.data.FieldNameAccess; |
7 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
8 |
import com.hardcode.gdbms.engine.data.ReadDriver; |
9 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
10 |
import com.hardcode.gdbms.engine.values.Value; |
11 |
import com.iver.utiles.XMLEntity; |
12 |
|
13 |
import java.io.IOException; |
14 |
import java.util.BitSet; |
15 |
import org.apache.log4j.Logger; |
16 |
|
17 |
|
18 |
/**
|
19 |
* DOCUMENT ME!
|
20 |
*
|
21 |
* @author Fernando Gonz?lez Cort?s
|
22 |
*/
|
23 |
public class SelectableDataSource implements DataSource { |
24 |
private static Logger logger = Logger.getLogger(SelectableDataSource.class.getName()); |
25 |
private String name; |
26 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
27 |
private DataSource dataSource; |
28 |
|
29 |
/**
|
30 |
* DOCUMENT ME!
|
31 |
*
|
32 |
* @param name DOCUMENT ME!
|
33 |
* @param ds
|
34 |
*/
|
35 |
public SelectableDataSource(String name, DataSource ds) { |
36 |
dataSource = ds; |
37 |
this.name = name;
|
38 |
} |
39 |
|
40 |
/**
|
41 |
* DOCUMENT ME!
|
42 |
*
|
43 |
* @param selectionSupport
|
44 |
*/
|
45 |
public void setSelectionSupport(SelectionSupport selectionSupport) { |
46 |
this.selectionSupport = selectionSupport;
|
47 |
} |
48 |
|
49 |
/**
|
50 |
* DOCUMENT ME!
|
51 |
*
|
52 |
* @return DOCUMENT ME!
|
53 |
*/
|
54 |
public String getDBMS() { |
55 |
return dataSource.getDBMS();
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* DOCUMENT ME!
|
60 |
*
|
61 |
* @return DOCUMENT ME!
|
62 |
*/
|
63 |
public ReadDriver getDriver() {
|
64 |
return dataSource.getDriver();
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* DOCUMENT ME!
|
69 |
*
|
70 |
* @return DOCUMENT ME!
|
71 |
*
|
72 |
* @throws DriverException DOCUMENT ME!
|
73 |
*/
|
74 |
public int getFieldCount() throws DriverException { |
75 |
return dataSource.getFieldCount();
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* DOCUMENT ME!
|
80 |
*
|
81 |
* @param arg0 DOCUMENT ME!
|
82 |
*
|
83 |
* @return DOCUMENT ME!
|
84 |
*
|
85 |
* @throws DriverException DOCUMENT ME!
|
86 |
* @throws FieldNotFoundException DOCUMENT ME!
|
87 |
*/
|
88 |
public int getFieldIndexByName(String arg0) |
89 |
throws DriverException, FieldNotFoundException {
|
90 |
return dataSource.getFieldIndexByName(arg0);
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* DOCUMENT ME!
|
95 |
*
|
96 |
* @param arg0 DOCUMENT ME!
|
97 |
*
|
98 |
* @return DOCUMENT ME!
|
99 |
*
|
100 |
* @throws DriverException DOCUMENT ME!
|
101 |
*/
|
102 |
public String getFieldName(int arg0) throws DriverException { |
103 |
return dataSource.getFieldName(arg0);
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* DOCUMENT ME!
|
108 |
*
|
109 |
* @param arg0 DOCUMENT ME!
|
110 |
* @param arg1 DOCUMENT ME!
|
111 |
*
|
112 |
* @return DOCUMENT ME!
|
113 |
*
|
114 |
* @throws DriverException DOCUMENT ME!
|
115 |
*/
|
116 |
public Value getFieldValue(long arg0, int arg1) throws DriverException { |
117 |
return dataSource.getFieldValue(arg0, arg1);
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* DOCUMENT ME!
|
122 |
*
|
123 |
* @return DOCUMENT ME!
|
124 |
*/
|
125 |
public String getName() { |
126 |
return dataSource.getName();
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* DOCUMENT ME!
|
131 |
*
|
132 |
* @return DOCUMENT ME!
|
133 |
*
|
134 |
* @throws DriverException DOCUMENT ME!
|
135 |
*/
|
136 |
public long getRowCount() throws DriverException { |
137 |
return dataSource.getRowCount();
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* DOCUMENT ME!
|
142 |
*
|
143 |
* @throws DriverException DOCUMENT ME!
|
144 |
*/
|
145 |
public void start() throws DriverException { |
146 |
logger.debug("dataSource.start()");
|
147 |
dataSource.start(); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* DOCUMENT ME!
|
152 |
*
|
153 |
* @throws DriverException DOCUMENT ME!
|
154 |
*/
|
155 |
public void stop() throws DriverException { |
156 |
logger.debug("dataSource.stop()");
|
157 |
dataSource.stop(); |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
162 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
163 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
164 |
* "r?faga" de eventos
|
165 |
*/
|
166 |
public void fireSelectionEvents() { |
167 |
selectionSupport.fireSelectionEvents(); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* DOCUMENT ME!
|
172 |
*
|
173 |
* @param listener DOCUMENT ME!
|
174 |
*/
|
175 |
public void addSelectionListener(SelectionListener listener) { |
176 |
selectionSupport.addSelectionListener(listener); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* DOCUMENT ME!
|
181 |
*
|
182 |
* @param listener DOCUMENT ME!
|
183 |
*/
|
184 |
public void removeSelectionListener(SelectionListener listener) { |
185 |
selectionSupport.removeSelectionListener(listener); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* DOCUMENT ME!
|
190 |
*/
|
191 |
public void clearSelection() { |
192 |
selectionSupport.clearSelection(); |
193 |
} |
194 |
|
195 |
/**
|
196 |
* DOCUMENT ME!
|
197 |
*
|
198 |
* @return DOCUMENT ME!
|
199 |
*/
|
200 |
public FBitSet getSelection() {
|
201 |
return selectionSupport.getSelection();
|
202 |
} |
203 |
public SelectionSupport getSelectionSupport(){
|
204 |
return selectionSupport;
|
205 |
} |
206 |
/**
|
207 |
* DOCUMENT ME!
|
208 |
*
|
209 |
* @param recordIndex DOCUMENT ME!
|
210 |
*
|
211 |
* @return DOCUMENT ME!
|
212 |
*/
|
213 |
public boolean isSelected(int recordIndex) { |
214 |
return selectionSupport.isSelected(recordIndex);
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* DOCUMENT ME!
|
219 |
*
|
220 |
* @param selection DOCUMENT ME!
|
221 |
*/
|
222 |
public void setSelection(FBitSet selection) { |
223 |
selectionSupport.setSelection(selection); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* DOCUMENT ME!
|
228 |
*
|
229 |
* @param name DOCUMENT ME!
|
230 |
*/
|
231 |
public void setName(String name) { |
232 |
try {
|
233 |
DataSourceFactory.changeDataSourceName(this.name, name);
|
234 |
} catch (NoSuchTableException e) {
|
235 |
throw new RuntimeException("No se encuentra la tabla????"); |
236 |
} |
237 |
|
238 |
this.name = name;
|
239 |
} |
240 |
public XMLEntity getXMLEntity(){
|
241 |
XMLEntity xml=new XMLEntity();
|
242 |
xml.putProperty("name",name);
|
243 |
///xml.addChild(dataSource.getXMLEntity());
|
244 |
xml.addChild(selectionSupport.getXMLEntity()); |
245 |
return xml;
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* @param child
|
250 |
*/
|
251 |
public void setXMLEntity(XMLEntity child) { |
252 |
selectionSupport.setXMLEntity(child.getChild(0));
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* @see com.hardcode.gdbms.engine.data.DataSource#getWhereFilter()
|
257 |
*/
|
258 |
public long[] getWhereFilter() throws IOException { |
259 |
return dataSource.getWhereFilter();
|
260 |
} |
261 |
} |