Revision 61
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.viewer/src/main/java/org/gvsig/educa/thematicmap/app/viewer/ThematicMapDocument.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.educa.thematicmap.app.viewer; |
23 | 23 |
|
24 |
import java.beans.PropertyChangeEvent; |
|
25 |
import java.beans.PropertyChangeListener; |
|
26 |
import java.io.IOException; |
|
27 |
|
|
24 | 28 |
import org.apache.commons.lang3.ObjectUtils; |
29 |
import org.apache.commons.lang3.StringUtils; |
|
25 | 30 |
|
31 |
import org.gvsig.app.project.Project; |
|
32 |
import org.gvsig.app.project.ProjectManager; |
|
26 | 33 |
import org.gvsig.app.project.documents.AbstractDocument; |
27 | 34 |
import org.gvsig.app.project.documents.DocumentManager; |
28 | 35 |
import org.gvsig.app.project.documents.view.ViewDocument; |
... | ... | |
30 | 37 |
import org.gvsig.educa.thematicmap.ThematicMapManager; |
31 | 38 |
import org.gvsig.educa.thematicmap.app.viewer.exception.ThematicMapLoadingException; |
32 | 39 |
import org.gvsig.educa.thematicmap.app.viewer.exception.ThematicMapNotFoundException; |
40 |
import org.gvsig.educa.thematicmap.map.CantLoadContextException; |
|
41 |
import org.gvsig.educa.thematicmap.map.InvalidThematicMapFormatException; |
|
33 | 42 |
import org.gvsig.educa.thematicmap.map.ThematicMap; |
34 | 43 |
import org.gvsig.educa.thematicmap.map.ThematicMapInformation; |
35 | 44 |
import org.gvsig.fmap.mapcontext.MapContext; |
... | ... | |
43 | 52 |
* @version $Id$ |
44 | 53 |
* |
45 | 54 |
*/ |
46 |
public class ThematicMapDocument extends AbstractDocument { |
|
55 |
public class ThematicMapDocument extends AbstractDocument implements |
|
56 |
PropertyChangeListener { |
|
47 | 57 |
|
48 | 58 |
/** |
49 | 59 |
* |
... | ... | |
88 | 98 |
return thematicMap; |
89 | 99 |
} |
90 | 100 |
|
91 |
public void reloadThematicMap() { |
|
92 |
// TODO |
|
93 |
// if (thematicMap == null) { |
|
94 |
// throw new IllegalStateException("Thematic not set"); |
|
95 |
// } |
|
96 |
// |
|
97 |
// try { |
|
98 |
// thematicMap.close(); |
|
99 |
// } catch (IOException ex) { |
|
100 |
// // TODO |
|
101 |
// } |
|
102 |
// ThematicMap newMap = |
|
103 |
// thMapManager.getMapById(thematicMap.getInformation().getId()); |
|
104 |
// |
|
105 |
// try { |
|
106 |
// newMap.open(); |
|
107 |
// } catch (InvalidThematicMapFormatException ex) { |
|
108 |
// // TODO Auto-generated catch block |
|
109 |
// ex.printStackTrace(); |
|
110 |
// } catch (CantLoadContextException ex) { |
|
111 |
// // TODO Auto-generated catch block |
|
112 |
// ex.printStackTrace(); |
|
113 |
// } catch (IOException ex) { |
|
114 |
// // TODO Auto-generated catch block |
|
115 |
// ex.printStackTrace(); |
|
116 |
// } |
|
117 |
// |
|
118 |
// // TODO raise a propertyChange event |
|
119 |
// thematicMap = newMap; |
|
101 |
public void reloadThematicMap() throws InvalidThematicMapFormatException, |
|
102 |
CantLoadContextException, IOException { |
|
103 |
if (thematicMap == null) { |
|
104 |
throw new IllegalStateException("Thematic not set"); |
|
105 |
} |
|
120 | 106 |
|
107 |
try { |
|
108 |
thematicMap.close(); |
|
109 |
} catch (IOException ex) { |
|
110 |
// TODO |
|
111 |
} |
|
112 |
ThematicMap newMap = |
|
113 |
thMapManager.getMapById(thematicMap.getInformation().getId()); |
|
114 |
|
|
115 |
newMap.open(); |
|
116 |
|
|
117 |
// TODO raise a propertyChange event (need access to supper |
|
118 |
// propertySupport |
|
119 |
thematicMap = newMap; |
|
120 |
|
|
121 | 121 |
} |
122 | 122 |
|
123 | 123 |
@Override |
... | ... | |
182 | 182 |
|
183 | 183 |
this.thematicMap = map; |
184 | 184 |
this.sourceView = sourceView; |
185 |
listenProjectChanges(sourceView != null); |
|
185 | 186 |
super.setName(name); |
186 | 187 |
super.setComment(comment); |
187 | 188 |
} |
... | ... | |
218 | 219 |
public void setSourceView(ViewDocument sourceView) { |
219 | 220 |
// TODO raise a propertyChange event |
220 | 221 |
this.sourceView = sourceView; |
222 |
listenProjectChanges(sourceView != null); |
|
221 | 223 |
} |
222 | 224 |
|
223 | 225 |
/** |
226 |
* Start or left to listen project changes (to get notify if related |
|
227 |
* document has been removed) |
|
228 |
* |
|
229 |
* @param listen |
|
230 |
*/ |
|
231 |
private void listenProjectChanges(boolean listen) { |
|
232 |
if (listen) { |
|
233 |
ProjectManager.getInstance().getCurrentProject() |
|
234 |
.addPropertyChangeListener(this); |
|
235 |
} else { |
|
236 |
// TODO remove this instance from project listener (NO API |
|
237 |
// TO DO IT) |
|
238 |
|
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
224 | 243 |
* @return the sourceView |
225 | 244 |
*/ |
226 | 245 |
public ViewDocument getSourceView() { |
227 | 246 |
return sourceView; |
228 | 247 |
} |
229 | 248 |
|
249 |
public void propertyChange(PropertyChangeEvent evt) { |
|
250 |
if (evt.getSource() instanceof Project) { |
|
251 |
// Check if removed related view |
|
252 |
if (sourceView == null) { |
|
253 |
listenProjectChanges(false); |
|
254 |
return; |
|
255 |
} |
|
256 |
if (StringUtils.equals(evt.getPropertyName(), "delDocument")) { |
|
257 |
if (ObjectUtils.equals(evt.getOldValue(), sourceView)) { |
|
258 |
sourceView = null; |
|
259 |
listenProjectChanges(false); |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
230 | 265 |
} |
Also available in: Unified diff