Revision 38056 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/PasteLayersTocMenuEntry.java
PasteLayersTocMenuEntry.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.project.documents.view.toc.actions; |
2 | 2 |
|
3 |
import java.awt.MouseInfo; |
|
4 |
import java.awt.PointerInfo; |
|
5 |
|
|
6 |
import javax.swing.JMenuItem; |
|
7 |
import javax.swing.JPopupMenu; |
|
8 |
import javax.swing.SwingUtilities; |
|
9 |
|
|
10 | 3 |
import org.exolab.castor.xml.MarshalException; |
11 | 4 |
import org.exolab.castor.xml.ValidationException; |
12 | 5 |
|
... | ... | |
44 | 37 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
45 | 38 |
if (isTocItemBranch(item)) { |
46 | 39 |
FLayer lyr = getNodeLayer(item); |
47 |
// if (lyr instanceof FLayers) { |
|
48 |
this.xml = this.getCheckedXMLFromClipboard();
|
|
49 |
// return true; |
|
50 |
// } |
|
40 |
// if (lyr instanceof FLayers) {
|
|
41 |
this.xml = this.getCheckedXMLFromClipboard(); |
|
42 |
// return true;
|
|
43 |
// }
|
|
51 | 44 |
return this.xml != null; // Podemos hacer paste en cualquier sitio y nos preguntar? si queremos meter la capa en ese sitio |
52 | 45 |
|
53 | 46 |
} else if (!isTocItemLeaf(item)) { |
... | ... | |
63 | 56 |
String sourceString = PluginServices.getFromClipboard(); |
64 | 57 |
if (sourceString == null) return null; |
65 | 58 |
|
66 |
// System.out.println(sourceString); |
|
59 |
// System.out.println(sourceString);
|
|
67 | 60 |
XMLEntity xml; |
68 | 61 |
try { |
69 | 62 |
xml = XMLEntity.parse(sourceString); |
... | ... | |
88 | 81 |
|
89 | 82 |
FLayer lyrOn = getNodeLayer(item); |
90 | 83 |
if (isTocItemBranch(item)) { |
91 |
if (lyrOn instanceof FLayers) { |
|
92 |
root = (FLayers)getNodeLayer(item); |
|
93 |
} |
|
94 |
else |
|
95 |
{ |
|
96 |
// Cambio: Siempre arriba |
|
97 |
// JPopupMenu pop = new JPopupMenu(PluginServices.getText(this, "Paste")); |
|
98 |
// JMenuItem itUp = new JMenuItem(PluginServices.getText(this, "Paste_above_layer") + " " + lyrOn.getName()); |
|
99 |
// JMenuItem itDown = new JMenuItem(PluginServices.getText(this, "Paste_below_layer") + " " + lyrOn.getName()); |
|
100 |
// |
|
101 |
// itUp.setActionCommand("UP"); |
|
102 |
// itDown.setActionCommand("DOWN"); |
|
103 |
// |
|
104 |
// MyPasteListener lis = new MyPasteListener(pop, item, this.xml, lyrOn, getMapContext()); |
|
105 |
// |
|
106 |
// itUp.addActionListener(lis); |
|
107 |
// itDown.addActionListener(lis); |
|
108 |
// |
|
109 |
// pop.add(itUp); |
|
110 |
// pop.add(itDown); |
|
111 |
// |
|
112 |
// PointerInfo pi = MouseInfo.getPointerInfo(); |
|
113 |
// |
|
114 |
// pop.show(null, pi.getLocation().x, pi.getLocation().y); |
|
84 |
MapContext mapContext = getMapContext(); |
|
85 |
mapContext.beginAtomicEvent(); |
|
86 |
FLayers all = lyrOn.getParentLayer(); |
|
115 | 87 |
|
116 |
MapContext mapContext = getMapContext(); |
|
117 |
mapContext.beginAtomicEvent(); |
|
118 |
try { |
|
119 |
|
|
120 |
FLayers all = mapContext.getLayers(); |
|
121 |
CopyPasteLayersUtiles.getInstance().loadLayersFromXML(xml, all); |
|
122 |
// ponemos las capas en posici?n |
|
123 |
int pos = -1; |
|
124 |
for (int j=0; j < all.getLayersCount(); j++) { |
|
125 |
if (all.getLayer(j).getName().equalsIgnoreCase(lyrOn.getName())) { |
|
126 |
pos = j; |
|
127 |
break; |
|
128 |
} |
|
129 |
} |
|
130 |
int corrected = 2; |
|
131 |
all.moveTo(0, all.getLayersCount()-corrected-pos); |
|
132 |
} catch (Exception ex) { |
|
133 |
ex.printStackTrace(); |
|
134 |
} |
|
135 |
|
|
136 |
mapContext.endAtomicEvent(); |
|
137 |
mapContext.invalidate(); |
|
138 |
|
|
88 |
CopyPasteLayersUtiles.getInstance().loadLayersFromXML(xml, all); |
|
89 |
int position = getPosition(all, lyrOn); |
|
90 |
all.moveTo(0, position); |
|
139 | 91 |
|
140 |
return;
|
|
141 |
}
|
|
142 |
} else if (lyrOn == null){ |
|
92 |
mapContext.endAtomicEvent();
|
|
93 |
mapContext.invalidate();
|
|
94 |
} else if (lyrOn == null) {
|
|
143 | 95 |
root = getMapContext().getLayers(); |
144 |
} else { |
|
145 |
return; |
|
146 |
} |
|
96 |
getMapContext().beginAtomicEvent(); |
|
147 | 97 |
|
148 |
getMapContext().beginAtomicEvent(); |
|
149 |
|
|
150 |
boolean isOK = this.utiles.loadLayersFromXML(this.xml,root); |
|
98 |
boolean isOK = this.utiles.loadLayersFromXML(this.xml,root); |
|
151 | 99 |
|
152 |
getMapContext().endAtomicEvent(); |
|
100 |
getMapContext().endAtomicEvent();
|
|
153 | 101 |
|
154 |
if (isOK) { |
|
155 |
getMapContext().invalidate(); |
|
156 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
|
157 |
project.setModified(true); |
|
102 |
if (isOK) { |
|
103 |
getMapContext().invalidate(); |
|
104 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
|
105 |
project.setModified(true); |
|
106 |
} |
|
158 | 107 |
} |
159 | 108 |
} |
160 | 109 |
|
110 |
private int getPosition(FLayers layerGroup, FLayer lyrSelected){ |
|
111 |
int pos = -1; |
|
112 |
for (int j=0; j < layerGroup.getLayersCount(); j++) { |
|
113 |
if (layerGroup.getLayer(j).getName().equalsIgnoreCase(lyrSelected.getName())) { |
|
114 |
pos = j; |
|
115 |
break; |
|
116 |
} |
|
117 |
} |
|
118 |
int offset = 2; |
|
119 |
return layerGroup.getLayersCount() - offset - pos; |
|
120 |
} |
|
161 | 121 |
|
162 | 122 |
} |
Also available in: Unified diff