root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / project / document / table / FeatureTableDocumentFactory.java @ 25214
History | View | Annotate | Download (11.9 KB)
1 |
package org.gvsig.project.document.table; |
---|---|
2 |
|
3 |
import java.text.DateFormat; |
4 |
import java.util.Date; |
5 |
import java.util.Hashtable; |
6 |
|
7 |
import javax.swing.ImageIcon; |
8 |
import javax.swing.JPanel; |
9 |
|
10 |
import org.gvsig.fmap.dal.DALLocator; |
11 |
import org.gvsig.fmap.dal.DataManager; |
12 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
13 |
import org.gvsig.project.document.table.gui.TableFileOpen; |
14 |
import org.gvsig.tools.ToolsLocator; |
15 |
|
16 |
import com.iver.andami.PluginServices; |
17 |
import com.iver.andami.messages.NotificationManager; |
18 |
import com.iver.cit.gvsig.AddLayer; |
19 |
import com.iver.cit.gvsig.addlayer.AddLayerDialog; |
20 |
import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard; |
21 |
import com.iver.cit.gvsig.project.Project; |
22 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
23 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
24 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CopyDocumentContextMenuAction; |
25 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CutDocumentContextMenuAction; |
26 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.PasteDocumentContextMenuAction; |
27 |
import com.iver.utiles.XMLEntity; |
28 |
|
29 |
|
30 |
/**
|
31 |
* Factory of Table.
|
32 |
*
|
33 |
* @author Vicente Caballero Navarro
|
34 |
*/
|
35 |
public class FeatureTableDocumentFactory extends ProjectDocumentFactory { |
36 |
public static String registerName = "ProjectTable"; |
37 |
|
38 |
static {
|
39 |
// A�adimos nuestra extension para el tratamiento de la apertura de ficheros
|
40 |
// dentro de gvSIG
|
41 |
ToolsLocator.getExtensionPointManager().add("FileTableOpenDialog", "") |
42 |
.append("FileOpenTable", "", TableFileOpen.class); |
43 |
} |
44 |
|
45 |
/**
|
46 |
* Returns image of button.
|
47 |
*
|
48 |
* @return Image button.
|
49 |
*/
|
50 |
public ImageIcon getButtonIcon() { |
51 |
return PluginServices.getIconTheme().get("document-table-icon"); |
52 |
} |
53 |
|
54 |
/**
|
55 |
* Returns image of selected button.
|
56 |
*
|
57 |
* @return Image button.
|
58 |
*/
|
59 |
public ImageIcon getSelectedButtonIcon() { |
60 |
return PluginServices.getIconTheme().get("document-table-icon-sel"); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Introduce a gui to be able from the characteristics that we want a ProjectDocument
|
65 |
*
|
66 |
* @param project present Project.
|
67 |
*
|
68 |
* @return new ProjectDocument.
|
69 |
*/
|
70 |
public ProjectDocument createFromGUI(Project project) {
|
71 |
try {
|
72 |
AddLayerDialog fopen = new AddLayerDialog(PluginServices.getText(this, |
73 |
"Nueva_tabla"));
|
74 |
FileOpenWizard fod = new FileOpenWizard("FileTableOpenDialog", false); |
75 |
fod.setTitle(PluginServices.getText(this, "Tablas")); |
76 |
|
77 |
// DataBaseOpenDialog dbod = new DataBaseOpenDialog();
|
78 |
// dbod.setClasses(new Class[] { DBStoreParameters.class });
|
79 |
fopen.addWizardTab(PluginServices.getText(this, "Fichero"), fod); |
80 |
// fopen.addTab(PluginServices.getText(this, "base_datos"), dbod);
|
81 |
// WizardVectorialDB wp=new WizardVectorialDB();
|
82 |
// wp.initWizard();
|
83 |
// fopen.addWizardTab(wp.getTabName(), wp);
|
84 |
PluginServices.getMDIManager().addWindow(fopen); |
85 |
// wp.setMapCtrl(null);
|
86 |
// wp.execute();
|
87 |
DataManager dm = DALLocator.getDataManager(); |
88 |
if (fopen.isAccepted()) {
|
89 |
JPanel panel = fopen.getSelectedTab();
|
90 |
|
91 |
if (panel instanceof FileOpenWizard) { |
92 |
((FileOpenWizard) panel).execute(); |
93 |
// File[] files = fod.getFiles();
|
94 |
// FeatureTableDocument projectTable = null;
|
95 |
// for (int i = 0; i < files.length; i++) {
|
96 |
// String name = files[i].getName();
|
97 |
// List stores = dm.getStoreProviders();
|
98 |
// for (int j = 0; j < stores.size(); j++) {
|
99 |
// DataStoreParameters dsp = dm
|
100 |
// .createStoreParameters((String) stores
|
101 |
// .get(j));
|
102 |
// if (dsp.getDescription().equals(driverNames[i])) {
|
103 |
// FilesystemStoreParameters fileParameters = (FilesystemStoreParameters) dsp;
|
104 |
// fileParameters.setFile(files[i]);
|
105 |
//
|
106 |
// FeatureStore fs = (FeatureStore) dm
|
107 |
// .createStore((DataStoreParameters) fileParameters);
|
108 |
//
|
109 |
// // LayerFactory.getDataSourceFactory().addFileDataSource(driverNames[i],
|
110 |
// // name, files[i].getAbsolutePath());
|
111 |
// //
|
112 |
// // DataSource dataSource = LayerFactory.getDataSourceFactory()
|
113 |
// // .createRandomDataSource(name,
|
114 |
// // DataSourceFactory.AUTOMATIC_OPENING);
|
115 |
// // SelectableDataSource sds = new SelectableDataSource(dataSource);
|
116 |
// // EditableAdapter auxea = new EditableAdapter();
|
117 |
// // auxea.setOriginalDataSource(sds);
|
118 |
//
|
119 |
// // TODO: fjp: ESTO HAY QUE REVISARLO.
|
120 |
// // Por ahora, para obtener un driver que sirva para esta
|
121 |
// // fuente de datos, compruebo que implementa IWriteable.
|
122 |
// // IWriter writer = (IWriter) LayerFactory.getWM().getWriter(driverNames[i]);
|
123 |
// // Driver drv = LayerFactory.getDM().getDriver(driverNames[i]);
|
124 |
// // if (drv instanceof IWriter)
|
125 |
// // {
|
126 |
// // auxea.setWriter((IWriter) drv);
|
127 |
// // }
|
128 |
// projectTable = ProjectFactory.createTable(name,
|
129 |
// fs);
|
130 |
//
|
131 |
// projectTable.setProjectDocumentFactory(this);
|
132 |
// FeatureTableDocument ftd = new FeatureTableDocument(
|
133 |
// fs);
|
134 |
// FeatureTableDocumentPanel ftdp = new FeatureTableDocumentPanel(
|
135 |
// fs);
|
136 |
// ftdp.setModel(ftd);
|
137 |
// // Table t = new Table();
|
138 |
// // t.setModel(projectTable);
|
139 |
// PluginServices.getMDIManager().addWindow(ftdp);
|
140 |
//
|
141 |
// }
|
142 |
// }
|
143 |
//
|
144 |
//
|
145 |
// }
|
146 |
return null; |
147 |
// FIXME
|
148 |
// } else if (panel instanceof WizardVectorialDB) {
|
149 |
// DBStoreParameters[] parameters = (DBStoreParameters[]) wp
|
150 |
// .getParameters();
|
151 |
// int port = -1;
|
152 |
//
|
153 |
// try {
|
154 |
// port = Integer.parseInt(dbod.getPort());
|
155 |
// } catch (NumberFormatException e) {
|
156 |
// }
|
157 |
//
|
158 |
// String name = dbod.getHost() + "/" + dbod.getDataBase();
|
159 |
//
|
160 |
// if (port != -1) {
|
161 |
// name = dbod.getHost() + ":" + port + "/" +
|
162 |
// dbod.getDataBase();
|
163 |
// }
|
164 |
//
|
165 |
// String user = dbod.getUser().trim();
|
166 |
// String password = dbod.getPassword();
|
167 |
//
|
168 |
// if (user.equals("")) {
|
169 |
// user = null;
|
170 |
// password = null;
|
171 |
// }
|
172 |
//
|
173 |
// name = name + " Table:" + dbod.getTable();
|
174 |
//
|
175 |
// DBParameters dbParameters=(DBParameters)dm.createDataStoreParameters(driverName);
|
176 |
// dbParameters.setHost(dbod.getHost());
|
177 |
// dbParameters.setPort(dbod.getPort());
|
178 |
// dbParameters.setUser(dbod.getUser());
|
179 |
// dbParameters.setPassw(dbod.getPassword());
|
180 |
// dbParameters.setDb(dbod.getDataBase());
|
181 |
// dbParameters.setTableName(dbod.getTable());
|
182 |
|
183 |
// FeatureTableDocument projectTable = null;
|
184 |
// for (int i = 0; i < parameters.length; i++) {
|
185 |
// FeatureStore fs=(FeatureStore)dm.createStore(parameters[i]);
|
186 |
// projectTable = ProjectFactory.createTable(parameters[i].getHost() + "/" + parameters[i].getDb(),
|
187 |
// fs);
|
188 |
// projectTable.setProjectDocumentFactory(this);
|
189 |
//
|
190 |
// FeatureTableDocumentPanel ftdp=new FeatureTableDocumentPanel(fs);
|
191 |
// ftdp.setModel(projectTable);
|
192 |
//// Table t = new Table();
|
193 |
//// t.setModel(projectTable);
|
194 |
// PluginServices.getMDIManager().addWindow(ftdp);
|
195 |
// }
|
196 |
// return projectTable;
|
197 |
|
198 |
} |
199 |
} |
200 |
} catch (Exception e) { |
201 |
NotificationManager.addError(e); |
202 |
} |
203 |
|
204 |
return null; |
205 |
} |
206 |
|
207 |
/**
|
208 |
* Create a new ProjectTable
|
209 |
*
|
210 |
* @param baseName name
|
211 |
*
|
212 |
* @return ProjectTable.
|
213 |
*/
|
214 |
public static FeatureTableDocument createTable(String name, FeatureStore fs) { |
215 |
FeatureTableDocument t = new FeatureTableDocument(fs);
|
216 |
|
217 |
// if (fs != null) {
|
218 |
// t.setModel(fs);
|
219 |
//
|
220 |
//// try {
|
221 |
//// t.createAlias();
|
222 |
//// } catch (ReadException e) {
|
223 |
//// e.printStackTrace();
|
224 |
//// }
|
225 |
// }
|
226 |
|
227 |
t.setName(name); |
228 |
t.setCreationDate(DateFormat.getInstance().format(new Date())); |
229 |
int numTables=(ProjectDocument.NUMS.get(registerName)).intValue();
|
230 |
ProjectDocument.NUMS.put(registerName,new Integer(numTables++)); |
231 |
|
232 |
return t;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Returns the name of registration in the point of extension.
|
237 |
*
|
238 |
* @return Name of registration
|
239 |
*/
|
240 |
public String getRegisterName() { |
241 |
return registerName;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Registers in the points of extension the Factory with alias.
|
246 |
*
|
247 |
*/
|
248 |
public static void register() { |
249 |
register(registerName, new FeatureTableDocumentFactory(),
|
250 |
"com.iver.cit.gvsig.project.ProjectTable");
|
251 |
|
252 |
registerAction(registerName,"copy",new CopyDocumentContextMenuAction()); |
253 |
registerAction(registerName,"cut",new CutDocumentContextMenuAction()); |
254 |
registerAction(registerName,"paste",new PasteDocumentContextMenuAction()); |
255 |
|
256 |
PluginServices.getIconTheme().registerDefault( |
257 |
"document-table-icon",
|
258 |
AddLayer.class.getClassLoader().getResource("images/tablas.png")
|
259 |
);//
|
260 |
PluginServices.getIconTheme().registerDefault( |
261 |
"document-table-icon-sel",
|
262 |
AddLayer.class.getClassLoader().getResource("images/tablas_sel.png")
|
263 |
); |
264 |
|
265 |
PluginServices.getIconTheme().registerDefault( |
266 |
"edit-copy",
|
267 |
AddLayer.class.getClassLoader().getResource("images/editcopy.png")
|
268 |
);//
|
269 |
PluginServices.getIconTheme().registerDefault( |
270 |
"edit-cut",
|
271 |
AddLayer.class.getClassLoader().getResource("images/editcut.png")
|
272 |
); |
273 |
PluginServices.getIconTheme().registerDefault( |
274 |
"edit-paste",
|
275 |
AddLayer.class.getClassLoader().getResource("images/editpaste.png")
|
276 |
); |
277 |
PluginServices.getIconTheme().registerDefault( |
278 |
"edit-delete",
|
279 |
AddLayer.class.getClassLoader().getResource("images/editdelete.png")
|
280 |
); |
281 |
} |
282 |
|
283 |
/**
|
284 |
* Returns the name of ProjectDocument.
|
285 |
*
|
286 |
* @return Name of ProjectDocument.
|
287 |
*/
|
288 |
public String getNameType() { |
289 |
return PluginServices.getText(this, "Tabla"); |
290 |
} |
291 |
|
292 |
|
293 |
/**
|
294 |
* Create a new ProjectDocument.
|
295 |
*
|
296 |
* @param project Opened project.
|
297 |
*
|
298 |
* @return ProjectDocument.
|
299 |
*/
|
300 |
public ProjectDocument create(Project project) {
|
301 |
FeatureTableDocument pt = null;
|
302 |
|
303 |
pt = FeatureTableDocumentFactory.createTable("", null); |
304 |
pt.setProject(project,0);
|
305 |
|
306 |
pt.setProjectDocumentFactory(this);
|
307 |
|
308 |
return pt;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Returns the priority of de ProjectDocument.
|
313 |
*
|
314 |
* @return Priority.
|
315 |
*/
|
316 |
public int getPriority() { |
317 |
return 1; |
318 |
} |
319 |
|
320 |
public boolean resolveImportXMLConflicts(XMLEntity root, Project project, Hashtable conflicts) { |
321 |
return true; |
322 |
} |
323 |
} |