Revision 47

View differences:

org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.main/src/main/java/org/gvsig/educa/thematicmap/main/Main.java
26 26
import java.awt.event.ActionEvent;
27 27
import java.io.File;
28 28
import java.io.IOException;
29
import java.net.URL;
29 30
import java.util.List;
30 31

  
31 32
import javax.swing.AbstractAction;
......
58 59
import org.gvsig.educa.thematicmap.swing.editor.ThematicMapCompilationEditor;
59 60
import org.gvsig.educa.thematicmap.swing.editor.ThematicMapCompilationEditorListener;
60 61
import org.gvsig.educa.thematicmap.swing.viewer.ThematicMapViewer;
62
import org.gvsig.installer.swing.api.SwingInstallerLocator;
63
import org.gvsig.installer.swing.api.SwingInstallerManager;
64
import org.gvsig.installer.swing.api.execution.InstallPackageWizardException;
65
import org.gvsig.installer.swing.api.wizard.AbstractInstallerWizard;
61 66
import org.gvsig.tools.ToolsLocator;
62 67
import org.gvsig.tools.dispose.DisposableManager;
63 68
import org.gvsig.tools.exception.BaseException;
......
81 86
    private final ThematicMapWindowManager winManager;
82 87
    private final UsabilitySwingManager usabManager;
83 88
    private final DisposableManager disposeManager;
89
    private final SwingInstallerManager swingInstallerManager;
84 90

  
85 91
    private final JFileChooser fileChooser;
86 92
    private JFrame mainFrame;
......
98 104

  
99 105
    private AbstractAction createCompilationFromMapAction;
100 106

  
107
    private AbstractAction installThematicMaps;
108

  
109
    private AbstractAction addInstallUrl;
110

  
101 111
    public static void main(String args[]) {
102 112
        new DefaultLibrariesInitializer().fullInitialize();
103 113

  
......
114 124
        winManager = swingManager.getWindowManager();
115 125
        usabManager = ToolsSwingLocator.getUsabilitySwingManager();
116 126
        disposeManager = ToolsLocator.getDisposableManager();
127
        swingInstallerManager =
128
            SwingInstallerLocator.getSwingInstallerManager();
117 129

  
118 130
        String defaultFolderPath =
119 131
            "gvSIG/plugins/org.gvsig.educa.thematicmap.app.viewer/thematicMaps";
......
237 249
            };
238 250
        createCompilationFromMapAction.setEnabled(false);
239 251

  
252
        addInstallUrl = new AbstractAction("Add a ThematicMap install URL") {
253

  
254
            public void actionPerformed(ActionEvent e) {
255
                addThematicMapUrl();
256
            }
257

  
258
        };
259

  
260
        installThematicMaps = new AbstractAction("Install ThematicMaps") {
261

  
262
            public void actionPerformed(ActionEvent e) {
263
                installThematicMap();
264
            }
265

  
266
        };
267
        installThematicMaps.setEnabled(false);
268

  
240 269
    }
