Revision 39136 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/toc/actions/CutLayersTocMenuEntry.java
CutLayersTocMenuEntry.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import javax.swing.JOptionPane; |
6 | 6 |
|
7 |
import org.slf4j.Logger; |
|
8 |
import org.slf4j.LoggerFactory; |
|
9 |
|
|
7 | 10 |
import org.gvsig.andami.PluginServices; |
8 |
import org.gvsig.app.extension.ProjectExtension; |
|
9 |
import org.gvsig.app.project.Project; |
|
10 | 11 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
11 | 12 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
12 | 13 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
13 |
import org.gvsig.utils.XMLEntity; |
|
14 |
import org.gvsig.i18n.Messages; |
|
15 |
import org.gvsig.tools.persistence.PersistentState; |
|
14 | 16 |
|
15 | 17 |
|
16 | 18 |
public class CutLayersTocMenuEntry extends AbstractTocContextMenuAction { |
17 |
private CopyPasteLayersUtiles utiles = CopyPasteLayersUtiles.getInstance(); |
|
18 | 19 |
|
20 |
private static Logger logger = |
|
21 |
LoggerFactory.getLogger(CutLayersTocMenuEntry.class); |
|
22 |
|
|
19 | 23 |
public String getGroup() { |
20 | 24 |
return "copyPasteLayer"; |
21 | 25 |
} |
... | ... | |
45 | 49 |
|
46 | 50 |
|
47 | 51 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
48 |
XMLEntity xml = this.utiles.generateXMLCopyLayers(selectedItems); |
|
49 |
if (xml == null) { |
|
50 |
JOptionPane.showMessageDialog( |
|
51 |
(Component)PluginServices.getMainFrame(), |
|
52 |
"<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
|
53 |
PluginServices.getText(this,"cortar"),//titulo |
|
54 |
JOptionPane.ERROR_MESSAGE |
|
55 |
); |
|
56 |
return; |
|
57 |
} |
|
52 |
|
|
53 |
PersistentState lyrs_state = null; |
|
54 |
|
|
55 |
try { |
|
56 |
lyrs_state = CopyPasteLayersUtils.getAsFLayersPersistentState( |
|
57 |
selectedItems, this.getMapContext()); |
|
58 |
/* |
|
59 |
* Saving layers data to clipboard. |
|
60 |
* Files and URLs are not relativized |
|
61 |
*/ |
|
62 |
CopyPasteLayersUtils.saveToClipboard(lyrs_state); |
|
58 | 63 |
|
59 |
String data = xml.toString(); |
|
60 |
if (data == null) { |
|
61 |
JOptionPane.showMessageDialog( |
|
62 |
(Component)PluginServices.getMainFrame(), |
|
63 |
"<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje |
|
64 |
PluginServices.getText(this,"cortar"),//titulo |
|
65 |
JOptionPane.ERROR_MESSAGE |
|
66 |
); |
|
67 |
return; |
|
68 |
} |
|
64 |
int option=JOptionPane.showConfirmDialog( |
|
65 |
(Component)PluginServices.getMainFrame(), |
|
66 |
PluginServices.getText(this,"desea_borrar_la_capa")); |
|
67 |
|
|
68 |
if (option == JOptionPane.OK_OPTION) { |
|
69 |
/* |
|
70 |
* If user says no, this is like copy (not cut) |
|
71 |
*/ |
|
72 |
CopyPasteLayersUtils.removeLayers( |
|
73 |
selectedItems, |
|
74 |
this.getMapContext()); |
|
75 |
} |
|
76 |
|
|
77 |
} catch (Exception e) { |
|
78 |
|
|
79 |
JOptionPane.showMessageDialog( |
|
80 |
(Component)PluginServices.getMainFrame(), |
|
81 |
Messages.getText("No_ha_sido_posible_realizar_la_operacion") |
|
82 |
+ "\n\n" + e.getMessage(), |
|
83 |
Messages.getText("cortar"), |
|
84 |
JOptionPane.ERROR_MESSAGE |
|
85 |
); |
|
86 |
logger.info("While cutting layers.", e); |
|
87 |
return; |
|
88 |
} |
|
69 | 89 |
|
70 | 90 |
|
71 |
PluginServices.putInClipboard(data); |
|
72 | 91 |
|
73 |
|
|
74 |
int option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa")); |
|
75 |
if (option!=JOptionPane.OK_OPTION) { |
|
76 |
return; |
|
77 |
} |
|
78 |
getMapContext().beginAtomicEvent(); |
|
79 |
|
|
80 |
|
|
81 |
boolean isOK =this.utiles.removeLayers(selectedItems); |
|
82 |
|
|
83 |
getMapContext().endAtomicEvent(); |
|
84 |
|
|
85 |
if (isOK) { |
|
86 |
getMapContext().invalidate(); |
|
87 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
|
88 |
project.setModified(true); |
|
89 |
if (getMapContext().getLayers().getLayersCount()==0) { |
|
90 |
PluginServices.getMainFrame().enableControls(); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 | 92 |
} |
95 | 93 |
|
96 | 94 |
} |
Also available in: Unified diff