Revision 42573 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/AddLayer.java

View differences:

AddLayer.java
49 49
import org.gvsig.fmap.mapcontext.layers.FLayers;
50 50
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
51 51
import org.gvsig.fmap.mapcontrol.MapControl;
52
import org.gvsig.tools.dispose.DisposeUtils;
52 53
import org.slf4j.Logger;
53 54
import org.slf4j.LoggerFactory;
54 55

  
......
58 59
 *
59 60
 */
60 61
public class AddLayer extends Extension {
62

  
61 63
    private static final Logger logger = LoggerFactory.getLogger(AddLayer.class);
62
    
64

  
63 65
    private static ArrayList<Class<? extends WizardPanel>> wizardStack = null;
64 66

  
65 67
    static {
66
        AddLayer.wizardStack = new ArrayList<Class<? extends WizardPanel>>();
67
		// Anadimos el panel al wizard de cargar capa. (Esto es temporal hasta que
68
        // el actual sea totalmente extensible)
68
        AddLayer.wizardStack = new ArrayList<>();
69
        // Anadimos el panel al wizard de cargar capa. 
69 70
        AddLayer.addWizard(FilesystemExplorerAddLayerWizardPanel.class);
70 71
    }
71 72

  
......
87 88
        return wp;
88 89
    }
89 90

  
91
    @Override
90 92
    public boolean isVisible() {
91 93
        ApplicationManager application = ApplicationLocator.getManager();
92 94

  
93 95
        return application.getActiveComponent(ViewDocument.class) != null;
94 96
    }
95 97

  
98
    @Override
96 99
    public void postInitialize() {
97 100
        super.postInitialize();
98 101
    }
......
109 112
            IProjection proj = lyr.getProjection();
110 113
            // Comprobar que la projecci�n es la misma que la vista
111 114
            if (proj == null) {
112
		// SUPONEMOS que la capa est� en la proyecci�n que
115
                // SUPONEMOS que la capa est� en la proyecci�n que
113 116
                // estamos pidiendo (que ya es mucho suponer, ya).
114 117
                lyrVect.setProjection(viewPort.getProjection());
115 118
                return;
116 119
            }
117
            int option = JOptionPane.YES_OPTION;
120
            int option;
118 121
            if (proj != viewPort.getProjection()) {
119 122
                option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), PluginServices
120 123
                        .getText(AddLayer.class, "reproyectar_aviso") + "\n" + PluginServices.getText(AddLayer.class, "Capa") + ": " + lyrVect.getName(), PluginServices
......
134 137

  
135 138
    }
136 139

  
140
    @Override
137 141
    public void execute(String actionCommand) {
138 142
        this.execute(actionCommand, null);
139 143
    }
140 144

  
145
    @Override
141 146
    public void execute(String command, Object[] args) {
142 147
        List<File> files = null;
143
        if( args!=null && args.length>=1 && args[0] instanceof List ) {
148
        if (args != null && args.length >= 1 && args[0] instanceof List) {
144 149
            files = (List<File>) args[0];
145 150
        }
146 151
        ApplicationManager application = ApplicationLocator.getManager();
......
150 155
            return;
151 156
        }
152 157
        ViewDocument document = view.getViewDocument();
153
        
158

  
154 159
        MapControl mapControl = view.getMapControl();
155 160
        this.doAddLayers(mapControl, mapControl.getMapContext(), files);
156 161
        mapControl.getMapContext().callLegendChanged();
157 162
        document.setModified(true);
158 163
    }
159 164

  
165
    @Override
160 166
    public boolean isEnabled() {
161 167
        return true;
162 168
    }
......
168 174
     */
