svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / CopyPasteExtension.java @ 11412
History | View | Annotate | Download (43.5 KB)
1 | 6635 | jmvivo | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | import java.awt.Component; |
||
4 | import java.awt.Toolkit; |
||
5 | import java.awt.datatransfer.DataFlavor; |
||
6 | import java.awt.datatransfer.StringSelection; |
||
7 | import java.awt.datatransfer.UnsupportedFlavorException; |
||
8 | import java.io.IOException; |
||
9 | import java.io.StringReader; |
||
10 | import java.io.StringWriter; |
||
11 | import java.util.ArrayList; |
||
12 | 6645 | jmvivo | import java.util.Arrays; |
13 | import java.util.Comparator; |
||
14 | 6635 | jmvivo | import java.util.Enumeration; |
15 | import java.util.Hashtable; |
||
16 | import java.util.Iterator; |
||
17 | import java.util.Map; |
||
18 | |||
19 | import javax.swing.JOptionPane; |
||
20 | |||
21 | import org.exolab.castor.xml.MarshalException; |
||
22 | import org.exolab.castor.xml.Marshaller; |
||
23 | import org.exolab.castor.xml.ValidationException; |
||
24 | |||
25 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
26 | 6635 | jmvivo | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
27 | import com.hardcode.gdbms.engine.data.SourceInfo; |
||
28 | import com.iver.andami.PluginServices; |
||
29 | import com.iver.andami.plugins.Extension; |
||
30 | 9532 | caballero | import com.iver.andami.ui.mdiManager.IWindow; |
31 | 6635 | jmvivo | import com.iver.cit.gvsig.fmap.layers.CancelationException; |
32 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
33 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
34 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
35 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
36 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
37 | import com.iver.cit.gvsig.project.Project; |
||
38 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
39 | 7742 | jmvivo | import com.iver.cit.gvsig.project.documents.contextMenu.AbstractDocumentContextMenuAction; |
40 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
41 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
42 | import com.iver.cit.gvsig.project.documents.layout.ProjectMap; |
||
43 | 7379 | caballero | import com.iver.cit.gvsig.project.documents.layout.ProjectMapFactory; |
44 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameView; |
45 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
46 | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
||
47 | 7379 | caballero | import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
48 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.ProjectView; |
49 | 7379 | caballero | import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
50 | 9532 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
51 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
52 | import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
||
53 | 6635 | jmvivo | import com.iver.utiles.XMLEntity; |
54 | import com.iver.utiles.extensionPoints.IExtensionBuilder; |
||
55 | import com.iver.utiles.xmlEntity.generate.XmlTag; |
||
56 | |||
57 | public class CopyPasteExtension extends Extension { |
||
58 | |||
59 | public void initialize() { |
||
60 | 7742 | jmvivo | /*
|
61 | 6676 | jmvivo | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
62 | 6865 | jaume | |
63 | |||
64 | |||
65 | 6635 | jmvivo | // TOC
|
66 | 6676 | jmvivo | MyTocMenuEntry copy = new CopyTocMenuEntry();
|
67 | MyTocMenuEntry cut = new CutTocMenuEntry();
|
||
68 | MyTocMenuEntry paste = new PasteTocMenuEntry();
|
||
69 | 6635 | jmvivo | Utiles utiles = new Utiles();
|
70 | copy.setUtiles(utiles);
|
||
71 | cut.setUtiles(utiles);
|
||
72 | paste.setUtiles(utiles);
|
||
73 | 6676 | jmvivo | |
74 | extensionPoints.add("View_TocActions","Copy","Copy selectes layers to system clipboard",copy);
|
||
75 | extensionPoints.add("View_TocActions","Cut","Cut selectes layers to system clipboard", cut);
|
||
76 | extensionPoints.add("View_TocActions","Paste","Paste layers from system clipboard",paste);
|
||
77 | |||
78 | 9392 | caballero | |
79 | 7742 | jmvivo | //FPopupMenu.addEntry(copy);
|
80 | //FPopupMenu.addEntry(cut);
|
||
81 | //FPopupMenu.addEntry(paste);
|
||
82 | 6865 | jaume | |
83 | 9392 | caballero | |
84 | 6865 | jaume | // ProjectWindow
|
85 | 6635 | jmvivo | CopyProjectElement copyProjectElement = new CopyProjectElement();
|
86 | CutProjectElement cutProjectElement = new CutProjectElement();
|
||
87 | PasteProjectElement pasteProjectElementView = new PasteProjectElement();
|
||
88 | PasteProjectElement pasteProjectElementTable = new PasteProjectElement();
|
||
89 | PasteProjectElement pasteProjectElementMap = new PasteProjectElement();
|
||
90 | 6865 | jaume | |
91 | 6635 | jmvivo | copyProjectElement.setUtiles(utiles);
|
92 | cutProjectElement.setUtiles(utiles);
|
||
93 | pasteProjectElementView.setUtiles(utiles);
|
||
94 | pasteProjectElementTable.setUtiles(utiles);
|
||
95 | pasteProjectElementMap.setUtiles(utiles);
|
||
96 | 6865 | jaume | |
97 | 6635 | jmvivo | pasteProjectElementView.setType("views");
|
98 | pasteProjectElementTable.setType("tables");
|
||
99 | pasteProjectElementMap.setType("maps");
|
||
100 | 6865 | jaume | |
101 | |||
102 | 6676 | jmvivo | extensionPoints.add("DocumentActions_View","Copy","Copy selectes documento to system clipboard",copyProjectElement);
|
103 | extensionPoints.add("DocumentActions_View","Cut","Cut selectes documento to system clipboard", cutProjectElement);
|
||
104 | extensionPoints.add("DocumentActions_View","Paste","Paste views from system clipboard",pasteProjectElementView);
|
||
105 | 6635 | jmvivo | |
106 | |||
107 | 6676 | jmvivo | extensionPoints.add("DocumentActions_Table","Copy","Copy selectes documento to system clipboard",copyProjectElement);
|
108 | extensionPoints.add("DocumentActions_Table","Cut","Cut selectes documento to system clipboard", cutProjectElement);
|
||
109 | extensionPoints.add("DocumentActions_Table","Paste","Paste tables from system clipboard",pasteProjectElementTable);
|
||
110 | 6635 | jmvivo | |
111 | 6676 | jmvivo | extensionPoints.add("DocumentActions_Map","Copy","Copy selectes documento to system clipboard",copyProjectElement);
|
112 | extensionPoints.add("DocumentActions_Map","Cut","Cut selectes documento to system clipboard", cutProjectElement);
|
||
113 | extensionPoints.add("DocumentActions_Map","Paste","Paste maps from system clipboard",pasteProjectElementMap);
|
||
114 | 6635 | jmvivo | |
115 | 7742 | jmvivo | */
|
116 | 6635 | jmvivo | } |
117 | |||
118 | public void execute(String actionCommand) { |
||
119 | // TODO Auto-generated method stub
|
||
120 | 6865 | jaume | |
121 | 6635 | jmvivo | } |
122 | |||
123 | public boolean isEnabled() { |
||
124 | return false; |
||
125 | } |
||
126 | |||
127 | public boolean isVisible() { |
||
128 | return false; |
||
129 | } |
||
130 | |||
131 | |||
132 | } |
||
133 | |||
134 | 6676 | jmvivo | abstract class MyDocumentAction extends AbstractDocumentContextMenuAction implements IExtensionBuilder { |
135 | 6635 | jmvivo | protected Utiles utiles;
|
136 | |||
137 | public void setUtiles(Utiles utiles) { |
||
138 | this.utiles = utiles;
|
||
139 | } |
||
140 | 6865 | jaume | |
141 | 6635 | jmvivo | public String getGroup() { |
142 | return "ClipboardActions"; |
||
143 | } |
||
144 | |||
145 | |||
146 | public Object create() { |
||
147 | return this; |
||
148 | } |
||
149 | |||
150 | public Object create(Object[] args) { |
||
151 | // TODO Auto-generated method stub
|
||
152 | return this; |
||
153 | } |
||
154 | |||
155 | public Object create(Map args) { |
||
156 | // TODO Auto-generated method stub
|
||
157 | 6865 | jaume | return this; |
158 | } |
||
159 | 6635 | jmvivo | } |
160 | |||
161 | |||
162 | 6676 | jmvivo | class CopyProjectElement extends MyDocumentAction{ |
163 | public String getDescription() { |
||
164 | //FIXME: Falta claves
|
||
165 | //return PluginServices.getText(this,"tooltip_copiar_al_portapapeles");
|
||
166 | return null; |
||
167 | } |
||
168 | 6865 | jaume | |
169 | 6635 | jmvivo | public int getOrder() { |
170 | 6865 | jaume | |
171 | 6635 | jmvivo | return 0; |
172 | } |
||
173 | 6865 | jaume | |
174 | 7304 | caballero | public boolean isVisible(ProjectDocument item, ProjectDocument[] selectedItems) { |
175 | 6635 | jmvivo | return true; |
176 | } |
||
177 | 6865 | jaume | |
178 | 7304 | caballero | public boolean isEnabled(ProjectDocument item, ProjectDocument[] selectedItems) { |
179 | 6635 | jmvivo | return selectedItems.length > 0; |
180 | } |
||
181 | |||
182 | |||
183 | 7304 | caballero | public void execute(ProjectDocument item, ProjectDocument[] selectedItems) { |
184 | 6635 | jmvivo | XMLEntity xml = this.utiles.generateXMLCopyDocuments(selectedItems);
|
185 | if (xml == null) { |
||
186 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
187 | (Component)PluginServices.getMainFrame(),
|
||
188 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
189 | PluginServices.getText(this,"pegar"),//titulo |
||
190 | JOptionPane.ERROR_MESSAGE
|
||
191 | ); |
||
192 | 6635 | jmvivo | return;
|
193 | } |
||
194 | 6865 | jaume | |
195 | 6635 | jmvivo | String data = this.utiles.marshallXMLEntity(xml); |
196 | if (data == null) { |
||
197 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
198 | (Component)PluginServices.getMainFrame(),
|
||
199 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
200 | PluginServices.getText(this,"pegar"),//titulo |
||
201 | JOptionPane.ERROR_MESSAGE
|
||
202 | ); |
||
203 | 6635 | jmvivo | return;
|
204 | } |
||
205 | 6865 | jaume | this.utiles.putInClipboard(data);
|
206 | 6635 | jmvivo | } |
207 | |||
208 | public String getText() { |
||
209 | return PluginServices.getText(this, "copiar"); |
||
210 | } |
||
211 | 6865 | jaume | |
212 | 6635 | jmvivo | } |
213 | |||
214 | 6676 | jmvivo | class CutProjectElement extends MyDocumentAction { |
215 | public String getDescription() { |
||
216 | //FIXME: Falta claves
|
||
217 | //return PluginServices.getText(this,"tooltip_cortar_al_portapapeles");
|
||
218 | return null; |
||
219 | } |
||
220 | |||
221 | 6635 | jmvivo | public int getOrder() { |
222 | return 1; |
||
223 | } |
||
224 | 6865 | jaume | |
225 | 7304 | caballero | public boolean isVisible(ProjectDocument item, ProjectDocument[] selectedItems) { |
226 | 6635 | jmvivo | return true; |
227 | } |
||
228 | 6865 | jaume | |
229 | 7304 | caballero | public boolean isEnabled(ProjectDocument item, ProjectDocument[] selectedItems) { |
230 | 6635 | jmvivo | return selectedItems.length > 0; |
231 | } |
||
232 | |||
233 | |||
234 | 7304 | caballero | public void execute(ProjectDocument item, ProjectDocument[] selectedItems) { |
235 | 6635 | jmvivo | XMLEntity xml = this.utiles.generateXMLCopyDocuments(selectedItems);
|
236 | if (xml == null) { |
||
237 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
238 | (Component)PluginServices.getMainFrame(),
|
||
239 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
240 | PluginServices.getText(this,"cortar"),//titulo |
||
241 | JOptionPane.ERROR_MESSAGE
|
||
242 | ); |
||
243 | 6635 | jmvivo | return;
|
244 | } |
||
245 | 6865 | jaume | |
246 | 6635 | jmvivo | String data = this.utiles.marshallXMLEntity(xml); |
247 | if (data == null) { |
||
248 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
249 | (Component)PluginServices.getMainFrame(),
|
||
250 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
251 | PluginServices.getText(this,"cortar"),//titulo |
||
252 | JOptionPane.ERROR_MESSAGE
|
||
253 | ); |
||
254 | 6635 | jmvivo | return;
|
255 | 6865 | jaume | } |
256 | 6635 | jmvivo | this.utiles.putInClipboard(data);
|
257 | 6865 | jaume | |
258 | |||
259 | 6635 | jmvivo | int option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_el_documento")); |
260 | if (option!=JOptionPane.OK_OPTION) { |
||
261 | return;
|
||
262 | 6865 | jaume | } |
263 | |||
264 | |||
265 | this.utiles.removeDocuments(selectedItems);
|
||
266 | |||
267 | 6635 | jmvivo | } |
268 | |||
269 | public String getText() { |
||
270 | return PluginServices.getText(this, "cortar"); |
||
271 | } |
||
272 | 6865 | jaume | |
273 | 6635 | jmvivo | } |
274 | |||
275 | class PasteProjectElement extends MyDocumentAction { |
||
276 | private String type; |
||
277 | 6865 | jaume | |
278 | 6676 | jmvivo | public String getDescription() { |
279 | //FIXME: Falta claves
|
||
280 | //return PluginServices.getText(this,"tooltip_pegar_desde_el_portapapeles");
|
||
281 | return null; |
||
282 | } |
||
283 | |||
284 | 6635 | jmvivo | public int getOrder() { |
285 | return 2; |
||
286 | } |
||
287 | 6865 | jaume | |
288 | 6635 | jmvivo | public void setType(String type) { |
289 | this.type = type;
|
||
290 | } |
||
291 | 6865 | jaume | |
292 | 6635 | jmvivo | public String getType(String type) { |
293 | return this.type; |
||
294 | } |
||
295 | 6865 | jaume | |
296 | 7304 | caballero | public boolean isVisible(ProjectDocument item, ProjectDocument[] selectedItems) { |
297 | 6635 | jmvivo | return true; |
298 | } |
||
299 | 6865 | jaume | |
300 | 7304 | caballero | public boolean isEnabled(ProjectDocument item, ProjectDocument[] selectedItems) { |
301 | 6635 | jmvivo | String sourceString = this.utiles.getFromClipboard(); |
302 | if (sourceString == null) return false; |
||
303 | 6865 | jaume | |
304 | 6635 | jmvivo | XMLEntity xml = this.utiles.unMarshallXMLEntity(sourceString);
|
305 | if (xml == null) return false; |
||
306 | 6865 | jaume | |
307 | 6635 | jmvivo | if (!this.utiles.checkXMLRootNode(xml)) return false; |
308 | 6865 | jaume | |
309 | 6635 | jmvivo | if (this.utiles.getXMLEntityChildOfType(xml,this.type) == null) return false; |
310 | return true; |
||
311 | } |
||
312 | |||
313 | |||
314 | 7304 | caballero | public void execute(ProjectDocument item, ProjectDocument[] selectedItems) { |
315 | 6635 | jmvivo | String sourceString = this.utiles.getFromClipboard(); |
316 | if (sourceString == null) return; |
||
317 | 6865 | jaume | |
318 | 6635 | jmvivo | XMLEntity xml = this.utiles.unMarshallXMLEntity(sourceString);
|
319 | if (xml == null) return; |
||
320 | 6865 | jaume | |
321 | 6635 | jmvivo | if (!this.utiles.checkXMLRootNode(xml)) return; |
322 | 6865 | jaume | |
323 | 6635 | jmvivo | if (this.type.equals("views")) { |
324 | this.utiles.loadViewsFromXML(xml);
|
||
325 | } else if (this.type.equals("tables")) { |
||
326 | 6865 | jaume | this.utiles.loadTablesFromXML(xml);
|
327 | 6635 | jmvivo | } else if (this.type.equals("maps")) { |
328 | this.utiles.loadMapsFromXML(xml);
|
||
329 | } else {
|
||
330 | //TODO que hacer aqui??
|
||
331 | return;
|
||
332 | } |
||
333 | 6865 | jaume | |
334 | 6635 | jmvivo | } |
335 | |||
336 | public String getText() { |
||
337 | return PluginServices.getText(this, "pegar"); |
||
338 | } |
||
339 | 6865 | jaume | |
340 | 6635 | jmvivo | } |
341 | |||
342 | |||
343 | |||
344 | 6865 | jaume | abstract class MyTocMenuEntry extends AbstractTocContextMenuAction { |
345 | 6635 | jmvivo | protected Utiles utiles;
|
346 | 6865 | jaume | |
347 | 6635 | jmvivo | public void setUtiles(Utiles utiles) { |
348 | this.utiles = utiles;
|
||
349 | } |
||
350 | 6676 | jmvivo | |
351 | public String getGroup() { |
||
352 | return "copyPasteLayer"; |
||
353 | } |
||
354 | |||
355 | public int getGroupOrder() { |
||
356 | return 60; |
||
357 | } |
||
358 | 6865 | jaume | |
359 | 6635 | jmvivo | } |
360 | |||
361 | 6676 | jmvivo | class CopyTocMenuEntry extends MyTocMenuEntry{ |
362 | public int getOrder() { |
||
363 | return 0; |
||
364 | } |
||
365 | 6865 | jaume | |
366 | 6676 | jmvivo | public String getText() { |
367 | 6865 | jaume | return PluginServices.getText(this, "copiar"); |
368 | 6676 | jmvivo | } |
369 | 6865 | jaume | |
370 | 6676 | jmvivo | public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
371 | 6865 | jaume | return selectedItems.length >= 1 && isTocItemBranch(item); |
372 | 6676 | jmvivo | } |
373 | 6635 | jmvivo | |
374 | |||
375 | 6865 | jaume | public void execute(ITocItem item, FLayer[] selectedItems) { |
376 | 6676 | jmvivo | XMLEntity xml = this.utiles.generateXMLCopyLayers(selectedItems);
|
377 | 6635 | jmvivo | if (xml == null) { |
378 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
379 | (Component)PluginServices.getMainFrame(),
|
||
380 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
381 | PluginServices.getText(this,"copiar"),//titulo |
||
382 | JOptionPane.ERROR_MESSAGE
|
||
383 | ); |
||
384 | 6635 | jmvivo | return;
|
385 | } |
||
386 | 6865 | jaume | |
387 | 6635 | jmvivo | String data = this.utiles.marshallXMLEntity(xml); |
388 | if (data == null) { |
||
389 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
390 | (Component)PluginServices.getMainFrame(),
|
||
391 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
392 | PluginServices.getText(this,"copiar"),//titulo |
||
393 | JOptionPane.ERROR_MESSAGE
|
||
394 | ); |
||
395 | 6635 | jmvivo | return;
|
396 | } |
||
397 | 6865 | jaume | |
398 | this.utiles.putInClipboard(data);
|
||
399 | |||
400 | 6635 | jmvivo | } |
401 | |||
402 | |||
403 | 6676 | jmvivo | } |
404 | 6635 | jmvivo | |
405 | 6676 | jmvivo | class CutTocMenuEntry extends MyTocMenuEntry{ |
406 | public int getOrder() { |
||
407 | return 1; |
||
408 | 6635 | jmvivo | } |
409 | 6865 | jaume | |
410 | 6676 | jmvivo | public String getText() { |
411 | 6865 | jaume | return PluginServices.getText(this, "cortar"); |
412 | 6676 | jmvivo | } |
413 | 6865 | jaume | |
414 | 6676 | jmvivo | public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
415 | 6865 | jaume | return selectedItems.length >= 1 && isTocItemBranch(item); |
416 | 6676 | jmvivo | } |
417 | 6635 | jmvivo | |
418 | 6676 | jmvivo | |
419 | 6865 | jaume | public void execute(ITocItem item, FLayer[] selectedItems) { |
420 | 6676 | jmvivo | XMLEntity xml = this.utiles.generateXMLCopyLayers(selectedItems);
|
421 | 6635 | jmvivo | if (xml == null) { |
422 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
423 | (Component)PluginServices.getMainFrame(),
|
||
424 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
425 | PluginServices.getText(this,"cortar"),//titulo |
||
426 | JOptionPane.ERROR_MESSAGE
|
||
427 | ); |
||
428 | 6635 | jmvivo | return;
|
429 | } |
||
430 | 6865 | jaume | |
431 | 6635 | jmvivo | String data = this.utiles.marshallXMLEntity(xml); |
432 | if (data == null) { |
||
433 | 6782 | jmvivo | JOptionPane.showMessageDialog(
|
434 | (Component)PluginServices.getMainFrame(),
|
||
435 | "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
||
436 | PluginServices.getText(this,"cortar"),//titulo |
||
437 | JOptionPane.ERROR_MESSAGE
|
||
438 | ); |
||
439 | 6635 | jmvivo | return;
|
440 | } |
||
441 | |||
442 | 6865 | jaume | |
443 | 6635 | jmvivo | this.utiles.putInClipboard(data);
|
444 | 6865 | jaume | |
445 | |||
446 | 6635 | jmvivo | int option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa")); |
447 | if (option!=JOptionPane.OK_OPTION) { |
||
448 | return;
|
||
449 | } |
||
450 | getMapContext().beginAtomicEvent(); |
||
451 | 6865 | jaume | |
452 | |||
453 | boolean isOK =this.utiles.removeLayers(selectedItems); |
||
454 | |||
455 | 6635 | jmvivo | getMapContext().endAtomicEvent(); |
456 | 6865 | jaume | |
457 | 6635 | jmvivo | if (isOK) {
|
458 | getMapContext().invalidate(); |
||
459 | if (getMapContext().getLayers().getLayersCount()==0) { |
||
460 | PluginServices.getMainFrame().enableControls(); |
||
461 | } |
||
462 | } |
||
463 | |||
464 | } |
||
465 | } |
||
466 | |||
467 | |||
468 | 6676 | jmvivo | class PasteTocMenuEntry extends MyTocMenuEntry{ |
469 | 6635 | jmvivo | private XMLEntity xml=null; |
470 | 6865 | jaume | |
471 | 6676 | jmvivo | public int getOrder() { |
472 | return 2; |
||
473 | } |
||
474 | 6865 | jaume | |
475 | 6676 | jmvivo | public String getText() { |
476 | 6865 | jaume | return PluginServices.getText(this, "pegar"); |
477 | 6676 | jmvivo | } |
478 | 6865 | jaume | |
479 | 6676 | jmvivo | public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
480 | if (isTocItemBranch(item)) {
|
||
481 | FLayer lyr = getNodeLayer(item); |
||
482 | 6635 | jmvivo | if (lyr instanceof FLayers) { |
483 | this.xml = this.getCheckedXMLFromClipboard(); |
||
484 | 6865 | jaume | return true; |
485 | 6635 | jmvivo | } |
486 | 6865 | jaume | |
487 | 6676 | jmvivo | } else if (!isTocItemLeaf(item)) { |
488 | if (getNodeLayer(item) == null) { |
||
489 | 6635 | jmvivo | this.xml = this.getCheckedXMLFromClipboard(); |
490 | 6676 | jmvivo | return this.xml != null; |
491 | 6865 | jaume | } |
492 | } |
||
493 | 6676 | jmvivo | return false; |
494 | 6635 | jmvivo | } |
495 | 6865 | jaume | |
496 | 6635 | jmvivo | private XMLEntity getCheckedXMLFromClipboard() {
|
497 | String sourceString = this.utiles.getFromClipboard(); |
||
498 | if (sourceString == null) return null; |
||
499 | 6865 | jaume | |
500 | 6635 | jmvivo | XMLEntity xml = this.utiles.unMarshallXMLEntity(sourceString);
|
501 | if (xml == null) return null; |
||
502 | 6865 | jaume | |
503 | 6635 | jmvivo | if (!this.utiles.checkXMLRootNode(xml)) return null; |
504 | 6865 | jaume | |
505 | 6635 | jmvivo | if (this.utiles.getXMLEntityChildOfType(xml,"layers") == null) return null; |
506 | 6865 | jaume | |
507 | 6635 | jmvivo | return xml;
|
508 | } |
||
509 | |||
510 | 6865 | jaume | public void execute(ITocItem item, FLayer[] selectedItems) { |
511 | 6635 | jmvivo | FLayers root; |
512 | 6865 | jaume | |
513 | 6635 | jmvivo | if (this.xml == null) return; |
514 | 6865 | jaume | |
515 | 6676 | jmvivo | if (isTocItemBranch(item)) {
|
516 | root = (FLayers)getNodeLayer(item); |
||
517 | } else if (getNodeLayer(item) == null){ |
||
518 | 6635 | jmvivo | root = getMapContext().getLayers(); |
519 | } else {
|
||
520 | return;
|
||
521 | } |
||
522 | getMapContext().beginAtomicEvent(); |
||
523 | 6865 | jaume | |
524 | 6635 | jmvivo | boolean isOK = this.utiles.loadLayersFromXML(this.xml,root); |
525 | 6865 | jaume | |
526 | 6635 | jmvivo | getMapContext().endAtomicEvent(); |
527 | 6865 | jaume | |
528 | 9532 | caballero | if (isOK) {
|
529 | getMapContext().invalidate(); |
||
530 | IWindow view=PluginServices.getMDIManager().getActiveWindow(); |
||
531 | if (view instanceof BaseView) |
||
532 | ((ProjectDocument)((BaseView)view).getModel()).setModified(true);
|
||
533 | } |
||
534 | 6635 | jmvivo | } |
535 | 6865 | jaume | |
536 | 6635 | jmvivo | } |
537 | |||
538 | |||
539 | class Utiles { |
||
540 | 6865 | jaume | |
541 | 6635 | jmvivo | /*
|
542 | *
|
||
543 | ======================================
|
||
544 | Comportamiento del Pegar documentos:
|
||
545 | ======================================
|
||
546 | 6865 | jaume | |
547 | 6635 | jmvivo | ?Pegar vista.
|
548 | Si ya existe una vista en el proyecto con el mismo nombre.
|
||
549 | 1. Abortar
|
||
550 | 2. Pedir nuevo nombre.
|
||
551 | Que hacemos con las tablas asociadas.
|
||
552 | No se pegan
|
||
553 | 6865 | jaume | Si alguna de las tablas a pegar de las que van en
|
554 | 6635 | jmvivo | el portapapeles ya existen en el proyecto.
|
555 | 1. abortamos
|
||
556 | 2. Informamos al usuario y no se pegan las tablas.
|
||
557 | 6865 | jaume | |
558 | 6635 | jmvivo | Pegar tabla.
|
559 | Si alguna de las tablas existe.
|
||
560 | Se pega igualmente (apareceran tablas duplicadas)
|
||
561 | 6865 | jaume | |
562 | 6635 | jmvivo | Pegar mapa.
|
563 | Si el mapa ya existe en el proyecto.
|
||
564 | 1. Abortar
|
||
565 | 2. renombrar el mapa
|
||
566 | Si alguna vista ya existe en el proyecto.
|
||
567 | 1. Abortar
|
||
568 | 2. Usar la vista que ya existe en el proyecto y no
|
||
569 | pegar la nueva vista.
|
||
570 | 6865 | jaume | Si alguna de las tablas a pegar de las que van en
|
571 | el portapapeles ya existen en el proyecto.
|
||
572 | 6635 | jmvivo | 1. abortamos
|
573 | 2. Informamos al usuario y no se pegan las tablas.
|
||
574 | 6865 | jaume | |
575 | |||
576 | 6635 | jmvivo | */
|
577 | 6865 | jaume | |
578 | |||
579 | 6635 | jmvivo | /*
|
580 | 6865 | jaume | *
|
581 | *
|
||
582 | *
|
||
583 | 6635 | jmvivo | * Funciones Publicas para generar XML (copiar)
|
584 | 6865 | jaume | *
|
585 | *
|
||
586 | 6635 | jmvivo | */
|
587 | 6865 | jaume | |
588 | 6635 | jmvivo | /**
|
589 | * Genera un XMLEntity con la informacion necesaria
|
||
590 | * para copiar los elementos de selectedItems en
|
||
591 | * otro proyecto
|
||
592 | */
|
||
593 | 7304 | caballero | public XMLEntity generateXMLCopyDocuments(ProjectDocument[] selectedItems) { |
594 | 6635 | jmvivo | if (selectedItems.length == 0) return null; |
595 | 6865 | jaume | |
596 | 6635 | jmvivo | if (selectedItems[0] instanceof ProjectView) { |
597 | ProjectView[] views = new ProjectView[selectedItems.length]; |
||
598 | System.arraycopy(selectedItems,0,views,0,selectedItems.length); |
||
599 | 6865 | jaume | return this.generateXMLCopyViews(views); |
600 | 6635 | jmvivo | } else if (selectedItems[0] instanceof ProjectMap) { |
601 | ProjectMap[] maps = new ProjectMap[selectedItems.length]; |
||
602 | System.arraycopy(selectedItems,0,maps,0,selectedItems.length); |
||
603 | return this.generateXMLCopyMaps(maps); |
||
604 | } else if (selectedItems[0] instanceof ProjectTable) { |
||
605 | ProjectTable[] tables = new ProjectTable[selectedItems.length]; |
||
606 | System.arraycopy(selectedItems,0,tables,0,selectedItems.length); |
||
607 | 6865 | jaume | return this.generateXMLCopyTables(tables); |
608 | 6635 | jmvivo | } else {
|
609 | //FIXME:????
|
||
610 | return null; |
||
611 | } |
||
612 | } |
||
613 | 6865 | jaume | |
614 | 6635 | jmvivo | public XMLEntity generateXMLCopyViews(ProjectView[] selectedItems) { |
615 | XMLEntity xml = this.newRootNode();
|
||
616 | 6865 | jaume | |
617 | 6635 | jmvivo | XMLEntity xmlTables = this.newTablesNode();
|
618 | XMLEntity xmlDataSources = this.newDataSourcesNode();
|
||
619 | XMLEntity xmlViews = this.newViewsNode();
|
||
620 | |||
621 | for (int i=0;i < selectedItems.length; i++) { |
||
622 | if (!this.addToXMLView(selectedItems[i],xmlViews,xmlTables,xmlDataSources)) return null; |
||
623 | 6865 | jaume | |
624 | 6635 | jmvivo | } |
625 | 6865 | jaume | |
626 | |||
627 | if (xmlDataSources.getChildrenCount() > 0) { |
||
628 | 6635 | jmvivo | xml.addChild(xmlDataSources); |
629 | 6865 | jaume | } |
630 | if (xmlViews.getChildrenCount() > 0) { |
||
631 | 6635 | jmvivo | xml.addChild(xmlViews); |
632 | } |
||
633 | 6865 | jaume | if (xmlTables.getChildrenCount() > 0) { |
634 | 6635 | jmvivo | xml.addChild(xmlTables); |
635 | } |
||
636 | 6865 | jaume | |
637 | 6635 | jmvivo | return xml;
|
638 | 6865 | jaume | |
639 | 6635 | jmvivo | } |
640 | |||
641 | 6865 | jaume | |
642 | 6635 | jmvivo | public XMLEntity generateXMLCopyMaps(ProjectMap[] selectedItems) { |
643 | XMLEntity xml = this.newRootNode();
|
||
644 | 6865 | jaume | |
645 | 6635 | jmvivo | XMLEntity xmlTables = this.newTablesNode();
|
646 | XMLEntity xmlDataSources = this.newDataSourcesNode();
|
||
647 | XMLEntity xmlViews = this.newViewsNode();
|
||
648 | XMLEntity xmlMaps = this.newMapsNode();
|
||
649 | |||
650 | for (int i=0;i < selectedItems.length; i++) { |
||
651 | if (!this.addToXMLMap(selectedItems[i],xmlMaps,xmlViews,xmlTables,xmlDataSources)) return null; |
||
652 | 6865 | jaume | |
653 | 6635 | jmvivo | } |
654 | 6865 | jaume | |
655 | |||
656 | if (xmlDataSources.getChildrenCount() > 0) { |
||
657 | 6635 | jmvivo | xml.addChild(xmlDataSources); |
658 | 6865 | jaume | } |
659 | if (xmlViews.getChildrenCount() > 0) { |
||
660 | 6635 | jmvivo | xml.addChild(xmlViews); |
661 | } |
||
662 | 6865 | jaume | if (xmlTables.getChildrenCount() > 0) { |
663 | 6635 | jmvivo | xml.addChild(xmlTables); |
664 | } |
||
665 | 6865 | jaume | if (xmlMaps.getChildrenCount() > 0) { |
666 | 6635 | jmvivo | xml.addChild(xmlMaps); |
667 | } |
||
668 | |||
669 | 6865 | jaume | |
670 | return xml;
|
||
671 | 6635 | jmvivo | } |
672 | 6865 | jaume | |
673 | 6635 | jmvivo | public XMLEntity generateXMLCopyTables(ProjectTable[] selectedItems) { |
674 | XMLEntity xml = this.newRootNode();
|
||
675 | 6865 | jaume | |
676 | 6635 | jmvivo | XMLEntity xmlTables = this.newTablesNode();
|
677 | XMLEntity xmlDataSources = this.newDataSourcesNode();
|
||
678 | |||
679 | for (int i=0;i < selectedItems.length; i++) { |
||
680 | if (!this.addToXMLTable(selectedItems[i],xmlTables,xmlDataSources,null)) return null; |
||
681 | } |
||
682 | 6865 | jaume | |
683 | |||
684 | if (xmlDataSources.getChildrenCount() > 0) { |
||
685 | 6635 | jmvivo | xml.addChild(xmlDataSources); |
686 | 6865 | jaume | } |
687 | if (xmlTables.getChildrenCount() > 0) { |
||
688 | 6635 | jmvivo | xml.addChild(xmlTables); |
689 | } |
||
690 | 6865 | jaume | |
691 | return xml;
|
||
692 | 6635 | jmvivo | } |
693 | |||
694 | 6865 | jaume | |
695 | 6635 | jmvivo | public XMLEntity generateXMLCopyLayers(FLayer[] actives) { |
696 | 6865 | jaume | |
697 | 6635 | jmvivo | XMLEntity xml = this.newRootNode();
|
698 | XMLEntity xmlLayers = this.newLayersNode();
|
||
699 | XMLEntity xmlTables = this.newTablesNode();
|
||
700 | XMLEntity xmlDataSources = this.newDataSourcesNode();
|
||
701 | 6865 | jaume | |
702 | 6635 | jmvivo | for (int i=0;i < actives.length; i++) { |
703 | if (!this.addToXMLLayer(actives[i],xmlLayers ,xmlTables,xmlDataSources)) return null; |
||
704 | 6865 | jaume | |
705 | 6635 | jmvivo | } |
706 | 6865 | jaume | |
707 | if (xmlDataSources.getChildrenCount() > 0) { |
||
708 | 6635 | jmvivo | xml.addChild(xmlDataSources); |
709 | 6865 | jaume | } |
710 | if (xmlLayers.getChildrenCount() > 0) { |
||
711 | 6635 | jmvivo | xml.addChild(xmlLayers); |
712 | } |
||
713 | 6865 | jaume | if (xmlTables.getChildrenCount() > 0) { |
714 | 6635 | jmvivo | xml.addChild(xmlTables); |
715 | } |
||
716 | 6865 | jaume | |
717 | 6635 | jmvivo | return xml;
|
718 | 6865 | jaume | |
719 | 6635 | jmvivo | } |
720 | |||
721 | |||
722 | 6865 | jaume | |
723 | 6635 | jmvivo | /*
|
724 | 6865 | jaume | *
|
725 | *
|
||
726 | *
|
||
727 | 6635 | jmvivo | * Funciones Publicas de carga de un XML (pegar)
|
728 | 6865 | jaume | *
|
729 | *
|
||
730 | *
|
||
731 | 6635 | jmvivo | */
|
732 | |||
733 | public boolean loadLayersFromXML(XMLEntity xml, FLayers root) { |
||
734 | XMLEntity xmlLayers = this.getXMLEntityChildOfType(xml,"layers"); |
||
735 | XMLEntity xmlTables = this.getXMLEntityChildOfType(xml,"tables"); |
||
736 | XMLEntity xmlDataSources = this.getXMLEntityChildOfType(xml,"dataSources"); |
||
737 | 6865 | jaume | |
738 | 6635 | jmvivo | if (xmlLayers == null ) return false; |
739 | 6865 | jaume | |
740 | // Se pegan las tablas igualmente
|
||
741 | 6635 | jmvivo | /*
|
742 | Project project = this.getProject();
|
||
743 | 6865 | jaume | |
744 | 6635 | jmvivo | Hashtable tablesConfits = this.getConflicts(xmlTables,project.getTables());
|
745 | */
|
||
746 | 6865 | jaume | |
747 | |||
748 | 6635 | jmvivo | if (xmlDataSources != null) { |
749 | if (!this.registerDataSources(xmlDataSources)) return false; |
||
750 | } |
||
751 | 6865 | jaume | |
752 | 6635 | jmvivo | if (!this.addLayers(xmlLayers,root)) return false; |
753 | 6865 | jaume | |
754 | 6635 | jmvivo | if (xmlTables != null) { |
755 | if (!this.addTables(xmlTables)) return false; |
||
756 | } |
||
757 | 6865 | jaume | |
758 | 6635 | jmvivo | return true; |
759 | 6865 | jaume | |
760 | 6635 | jmvivo | } |
761 | 6865 | jaume | |
762 | |||
763 | 6635 | jmvivo | public boolean loadViewsFromXML(XMLEntity xml) { |
764 | XMLEntity xmlViews = this.getXMLEntityChildOfType(xml,"views"); |
||
765 | XMLEntity xmlTables = this.getXMLEntityChildOfType(xml,"tables"); |
||
766 | XMLEntity xmlDataSources = this.getXMLEntityChildOfType(xml,"dataSources"); |
||
767 | 6865 | jaume | |
768 | 6635 | jmvivo | if (xmlViews == null ) return false; |
769 | |||
770 | Project project = this.getProject();
|
||
771 | |||
772 | 7379 | caballero | Hashtable viewsConflits = this.getConflicts(xmlViews,project.getDocumentsByType(ProjectViewFactory.registerName)); |
773 | 6865 | jaume | |
774 | 7379 | caballero | Hashtable tablesConflits = this.getConflicts(xmlTables,project.getDocumentsByType(ProjectTableFactory.registerName)); |
775 | 6865 | jaume | |
776 | 6635 | jmvivo | if (viewsConflits != null && viewsConflits.size() > 0) { |
777 | int option = JOptionPane.showConfirmDialog( |
||
778 | (Component)PluginServices.getMainFrame(),
|
||
779 | "<html>"+
|
||
780 | 6645 | jmvivo | PluginServices.getText(this,"conflicto_de_nombres_de_vistas_al_pegar") + "<br>" + |
781 | PluginServices.getText(this,"debera_introducir_nombres_para_las_vistas_a_pegar") + "<br>" + |
||
782 | 6635 | jmvivo | PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
783 | PluginServices.getText(this,"desea_continuar") + |
||
784 | "</html>",
|
||
785 | PluginServices.getText(this,"pegar_vistas"), |
||
786 | JOptionPane.YES_NO_OPTION
|
||
787 | ); |
||
788 | if (option != JOptionPane.YES_OPTION) { |
||
789 | return false; |
||
790 | } |
||
791 | Enumeration en = viewsConflits.elements();
|
||
792 | while (en.hasMoreElements()) {
|
||
793 | XMLEntity view = (XMLEntity)en.nextElement(); |
||
794 | String newName = JOptionPane.showInputDialog( |
||
795 | (Component)PluginServices.getMainFrame(),
|
||
796 | "<html>"+
|
||
797 | 6645 | jmvivo | PluginServices.getText(this,"introduzca_nuevo_nombre_para_la_vista") +" "+ view.getStringProperty("name") + ":" + |
798 | 6635 | jmvivo | "</html>", //Mensaje |
799 | view.getStringProperty("name") //Valor por defecto |
||
800 | ); |
||
801 | if (newName == null) { |
||
802 | JOptionPane.showMessageDialog(
|
||
803 | (Component)PluginServices.getMainFrame(),
|
||
804 | "<html>"+PluginServices.getText(this,"operacion_cancelada")+"</html>",//Mensaje |
||
805 | PluginServices.getText(this,"pegar_vistas"),//titulo |
||
806 | JOptionPane.ERROR_MESSAGE
|
||
807 | ); |
||
808 | } else if (newName.equalsIgnoreCase(view.getStringProperty("name")) ) { |
||
809 | JOptionPane.showMessageDialog(
|
||
810 | (Component)PluginServices.getMainFrame(),
|
||
811 | "<html>"+
|
||
812 | 6865 | jaume | PluginServices.getText(this,"operacion_cancelada") +":<br>" + |
813 | 6635 | jmvivo | PluginServices.getText(this,"nombre_no_valido")+ |
814 | "</html>",//Mensaje |
||
815 | PluginServices.getText(this,"pegar_vistas"),//FIXME: getText |
||
816 | JOptionPane.ERROR_MESSAGE
|
||
817 | ); |
||
818 | return false; |
||
819 | } |
||
820 | view.setName(newName); |
||
821 | 6865 | jaume | } |
822 | 7742 | jmvivo | if (xmlTables != null) xmlTables.removeAllChildren(); |
823 | 6635 | jmvivo | tablesConflits = null;
|
824 | } |
||
825 | 6865 | jaume | |
826 | 6635 | jmvivo | if (tablesConflits != null && tablesConflits.size() > 0) { |
827 | int option = JOptionPane.showConfirmDialog( |
||
828 | (Component)PluginServices.getMainFrame(),
|
||
829 | "<html>" +
|
||
830 | 6645 | jmvivo | PluginServices.getText(this,"conflicto_de_nombres_de_tablas_al_pegar") + "<br>" + |
831 | 6635 | jmvivo | PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
832 | PluginServices.getText(this,"desea_continuar") + |
||
833 | "</html>", //Mensaje |
||
834 | PluginServices.getText(this,"pegar_vistas"),//FIXME: getText |
||
835 | JOptionPane.YES_NO_OPTION
|
||
836 | ); |
||
837 | if (option != JOptionPane.YES_OPTION) { |
||
838 | return false; |
||
839 | } |
||
840 | 7742 | jmvivo | xmlTables.removeAllChildren(); |
841 | 6635 | jmvivo | } |
842 | |||
843 | |||
844 | if (xmlDataSources != null) { |
||
845 | if (!this.registerDataSources(xmlDataSources)) return false; |
||
846 | } |
||
847 | 6865 | jaume | |
848 | 6635 | jmvivo | if (!this.addViews(xmlViews)) return false; |
849 | 6865 | jaume | |
850 | 6635 | jmvivo | if (xmlTables != null) { |
851 | if (!this.addTables(xmlTables)) return false; |
||
852 | } |
||
853 | |||
854 | return true; |
||
855 | } |
||
856 | |||
857 | public boolean loadTablesFromXML(XMLEntity xml) { |
||
858 | XMLEntity xmlTables = this.getXMLEntityChildOfType(xml,"tables"); |
||
859 | XMLEntity xmlDataSources = this.getXMLEntityChildOfType(xml,"dataSources"); |
||
860 | 6865 | jaume | |
861 | |||
862 | 6635 | jmvivo | if (xmlTables == null ) return false; |
863 | 6865 | jaume | |
864 | 6635 | jmvivo | /*
|
865 | Project project = this.getProject();
|
||
866 | 6865 | jaume | |
867 | 6635 | jmvivo | Hashtable tablesConfits = this.getConflicts(xmlTables,project.getTables());
|
868 | */
|
||
869 | |||
870 | if (xmlDataSources != null) { |
||
871 | if (!this.registerDataSources(xmlDataSources)) return false; |
||
872 | } |
||
873 | 6865 | jaume | |
874 | |||
875 | |||
876 | 6635 | jmvivo | return this.addTables(xmlTables); |
877 | } |
||
878 | 6865 | jaume | |
879 | 6635 | jmvivo | public boolean loadMapsFromXML(XMLEntity xml) { |
880 | XMLEntity xmlMaps = this.getXMLEntityChildOfType(xml,"Maps"); |
||
881 | XMLEntity xmlViews = this.getXMLEntityChildOfType(xml,"views"); |
||
882 | XMLEntity xmlTables = this.getXMLEntityChildOfType(xml,"tables"); |
||
883 | XMLEntity xmlDataSources = this.getXMLEntityChildOfType(xml,"dataSources"); |
||
884 | 6865 | jaume | |
885 | 6635 | jmvivo | if (xmlMaps == null ) return false; |
886 | 6865 | jaume | |
887 | 6635 | jmvivo | Project project = this.getProject();
|
888 | |||
889 | 7379 | caballero | Hashtable mapsConflits = this.getConflicts(xmlMaps,project.getDocumentsByType(ProjectMapFactory.registerName)); |
890 | 6865 | jaume | |
891 | 7379 | caballero | Hashtable viewsConflits = this.getConflicts(xmlViews,project.getDocumentsByType(ProjectViewFactory.registerName)); |
892 | 6865 | jaume | |
893 | 7379 | caballero | Hashtable tablesConflits = this.getConflicts(xmlTables,project.getDocumentsByType(ProjectTableFactory.registerName)); |
894 | 6865 | jaume | |
895 | |||
896 | 6635 | jmvivo | if (mapsConflits != null && mapsConflits.size() > 0) { |
897 | int option = JOptionPane.showConfirmDialog( |
||
898 | (Component)PluginServices.getMainFrame(),
|
||
899 | "<html>"+
|
||
900 | 6645 | jmvivo | PluginServices.getText(this,"conflicto_de_nombres_de_mapas_al_pegar") + "<br>" + |
901 | PluginServices.getText(this,"debera_introducir_nombres_para_los_mapas_a_pegar") + "<br>" + |
||
902 | 6635 | jmvivo | "</html>", //Mensaje |
903 | PluginServices.getText(this,"pegar_mapas"),//titulo |
||
904 | JOptionPane.YES_NO_OPTION
|
||
905 | ); |
||
906 | if (option != JOptionPane.YES_OPTION) { |
||
907 | return false; |
||
908 | } |
||
909 | Enumeration en = mapsConflits.elements();
|
||
910 | while (en.hasMoreElements()) {
|
||
911 | XMLEntity map = (XMLEntity)en.nextElement(); |
||
912 | String newName = JOptionPane.showInputDialog( |
||
913 | (Component)PluginServices.getMainFrame(),
|
||
914 | "<html>"+
|
||
915 | PluginServices.getText(this,"nuevo_nombre_para_el_mapa") +" "+ map.getStringProperty("name") + ":" + |
||
916 | "</html>", //Mensaje |
||
917 | map.getStringProperty("name") //Valor por defecto |
||
918 | ); |
||
919 | if (newName == null) { |
||
920 | JOptionPane.showMessageDialog(
|
||
921 | (Component)PluginServices.getMainFrame(),
|
||
922 | "<html>"+PluginServices.getText(this,"operacion_cancelada")+"</html>",//Mensaje |
||
923 | PluginServices.getText(this,"pegar_mapas"),//titulo |
||
924 | JOptionPane.ERROR_MESSAGE
|
||
925 | ); |
||
926 | } else if (newName.equalsIgnoreCase(map.getStringProperty("name")) ) { |
||
927 | JOptionPane.showMessageDialog(
|
||
928 | (Component)PluginServices.getMainFrame(),
|
||
929 | "<html>"+
|
||
930 | 6865 | jaume | PluginServices.getText(this,"operacion_cancelada") +":<br>" + |
931 | 6635 | jmvivo | PluginServices.getText(this,"nombre_no_valido")+ |
932 | 6865 | jaume | "</html>",//Mensaje |
933 | 6635 | jmvivo | PluginServices.getText(this,"pegar_mapas"),//titulo |
934 | JOptionPane.ERROR_MESSAGE
|
||
935 | ); |
||
936 | return false; |
||
937 | } |
||
938 | map.setName(newName); |
||
939 | 6865 | jaume | } |
940 | 6635 | jmvivo | } |
941 | 6865 | jaume | |
942 | 6635 | jmvivo | if (viewsConflits != null && viewsConflits.size() > 0) { |
943 | int option = JOptionPane.showConfirmDialog( |
||
944 | (Component)PluginServices.getMainFrame(),
|
||
945 | "<html>"+
|
||
946 | 6865 | jaume | PluginServices.getText(this,"conflicto_de_nombres_de_vistas_al_pegar") + "<br>" + |
947 | 6635 | jmvivo | PluginServices.getText(this,"no_se_pegaran_las_vistas_del_conflicto") + "<br>" + |
948 | PluginServices.getText(this,"desea_continuar") + |
||
949 | "</html>",
|
||
950 | PluginServices.getText(this,"pegar_mapas"),//titulo |
||
951 | JOptionPane.YES_NO_OPTION
|
||
952 | ); |
||
953 | if (option != JOptionPane.YES_OPTION) { |
||
954 | return false; |
||
955 | } |
||
956 | 6645 | jmvivo | // Eliminamos las vistas del xml que no vamos a importar
|
957 | 6865 | jaume | |
958 | 6645 | jmvivo | // Esto me devuelve los indices en orden inverso
|
959 | int[] indexes = this.getIndexOfConflict(viewsConflits); |
||
960 | for (int i=0;i < indexes.length;i++) { |
||
961 | xmlViews.removeChild(indexes[i]); |
||
962 | } |
||
963 | 6865 | jaume | viewsConflits = null;
|
964 | |||
965 | 6635 | jmvivo | } |
966 | |||
967 | 6865 | jaume | |
968 | 6635 | jmvivo | if (tablesConflits != null && tablesConflits.size() > 0) { |
969 | int option = JOptionPane.showConfirmDialog( |
||
970 | (Component)PluginServices.getMainFrame(),
|
||
971 | "<html>" +
|
||
972 | PluginServices.getText(this,"conflito_de_nombres_de_tablas_al_pegar") + "<br>" + |
||
973 | PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
||
974 | PluginServices.getText(this,"desea_continuar") + |
||
975 | "</html>", //Mensaje |
||
976 | PluginServices.getText(this,"pegar_mapas"), |
||
977 | JOptionPane.YES_NO_OPTION
|
||
978 | ); |
||
979 | if (option != JOptionPane.YES_OPTION) { |
||
980 | return false; |
||
981 | } |
||
982 | 7742 | jmvivo | xmlTables.removeAllChildren(); |
983 | 6635 | jmvivo | } |
984 | |||
985 | |||
986 | if (xmlDataSources != null) { |
||
987 | if (!this.registerDataSources(xmlDataSources)) return false; |
||
988 | } |
||
989 | 6865 | jaume | |
990 | 6635 | jmvivo | if (xmlViews != null) { |
991 | if (!this.addViews(xmlViews)) return false; |
||
992 | } |
||
993 | |||
994 | if (xmlTables != null) { |
||
995 | if (!this.addTables(xmlTables)) return false; |
||
996 | 6865 | jaume | } |
997 | |||
998 | 6635 | jmvivo | return this.addMaps(xmlMaps); |
999 | |||
1000 | } |
||
1001 | |||
1002 | 6865 | jaume | |
1003 | |||
1004 | |||
1005 | |||
1006 | |||
1007 | |||
1008 | |||
1009 | |||
1010 | |||
1011 | |||
1012 | 6645 | jmvivo | /**
|
1013 | * Devuelve las claves de conflits ordenados
|
||
1014 | * en orden inverso. Las claves se esperan que
|
||
1015 | * sean instancias de Integer
|
||
1016 | 6865 | jaume | */
|
1017 | 6645 | jmvivo | private int[] getIndexOfConflict(Hashtable conflits) { |
1018 | Object[] tmpArray = conflits.keySet().toArray(); |
||
1019 | Arrays.sort(tmpArray,new Comparator() { |
||
1020 | public int compare(Object o1, Object o2) { |
||
1021 | return ((Integer)o2).intValue() - ((Integer)o1).intValue(); |
||
1022 | } |
||
1023 | } |
||
1024 | ); |
||
1025 | int[] indexes = new int[] {tmpArray.length}; |
||
1026 | for (int i = 0;i< tmpArray.length;i++) { |
||
1027 | indexes[i] = ((Integer)tmpArray[i]).intValue();
|
||
1028 | } |
||
1029 | 6865 | jaume | return indexes;
|
1030 | |||
1031 | |||
1032 | 6645 | jmvivo | } |
1033 | 6865 | jaume | |
1034 | |||
1035 | 6635 | jmvivo | private boolean addToXMLMapDependencies(ProjectMap map, XMLEntity xmlViews,XMLEntity xmlTables, XMLEntity xmlDataSources) { |
1036 | 9392 | caballero | IFFrame[] components = map.getModel().getLayoutContext().getFFrames();
|
1037 | 6865 | jaume | for (int i=0; i < components.length; i++) { |
1038 | if (components[i] instanceof FFrameView) { |
||
1039 | 6635 | jmvivo | ProjectView view = ((FFrameView)components[i]).getView(); |
1040 | if (findChildInXML(xmlViews,"name",view.getName())==null) { |
||
1041 | if (!this.addToXMLView(view,xmlViews,xmlTables,xmlDataSources)) return false; |
||
1042 | } |
||
1043 | } |
||
1044 | } |
||
1045 | 6865 | jaume | |
1046 | 6635 | jmvivo | return true; |
1047 | } |
||
1048 | 6865 | jaume | |
1049 | 6635 | jmvivo | private boolean addToXMLMap(ProjectMap map,XMLEntity xmlMaps,XMLEntity xmlViews,XMLEntity xmlTables,XMLEntity xmlDataSources) { |
1050 | try {
|
||
1051 | xmlMaps.addChild(map.getXMLEntity()); |
||
1052 | 6865 | jaume | |
1053 | 6635 | jmvivo | return this.addToXMLMapDependencies(map,xmlViews,xmlTables,xmlDataSources); |
1054 | 6865 | jaume | |
1055 | 6635 | jmvivo | } catch (SaveException e) {
|
1056 | // TODO Auto-generated catch block
|
||
1057 | e.printStackTrace(); |
||
1058 | return false; |
||
1059 | } |
||
1060 | } |
||
1061 | 6865 | jaume | |
1062 | 6635 | jmvivo | private boolean addToXMLView(ProjectView view,XMLEntity xmlViews,XMLEntity xmlTables,XMLEntity xmlDataSources) { |
1063 | try {
|
||
1064 | xmlViews.addChild(view.getXMLEntity()); |
||
1065 | 6865 | jaume | |
1066 | 6635 | jmvivo | if (!this.addToXMLLayerDependencies(view.getMapContext().getLayers(),xmlTables,xmlDataSources)) return false; |
1067 | 6865 | jaume | |
1068 | 6701 | jmvivo | if (view.getMapOverViewContext() != null) { |
1069 | return this.addToXMLLayerDependencies(view.getMapOverViewContext().getLayers(),xmlTables,xmlDataSources); |
||
1070 | } else {
|
||
1071 | return true; |
||
1072 | } |
||
1073 | 6865 | jaume | |
1074 | |||
1075 | |||
1076 | 6635 | jmvivo | } catch (SaveException e) {
|
1077 | // TODO Auto-generated catch block
|
||
1078 | e.printStackTrace(); |
||
1079 | return false; |
||
1080 | } |
||
1081 | } |
||
1082 | |||
1083 | |||
1084 | |||
1085 | public boolean checkXMLRootNode(XMLEntity xml) { |
||
1086 | if (!xml.contains("applicationName")) return false; |
||
1087 | if (!xml.getStringProperty("applicationName").equalsIgnoreCase("gvSIG")) return false; |
||
1088 | 6865 | jaume | |
1089 | 6635 | jmvivo | if (!xml.contains("version")) return false; |
1090 | if (!xml.getStringProperty("version").equalsIgnoreCase(Version.format())) return false; |
||
1091 | 6865 | jaume | |
1092 | 6635 | jmvivo | return true; |
1093 | } |
||
1094 | 6865 | jaume | |
1095 | 6635 | jmvivo | private void fillXMLRootNode(XMLEntity xml) { |
1096 | xml.putProperty("applicationName","gvSIG"); |
||
1097 | 6865 | jaume | xml.putProperty("version",Version.format());
|
1098 | 6635 | jmvivo | } |
1099 | 6865 | jaume | |
1100 | 6635 | jmvivo | public XMLEntity getXMLEntityChildOfType(XMLEntity xml,String type) { |
1101 | 6865 | jaume | int childCount = xml.getChildrenCount();
|
1102 | 6635 | jmvivo | XMLEntity child; |
1103 | for (int i=0; i < childCount; i++ ) { |
||
1104 | child = xml.getChild(i); |
||
1105 | if (child.contains("type")) { |
||
1106 | if (child.getStringProperty("type").equalsIgnoreCase(type)) { |
||
1107 | return child;
|
||
1108 | } |
||
1109 | } |
||
1110 | } |
||
1111 | return null; |
||
1112 | 6865 | jaume | |
1113 | 6635 | jmvivo | } |
1114 | 6865 | jaume | |
1115 | private Hashtable getConflicts(XMLEntity xml,ArrayList elements) { |
||
1116 | if (xml == null || xml.getChildrenCount() < 1) return null; |
||
1117 | 6635 | jmvivo | Hashtable conflits = new Hashtable(); |
1118 | 6865 | jaume | for (int iXML=0;iXML < xml.getChildrenCount();iXML++) { |
1119 | 6635 | jmvivo | XMLEntity child = xml.getChild(iXML); |
1120 | Iterator iter = elements.iterator();
|
||
1121 | while (iter.hasNext()) {
|
||
1122 | 7304 | caballero | ProjectDocument element = (ProjectDocument)iter.next(); |
1123 | 6635 | jmvivo | if (element.getName().equalsIgnoreCase(child.getStringProperty("name"))) { |
1124 | conflits.put(new Integer(iXML),child); |
||
1125 | break;
|
||
1126 | } |
||
1127 | 6865 | jaume | |
1128 | 6635 | jmvivo | } |
1129 | } |
||
1130 | return conflits;
|
||
1131 | } |
||
1132 | |||
1133 | |||
1134 | |||
1135 | private boolean registerDataSources(XMLEntity xmlDataSources) { |
||
1136 | try {
|
||
1137 | 6865 | jaume | int numDataSources = xmlDataSources.getChildrenCount();
|
1138 | |||
1139 | 6635 | jmvivo | if (numDataSources == 0) return true; |
1140 | DataSourceFactory dsFactory = LayerFactory.getDataSourceFactory(); |
||
1141 | 6865 | jaume | |
1142 | 6635 | jmvivo | for (int i = 0; i < numDataSources; i++) { |
1143 | XMLEntity child = xmlDataSources.getChild(i); |
||
1144 | String name = child.getStringProperty("gdbmsname"); |
||
1145 | 6865 | jaume | |
1146 | 6635 | jmvivo | if (dsFactory.getDriverInfo(name) == null) { |
1147 | 6865 | jaume | if (child.getStringProperty("type").equals("otherDriverFile")) { |
1148 | 6635 | jmvivo | LayerFactory.getDataSourceFactory().addFileDataSource( |
1149 | 6865 | jaume | child.getStringProperty("driverName"),
|
1150 | 6635 | jmvivo | name, |
1151 | child.getStringProperty("file")
|
||
1152 | ); |
||
1153 | 6865 | jaume | |
1154 | |||
1155 | 6635 | jmvivo | } else if (child.getStringProperty("type").equals("sameDriverFile")) { |
1156 | /* String layerName = child.getStringProperty("layerName");
|
||
1157 | ProjectView vista = project.getViewByName(child.getStringProperty(
|
||
1158 | "viewName"));
|
||
1159 | FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
|
||
1160 | 6865 | jaume | |
1161 | 6635 | jmvivo | modelo = ((AlphanumericData) layer).getRecordset();
|
1162 | associatedTable = (AlphanumericData) layer;
|
||
1163 | */
|
||
1164 | } else if (child.getStringProperty("type").equals("db")) { |
||
1165 | LayerFactory.getDataSourceFactory().addDBDataSourceByTable( |
||
1166 | name, |
||
1167 | child.getStringProperty("host"),
|
||
1168 | child.getIntProperty("port"),
|
||
1169 | child.getStringProperty("user"),
|
||
1170 | child.getStringProperty("password"),
|
||
1171 | child.getStringProperty("dbName"),
|
||
1172 | child.getStringProperty("tableName"),
|
||
1173 | child.getStringProperty("driverInfo")
|
||
1174 | ); |
||
1175 | } |
||
1176 | } |
||
1177 | } |
||
1178 | 6865 | jaume | |
1179 | 6635 | jmvivo | return true; |
1180 | } catch (Exception e) { |
||
1181 | e.printStackTrace(); |
||
1182 | return false; |
||
1183 | } |
||
1184 | } |
||
1185 | 6865 | jaume | |
1186 | 6635 | jmvivo | private boolean addTables(XMLEntity xmlTables) { |
1187 | try {
|
||
1188 | 6865 | jaume | int numTables = xmlTables.getChildrenCount();
|
1189 | 6635 | jmvivo | if (numTables == 0) return true; |
1190 | 6865 | jaume | |
1191 | 6635 | jmvivo | Project project = this.getProject();
|
1192 | 6865 | jaume | |
1193 | 6635 | jmvivo | for (int i = 0; i < numTables; i++) { |
1194 | try{
|
||
1195 | ProjectTable ptable = (ProjectTable) ProjectTable.createFromXML(xmlTables.getChild(i), project); |
||
1196 | 7304 | caballero | project.addDocument(ptable); |
1197 | 6635 | jmvivo | /*
|
1198 | if (ptable.getSeedViewInfo()!=null && ptable.getAndamiView()!=null) { // open the view, if it was open, and restore its dimensions
|
||
1199 | PluginServices.getMDIManager().addView(ptable.getAndamiView());
|
||
1200 | PluginServices.getMDIManager().changeViewInfo(ptable.getAndamiView(), ptable.getSeedViewInfo());
|
||
1201 | }
|
||
1202 | */
|
||
1203 | }catch(OpenException e){
|
||
1204 | e.printStackTrace(); |
||
1205 | return false; |
||
1206 | } |
||
1207 | } |
||
1208 | 6865 | jaume | |
1209 | 6635 | jmvivo | project.setLinkTable(); |
1210 | |||
1211 | return true; |
||
1212 | } catch (Exception e) { |
||
1213 | e.printStackTrace(); |
||
1214 | 6865 | jaume | return false; |
1215 | 6635 | jmvivo | } |
1216 | } |
||
1217 | 6865 | jaume | |
1218 | 6635 | jmvivo | public XMLEntity findChildInXML(XMLEntity xml,String propName,String value) { |
1219 | 6865 | jaume | int num = xml.getChildrenCount();
|
1220 | 6635 | jmvivo | XMLEntity child; |
1221 | for (int i=0;i < num; i++) { |
||
1222 | child = xml.getChild(i); |
||
1223 | if (child.getStringProperty(propName).equals(value)) {
|
||
1224 | return child;
|
||
1225 | } |
||
1226 | } |
||
1227 | return null; |
||
1228 | } |
||
1229 | 6865 | jaume | |
1230 | 6635 | jmvivo | private boolean addLayers(XMLEntity xmlLayers,FLayers root) { |
1231 | try {
|
||
1232 | XMLEntity child; |
||
1233 | 6865 | jaume | int numLayers = xmlLayers.getChildrenCount();
|
1234 | 6635 | jmvivo | for (int i = 0; i < numLayers; i++) { |
1235 | child = xmlLayers.getChild(i); |
||
1236 | if (!root.addLayerFromXMLEntity(child,null)) return false; |
||
1237 | } |
||
1238 | return true; |
||
1239 | } catch (Exception e) { |
||
1240 | e.printStackTrace(); |
||
1241 | 6865 | jaume | return false; |
1242 | 6635 | jmvivo | } |
1243 | 6865 | jaume | |
1244 | 6635 | jmvivo | } |
1245 | 6865 | jaume | |
1246 | |||
1247 | 6635 | jmvivo | private boolean addViews(XMLEntity xmlViews) { |
1248 | try {
|
||
1249 | Project project = this.getProject();
|
||
1250 | XMLEntity child; |
||
1251 | 6865 | jaume | int numLayers = xmlViews.getChildrenCount();
|
1252 | 6635 | jmvivo | for (int i = 0; i < numLayers; i++) { |
1253 | child = xmlViews.getChild(i); |
||
1254 | |||
1255 | ProjectView pv = (ProjectView) ProjectView.createFromXML(child, project); |
||
1256 | 7304 | caballero | project.addDocument(pv); |
1257 | 6865 | jaume | |
1258 | 6635 | jmvivo | } |
1259 | return true; |
||
1260 | } catch (Exception e) { |
||
1261 | e.printStackTrace(); |
||
1262 | 6865 | jaume | return false; |
1263 | 6635 | jmvivo | } |
1264 | 6865 | jaume | |
1265 | 6635 | jmvivo | } |
1266 | 6865 | jaume | |
1267 | 6635 | jmvivo | private boolean addMaps(XMLEntity xmlMaps) { |
1268 | try {
|
||
1269 | Project project = this.getProject();
|
||
1270 | XMLEntity child; |
||
1271 | 6865 | jaume | int numLayers = xmlMaps.getChildrenCount();
|
1272 | 6635 | jmvivo | for (int i = 0; i < numLayers; i++) { |
1273 | child = xmlMaps.getChild(i); |
||
1274 | |||
1275 | ProjectMap pm = (ProjectMap) ProjectMap.createFromXML(child, project); |
||
1276 | 7304 | caballero | project.addDocument(pm); |
1277 | 6865 | jaume | |
1278 | 6635 | jmvivo | } |
1279 | return true; |
||
1280 | } catch (Exception e) { |
||
1281 | e.printStackTrace(); |
||
1282 | 6865 | jaume | return false; |
1283 | 6635 | jmvivo | } |
1284 | 6865 | jaume | |
1285 | 6635 | jmvivo | } |
1286 | 6865 | jaume | |
1287 | 6635 | jmvivo | private Project getProject() {
|
1288 | return ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
|
||
1289 | } |
||
1290 | 6865 | jaume | |
1291 | 6635 | jmvivo | private boolean addToXMLDataSource(SourceInfo source,XMLEntity xmlDataSources, Project project) { |
1292 | if (project== null) { |
||
1293 | project = this.getProject();
|
||
1294 | 6865 | jaume | } |
1295 | 6635 | jmvivo | xmlDataSources.addChild(project.getSourceInfoXMLEntity(source)); |
1296 | 6865 | jaume | |
1297 | 6635 | jmvivo | return true; |
1298 | } |
||
1299 | 6865 | jaume | |
1300 | private boolean addToXMLTable(ProjectTable pt,XMLEntity xmlTables,XMLEntity xmlDataSources,Project project) { |
||
1301 | 6635 | jmvivo | if (project== null) { |
1302 | project = this.getProject();
|
||
1303 | } |
||
1304 | if (findChildInXML(xmlTables,"name",pt.getName()) != null) return true; |
||
1305 | XMLEntity xmlTable = null;
|
||
1306 | try {
|
||
1307 | xmlTable = pt.getXMLEntity(); |
||
1308 | 6865 | jaume | |
1309 | 6635 | jmvivo | xmlTables.addChild(xmlTable); |
1310 | 6865 | jaume | |
1311 | 6701 | jmvivo | if (pt.getAssociatedTable() != null) { |
1312 | this.addToXMLDataSource(pt.getAssociatedTable().getRecordset().getSourceInfo(),xmlDataSources,project);
|
||
1313 | } |
||
1314 | 6865 | jaume | |
1315 | 6635 | jmvivo | if (pt.getLinkTable() != null) { |
1316 | if (findChildInXML(xmlTables,"name",pt.getLinkTable()) == null) { |
||
1317 | ProjectTable ptLink = project.getTable(pt.getLinkTable()); |
||
1318 | if (!this.addToXMLTable(ptLink,xmlTables,xmlDataSources,project)) return false; |
||
1319 | } |
||
1320 | } |
||
1321 | } catch (SaveException e) {
|
||
1322 | e.printStackTrace(); |
||
1323 | return false; |
||
1324 | 10626 | caballero | } catch (ReadDriverException e) {
|
1325 | 6635 | jmvivo | e.printStackTrace(); |
1326 | return false; |
||
1327 | 6865 | jaume | } |
1328 | |||
1329 | return true; |
||
1330 | 6635 | jmvivo | } |
1331 | 6865 | jaume | |
1332 | 6635 | jmvivo | private boolean addToXMLLayerDependencies(FLayer lyr,XMLEntity xmlTables,XMLEntity xmlDataSources) { |
1333 | try {
|
||
1334 | Project project = this.getProject();
|
||
1335 | 6865 | jaume | |
1336 | 6635 | jmvivo | if (lyr instanceof FLayers) { |
1337 | FLayers lyrs = (FLayers)lyr; |
||
1338 | int count = lyrs.getLayersCount();
|
||
1339 | for (int i=0;i < count;i++) { |
||
1340 | FLayer subLyr = lyrs.getLayer(i); |
||
1341 | this.addToXMLLayerDependencies(subLyr,xmlTables,xmlDataSources);
|
||
1342 | } |
||
1343 | |||
1344 | 6865 | jaume | } else if (lyr instanceof AlphanumericData){ |
1345 | 6635 | jmvivo | if (!this.addToXMLDataSource( |
1346 | ((AlphanumericData)lyr).getRecordset().getSourceInfo(), |
||
1347 | xmlDataSources, |
||
1348 | project |
||
1349 | 6865 | jaume | |
1350 | 6635 | jmvivo | )) return false; |
1351 | 6865 | jaume | |
1352 | 6635 | jmvivo | ProjectTable pt = project.getTable((AlphanumericData) lyr); |
1353 | 6865 | jaume | if (pt != null) { |
1354 | 6635 | jmvivo | if (!this.addToXMLTable(pt,xmlTables,xmlDataSources,project)) return false; |
1355 | } |
||
1356 | |||
1357 | } |
||
1358 | |||
1359 | 10626 | caballero | } catch (ReadDriverException e) {
|
1360 | 6635 | jmvivo | e.printStackTrace(); |
1361 | return false; |
||
1362 | 6778 | jmvivo | } catch (Exception e) { |
1363 | e.printStackTrace(); |
||
1364 | 6865 | jaume | return false; |
1365 | |||
1366 | 6635 | jmvivo | } |
1367 | return true; |
||
1368 | 6865 | jaume | |
1369 | 6635 | jmvivo | } |
1370 | 6865 | jaume | |
1371 | private boolean addToXMLLayer(FLayer lyr,XMLEntity xmlLayers,XMLEntity xmlTables,XMLEntity xmlDataSources) { |
||
1372 | 6635 | jmvivo | try {
|
1373 | xmlLayers.addChild(lyr.getXMLEntity()); |
||
1374 | 6865 | jaume | |
1375 | 6635 | jmvivo | return this.addToXMLLayerDependencies(lyr,xmlTables,xmlDataSources); |
1376 | |||
1377 | } catch (XMLException e) {
|
||
1378 | e.printStackTrace(); |
||
1379 | return false; |
||
1380 | 6778 | jmvivo | } catch (Exception e) { |
1381 | e.printStackTrace(); |
||
1382 | 6865 | jaume | return false; |
1383 | 6635 | jmvivo | } |
1384 | } |
||
1385 | 6865 | jaume | |
1386 | 6635 | jmvivo | private XMLEntity newRootNode() {
|
1387 | XMLEntity xml = new XMLEntity();
|
||
1388 | fillXMLRootNode(xml); |
||
1389 | return xml;
|
||
1390 | } |
||
1391 | |||
1392 | private XMLEntity newLayersNode() {
|
||
1393 | XMLEntity xmlLayers = new XMLEntity();
|
||
1394 | xmlLayers.putProperty("type","layers"); |
||
1395 | return xmlLayers;
|
||
1396 | } |
||
1397 | |||
1398 | private XMLEntity newDataSourcesNode() {
|
||
1399 | XMLEntity xmlDataSources = new XMLEntity();
|
||
1400 | xmlDataSources.putProperty("type","dataSources"); |
||
1401 | return xmlDataSources;
|
||
1402 | } |
||
1403 | |||
1404 | private XMLEntity newTablesNode() {
|
||
1405 | XMLEntity xmlTables = new XMLEntity();
|
||
1406 | xmlTables.putProperty("type","tables"); |
||
1407 | return xmlTables;
|
||
1408 | } |
||
1409 | 6865 | jaume | |
1410 | 6635 | jmvivo | private XMLEntity newViewsNode() {
|
1411 | XMLEntity xmlTables = new XMLEntity();
|
||
1412 | xmlTables.putProperty("type","views"); |
||
1413 | return xmlTables;
|
||
1414 | } |
||
1415 | |||
1416 | private XMLEntity newMapsNode() {
|
||
1417 | XMLEntity xmlTables = new XMLEntity();
|
||
1418 | xmlTables.putProperty("type","maps"); |
||
1419 | return xmlTables;
|
||
1420 | } |
||
1421 | |||
1422 | |||
1423 | public void putInClipboard(String data) { |
||
1424 | StringSelection ss = new StringSelection(data); |
||
1425 | 6865 | jaume | |
1426 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
|
||
1427 | 6635 | jmvivo | } |
1428 | 6865 | jaume | |
1429 | 6635 | jmvivo | public String marshallXMLEntity(XMLEntity xml) { |
1430 | StringWriter buffer = new StringWriter(); |
||
1431 | |||
1432 | Marshaller m; |
||
1433 | try {
|
||
1434 | m = new Marshaller(buffer);
|
||
1435 | } catch (IOException e4) { |
||
1436 | // TODO Auto-generated catch block
|
||
1437 | e4.printStackTrace(); |
||
1438 | return null; |
||
1439 | } |
||
1440 | m.setEncoding("ISO-8859-1");
|
||
1441 | |||
1442 | try {
|
||
1443 | m.marshal(xml.getXmlTag()); |
||
1444 | //if (i < actives.length-1) buffer.write("\n##layer-separator##\n");
|
||
1445 | } catch (MarshalException e2) { |
||
1446 | // TODO Auto-generated catch block
|
||
1447 | e2.printStackTrace(); |
||
1448 | return null; |
||
1449 | } catch (ValidationException e3) {
|
||
1450 | // TODO Auto-generated catch block
|
||
1451 | e3.printStackTrace(); |
||
1452 | return null; |
||
1453 | } |
||
1454 | 6865 | jaume | |
1455 | 6635 | jmvivo | return buffer.toString();
|
1456 | 6865 | jaume | |
1457 | 6635 | jmvivo | } |
1458 | 6865 | jaume | |
1459 | 6635 | jmvivo | public XMLEntity unMarshallXMLEntity(String data) { |
1460 | StringReader reader = new StringReader(data); |
||
1461 | 6865 | jaume | |
1462 | 6635 | jmvivo | XmlTag tag; |
1463 | try {
|
||
1464 | tag = (XmlTag) XmlTag.unmarshal(reader); |
||
1465 | } catch (MarshalException e) { |
||
1466 | return null; |
||
1467 | } catch (ValidationException e) {
|
||
1468 | return null; |
||
1469 | } |
||
1470 | XMLEntity xml=new XMLEntity(tag);
|
||
1471 | 6865 | jaume | |
1472 | 6635 | jmvivo | return xml;
|
1473 | } |
||
1474 | |||
1475 | 6865 | jaume | public String getFromClipboard() { |
1476 | |||
1477 | 6635 | jmvivo | try {
|
1478 | return (String)Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor); |
||
1479 | } catch (UnsupportedFlavorException e) { |
||
1480 | return null; |
||
1481 | } catch (IOException e) { |
||
1482 | // TODO Auto-generated catch block
|
||
1483 | return null; |
||
1484 | 6865 | jaume | } |
1485 | 6635 | jmvivo | } |
1486 | 6865 | jaume | |
1487 | 6635 | jmvivo | public boolean removeLayers(FLayer[] actives) { |
1488 | for (int i = actives.length-1; i>=0; i--){ |
||
1489 | try {
|
||
1490 | //actives[i].getParentLayer().removeLayer(actives[i]);
|
||
1491 | //FLayers lyrs=getMapContext().getLayers();
|
||
1492 | //lyrs.addLayer(actives[i]);
|
||
1493 | actives[i].getParentLayer().removeLayer(actives[i]); |
||
1494 | |||
1495 | if (actives[i] instanceof AlphanumericData){ |
||
1496 | Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
||
1497 | ProjectTable pt = project.getTable((AlphanumericData) actives[i]); |
||
1498 | |||
1499 | 7379 | caballero | ArrayList tables = project.getDocumentsByType(ProjectTableFactory.registerName);
|
1500 | 6635 | jmvivo | for (int j = 0; j < tables.size(); j++) { |
1501 | if (tables.get(j) == pt){
|
||
1502 | 7304 | caballero | project.delDocument((ProjectDocument)tables.get(j)); |
1503 | 6635 | jmvivo | break;
|
1504 | } |
||
1505 | } |
||
1506 | |||
1507 | 6880 | cesar | PluginServices.getMDIManager().closeSingletonWindow(pt); |
1508 | 6635 | jmvivo | } |
1509 | |||
1510 | |||
1511 | } catch (CancelationException e1) {
|
||
1512 | e1.printStackTrace(); |
||
1513 | return false; |
||
1514 | } |
||
1515 | } |
||
1516 | return true; |
||
1517 | } |
||
1518 | 6865 | jaume | |
1519 | 7304 | caballero | public boolean removeDocuments(ProjectDocument[] selectedItems) { |
1520 | 6701 | jmvivo | Project p = this.getProject();
|
1521 | 7304 | caballero | ProjectDocument element; |
1522 | 6701 | jmvivo | int index;
|
1523 | for (int i=selectedItems.length-1;i>=0;i--) { |
||
1524 | 6865 | jaume | |
1525 | 6701 | jmvivo | element = selectedItems[i]; |
1526 | 6865 | jaume | |
1527 | 6701 | jmvivo | if (element instanceof ProjectMap) { |
1528 | 6865 | jaume | |
1529 | 6701 | jmvivo | if (element.isLocked()) {
|
1530 | JOptionPane.showMessageDialog(
|
||
1531 | (Component)PluginServices.getMainFrame(),
|
||
1532 | PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +element.getName() |
||
1533 | ); |
||
1534 | //return false;
|
||
1535 | } else {
|
||
1536 | 6880 | cesar | PluginServices.getMDIManager().closeSingletonWindow(element); |
1537 | 7304 | caballero | p.delDocument(element); |
1538 | 6701 | jmvivo | } |
1539 | } else if (element instanceof ProjectTable) { |
||
1540 | if (element.isLocked()) {
|
||
1541 | JOptionPane.showMessageDialog(
|
||
1542 | (Component)PluginServices.getMainFrame(),
|
||
1543 | PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +element.getName() |
||
1544 | ); |
||
1545 | 6635 | jmvivo | |
1546 | 6701 | jmvivo | //return false;
|
1547 | } else {
|
||
1548 | 6880 | cesar | PluginServices.getMDIManager().closeSingletonWindow(element); |
1549 | 7304 | caballero | p.delDocument(element); |
1550 | 6865 | jaume | } |
1551 | 6701 | jmvivo | } else {
|
1552 | if (element.isLocked()) {
|
||
1553 | JOptionPane.showMessageDialog(
|
||
1554 | (Component)PluginServices.getMainFrame(),
|
||
1555 | PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +element.getName() |
||
1556 | ); |
||
1557 | //return false;
|
||
1558 | } else {
|
||
1559 | 6880 | cesar | PluginServices.getMDIManager().closeSingletonWindow(element); |
1560 | 7304 | caballero | p.delDocument(element); |
1561 | 6701 | jmvivo | } |
1562 | } |
||
1563 | 6865 | jaume | } |
1564 | 6701 | jmvivo | return true; |
1565 | } |
||
1566 | |||
1567 | 6635 | jmvivo | } |