Statistics
| Revision:

gvsig-educa / org.gvsig.educa.thematicmap / trunk / org.gvsig.educa.thematicmap / org.gvsig.educa.thematicmap.lib / org.gvsig.educa.thematicmap.lib.impl / src / main / java / org / gvsig / educa / thematicmap / impl / compilation / DefaultThematicMapCompilation.java @ 45

History | View | Annotate | Download (6.04 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.thematicmap.impl.compilation;
23

    
24
import java.util.List;
25

    
26
import org.apache.commons.lang3.StringUtils;
27

    
28
import org.gvsig.educa.thematicmap.compilation.CompilationValidationMessage;
29
import org.gvsig.educa.thematicmap.compilation.CompilationValidationMessage.Type;
30
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilation;
31
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilationInformation;
32
import org.gvsig.educa.thematicmap.map.ThematicMap;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.mapcontext.MapContext;
35
import org.gvsig.fmap.mapcontext.ViewPort;
36
import org.gvsig.fmap.mapcontext.layers.FLayers;
37

    
38
/**
39
 * Default implementation of a {@link ThematicMapCompilation}
40
 * 
41
 * @author gvSIG Team
42
 * @version $Id$
43
 * 
44
 */
45
public class DefaultThematicMapCompilation implements ThematicMapCompilation {
46

    
47
    private DefaultThematicMapCompilationInformation info;
48
    private MapContext mapContext;
49

    
50
    public DefaultThematicMapCompilation() {
51
        info = new DefaultThematicMapCompilationInformation();
52
        mapContext =
53
            new MapContext(new ViewPort(CRSFactory.getCRS("EPSG:23030")));
54
    }
55

    
56
    public DefaultThematicMapCompilation(ThematicMap map) {
57
        info =
58
            new DefaultThematicMapCompilationInformation(map.getInformation());
59
        mapContext = map.getMapContext().cloneFMap();
60
    }
61

    
62
    /** {@inheridDoc} */
63
    public ThematicMapCompilationInformation getInformation() {
64
        return info;
65
    }
66

    
67
    /** {@inheridDoc} */
68
    public void setMapContext(MapContext mapContext) {
69
        this.mapContext = mapContext;
70
    }
71

    
72
    /** {@inheridDoc} */
73
    public MapContext getMapContext() {
74
        return mapContext;
75
    }
76

    
77
    /** {@inheridDoc} */
78
    public boolean isValid(List<CompilationValidationMessage> messages) {
79
        boolean isOk = true;
80
        if (mapContext == null) {
81
            addMsgError(messages, "Missing mapContext", "General");
82
            isOk = false;
83
        } else {
84
            isOk = isOk && checkInfoData(messages);
85
            isOk = isOk && checkMapContext(messages);
86
        }
87
        return isOk;
88
    }
89

    
90
    /**
91
     * Checks if is set all required data in Info
92
     * 
93
     * @param messages
94
     * @return
95
     */
96
    private boolean checkInfoData(List<CompilationValidationMessage> messages) {
97
        boolean isOk = true;
98
        final String source = "Map information";
99
        if (StringUtils.isEmpty(info.getId())) {
100
            addMsgError(messages, "Missing Id", source);
101
            isOk = false;
102
        }
103
        if (StringUtils.isEmpty(info.getName())) {
104
            addMsgError(messages, "Missing Name", source);
105
            isOk = false;
106
        }
107
        if (StringUtils.isEmpty(info.getDescription())) {
108
            addMsgWarning(messages, "Missing Description", source);
109
        }
110
        // TODO more checks
111
        return isOk;
112
    }
113

    
114
    /**
115
     * Checks mapContext if it's valid to compile
116
     * 
117
     * @param messages
118
     * @return
119
     */
120
    private boolean checkMapContext(List<CompilationValidationMessage> messages) {
121
        boolean isOk = true;
122
        final String source = "Map information";
123
        FLayers layers = mapContext.getLayers();
124
        if (layers.getLayersCount() < 1) {
125
            addMsgWarning(messages, "No layers in Map", source);
126
        } else {
127
            ValidationLayerIterator layerIterator =
128
                new ValidationLayerIterator(source, layers);
129

    
130
            messages.addAll(layerIterator.getMessages());
131

    
132
            if (!layerIterator.hasNext()) {
133
                addMsgWarning(messages, "No valid layers to generate in Map",
134
                    source);
135
            }
136
        }
137
        // if (mapContext.getGraphicsLayer().isVisible()){
138
        // // TODO check this (graphic layer is empty or not
139
        // addMsg(messages, "Graphics layer will be exported", source);
140
        // }
141

    
142
        return isOk;
143
    }
144

    
145
    /**
146
     * Add a error message. Utility method
147
     * 
148
     * @param messages
149
     * @param description
150
     * @param source
151
     */
152
    private void addMsgError(List<CompilationValidationMessage> messages,
153
        String description, String source) {
154
        messages.add(new DefaultCompilationValidationMessage(Type.ERROR,
155
            description, source));
156
    }
157

    
158
    /**
159
     * Add a warning message. Utility method
160
     * 
161
     * @param messages
162
     * @param description
163
     * @param source
164
     */
165
    private void addMsgWarning(List<CompilationValidationMessage> messages,
166
        String description, String source) {
167
        messages.add(new DefaultCompilationValidationMessage(Type.WARNING,
168
            description, source));
169
    }
170

    
171
    /**
172
     * Add a information message. Utility method
173
     * 
174
     * @param messages
175
     * @param description
176
     * @param source
177
     */
178
    @SuppressWarnings("unused")
179
    private void addMsg(List<CompilationValidationMessage> messages,
180
        String description, String source) {
181
        messages.add(new DefaultCompilationValidationMessage(Type.MESSAGE,
182
            description, source));
183
    }
184

    
185
    /**
186
     * Updates map info after a compilation
187
     * 
188
     * @param info2
189
     */
190
    public void updateInfo(DefaultThematicMapCompilationInformation info2) {
191
        info = info2;
192
    }
193
}