241 270

  
242 271
    /**
......
256 285
        menuFile.add(new JMenuItem(createCompilationAction));
257 286
        menuFile.add(new JMenuItem(createCompilationFromMapAction));
258 287
        menuFile.addSeparator();
288
        menuFile.add(new JMenuItem(addInstallUrl));
289
        menuFile.add(new JMenuItem(installThematicMaps));
290
        menuFile.addSeparator();
259 291
        menuFile.add(new JMenuItem(exitAction));
260 292

  
261 293
        JMenu menuViewer = new JMenu("Viewer");
......
409 441
        setPanToolAction.setEnabled(curViewer != null);
410 442
        closeThematicMapAction.setEnabled(curViewer != null);
411 443
        zoomAllAction.setEnabled(curViewer != null);
444
        installThematicMaps
445
            .setEnabled(manager.getInstallationMapFolder() != null);
412 446

  
413 447
        mainFrame.getContentPane().invalidate();
414 448
        mainFrame.doLayout();
......
554 588

  
555 589
    }
556 590

  
591
    public void installThematicMap() {
592
        AbstractInstallerWizard panel;
593
        try {
594
            panel =
595
                swingInstallerManager.createInstallPackageWizard(new File("."),
596
                    new File(manager.getInstallationMapFolder()), null);
597
        } catch (InstallPackageWizardException ex) {
598
            LOG.error("Error opening installer panel", ex);
599
            winManager.showMessageDialog("Install Thematic Maps",
600
                "Error opening installer panel", MESSAGE_DIALOG_TYPE.ERROR);
601
            return;
602

  
603
        }
604

  
605
        winManager.showWindow(panel, "Install Thematic Map", MODE.DIALOG);
606

  
607
    }
608

  
609
    public void addThematicMapUrl() {
610
        String inUrl =
611
            winManager.showInputStringDialog("Input the url",
612
                "Add install Thematic Map URL", "http://",
613
                MESSAGE_DIALOG_TYPE.QUESTION);
614
        URL url;
615
        try {
616
            url = new URL(inUrl);
617
        } catch (Exception ex) {
618
            LOG.error("Invalid URL: ".concat(inUrl).concat("'"), ex);
619
            winManager.showMessageDialog("Add install Thematic Map URL",
620
                "Invalid URL: '".concat(inUrl).concat("'"),
621
                MESSAGE_DIALOG_TYPE.ERROR);
622
            return;
623
        }
624
        swingInstallerManager.addDefaultDownloadURL(url);
625
    }
626

  
557 627
    public void compileMap(ThematicMapCompilation compilation) {
558 628
        ThematicMapCompiler compiler = manager.createCompilerInstance();
559 629
        compiler.setTargetFolder(manager.getInstallationMapFolder());
......
567 637
        compiler.setCompilerListener(new CompilerProcessListener(LOG));
568 638
        ThematicMapCompilerStatus resul = compiler.compile(compilation);
569 639

  
570
        if (resul.getStatus() == ThematicMapCompilerStatus.Status.finished_ok) {
640
        if (resul.getStatus() != ThematicMapCompilerStatus.Status.finished_ok) {
571 641
            winManager.showMessageDialog(mainFrame, "Compile Thematic Map",
572
                "<html>Process successful:<br>"
573
                    + resul.getGeneratedThematicMapFile().getAbsolutePath() + "</html>",
574
                MESSAGE_DIALOG_TYPE.INFO);
575

  
576
        } else {
577
            winManager.showMessageDialog(mainFrame, "Compile Thematic Map",
578 642
                "Problems found in process (show log for more info)",
579 643
                MESSAGE_DIALOG_TYPE.ERROR);
644
            return;
645

  
580 646
        }
647
        winManager.showMessageDialog(mainFrame, "Compile Thematic Map",
648
            "<html>Process successful:<br>"
649
                + resul.getGeneratedThematicMapFile().getAbsolutePath()
650
                + "</html>", MESSAGE_DIALOG_TYPE.INFO);
581 651

  
652
        CONFIRM_DIALOG_OPTION generatePkg =
653
            winManager.showConfirmDialog(
654
                "Would you like to generete a gvSIG pakage file?",
655
                "Compile Thematic Map", CONFIRM_DIALOG_TYPE.YES_NO,
656
                MESSAGE_DIALOG_TYPE.QUESTION);
657

  
658
        if (generatePkg != CONFIRM_DIALOG_OPTION.OK_YES) {
659
            return;
660
        }
661
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
662
        int targetFolderAnswere =
663
            fileChooser.showDialog(mainFrame,
664
                "Select folder where store the package file");
665
        if (targetFolderAnswere != JFileChooser.APPROVE_OPTION) {
666
            return;
667
        }
668
        File gvsigPkg = null;
669
        try {
670
            gvsigPkg =
671
                manager.generatePackageFile(
672
                    resul.getGeneratedInstalationThematicMapFolder(),
673
                    fileChooser.getSelectedFile());
674
        } catch (Exception ex) {
675
            LOG.error("Error generating gvSIG package", ex);
676
            winManager
677
                .showMessageDialog(
678
                    mainFrame,
679
                    "Compile Thematic Map",
680
                    "Problems found generating gvSIG package (show log for more info)",
681
                    MESSAGE_DIALOG_TYPE.ERROR);
682
            return;
683

  
684
        }
685
        winManager.showMessageDialog(mainFrame, "Compile Thematic Map",
686
            "<html>Generated gvSIG package:<br>" + gvsigPkg.getAbsolutePath()
687
                + "</html>", MESSAGE_DIALOG_TYPE.INFO);
582 688
    }
583 689

  
584 690
    private class CompilerProcessListener implements
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.main/pom.xml
176 176
			<groupId>org.gvsig</groupId>
177 177
			<artifactId>org.gvsig.installer.lib.impl</artifactId>
178 178
		</dependency>
179
		<dependency>
180
			<groupId>org.gvsig</groupId>
181
			<artifactId>org.gvsig.installer.swing.api</artifactId>
182
		</dependency>
183
		<dependency>
184
			<groupId>org.gvsig</groupId>
185
			<artifactId>org.gvsig.installer.swing.impl</artifactId>
186
		</dependency>
179 187

  
180 188

  
181 189
	</dependencies>
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.main/.classpath
16 16
	<classpathentry kind="var" path="M2_REPO/org/apache/xmlgraphics/batik-dom/1.7/batik-dom-1.7.jar"/>
17 17
	<classpathentry kind="var" path="M2_REPO/org/apache/xmlgraphics/batik-ext/1.7/batik-ext-1.7.jar"/>
18 18
	<classpathentry kind="var" path="M2_REPO/org/gvsig/batik-ext-gvsig-custom/1.7.0/batik-ext-gvsig-custom-1.7.0.jar"/>
19
	<classpathentry kind="var" path="M2_REPO/org/apache/xmlgraphics/batik-gui-util/1.7/batik-gui-util-1.7.jar"/>
19 20
	<classpathentry kind="var" path="M2_REPO/org/apache/xmlgraphics/batik-gvt/1.7/batik-gvt-1.7.jar"/>
20 21
	<classpathentry kind="var" path="M2_REPO/org/apache/xmlgraphics/batik-js/1.7/batik-js-1.7.jar"/>
21 22
	<classpathentry kind="var" path="M2_REPO/org/apache/xmlgraphics/batik-parser/1.7/batik-parser-1.7.jar"/>
......
139 140
			<attribute name="javadoc_location" value="jar:file:/home/jmvivo/.m2/repository/org/gvsig/org.gvsig.i18n/2.0-SNAPSHOT/org.gvsig.i18n-2.0-SNAPSHOT-javadoc.jar!/"/>
140 141
		</attributes>
141 142
	</classpathentry>
143
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.installer.lib.api/1.0.1-SNAPSHOT/org.gvsig.installer.lib.api-1.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.installer.lib.api/1.0.1-SNAPSHOT/org.gvsig.installer.lib.api-1.0.1-SNAPSHOT-sources.jar"/>
144
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.installer.lib.impl/1.0.1-SNAPSHOT/org.gvsig.installer.lib.impl-1.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.installer.lib.impl/1.0.1-SNAPSHOT/org.gvsig.installer.lib.impl-1.0.1-SNAPSHOT-sources.jar"/>
145
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.installer.lib.spi/1.0.1-SNAPSHOT/org.gvsig.installer.lib.spi-1.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.installer.lib.spi/1.0.1-SNAPSHOT/org.gvsig.installer.lib.spi-1.0.1-SNAPSHOT-sources.jar"/>
146
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.installer.swing.api/1.0.1-SNAPSHOT/org.gvsig.installer.swing.api-1.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.installer.swing.api/1.0.1-SNAPSHOT/org.gvsig.installer.swing.api-1.0.1-SNAPSHOT-sources.jar"/>
147
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.installer.swing.impl/1.0.1-SNAPSHOT/org.gvsig.installer.swing.impl-1.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.installer.swing.impl/1.0.1-SNAPSHOT/org.gvsig.installer.swing.impl-1.0.1-SNAPSHOT-sources.jar"/>
142 148
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jdk.v1_6/1.0.0-SNAPSHOT/org.gvsig.jdk.v1_6-1.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.jdk.v1_6/1.0.0-SNAPSHOT/org.gvsig.jdk.v1_6-1.0.0-SNAPSHOT-sources.jar"/>
143 149
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.maven.base.tools/1.0.8-SNAPSHOT/org.gvsig.maven.base.tools-1.0.8-SNAPSHOT.jar"/>
144 150
	<classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.metadata.lib.basic.api/1.0.0-SNAPSHOT/org.gvsig.metadata.lib.basic.api-1.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.metadata.lib.basic.api/1.0.0-SNAPSHOT/org.gvsig.metadata.lib.basic.api-1.0.0-SNAPSHOT-sources.jar"/>
......
187 193
	<classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis-ext/1.3.04/xml-apis-ext-1.3.04.jar"/>
188 194
	<classpathentry kind="var" path="M2_REPO/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar"/>
189 195
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
196
	<classpathentry combineaccessrules="false" kind="src" path="/org.gvsig.educa.thematicmap.installer.provider"/>
190 197
	<classpathentry combineaccessrules="false" kind="src" path="/org.gvsig.educa.thematicmap.lib.api"/>
191 198
	<classpathentry combineaccessrules="false" kind="src" path="/org.gvsig.educa.thematicmap.lib.impl"/>
192 199
	<classpathentry combineaccessrules="false" kind="src" path="/org.gvsig.educa.thematicmap.swing.api"/>
193 200

  
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.lib/org.gvsig.educa.thematicmap.lib.api/src/main/java/org/gvsig/educa/thematicmap/ThematicMapManager.java
194 194
    String getBaseFileNameFromInfo(String id, String name, int version,
195 195
        int buildNumber);
196 196

  
197
    /**
198
     * Create a gvSIG package file (gvspkg) from a thematicMap
199
     * 
200
     * @param mapId
201
     *            id of map to export
202
     * @param targetFolder
203
     *            where write package file
204
     * @return
205
     * @throws ThematicMapException
206
     * @throws IOException
207
     */
