Revision 62

View differences:

org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/pom.xml
103 103
			</dependency>
104 104
			<dependency>
105 105
				<groupId>org.gvsig</groupId>
106
				<artifactId>org.gvsig.educa.thematicmap.lib.prov.installer</artifactId>
107
				<version>${educa.version}</version>
108
        <scope>runtime</scope>
109
			</dependency>
110
			<dependency>
111
				<groupId>org.gvsig</groupId>
106 112
				<artifactId>org.gvsig.educa.thematicmap.swing.api</artifactId>
107 113
				<version>${educa.version}</version>
108 114
			</dependency>
......
113 119
        <scope>runtime</scope>
114 120
			</dependency>
115 121

  
122
      <!-- gvSIG educa app -->
123
			<dependency>
124
				<groupId>org.gvsig</groupId>
125
				<artifactId>org.gvsig.educa.thematicmap.app.viewer</artifactId>
126
				<version>${educa.app.version}</version>
127
			</dependency>
128
			<dependency>
129
				<groupId>org.gvsig</groupId>
130
				<artifactId>org.gvsig.educa.thematicmap.app.editor</artifactId>
131
				<version>${educa.app.version}</version>
132
			</dependency>
133

  
134

  
135

  
116 136
      <!-- gvSIG -->
117 137
      <!--
118 138
			<dependency>
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/buildNumber.properties
1
buildNumber=0
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed Nov 23 09:49:27 CET 2011
3
buildNumber=2042
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/package.info
1
#
2
#Thu Dec 22 17:30:55 CET 2011
3
state=devel
4
name=org.gvsig.educa.thematicmap.app.editor
5
buildNumber=2042
6
official=true
7
owner=gvSIG Association
8
code=org.gvsig.educa.thematicmap.app.editor
9
operating-system=all
10
architecture=all
11
web-url=http\://www.gvsig.com
12
java-version=j1_5
13
gvSIG-version=2.0.0
14
sources-url=https\://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.educa.thematicmap/extension/trunk/?root\=gvsig-thematicmap/org.gvsig.educa.thematicmap.app.editor
15
version=1.0.0-SNAPSHOT-2042
16
dependencies=
17
type=plugin
18
description=Application of the ThematicMap project
19
model-version=1.0.1
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/GvSIGThematicMapWindowManager.java
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.app.editor;
23

  
24
import java.awt.event.ComponentEvent;
25
import java.awt.event.ComponentListener;
26
import java.util.HashMap;
27
import java.util.Map;
28

  
29
import javax.swing.JPanel;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.ui.mdiManager.IWindow;
33
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager;
34

  
35
/**
36
 * {@link ThematicMapWindowManager} implementation to show ThematicMap
37
 * windows as gvSIG windows
38
 * 
39
 * @author gvSIG Team
40
 * @version $Id$
41
 */
