Revision 7758 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/layout/ProjectMapFactory.java
ProjectMapFactory.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.project.documents.layout; |
2 | 2 |
|
3 |
import java.awt.Component; |
|
3 | 4 |
import java.text.DateFormat; |
5 |
import java.util.Arrays; |
|
6 |
import java.util.Comparator; |
|
4 | 7 |
import java.util.Date; |
8 |
import java.util.Enumeration; |
|
9 |
import java.util.Hashtable; |
|
5 | 10 |
|
6 | 11 |
import javax.swing.ImageIcon; |
12 |
import javax.swing.JOptionPane; |
|
7 | 13 |
|
8 | 14 |
import com.iver.andami.PluginServices; |
9 | 15 |
import com.iver.cit.gvsig.gui.layout.Layout; |
10 | 16 |
import com.iver.cit.gvsig.project.Project; |
11 | 17 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
12 | 18 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
19 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CopyDocumentContextMenuAction; |
|
20 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CutDocumentContextMenuAction; |
|
21 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.PasteDocumentContextMenuAction; |
|
22 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
|
23 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
|
24 |
import com.iver.utiles.XMLEntity; |
|
13 | 25 |
|
14 | 26 |
|
15 | 27 |
/** |
... | ... | |
50 | 62 |
map.setModel(new Layout()); |
51 | 63 |
map.getModel().setProjectMap(map); |
52 | 64 |
map.setProject(project, 0); |
65 |
map.setProjectDocumentFactory(this); |
|
53 | 66 |
|
54 | 67 |
return map; |
55 | 68 |
} |
... | ... | |
95 | 108 |
public static void register() { |
96 | 109 |
register(registerName, new ProjectMapFactory(), |
97 | 110 |
"com.iver.cit.gvsig.project.ProjectMap"); |
111 |
|
|
112 |
registerAction(registerName,"copy",new CopyDocumentContextMenuAction()); |
|
113 |
registerAction(registerName,"cut",new CutDocumentContextMenuAction()); |
|
114 |
registerAction(registerName,"paste",new PasteDocumentContextMenuAction()); |
|
98 | 115 |
} |
99 | 116 |
|
100 | 117 |
/** |
... | ... | |
105 | 122 |
public int getPriority() { |
106 | 123 |
return 2; |
107 | 124 |
} |
125 |
|
|
126 |
public boolean resolveImportXMLConflicts(XMLEntity root, Project project, Hashtable conflicts) { |
|
127 |
XMLEntity xmlMaps = root.firstChild("type",this.getRegisterName()); |
|
128 |
XMLEntity xmlViews = root.firstChild("type",ProjectViewFactory.registerName); |
|
129 |
XMLEntity xmlTables = root.firstChild("type",ProjectTableFactory.registerName); |
|
130 |
|
|
131 |
Hashtable mapsConflits = (Hashtable)conflicts.get(ProjectMapFactory.registerName); |
|
132 |
|
|
133 |
Hashtable viewsConflits = (Hashtable)conflicts.get(ProjectViewFactory.registerName); |
|
134 |
|
|
135 |
Hashtable tablesConflits = (Hashtable)conflicts.get(ProjectTableFactory.registerName); |
|
136 |
|
|
137 |
|
|
138 |
if (mapsConflits != null && mapsConflits.size() > 0) { |
|
139 |
int option = JOptionPane.showConfirmDialog( |
|
140 |
(Component)PluginServices.getMainFrame(), |
|
141 |
"<html>"+ |
|
142 |
PluginServices.getText(this,"conflicto_de_nombres_de_mapas_al_pegar") + "<br>" + |
|
143 |
PluginServices.getText(this,"debera_introducir_nombres_para_los_mapas_a_pegar") + "<br>" + |
|
144 |
"</html>", //Mensaje |
|
145 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
|
146 |
JOptionPane.YES_NO_OPTION |
|
147 |
); |
|
148 |
if (option != JOptionPane.YES_OPTION) { |
|
149 |
return false; |
|
150 |
} |
|
151 |
Enumeration en = mapsConflits.elements(); |
|
152 |
while (en.hasMoreElements()) { |
|
153 |
XMLEntity map = (XMLEntity)en.nextElement(); |
|
154 |
String newName = JOptionPane.showInputDialog( |
|
155 |
(Component)PluginServices.getMainFrame(), |
|
156 |
"<html>"+ |
|
157 |
PluginServices.getText(this,"nuevo_nombre_para_el_mapa") +" "+ map.getStringProperty("name") + ":" + |
|
158 |
"</html>", //Mensaje |
|
159 |
map.getStringProperty("name") //Valor por defecto |
|
160 |
); |
|
161 |
if (newName == null) { |
|
162 |
JOptionPane.showMessageDialog( |
|
163 |
(Component)PluginServices.getMainFrame(), |
|
164 |
"<html>"+PluginServices.getText(this,"operacion_cancelada")+"</html>",//Mensaje |
|
165 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
|
166 |
JOptionPane.ERROR_MESSAGE |
|
167 |
); |
|
168 |
} else if (newName.equalsIgnoreCase(map.getStringProperty("name")) ) { |
|
169 |
JOptionPane.showMessageDialog( |
|
170 |
(Component)PluginServices.getMainFrame(), |
|
171 |
"<html>"+ |
|
172 |
PluginServices.getText(this,"operacion_cancelada") +":<br>" + |
|
173 |
PluginServices.getText(this,"nombre_no_valido")+ |
|
174 |
"</html>",//Mensaje |
|
175 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
|
176 |
JOptionPane.ERROR_MESSAGE |
|
177 |
); |
|
178 |
return false; |
|
179 |
} |
|
180 |
map.setName(newName); |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
if (viewsConflits != null && viewsConflits.size() > 0) { |
|
185 |
int option = JOptionPane.showConfirmDialog( |
|
186 |
(Component)PluginServices.getMainFrame(), |
|
187 |
"<html>"+ |
|
188 |
PluginServices.getText(this,"conflicto_de_nombres_de_vistas_al_pegar") + "<br>" + |
|
189 |
PluginServices.getText(this,"no_se_pegaran_las_vistas_del_conflicto") + "<br>" + |
|
190 |
PluginServices.getText(this,"desea_continuar") + |
|
191 |
"</html>", |
|
192 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
|
193 |
JOptionPane.YES_NO_OPTION |
|
194 |
); |
|
195 |
if (option != JOptionPane.YES_OPTION) { |
|
196 |
return false; |
|
197 |
} |
|
198 |
// Eliminamos las vistas del xml que no vamos a importar |
|
199 |
|
|
200 |
// Esto me devuelve los indices en orden inverso |
|
201 |
int[] indexes = this.getIndexOfConflict(viewsConflits); |
|
202 |
for (int i=0;i < indexes.length;i++) { |
|
203 |
xmlViews.removeChild(indexes[i]); |
|
204 |
} |
|
205 |
viewsConflits = null; |
|
206 |
|
|
207 |
} |
|
208 |
|
|
209 |
|
|
210 |
if (tablesConflits != null && tablesConflits.size() > 0) { |
|
211 |
int option = JOptionPane.showConfirmDialog( |
|
212 |
(Component)PluginServices.getMainFrame(), |
|
213 |
"<html>" + |
|
214 |
PluginServices.getText(this,"conflito_de_nombres_de_tablas_al_pegar") + "<br>" + |
|
215 |
PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
|
216 |
PluginServices.getText(this,"desea_continuar") + |
|
217 |
"</html>", //Mensaje |
|
218 |
PluginServices.getText(this,"pegar_mapas"), |
|
219 |
JOptionPane.YES_NO_OPTION |
|
220 |
); |
|
221 |
if (option != JOptionPane.YES_OPTION) { |
|
222 |
return false; |
|
223 |
} |
|
224 |
xmlTables.removeAllChildren(); |
|
225 |
} |
|
226 |
|
|
227 |
|
|
228 |
return true; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Devuelve las claves de conflits ordenados |
|
233 |
* en orden inverso. Las claves se esperan que |
|
234 |
* sean instancias de Integer |
|
235 |
*/ |
|
236 |
private int[] getIndexOfConflict(Hashtable conflits) { |
|
237 |
Object[] tmpArray = conflits.keySet().toArray(); |
|
238 |
Arrays.sort(tmpArray,new Comparator() { |
|
239 |
public int compare(Object o1, Object o2) { |
|
240 |
return ((Integer)o2).intValue() - ((Integer)o1).intValue(); |
|
241 |
} |
|
242 |
} |
|
243 |
); |
|
244 |
int[] indexes = new int[] {tmpArray.length}; |
|
245 |
for (int i = 0;i< tmpArray.length;i++) { |
|
246 |
indexes[i] = ((Integer)tmpArray[i]).intValue(); |
|
247 |
} |
|
248 |
return indexes; |
|
249 |
|
|
250 |
|
|
251 |
} |
|
108 | 252 |
} |
Also available in: Unified diff