Revision 168 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java

View differences:

FFrameView.java
44 44
import org.gvsig.app.project.documents.layout.FLayoutFunctions;
45 45
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
46 46
import org.gvsig.app.project.documents.layout.LayoutNotification;
47
import org.gvsig.app.project.documents.layout.TocModelChangedImpl;
48
import org.gvsig.app.project.documents.layout.TocModelChangedNotification;
47 49
import org.gvsig.app.project.documents.view.ViewDocument;
48
import org.gvsig.app.project.documents.view.toc.gui.TOC;
49 50
import org.gvsig.compat.print.PrintAttributes;
50 51
import org.gvsig.fmap.dal.exception.ReadException;
51 52
import org.gvsig.fmap.geom.Geometry;
......
62 63
import org.gvsig.fmap.mapcontext.layers.CancelationException;
63 64
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
64 65
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
66
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
65 67
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
66
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
67
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
68 68
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
69 69
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
70 70
import org.gvsig.gui.beans.Messages;
......
95 95
    private static final String ENVELOPE_FIELD = "envelope";
96 96
    private static final String SHOWGRID_FIELD = "showGrid";
97 97
    private static final String GRID_FIELD = "gridview";
98
    private static final String MAPCONTEXT_FIELD = "mapContext";
99 98
    // following fields are unused - should be deleted? 
100 99
    private static final String EXTENSION_FIELD = "extension";
101 100
    private static final String HAS_TOC = "hasToc";
......
129 128
	protected OwnMapContextListener ownMapContextListener;
130 129
	private boolean b_hasToc = false;
131 130

  
131
	private boolean b_updatingToc=false;
132 132

  
133

  
133 134
    /**
134 135
     * Creates a new FFrameView object.
135 136
     */
......
771 772
            definition.addDynFieldBoolean(SHOWGRID_FIELD).setMandatory(true);
772 773
            definition.addDynFieldObject(GRID_FIELD)
773 774
                .setClassOfValue(IFFrame.class).setMandatory(false);
774
            definition.addDynFieldObject(MAPCONTEXT_FIELD)
775
                .setClassOfValue(MapContext.class).setMandatory(false);
776 775
            definition.addDynFieldBoolean(HAS_TOC).setMandatory(false);
777 776
        }
778 777
    }
......
787 786
        linked = state.getBoolean(BLINKED_FIELD);
788 787
        mapUnits = state.getInt(MAPUNITS_FIELD);;
789 788
        viewDocument = (ViewDocument) state.get(VIEW_FIELD);
789
        if (state.hasValue(HAS_TOC)) {
790
        	this.b_hasToc = state.getBoolean(HAS_TOC);
791
        }        
792
        if (viewDocument!=null) {
793
        	this.setView(viewDocument);
794
        	// it is crucial to don't persist the MapContext and get a cloned one from the View instead,
795
        	// as the cloned instance is different from the one created using persistence. In particular,
796
        	// the cloned one will share the EventBuffer with the original one, while persistence would
797
        	// create 2 separate EventBuffers, which will then have a very stange behaviour
798
        }
799
        if (getMapContext()!=null) {
800
        	double mapScale = state.getDouble(SCALE_FIELD);
801
        	getMapContext().setScaleView((long)mapScale); // FIXME: really needed?? probably already persisted on Mapcontext
802
        	getMapContext().getViewPort().setEnvelope(
803
                (Envelope) state.get(ENVELOPE_FIELD));
804
        	if (this.getLayoutContext()!=null) {
805
        		this.getLayoutContext().setTocModel(getMapContext());
806
        	}
790 807

  
791
        if (state.hasValue(MAPCONTEXT_FIELD)) {
792
            MapContext mctxt = (MapContext) state.get(MAPCONTEXT_FIELD);
793
            this.setViewMapContext(mctxt);
794
            double mapScale = state.getDouble(SCALE_FIELD);
795
            mapContext.getViewPort().setDPI(getDrawPaperDPI());
796
            mapContext.setScaleView((long)mapScale); // FIXME: really needed?? probably already persisted on Mapcontext
797
            mapContext.getViewPort().setEnvelope(
798
                (Envelope) state.get(ENVELOPE_FIELD));
799
            if (state.hasValue(HAS_TOC)) {
800
            	this.b_hasToc = state.getBoolean(HAS_TOC);
801
            	if (this.getLayoutContext()!=null) {
802
            		this.getLayoutContext().setTocModel(mapContext);
803
            	}
804
            }
805 808
        }
806

  
807 809
        showGrid = state.getBoolean(SHOWGRID_FIELD);
808 810
        grid = (IFFrame) state.get(GRID_FIELD);
809 811
    }
......
824 826
            state.set(ENVELOPE_FIELD, getMapContext().getViewPort()
825 827
                .getEnvelope());
826 828
            state.set(SCALE_FIELD, (double)getMapContext().getScaleView());
827
            state.set(MAPCONTEXT_FIELD, getMapContext());
828 829
        }
829 830

  
830 831
        state.set(SHOWGRID_FIELD, showGrid);
......
866 867
	
867 868
	protected void invalidateToc() {
868 869
		if (getLayoutContext()!=null) {
869
			getLayoutContext().updateFFrames();
870
			getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.MODEL_CHANGED);
870 871
		}
871
			
872 872
	}
873 873

  
874 874
	public void refresh() {
......
1060 1060

  
1061 1061
		public void visibilityChanged(LayerCollectionEvent e)
1062 1062
				throws CancelationException {
1063
			// this event is not being received, maybe is only triggered if the
1064
			// visibility of the whole group changes??
1063 1065
			conditionalRedraw();
1064 1066
			invalidateToc();
1065 1067
		}
......
1071 1073
	}
1072 1074

  
1073 1075
	private class OwnMapContextListener
1074
	implements ViewPortListener, LegendListener, LayerCollectionListener {
1076
		implements ViewPortListener, LegendListener, LayerCollectionListener {
1075 1077

  
1076 1078
		public void extentChanged(ExtentEvent e) {
1077 1079
			if (!b_viewOriginatedUpdate && (getTypeScale() == AUTOMATICO)) {
......
1119 1121

  
1120 1122
		public void legendChanged(final LegendChangedEvent e) {
1121 1123
			conditionalRedraw();
1124
			invalidateToc();
1122 1125
		}
1123 1126

  
1124 1127
		public void layerAdded(final LayerCollectionEvent e) {
1125 1128
			conditionalRedraw();
1129
			invalidateToc();
1126 1130
		}
1127 1131

  
1128 1132
		public void layerMoved(final LayerPositionEvent e) {
1129 1133
			conditionalRedraw();
1134
			invalidateToc();
1130 1135
		}
1131 1136

  
1132 1137
		public void layerRemoved(final LayerCollectionEvent e) {
1133 1138
			conditionalRedraw();
1139
			invalidateToc();
1134 1140
		}
1135 1141

  
1136 1142
		public void layerAdding(LayerCollectionEvent e)

Also available in: Unified diff