208
    File generatePackageFile(String mapId, File targetFolder)
209
        throws ThematicMapException, IOException;
210

  
211
    /**
212
     * Create a gvSIG package file (gvspkg) from a thematicMap installed folder
213
     * 
214
     * @param thematicMapIntallFolder
215
     *            folder of a installed ThematicMap
216
     * @param targetFolder
217
     *            where write package file
218
     * @return
219
     * @throws ThematicMapException
220
     * @throws IOException
221
     */
222
    File generatePackageFile(File thematicMapIntallFolder, File targetFolder)
223
        throws ThematicMapException, IOException;
197 224
}
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/DefaultThematicMapManager.java
48 48
import org.gvsig.educa.thematicmap.map.InvalidThematicMapFormatException;
49 49
import org.gvsig.educa.thematicmap.map.ThematicMap;
50 50
import org.gvsig.educa.thematicmap.map.ThematicMapInformation;
51
import org.gvsig.installer.lib.api.InstallerLocator;
52
import org.gvsig.installer.lib.api.InstallerManager;
51 53
import org.gvsig.installer.lib.api.PackageInfo;
52 54
import org.gvsig.tools.ToolsLocator;
53 55

  
......
69 71

  
70 72
    public static final String BASENAME_FORMAT_STRING = "{0}-{1}-BN{2}";
