Statistics
| Revision:

gvsig-educa / org.gvsig.educa.portableview / trunk / org.gvsig.educa.portableview / org.gvsig.educa.portableview.lib / org.gvsig.educa.portableview.lib.impl / src / main / java / org / gvsig / educa / portableview / impl / compilation / DefaultPortableViewCompilation.java @ 256

History | View | Annotate | Download (6.05 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.portableview.impl.compilation;
23

    
24
import java.util.List;
25

    
26
import org.apache.commons.lang3.StringUtils;
27
import org.gvsig.educa.portableview.compilation.CompilationValidationMessage;
28
import org.gvsig.educa.portableview.compilation.PortableViewCompilation;
29
import org.gvsig.educa.portableview.compilation.PortableViewCompilationInformation;
30
import org.gvsig.educa.portableview.compilation.CompilationValidationMessage.Type;
31
import org.gvsig.educa.portableview.map.PortableView;
32
import org.gvsig.fmap.crs.CRSFactory;
33
import org.gvsig.fmap.mapcontext.MapContext;
34
import org.gvsig.fmap.mapcontext.ViewPort;
35
import org.gvsig.fmap.mapcontext.layers.FLayers;
36

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

    
46
    private DefaultPortableViewCompilationInformation info;
47
    private MapContext mapContext;
48

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

    
55
    public DefaultPortableViewCompilation(PortableView map) {
56
        info =
57
            new DefaultPortableViewCompilationInformation(map.getInformation());
58
        mapContext = map.getMapContext().cloneFMap();
59
    }
60

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

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

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

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

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

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

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

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

    
141
        return isOk;
142
    }
143

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

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

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

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