root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectViewBase.java @ 12136
History | View | Annotate | Download (7.33 KB)
1 |
package com.iver.cit.gvsig.project.documents.view; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Component; |
5 |
import java.util.ArrayList; |
6 |
import java.util.List; |
7 |
|
8 |
import javax.swing.JOptionPane; |
9 |
|
10 |
import org.cresques.cts.IProjection; |
11 |
|
12 |
import com.iver.andami.PluginServices; |
13 |
import com.iver.andami.ui.mdiManager.IWindow; |
14 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
15 |
import com.iver.cit.gvsig.ProjectExtension; |
16 |
import com.iver.cit.gvsig.fmap.DriverException; |
17 |
import com.iver.cit.gvsig.fmap.ErrorEvent; |
18 |
import com.iver.cit.gvsig.fmap.ErrorListener; |
19 |
import com.iver.cit.gvsig.fmap.MapContext; |
20 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
21 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
22 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
23 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
24 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
25 |
import com.iver.cit.gvsig.project.Project; |
26 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
27 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
28 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
29 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
30 |
import com.iver.cit.gvsig.project.documents.view.info.gui.HTMLInfoToolPanel; |
31 |
import com.iver.utiles.XMLEntity; |
32 |
|
33 |
public abstract class ProjectViewBase extends ProjectDocument implements ErrorListener, |
34 |
IProjectView { |
35 |
|
36 |
protected MapContext mapOverViewContext;
|
37 |
protected MapContext mapContext;
|
38 |
protected int m_typeLink = 0; |
39 |
protected String m_extLink; |
40 |
protected String m_selectedField = null; |
41 |
|
42 |
// OVERRIDE THESE
|
43 |
public IWindow createWindow() { return null;} |
44 |
public IWindow getProperties() { return null;} |
45 |
|
46 |
/**
|
47 |
* Gets the FMap's contexts of the main map in the view.
|
48 |
*
|
49 |
* @return
|
50 |
*/
|
51 |
public MapContext getMapContext() {
|
52 |
return mapContext;
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Gets the FMap's context from the locator, which is the
|
57 |
* small map in the left-bottom corner of the View.
|
58 |
*
|
59 |
* @return
|
60 |
*/
|
61 |
public MapContext getMapOverViewContext() {
|
62 |
return mapOverViewContext;
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* @see com.iver.cit.gvsig.project.documents.view.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.MapContext)
|
67 |
*/
|
68 |
public void setMapContext(MapContext fmap) { |
69 |
mapContext = fmap; |
70 |
fmap.addErrorListener(this);
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* DOCUMENT ME!
|
75 |
*
|
76 |
* @param fmap DOCUMENT ME!
|
77 |
*/
|
78 |
public void setMapOverViewContext(MapContext fmap) { |
79 |
mapOverViewContext = fmap; |
80 |
mapOverViewContext.setProjection(mapContext.getProjection()); |
81 |
} |
82 |
|
83 |
public void setXMLEntity(XMLEntity xml, Project p) throws XMLException, |
84 |
DriverException, DriverIOException, OpenException { } |
85 |
|
86 |
public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException, |
87 |
DriverException, DriverIOException { } |
88 |
|
89 |
public void showErrors(){ |
90 |
if (mapContext.getLayersError().size()>0){ |
91 |
String layersError=""; |
92 |
for (int i=0;i<mapContext.getLayersError().size();i++){ |
93 |
layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
94 |
} |
95 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
96 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
97 |
layersError); |
98 |
} |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Reports to the user a bundle of driver exceptions produced in the
|
103 |
* same atomic MapContext transaction
|
104 |
*/
|
105 |
public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
106 |
HtmlWindow htmlPanel = new HtmlWindow(570, 450, "Excepciones de driver"); |
107 |
String htmlText = null; |
108 |
if(introductoryText == null){ |
109 |
htmlText += "<p>Se han producido los siguientes errores durante la carga de capas.</p>";
|
110 |
}else{
|
111 |
htmlText += introductoryText; |
112 |
} |
113 |
int numErrors = driverExceptions.size();
|
114 |
for(int i = 0; i < numErrors; i++){ |
115 |
htmlText += "<br>\n";
|
116 |
DriverException exception = (DriverException) driverExceptions.get(i); |
117 |
htmlText += exception.getExceptionType().getHtmlErrorMessage(); |
118 |
} |
119 |
System.out.println(htmlText);
|
120 |
htmlPanel.show(htmlText); |
121 |
|
122 |
PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
123 |
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* HtmlInfoToolPanel that implements IWindow
|
128 |
* @author azabala
|
129 |
*
|
130 |
*/
|
131 |
class HtmlWindow extends HTMLInfoToolPanel implements IWindow { |
132 |
WindowInfo viewInfo = null;
|
133 |
public HtmlWindow(int width, int height, String windowTitle){ |
134 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
135 |
viewInfo.setTitle(windowTitle); |
136 |
viewInfo.setWidth(width); |
137 |
viewInfo.setHeight(height); |
138 |
} |
139 |
|
140 |
public WindowInfo getWindowInfo() {
|
141 |
return viewInfo;
|
142 |
} |
143 |
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* DOCUMENT ME!
|
148 |
*
|
149 |
* @return DOCUMENT ME!
|
150 |
*/
|
151 |
public IProjection getProjection() {
|
152 |
return mapContext.getProjection();
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* DOCUMENT ME!
|
157 |
*
|
158 |
* @return DOCUMENT ME!
|
159 |
*/
|
160 |
public IProjection getOverViewProjection() {
|
161 |
return mapOverViewContext.getProjection();
|
162 |
} |
163 |
|
164 |
public void setProjection (IProjection proj) { |
165 |
mapContext.setProjection(proj); |
166 |
mapOverViewContext.setProjection(proj); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* DOCUMENT ME!
|
171 |
*
|
172 |
* @return DOCUMENT ME!
|
173 |
*/
|
174 |
public String getExtLink() { |
175 |
return m_extLink;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* DOCUMENT ME!
|
180 |
*
|
181 |
* @return DOCUMENT ME!
|
182 |
*/
|
183 |
public int getTypeLink() { |
184 |
return m_typeLink;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Se selecciona la extensi?n para realizar cuando se quiera el link.
|
189 |
*
|
190 |
* @param s nombre del campo.
|
191 |
*/
|
192 |
public void setExtLink(String s) { |
193 |
m_extLink = s; |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
198 |
*
|
199 |
* @param i tipo de fichero.
|
200 |
*/
|
201 |
public void setTypeLink(int i) { |
202 |
m_typeLink = i; |
203 |
} |
204 |
|
205 |
public void afterRemove() { |
206 |
FLayers layers=this.getMapContext().getLayers();
|
207 |
|
208 |
for (int i = layers.getLayersCount()-1; i>=0; i--){ |
209 |
try {
|
210 |
if (layers.getLayer(i) instanceof AlphanumericData){ |
211 |
Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
212 |
ProjectTable pt = project.getTable((AlphanumericData) layers.getLayer(i)); |
213 |
|
214 |
ArrayList tables = project.getDocumentsByType(ProjectTableFactory.registerName);
|
215 |
for (int j = 0; j < tables.size(); j++) { |
216 |
if (tables.get(j) == pt){
|
217 |
project.delDocument((ProjectDocument)tables.get(j)); |
218 |
break;
|
219 |
} |
220 |
} |
221 |
|
222 |
PluginServices.getMDIManager().closeSingletonWindow(pt); |
223 |
} |
224 |
layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
225 |
} catch (CancelationException e1) {
|
226 |
e1.printStackTrace(); |
227 |
} |
228 |
} |
229 |
|
230 |
} |
231 |
|
232 |
public void afterAdd() { |
233 |
// TODO Auto-generated method stub
|
234 |
|
235 |
} |
236 |
|
237 |
|
238 |
/**
|
239 |
* DOCUMENT ME!
|
240 |
*
|
241 |
* @param c DOCUMENT ME!
|
242 |
*/
|
243 |
public void setBackColor(Color c) { |
244 |
// getMapContext().getViewPort().addViewPortListener(getMapContext()
|
245 |
// .getEventBuffer());
|
246 |
getMapContext().getViewPort().setBackColor(c); |
247 |
//getMapContext().getViewPort().removeViewPortListener(getMapContext()
|
248 |
// .getEventBuffer());
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* Se selecciona el nombre del campo para realizar cuando se quiera el
|
253 |
* link.
|
254 |
*
|
255 |
* @param s nombre del campo.
|
256 |
*/
|
257 |
public void setSelectedField(String s) { |
258 |
m_selectedField = s; |
259 |
} |
260 |
|
261 |
/**
|
262 |
* DOCUMENT ME!
|
263 |
*
|
264 |
* @return DOCUMENT ME!
|
265 |
*/
|
266 |
public String getSelectedField() { |
267 |
return m_selectedField;
|
268 |
} |
269 |
|
270 |
public void errorThrown(ErrorEvent e) { |
271 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
272 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
273 |
e.getMessage()); |
274 |
|
275 |
} |
276 |
|
277 |
} |