71 73

  
74
    public static final String PACKAGE_BASENAME_FORMAT_STRING =
75
        "ThematicMap-{0}-{1}-BN{2}";
76

  
72 77
    /**
73 78
     * Manager which manages when deploy/clean maps in
74 79
     * temporal folder
......
77 82

  
78 83
    private final ThematicMapLoader mapLoader;
79 84

  
85
    private final InstallerManager installerManager;
86

  
80 87
    /**
81 88
     * Map Instalation's folder
82 89
     */
......
111 118
        // Create resource manager instance
112 119
        resourceManager = new MapResoucesManager(mapLoader);
113 120

  
121
        installerManager = InstallerLocator.getInstallerManager();
114 122
    }
115 123

  
116 124
    /** {@inheridDoc} */
......
393 401

  
394 402
    }
395 403

  
404
    /** {@inheridDoc} */
396 405
    public String getBaseFileNameFromInfo(ThematicMapInformation info) {
397 406
        return getBaseFileNameFromInfo(info.getId(), info.getName(),
398 407
            info.getVersion(), info.getBuildNumber());
399 408
    }
400 409

  
410
    /** {@inheridDoc} */
401 411
    public String getBaseFileNameFromInfo(String id, String name, int version,
402 412
        int buildNumber) {
403 413
        return MessageFormat.format(BASENAME_FORMAT_STRING, id, version,
404 414
            buildNumber);
405 415
    }