169 175
    private AddLayerDialog createFOpenDialog(MapControl mapControl, MapContext mapContext, List<File> files) {
170 176
        AddLayerDialog fopen = new AddLayerDialog();
171
        for (int i = 0; i < wizardStack.size(); i++) {
177
        for (Class<? extends WizardPanel> wpClass : wizardStack) {
172 178
            WizardPanel wp;
173 179
            try {
174
                Class<? extends WizardPanel> wpClass = AddLayer.wizardStack.get(i);
175 180
                Object[] params = {};
176 181
                wp = wpClass.getConstructor()
177 182
                        .newInstance(params);
178 183
                wp.setMapCtrl(mapControl);
179 184
                wp.setMapContext(mapContext);
180 185
                wp.initWizard();
181
                if( wp instanceof FilesystemExplorerWizardPanel && files!=null && !files.isEmpty() ) {
182
                    FilesystemExplorerWizardPanel fswp = (FilesystemExplorerWizardPanel)wp;
186
                if (wp instanceof FilesystemExplorerWizardPanel && files != null && !files.isEmpty()) {
187
                    FilesystemExplorerWizardPanel fswp = (FilesystemExplorerWizardPanel) wp;
183 188
                    fswp.addFiles(files);
184 189
                }
185

  
186 190
                fopen.addWizardTab(wp.getTabName(), wp);
187 191
            } catch (Exception e) {
188
                logger.warn("Can't create layer open dialog.",e);
192
                logger.warn("Can't create layer open dialog.", e);
189 193
            }
190 194
        }
191 195
        fopen.updateOkButtonState();
......
201 205
     * @param wizardPanel WizardPanel where user selected the layers to load
202 206
     * @return
203 207
     */
204
    private boolean loadGenericWizardPanelLayers(MapContext mapContext, WizardPanel wp, boolean mapControlAvailable) {
205
        wp.setMapContext(mapContext);
206
        wp.executeWizard();
207
        return true;
208
    }
209

  
208
//    private boolean loadGenericWizardPanelLayers(MapContext mapContext, WizardPanel wp, boolean mapControlAvailable) {
209
//        wp.setMapContext(mapContext);
210
//        wp.executeWizard();
211
//        return true;
212
//    }
210 213
    /**
211 214
     * Opens the AddLayer dialog, and adds the selected layers to the provided
212 215
     * MapContext.
213 216
     *
214 217
     * This method is useful when we want to add a layer but we don't have an
215
     * associated View. If a View or a MapControl is available, you will
216
     * usually prefer the {@link #addLayers(MapControl)} method.
217
     * 
218
     * associated View. If a View or a MapControl is available, you will usually
219
     * prefer the {@link #addLayers(MapControl)} method.
220
     *
218 221
     * @param mapContext The MapContext to add the layers to
219 222
     * @return <code>true</code> if any layer has been added.
220 223
     */
221 224
    public boolean addLayers(MapContext mapContext) {
222
    	return doAddLayers(null, mapContext, null);
225
        return doAddLayers(null, mapContext, null);
223 226
    }
224 227

  
225 228
    /**
226 229
     * Opens the AddLayer dialog, and adds the selected layers to the provided
227 230
     * mapControl.
228
     * 
231
     *
229 232
     * @param mapControl The MapControl to add the layers to
230
     * 
233
     *
231 234
     * @return <code>true</code> if any layer has been added.
232 235
     */
233 236
    public boolean addLayers(MapControl mapControl) {
234
    	return doAddLayers(mapControl, mapControl.getMapContext(), null);
237
        return doAddLayers(mapControl, mapControl.getMapContext(), null);
235 238
    }
236
    
237
    private boolean doAddLayers(MapControl mapControl, MapContext mapContext, List<File>files) {
239

  
240
    private boolean doAddLayers(MapControl mapControl, MapContext mapContext, List<File> files) {
238 241
        AddLayerDialog fopen = null;
239 242
        try {
240 243
            fopen = createFOpenDialog(mapControl, mapContext, files);
......
252 255
            }
253 256
            return false;
254 257
        } finally {
255
            if (fopen != null) {
256
                fopen.dispose();
257
                fopen = null;
258
            }
258
            DisposeUtils.disposeQuietly(fopen);
259 259
        }
260 260
    }
261 261

  
262
    @Override
262 263
    public void initialize() {
263 264
        IconThemeHelper.registerIcon("action", "view-layer-add", this);
264 265
    }

Also available in: Unified diff