gvsig-educa / org.gvsig.educa.portableview / trunk / org.gvsig.educa.portableview / org.gvsig.educa.portableview.app / org.gvsig.educa.portableview.app.editor / src / main / java / org / gvsig / educa / portableview / app / editor / document / ViewToPortableViewAction.java @ 313
History | View | Annotate | Download (3.64 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.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.app.project.documents.view.ViewDocument; |
34 |
import org.gvsig.educa.portableview.app.editor.PortableViewEditorLocator; |
35 |
import org.gvsig.educa.portableview.app.editor.PortableViewEditorManager; |
36 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
37 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
38 |
import org.gvsig.fmap.mapcontext.MapContext; |
39 |
|
40 |
/**
|
41 |
* Document action which create a Portable View from a View
|
42 |
*
|
43 |
* @author gvSIG Team
|
44 |
* @version $Id$
|
45 |
*
|
46 |
*/
|
47 |
public class ViewToPortableViewAction extends AbstractDocumentAction { |
48 |
|
49 |
private final PortableViewEditorManager editorManager; |
50 |
private final PortableViewSwingManager swingManager; |
51 |
|
52 |
/**
|
53 |
*
|
54 |
*/
|
55 |
public ViewToPortableViewAction() {
|
56 |
super("ViewToPortableView"); |
57 |
this.order = 0; |
58 |
this.title = PluginServices.getText(this, "create_portable_view"); |
59 |
this.group = ProjectManager.getInstance().addDocumentActionGroup(
|
60 |
"PortableViewActions", "Portable View actions", null, 0); |
61 |
editorManager = PortableViewEditorLocator.getManager(); |
62 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
63 |
} |
64 |
|
65 |
/** {@inheridDoc} */
|
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 |
/** {@inheridDoc} */
|
74 |
public boolean isAvailable(Document document, List<Document> documents) { |
75 |
Document doc = null; |
76 |
if (document != null) { |
77 |
doc = document; |
78 |
} else {
|
79 |
if (documents != null && !documents.isEmpty()) { |
80 |
doc = documents.get(0);
|
81 |
} |
82 |
} |
83 |
if (doc == null) { |
84 |
return false; |
85 |
} |
86 |
|
87 |
if (doc instanceof ViewDocument) { |
88 |
MapContext mapContenxt = ((ViewDocument) doc).getMapContext(); |
89 |
if(mapContenxt.getLayers().getLayersCount() > 0){ |
90 |
return true; |
91 |
} |
92 |
} |
93 |
|
94 |
return false; |
95 |
} |
96 |
|
97 |
/** {@inheridDoc} */
|
98 |
public void execute(Document document, List<Document> documents) { |
99 |
final ViewDocument viewDoc;
|
100 |
if (document != null) { |
101 |
viewDoc = (ViewDocument) document; |
102 |
} else {
|
103 |
if (documents.size() != 1) { |
104 |
return;
|
105 |
} |
106 |
viewDoc = (ViewDocument) documents.get(0);
|
107 |
} |
108 |
|
109 |
SwingUtilities.invokeLater(new Runnable() { |
110 |
|
111 |
public void run() { |
112 |
try {
|
113 |
editorManager.createPortableViewFromView(viewDoc, null,
|
114 |
true);
|
115 |
} catch (Exception ex) { |
116 |
NotificationManager.addError( |
117 |
swingManager |
118 |
.getTranslation("problems_creating_portable_view_from_a_view"),
|
119 |
ex); |
120 |
} |
121 |
|
122 |
} |
123 |
}); |
124 |
} |
125 |
} |