416

  
417
    /** {@inheridDoc} */
418
    public File generatePackageFile(String mapId, File targetFolder)
419
        throws ThematicMapException, IOException {
420

  
421
        ThematicMap map = getMapById(mapId);
422
        if (map == null) {
423
            throw new IllegalArgumentException("Thematic Map not foudn: '"
424
                .concat(mapId).concat("'"));
425
        }
426

  
427
        File mapFolder = new File(installationFolder, mapId);
428

  
429
        return generatePackageFile(mapFolder, targetFolder);
430
    }
431

  
432
    /** {@inheridDoc} */
433
    public File generatePackageFile(File thematicMapIntallFolder,
434
        File targetFolder) throws ThematicMapException, IOException {
435

  
436
        // Checks if it's a map folder
437
        ThematicMap map = null;
438
        try {
439
            map = getThematicMapIntalledFolder(thematicMapIntallFolder);
440
        } catch (Exception ex) {
441
            throw new IllegalArgumentException("Source is not a map folder: '"
442
                .concat(thematicMapIntallFolder.getAbsolutePath()).concat("'"));
443
        }
444
        if (map == null) {
445
            throw new IllegalArgumentException("Source is not a map folder: '"
446
                .concat(thematicMapIntallFolder.getAbsolutePath()).concat("'"));
447
        }
448

  
449
        // Check target folder
450
        if (!FileUtils.isWritableFolder(targetFolder)) {
451
            throw new IllegalArgumentException(
452
                "Target is not a writable folder: '".concat(
453
                    targetFolder.getAbsolutePath()).concat("'"));
454
        }
455

  
456
        // Prepare target file name
457
        ThematicMapInformation info = map.getInformation();
458
        String pkgFileName =
459
            MessageFormat
460
                .format(PACKAGE_BASENAME_FORMAT_STRING, info.getId(),
461
                    info.getVersion(), info.getBuildNumber()).concat(".")
462
                .concat(installerManager.getDefaultPackageFileExtension());
463
        File targetFile = new File(targetFolder, pkgFileName);
464

  
465
        // Prepare temporal folder
466
        File workFolder =
467
            FileUtils.getNewWritableFolder(temporalDeployMapFolder,
468
                "__tmp__".concat(pkgFileName));
469
        File tempFolder = new File(workFolder, info.getId());
470

  
471
        // Copy all content of map folder
472
        FileUtils.copyDirectory(thematicMapIntallFolder, tempFolder, true);
473

  
474
        // Remove unused thematicMap files
475
        String mapFileName = FilenameUtils.getName(map.getSourceFilePath());
476
        File[] tmFiles = tempFolder.listFiles(thematicMapFileFilter);
477
        for (File thFile : tmFiles) {
478
            if (!StringUtils.equals(thFile.getName(), mapFileName)) {
479
                thFile.delete();
480
            }
481
        }
482

  
483
        // Zip file
484
        FileUtils.zipFolder(workFolder, targetFile);
485

  
486
        return targetFile;
487
    }
406 488
}
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/pom.xml
125 125
				<artifactId>org.gvsig.educa.thematicmap.swing.impl</artifactId>
126 126
				<version>${educa.version}</version>
127 127
			</dependency>
128
			<dependency>
129
				<groupId>org.gvsig</groupId>
130
				<artifactId>org.gvsig.educa.thematicmap.installer.provider</artifactId>
131
				<version>${educa.version}</version>
132
			</dependency>
128 133

  
129 134
			<!-- gvSIG -->
130 135
			<dependency>
......
286 291
				<version>${gvsig.installer.version}</version>
287 292
				<scope>runtime</scope>
288 293
			</dependency>
294
			<dependency>
295
				<groupId>org.gvsig</groupId>
296
				<artifactId>org.gvsig.installer.swing.api</artifactId>
297
				<version>${gvsig.installer.version}</version>
298
			</dependency>
299
			<dependency>
300
				<groupId>org.gvsig</groupId>
301
				<artifactId>org.gvsig.installer.swing.impl</artifactId>
302
				<version>${gvsig.installer.version}</version>
303
				<scope>runtime</scope>
304
			</dependency>
289 305

  
290 306

  
291 307
			<!-- apache commons -->

Also available in: Unified diff