42
public class GvSIGThematicMapWindowManager implements
43
    ThematicMapWindowManager, ComponentListener {
44

  
45
    private Map<JPanel, IWindow> panelToWindow = new HashMap<JPanel, IWindow>();
46
    
47
    public void showPanel(JPanel panel, String title, int mode) {
48
        ThematicMapWindow window =
49
            new ThematicMapWindow(panel, title, mode);
50

  
51
        panel.addComponentListener(this);
52
        
53
        panelToWindow.put(panel, window);
54

  
55
        PluginServices.getMDIManager().addCentredWindow(window);
56
    }
57

  
58
    public void componentHidden(ComponentEvent componentEvent) {
59
        JPanel panel = (JPanel) componentEvent.getSource();
60
        IWindow window = panelToWindow.get(panel);
61
        PluginServices.getMDIManager().closeWindow(window);
62
        panelToWindow.remove(panel);
63
    }
64

  
65
    public void componentMoved(ComponentEvent e) {
66
        // Nothing to do
67
    }
68

  
69
    public void componentResized(ComponentEvent e) {
70
        // Nothing to do
71
    }
72

  
73
    public void componentShown(ComponentEvent e) {
74
        // Nothing to do
75
    }
76
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/ThematicMapWindow.java
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.app.editor;
23

  
24
import java.awt.Dimension;
25

  
26
import javax.swing.JPanel;
27

  
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.andami.ui.mdiManager.WindowInfo;
30
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager;
31

  
32
/**
33
 * {@link IWindow} to show a ThematicMap.
34
 * 
35
 * @author gvSIG Team
36
 * @version $Id$
37
 */
38
public class ThematicMapWindow extends JPanel implements IWindow {
39

  
40
    private static final long serialVersionUID = -4401123724140025094L;
41

  
42
    private WindowInfo info;
43

  
44
    private Object profile = WindowInfo.EDITOR_PROFILE;
45

  
46
    /**
47
     * Constructor.
48
     * 
49
     * @param panel
50
     *            the panel to show
51
     * @param title
52
     *            the window title
53
     * @param mode
54
     *            the window mode
55
     * @see {@link ThematicMapWindowManager#MODE_DIALOG}
56
     * @see {@link ThematicMapWindowManager#MODE_TOOL}
57
     * @see {@link ThematicMapWindowManager#MODE_WINDOW}
58
     */
59
    public ThematicMapWindow(JPanel panel, String title, int mode) {
60
        add(panel);
61
        Dimension dimension = new Dimension(600, 200);
62
        setSize(dimension);
63
        int code =
64
            WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
65
                | WindowInfo.RESIZABLE;
66
        switch (mode) {
67
        case ThematicMapWindowManager.MODE_DIALOG:
68
            code |= WindowInfo.MODALDIALOG;
69
            profile = WindowInfo.DIALOG_PROFILE;
70
            break;
71
        case ThematicMapWindowManager.MODE_TOOL:
72
            code |= WindowInfo.PALETTE;
73
            profile = WindowInfo.TOOL_PROFILE;
74
            break;
75
        case ThematicMapWindowManager.MODE_WINDOW:
76
        default:
77
            code |= WindowInfo.MODELESSDIALOG;
78
            profile = WindowInfo.EDITOR_PROFILE;
79
        }
80
        info = new WindowInfo(code);
81
        info.setTitle(title);
82
        info.setMinimumSize(dimension);
83
    }
84

  
85
    public WindowInfo getWindowInfo() {
86
        return info;
87
    }
88

  
89
    public Object getWindowProfile() {
90
        return profile;
91
    }
92
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/ThematicMapExtension.java
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.app.editor;
23

  
24
import org.gvsig.andami.messages.NotificationManager;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.educa.thematicmap.ThematicMapLocator;
27
import org.gvsig.educa.thematicmap.ThematicMapManager;
28
import org.gvsig.educa.thematicmap.ThematicMapService;
29
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
30
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
31
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager;
32
import org.gvsig.educa.thematicmap.swing.JThematicMapServicePanel;
33
import org.gvsig.tools.service.ServiceException;
34

  
35
/**
36
 * Andami extension to show ThematicMap in the application.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class ThematicMapExtension extends Extension {
42

  
43
    private ThematicMapManager manager;
44
    private ThematicMapSwingManager swingManager;
45

  
46
    public void initialize() {
47
        // Do nothing
48
    }
49

  
50
    @Override
51
    public void postInitialize() {
52
        super.postInitialize();
53
        manager = ThematicMapLocator.getManager();
54
        // Asignamos el locator e iniciamos la instancia
55
        swingManager = ThematicMapSwingLocator.getSwingManager();
56

  
57
        swingManager
58
            .registerWindowManager(new GvSIGThematicMapWindowManager());
59
    }
60

  
61
    public void execute(String actionCommand) {
62
        showThematicMap(manager);
63
    }
64

  
65
    public void showThematicMap(ThematicMapManager manager) {
66
        try {
67
            ThematicMapService service =
68
                (ThematicMapService) manager.getThematicMapService();
69
            JThematicMapServicePanel panel =
70
                swingManager.createThematicMap(service);
71
            swingManager.getWindowManager().showPanel(panel, "ThematicMap",
72
                ThematicMapWindowManager.MODE_DIALOG);
73

  
74
        } catch (ServiceException e) {
75
            NotificationManager.addError(e);
76
        }
77
    }
78

  
79
    public boolean isEnabled() {
80
        return true;
81
    }
82

  
83
    public boolean isVisible() {
84
        return true;
85
    }
86

  
87
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/RegenerateThematicMapExtension.java
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.app.editor;
23

  
24
import javax.swing.SwingUtilities;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.andami.messages.NotificationManager;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.andami.ui.mdiManager.IWindow;
30
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
31
import org.gvsig.educa.thematicmap.app.viewer.ui.ThematicMapDocumentViewer;
32
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
33
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
34

  
35
/**
36
 * Andami extension to create a gvSIG add-on manager package of a Thematic Map.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class RegenerateThematicMapExtension extends Extension {
42

  
43
    private ThematicMapEditorManager editorManager;
44
    private ThematicMapSwingManager swingManager;
45

  
46
    public void initialize() {
47
        // Do nothing
48
    }
49

  
50
    @Override
51
    public void postInitialize() {
52
        editorManager = ThematicMapEditorLocator.getManager();
53
        swingManager = ThematicMapSwingLocator.getSwingManager();
54
    }
55

  
56
    public void execute(String actionCommand) {
57
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
58
        if (!(window instanceof ThematicMapDocumentViewer)) {
59
            return;
60
        }
61
        final ThematicMapDocument tmDocument =
62
            ((ThematicMapDocumentViewer) window).getThematicMapDocument();
63

  
64
        SwingUtilities.invokeLater(new Runnable() {
65

  
66
            public void run() {
67
                try {
68
                    editorManager.regenerateThematicMap(tmDocument, null, true);
69
                } catch (Exception ex) {
70
                    NotificationManager.addError(
71
                        "problems_regeneration_thematic_map", ex);
72
                }
73

  
74
            }
75
        });
76
    }
77

  
78
    public boolean isEnabled() {
79
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
80
        if (window instanceof ThematicMapDocumentViewer) {
81
            return ((ThematicMapDocumentViewer) window)
82
                .getThematicMapDocument().getSourceView() != null;
83
        }
84
        return false;
85
    }
86

  
87
    public boolean isVisible() {
88
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
89
        return window instanceof ThematicMapDocumentViewer;
90
    }
91
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/ThematicMapEditorManager.java
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.app.editor;
23

  
24
import java.io.File;
25
import java.io.IOException;
26

  
27
import org.gvsig.app.project.documents.view.ViewDocument;
28
import org.gvsig.educa.thematicmap.ThematicMapException;
29
import org.gvsig.educa.thematicmap.ThematicMapManager;
30
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
31
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocumentManager;
32
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilation;
33
import org.gvsig.educa.thematicmap.map.CantLoadContextException;
34
import org.gvsig.educa.thematicmap.map.InvalidThematicMapFormatException;
35
import org.gvsig.educa.thematicmap.map.ThematicMap;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37

  
38
/**
39
 * @author gvSIG Team
40
 * @version $Id$
41
 * 
42
 */
43
public interface ThematicMapEditorManager {
44

  
45
    /**
46
     * Returns {@link ThematicMapDocumentManager} instance
47
     * 
48
     * @return
49
     */
50
    ThematicMapDocumentManager getDocManager();
51

  
52
    /**
53
     * Compile a {@link ThematicMapCompilation} and deploy it in current install
54
     * folder ( {@link ThematicMapManager#getInstallationMapFolder()} )
55
     * 
56
     * @param compilation
57
     *            to compile
58
     * 
59
     * @param listener
60
     *            of the process
61
     */
62
    void compileInInstallFolder(ThematicMapCompilation compilation,
63
        CompilationListener listener);
64

  
65
    /**
66
     * <p>
67
     * Create a new {@link ThematicMap} from a view contents and open it as a
68
     * {@link ThematicMapDocument}
69
     * </p>
70
     * <p>
71
     * {@link ThematicMapDocument} will be linked to source view so it can be
72
     * regenerated.
73
     * </p>
74
     * 
75
     * @param view
76
     * @param listener
77
     * @param openWindow
78
     */
79
    void createThematicMapFromView(ViewDocument view,
80
        CompilationListener listener, boolean openWindow);
81

  
82
    /**
83
     * Gets the {@link ThematicMapDocument} linked to a {@link ViewDocument}
84
     * 
85
     * @param view
86
     * @return the document or null if not found
87
     */
88
    ThematicMapDocument getThematicMapDocumentByView(ViewDocument view);
89

  
90
    /**
91
     * Generate a gvSIG add-ons installer package from a
92
     * {@link ThematicMapDocument}
93
     * 
94
     * @param thematicMap
95
     *            to packing
96
     * @param targetFolder
97
     *            to store result file
98
     * @return
99
     * @throws IOException
100
     * @throws ThematicMapException
101
     */
102
    File generatePackage(ThematicMapDocument thematicMap, File targetFolder)
103
        throws ThematicMapException, IOException;
104

  
105
    /**
106
     * <p>
107
     * Generate a gvSIG add-ons installer package from a
108
     * {@link ThematicMapDocument}
109
     * </p>
110
     * <p>
111
     * User will be prompted for folder to store result file
112
     * </p>
113
     * 
114
     * @param thematicMap
115
     * @return
116
     * @throws IOException
117
     * @throws ThematicMapException
118
     */
119
    File generatePackage(ThematicMapDocument thematicMap)
120
        throws ThematicMapException, IOException;
121

  
122
    /**
123
     * Export the contents of a Thematic Map into a folder and create a
124
     * {@link ViewDocument} in project with it's layers
125
     * <p>
126
     * User will be prompted for extract folder
127
     * </p>
128
     * <p>
129
     * If Thematic map document has no related view link the new one to it
130
     * </p>
131
     * 
132
     * @param map
133
     * @param openViewWindow
134
     * @return
135
     * @throws IOException
136
     * @throws InvalidThematicMapFormatException
137
     * @throws PersistenceException
138
     */
139
    ViewDocument exportThematicMapToView(ThematicMapDocument map,
140
        boolean openViewWindow) throws IOException,
141
        InvalidThematicMapFormatException, PersistenceException;
142

  
143
    /**
144
     * Export the contents of a Thematic Map into a folder and create a
145
     * {@link ViewDocument} in project with it's layers
146
     * <p>
147
     * If Thematic map document has no related view link the new one to it
148
     * </p>
149
     * 
150
     * @param map
151
     * @param exportFolder
152
     *            <b>Warning:</b> this folder must be empty
153
     * @return
154
     * @throws IOException
155
     * @throws InvalidThematicMapFormatException
156
     * @throws PersistenceException
157
     */
158
    ViewDocument exportThematicMapToView(ThematicMapDocument map,
159
        File exportFolder, boolean openViewWindow) throws IOException,
160
        InvalidThematicMapFormatException, PersistenceException;
161

  
162
    /**
163
     * <p>
164
     * Regenerates the Thematic Map from current state of source View
165
     * </p>
166
     * <p>
167
     * Thematic Map document must be linked to a view, otherwise this method do
168
     * nothing.
169
     * </p>
170
     * 
171
     * @param map
172
     * @param listener
173
     * @param openWindow
174
     * @throws IOException
175
     * @throws CantLoadContextException
176
     * @throws InvalidThematicMapFormatException
177
     */
178
    void regenerateThematicMap(ThematicMapDocument map,
179
        CompilationListener listener, boolean openWindow)
180
        throws InvalidThematicMapFormatException, CantLoadContextException,
181
        IOException;
182

  
183
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/document/GeneratePackageOfThematicMapAction.java
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.app.editor.document;
23

  
24
import java.io.File;
25
import java.util.List;
26

  
27
import javax.swing.SwingUtilities;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.messages.NotificationManager;
31
import org.gvsig.app.project.ProjectManager;
32
import org.gvsig.app.project.documents.AbstractDocumentAction;
33
import org.gvsig.app.project.documents.Document;
34
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorLocator;
35
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorManager;
36
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
37
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
38
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
39
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager.MESSAGE_DIALOG_TYPE;
40

  
41
/**
42
 * @author gvSIG Team
43
 * @version $Id$
44
 * 
45
 */
46
public class GeneratePackageOfThematicMapAction extends AbstractDocumentAction {
47

  
48
    private final ThematicMapEditorManager editorManager;
49
    private final ThematicMapSwingManager swingManager;
50

  
51
    /**
52
     *
53
     */
54
    public GeneratePackageOfThematicMapAction() {
55
        super("GeneratePackageOfThematicMap");
56
        this.order = 0;
57
        this.title = PluginServices.getText(this, "generate_package");
58
        this.group =
59
            ProjectManager.getInstance().addDocumentActionGroup(
60
                "ThematicMapActions", "Thematic Map actions", null, 0);
61

  
62
        editorManager = ThematicMapEditorLocator.getManager();
63
        swingManager = ThematicMapSwingLocator.getSwingManager();
64
    }
65

  
66
    public boolean isVisible(Document document, List<Document> documents) {
67
        if (document != null || documents.size() != 1) {
68
            return false;
69
        }
70
        return true;
71
    }
72

  
73
    public boolean isAvailable(Document document, List<Document> documents) {
74
        return true;
75
    }
76

  
77
    public void execute(Document document, List<Document> documents) {
78
        final ThematicMapDocument tmDocument;
79
        if (document != null) {
80
            tmDocument = (ThematicMapDocument) document;
81
        } else {
82
            if (documents.size() != 1) {
83
                return;
84
            }
85
            tmDocument = (ThematicMapDocument) documents.get(0);
86
        }
87
        SwingUtilities.invokeLater(new Runnable() {
88

  
89
            public void run() {
90
                try {
91
                    File file = editorManager.generatePackage(tmDocument);
92
                    if (file != null) {
93
                        swingManager.getWindowManager().showMessageDialog(
94
                            swingManager.getTranslation("generate_package"),
95
                            swingManager.getTranslation("generated_file")
96
                                .concat(":").concat(file.getAbsolutePath()),
97
                            MESSAGE_DIALOG_TYPE.INFO);
98
                    }
99
                } catch (Exception ex) {
100
                    NotificationManager.addError(
101
                        "problems_exporting_thematic_map_to_view", ex);
102
                }
103

  
104
            }
105
        });
106
    }
107

  
108
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/document/ThematicMapToViewAction.java
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.app.editor.document;
23

  
24
import java.util.List;
25

  
26
import javax.swing.SwingUtilities;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.andami.messages.NotificationManager;
30
import org.gvsig.app.project.ProjectManager;
31
import org.gvsig.app.project.documents.AbstractDocumentAction;
32
import org.gvsig.app.project.documents.Document;
33
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorLocator;
34
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorManager;
35
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
36
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
37
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
38

  
39
/**
40
 * @author gvSIG Team
41
 * @version $Id$
42
 * 
43
 */
44
public class ThematicMapToViewAction extends AbstractDocumentAction {
45

  
46
    private final ThematicMapEditorManager editorManager;
47
    private final ThematicMapSwingManager swingManager;
48

  
49
    /**
50
     *
51
     */
52
    public ThematicMapToViewAction() {
53
        super("ThematicMapToView");
54
        this.order = 0;
55
        this.title = PluginServices.getText(this, "export_to_view");
56
        this.group =
57
            ProjectManager.getInstance().addDocumentActionGroup(
58
                "ThematicMapActions", "Thematic Map actions", null, 0);
59
        editorManager = ThematicMapEditorLocator.getManager();
60
        swingManager = ThematicMapSwingLocator.getSwingManager();
61
    }
62

  
63
    public boolean isVisible(Document document, List<Document> documents) {
64
        if (document != null || documents.size() != 1) {
65
            return false;
66
        }
67
        return true;
68
    }
69

  
70
    public boolean isAvailable(Document document, List<Document> documents) {
71
        return true;
72
    }
73

  
74
    public void execute(Document document, List<Document> documents) {
75
        final ThematicMapDocument tmDoc;
76
        if (document != null) {
77
            tmDoc = (ThematicMapDocument) document;
78
        } else {
79
            if (documents.size() != 1) {
80
                return;
81
            }
82
            tmDoc = (ThematicMapDocument) documents.get(0);
83
        }
84

  
85
        SwingUtilities.invokeLater(new Runnable() {
86

  
87
            public void run() {
88
                try {
89
                    editorManager.exportThematicMapToView(tmDoc, true);
90
                } catch (Exception ex) {
91
                    NotificationManager.addError(
92
                        swingManager
93
                            .getTranslation("problems_exporting_thematic_map_to_view"),
94
                        ex);
95
                }
96

  
97
            }
98
        });
99

  
100
    }
101

  
102
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/document/RegenerateThematicMapFromViewAction.java
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.app.editor.document;
23

  
24
import java.util.List;
25

  
26
import javax.swing.SwingUtilities;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.andami.messages.NotificationManager;
30
import org.gvsig.app.project.ProjectManager;
31
import org.gvsig.app.project.documents.AbstractDocumentAction;
32
import org.gvsig.app.project.documents.Document;
33
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorLocator;
34
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorManager;
35
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
36

  
37
/**
38
 * @author gvSIG Team
39
 * @version $Id$
40
 * 
41
 */
42
public class RegenerateThematicMapFromViewAction extends AbstractDocumentAction {
43

  
44
    private final ThematicMapEditorManager editorManager;
45

  
46
    /**
47
     *
48
     */
49
    public RegenerateThematicMapFromViewAction() {
50
        super("NewThematicMapFromView");
51
        this.order = 0;
52
        this.title =
53
            PluginServices.getText(this, "regenerate_thematic_map_from_a_view");
54
        this.group =
55
            ProjectManager.getInstance().addDocumentActionGroup(
56
                "ThematicMapActions", "Thematic Map actions", null, 0);
57
        editorManager = ThematicMapEditorLocator.getManager();
58
    }
59

  
60
    public boolean isVisible(Document document, List<Document> documents) {
61
        if (document != null || documents.size() != 1) {
62
            return false;
63
        }
64
        return true;
65
    }
66

  
67
    public boolean isAvailable(Document document, List<Document> documents) {
68
        ThematicMapDocument thMapDoc = null;
69
        if (document != null) {
70
            thMapDoc = (ThematicMapDocument) document;
71
        } else {
72
            if (documents != null && !documents.isEmpty()) {
73
                thMapDoc = (ThematicMapDocument) documents.get(0);
74
            }
75
        }
76
        return thMapDoc != null && thMapDoc.getSourceView() != null;
77
    }
78

  
79
    public void execute(Document document, List<Document> documents) {
80
        final ThematicMapDocument tmDocument;
81
        if (document != null) {
82
            tmDocument = (ThematicMapDocument) document;
83
        } else {
84
            if (documents.size() != 1) {
85
                return;
86
            }
87
            tmDocument = (ThematicMapDocument) documents.get(0);
88
        }
89
        SwingUtilities.invokeLater(new Runnable() {
90

  
91
            public void run() {
92
                try {
93
                    editorManager.regenerateThematicMap(tmDocument, null, true);
94
                } catch (Exception ex) {
95
                    NotificationManager.addError(
96
                        "problems_exporting_thematic_map_to_view", ex);
97
                }
98

  
99
            }
100
        });
101
    }
102
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/GeneratePackageThematicMapExtension.java
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.app.editor;
23

  
24
import java.io.File;
25

  
26
import javax.swing.SwingUtilities;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.andami.messages.NotificationManager;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
33
import org.gvsig.educa.thematicmap.app.viewer.ui.ThematicMapDocumentViewer;
34
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
35
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
36
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager.MESSAGE_DIALOG_TYPE;
37

  
38
/**
39
 * Andami extension to create a gvSIG add-on manager package of a Thematic Map.
40
 * 
41
 * @author gvSIG Team
42
 * @version $Id$
43
 */
44
public class GeneratePackageThematicMapExtension extends Extension {
45

  
46
    private ThematicMapEditorManager editorManager;
47
    private ThematicMapSwingManager swingManager;
48

  
49
    public void initialize() {
50
        // Do nothing
51
    }
52

  
53
    @Override
54
    public void postInitialize() {
55
        editorManager = ThematicMapEditorLocator.getManager();
56
        swingManager = ThematicMapSwingLocator.getSwingManager();
57
    }
58

  
59
    public void execute(String actionCommand) {
60
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
61
        if (!(window instanceof ThematicMapDocumentViewer)) {
62
            return;
63
        }
64
        final ThematicMapDocument tmDocument =
65
            ((ThematicMapDocumentViewer) window).getThematicMapDocument();
66

  
67
        SwingUtilities.invokeLater(new Runnable() {
68

  
69
            public void run() {
70
                try {
71
                    File file = editorManager.generatePackage(tmDocument);
72
                    if (file != null) {
73
                        swingManager.getWindowManager().showMessageDialog(
74
                            swingManager.getTranslation("generate_package"),
75
                            swingManager.getTranslation("generated_file")
76
                                .concat(":").concat(file.getAbsolutePath()),
77
                            MESSAGE_DIALOG_TYPE.INFO);
78
                    }
79
                } catch (Exception ex) {
80
                    NotificationManager.addError(
81
                        "problems_exporting_thematic_map_to_view", ex);
82
                }
83

  
84
            }
85
        });
86
    }
87

  
88
    public boolean isEnabled() {
89
        return true;
90
    }
91

  
92
    public boolean isVisible() {
93
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
94
        return window instanceof ThematicMapDocumentViewer;
95
    }
96
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/ThematicMapEditorExtension.java
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.app.editor;
23

  
24
import org.gvsig.andami.plugins.Extension;
25
import org.gvsig.app.project.ProjectManager;
26
import org.gvsig.educa.thematicmap.ThematicMapLocator;
27
import org.gvsig.educa.thematicmap.ThematicMapManager;
28
import org.gvsig.educa.thematicmap.app.editor.document.GeneratePackageOfThematicMapAction;
29
import org.gvsig.educa.thematicmap.app.editor.document.RegenerateThematicMapFromViewAction;
30
import org.gvsig.educa.thematicmap.app.editor.document.ThematicMapToViewAction;
31
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocumentManager;
32
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
33
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
34

  
35
/**
36
 * Andami extension to show ThematicMap in the application.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class ThematicMapEditorExtension extends Extension {
42

  
43
    private ThematicMapManager manager;
44
    private ThematicMapSwingManager swingManager;
45

  
46
    public void initialize() {
47
        // Do nothing
48
    }
49

  
50
    @Override
51
    public void postInitialize() {
52

  
53
        super.postInitialize();
54
        manager = ThematicMapLocator.getManager();
55
        swingManager = ThematicMapSwingLocator.getSwingManager();
56

  
57
        // Register Document action
58
        ProjectManager projectManager = ProjectManager.getInstance();
59

  
60
        projectManager.registerDocumentAction(
61
            ThematicMapDocumentManager.TYPENAME, new ThematicMapToViewAction());
62
        projectManager.registerDocumentAction(
63
            ThematicMapDocumentManager.TYPENAME,
64
            new RegenerateThematicMapFromViewAction());
65
        projectManager.registerDocumentAction(
66
            ThematicMapDocumentManager.TYPENAME,
67
            new GeneratePackageOfThematicMapAction());
68

  
69
    }
70

  
71
    public boolean isEnabled() {
72
        return true;
73
    }
74

  
75
    public boolean isVisible() {
76
        return true;
77
    }
78

  
79
    public void execute(String actionCommand) {
80

  
81
    }
82
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/impl/ThematicMapEditorDefaultImplLibrary.java
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.app.editor.impl;
23

  
24
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorLibrary;
25
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorLocator;
26
import org.gvsig.tools.library.AbstractLibrary;
27
import org.gvsig.tools.library.LibraryException;
28

  
29
/**
30
 * Library for default implementation initialization and configuration.
31
 * 
32
 * @author gvSIG team
33
 * @version $Id$
34
 */
35
public class ThematicMapEditorDefaultImplLibrary extends AbstractLibrary {
36

  
37
    @Override
38
    public void doRegistration() {
39
        registerAsImplementationOf(ThematicMapEditorLibrary.class);
40
    }
41

  
42
    /** {@inheridDoc} */
43
    @Override
44
    protected void doInitialize() throws LibraryException {
45
        ThematicMapEditorLocator
46
            .registerManager(DefaultThematicMapEditorManager.class);
47
    }
48

  
49
    /** {@inheridDoc} */
50
    @Override
51
    protected void doPostInitialize() throws LibraryException {
52
        // Do Nothing
53
    }
54

  
55
}
org.gvsig.educa.thematicmap.app/trunk/org.gvsig.educa.thematicmap.app/org.gvsig.educa.thematicmap.app.editor/src/main/java/org/gvsig/educa/thematicmap/app/editor/impl/DefaultThematicMapEditorManager.java
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.app.editor.impl;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.util.List;
27

  
28
import javax.swing.JFileChooser;
29
import javax.swing.SwingUtilities;
30

  
31
import org.apache.commons.lang3.ObjectUtils;
32
import org.apache.commons.lang3.StringUtils;
33

  
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.messages.NotificationManager;
36
import org.gvsig.andami.ui.mdiManager.IWindow;
37
import org.gvsig.app.project.Project;
38
import org.gvsig.app.project.ProjectManager;
39
import org.gvsig.app.project.documents.Document;
40
import org.gvsig.app.project.documents.view.ViewDocument;
41
import org.gvsig.app.project.documents.view.ViewManager;
42
import org.gvsig.educa.thematicmap.ThematicMapException;
43
import org.gvsig.educa.thematicmap.ThematicMapFileServices;
44
import org.gvsig.educa.thematicmap.ThematicMapLocator;
45
import org.gvsig.educa.thematicmap.ThematicMapManager;
46
import org.gvsig.educa.thematicmap.app.editor.CompilationListener;
47
import org.gvsig.educa.thematicmap.app.editor.ThematicMapEditorManager;
48
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument;
49
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocumentManager;
50
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilation;
51
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilationInformation;
52
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompiler;
53
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilerStatus;
54
import org.gvsig.educa.thematicmap.map.CantLoadContextException;
55
import org.gvsig.educa.thematicmap.map.InvalidThematicMapFormatException;
56
import org.gvsig.educa.thematicmap.map.ThematicMap;
57
import org.gvsig.educa.thematicmap.map.ThematicMapInformation;
58
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
59
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager;
60
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager;
61
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager.MESSAGE_DIALOG_TYPE;
62
import org.gvsig.educa.thematicmap.swing.editor.ThematicMapCompilationEditor;
63
import org.gvsig.educa.thematicmap.swing.editor.ThematicMapCompilationEditorListener;
64
import org.gvsig.fmap.mapcontext.MapContext;
65
import org.gvsig.tools.persistence.exception.PersistenceException;
66
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
67

  
68
/**
69
 * @author gvSIG Team
70
 * @version $Id$
71
 * 
72
 */
73
public class DefaultThematicMapEditorManager implements
74
    ThematicMapEditorManager {
75

  
76
    private ThematicMapDocumentManager docManager;
77
    private final ThematicMapManager manager;
78
    private final ThematicMapSwingManager swingManager;
79
    private final ThematicMapWindowManager winManager;
80
    private final ThematicMapFileServices fileServices;
81
    private File workFolder;
82
    private final JFileChooser fileChooser;
83

  
84
    /**
85
     *
86
     */
87
    public DefaultThematicMapEditorManager() {
88
        swingManager = ThematicMapSwingLocator.getSwingManager();
89
        manager = swingManager.getManager();
90
        fileServices = ThematicMapLocator.getFileServices();
91
        winManager = swingManager.getWindowManager();
92
        fileChooser = new JFileChooser();
93
    }
94

  
95
    /**
96
     * <p>
97
     * {@link CompilationListener} instance which create a new
98
     * {@link ThematicMapDocument} from a {@link ViewDocument}
99
     * </p>
100
     * <p>
101
     * Delegates on previously received listener (if any)
102
     * </p>
103
     * 
104
     * @author gvSIG Team
105
     * @version $Id$
106
     * 
107
     */
108
    private class CreateDocumentListener implements CompilationListener {
109

  
110
        private final CompilationListener delegate;
111
        private final boolean openWindow;
112
        private final ViewDocument sourceView;
113

  
114
        /**
115
         * @param openWindow
116
         * 
117
         */
118
        public CreateDocumentListener(ViewDocument sourceView,
119
            CompilationListener delegate, boolean openWindow) {
120
            this.sourceView = sourceView;
121
            this.delegate = delegate;
122
            this.openWindow = openWindow;
123
        }
124

  
125
        public void finished(ThematicMapCompilerStatus status) {
126
            // Gets created map
127
            ThematicMap map =
128
                manager.getMapById(status.getResultCompilation()
129
                    .getInformation().getId());
130

  
131
            // Check if a document already exist for this map
132
            ThematicMapDocumentManager docManager = getDocManager();
133
            ThematicMapDocument doc = docManager.getDocumentForMap(map);
134
            if (doc == null) {
135
                doc = docManager.createDocument(map);
136
                getProject().add(doc);
137
            } else {
138
                // If exist reload
139
                try {
140
                    doc.reloadThematicMap();
141
                } catch (Exception ex) {
142
                    NotificationManager.addError(swingManager
143
                        .getTranslation("problems_reloading_thematic_map"), ex);
144
                }
145
            }
146
            // Link view to thematic map
147
            doc.setSourceView(sourceView);
148

  
149
            if (openWindow) {
150
                final IWindow window = docManager.getMainWindow(doc);
151
                SwingUtilities.invokeLater(new Runnable() {
152

  
153
                    public void run() {
154
                        PluginServices.getMDIManager().addWindow(window);
155
                    }
156
                });
157
            }
158

  
159
            if (delegate != null) {
160
                delegate.finished(status);
161
            }
162
        }
163

  
164
        public void canceledCompilation(ThematicMapCompilerStatus status) {
165
            if (delegate != null) {
166
                delegate.canceledCompilation(status);
167
            }
168
        }
169

  
170
        public void canceledEditing(ThematicMapCompilation compilation) {
171
            if (delegate != null) {
172
                delegate.canceledEditing(compilation);
173
            }
174
        }
175

  
176
        public void fail(ThematicMapCompilerStatus status) {
177
            if (delegate != null) {
178
                delegate.fail(status);
179
            }
180

  
181
        }
182

  
183
    }
184

  
185
    /**
186
     * <p>
187
     * {@link CompilationListener} instance which update the
188
     * {@link ThematicMapDocument} from its related {@link ViewDocument} (
189
     * {@link ThematicMapDocument#getSourceView()})
190
     * </p>
191
     * <p>
192
     * Delegates on previously received listener (if any)
193
     * </p>
194
     * 
195
     * @author gvSIG Team
196
     * @version $Id$
197
     * 
198
     */
199
    private class UpdateDocumentListener implements CompilationListener {
200

  
201
        private final CompilationListener delegate;
202
        private final boolean openWindow;
203
        private final ThematicMapDocument toUpdate;
204

  
205
        /**
206
         * @param openWindow
207
         * 
208
         */
209
        public UpdateDocumentListener(ThematicMapDocument toUpdate,
210
            CompilationListener delegate, boolean openWindow) {
211
            this.toUpdate = toUpdate;
212
            this.delegate = delegate;
213
            this.openWindow = openWindow;
214
        }
215

  
216
        public void finished(ThematicMapCompilerStatus status) {
217

  
218
            // close doc windows if it was opened
219
            PluginServices.getMDIManager().closeSingletonWindow(toUpdate);
220

  
221
            // Reload maps
222
            try {
223
                toUpdate.reloadThematicMap();
224
            } catch (Exception ex) {
225
                NotificationManager.addError(swingManager
226
                    .getTranslation("problems_reloading_thematic_map"), ex);
227
            }
228

  
229
            if (openWindow) {
230
                final IWindow window = docManager.getMainWindow(toUpdate);
231
                SwingUtilities.invokeLater(new Runnable() {
232

  
233
                    public void run() {
234
                        PluginServices.getMDIManager().addWindow(window);
235
                    }
236
                });
237
            }
238

  
239
            if (delegate != null) {
240
                delegate.finished(status);
241
            }
242
        }
243

  
244
        public void canceledCompilation(ThematicMapCompilerStatus status) {
245
            if (delegate != null) {
246
                delegate.canceledCompilation(status);
247
            }
248
        }
249

  
250
        public void canceledEditing(ThematicMapCompilation compilation) {
251
            if (delegate != null) {
252
                delegate.canceledEditing(compilation);
253
            }
254
        }
255

  
256
        public void fail(ThematicMapCompilerStatus status) {
257
            if (delegate != null) {
258
                delegate.fail(status);
259
            }
260

  
261
        }
262

  
263
    }
264

  
265
    public void createThematicMapFromView(ViewDocument view,
266
        CompilationListener listener, boolean openWindow) {
267

  
268
        if (view == null) {
269
            throw new IllegalArgumentException("View document required");
270
        }
271

  
272
        ThematicMapCompilation compilation =
273
            manager.createCompilationInstance();
274

  
275
        ThematicMapCompilationInformation info = compilation.getInformation();
276
        info.setName(view.getName());
277
        info.setId(generateIdForViewName(view.getName()));
278
        info.setVersion(1);
279

  
280
        compilation.setMapContext(view.getMapContext().cloneFMap());
281

  
282
        ThematicMapCompilationEditor editor =
283
            swingManager.getCopilationEditor(compilation, false);
284

  
285
        final CreateDocumentListener myListener =
286
            new CreateDocumentListener(view, listener, openWindow);
287

  
288
        editor.setListener(new ThematicMapCompilationEditorListener() {
289

  
290
            public void finished(final ThematicMapCompilationEditor editor) {
291
                editor.getSwingComponent().setVisible(false);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff