Revision 313 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
ViewToPortableViewAction.java | ||
---|---|---|
35 | 35 |
import org.gvsig.educa.portableview.app.editor.PortableViewEditorManager; |
36 | 36 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
37 | 37 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
38 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
38 | 39 |
|
39 | 40 |
/** |
40 | 41 |
* Document action which create a Portable View from a View |
... | ... | |
45 | 46 |
*/ |
46 | 47 |
public class ViewToPortableViewAction extends AbstractDocumentAction { |
47 | 48 |
|
48 |
private final PortableViewEditorManager editorManager;
|
|
49 |
private final PortableViewSwingManager swingManager;
|
|
49 |
private final PortableViewEditorManager editorManager;
|
|
50 |
private final PortableViewSwingManager swingManager;
|
|
50 | 51 |
|
51 |
/**
|
|
52 |
/**
|
|
52 | 53 |
* |
53 | 54 |
*/ |
54 |
public ViewToPortableViewAction() { |
|
55 |
super("ViewToPortableView"); |
|
56 |
this.order = 0; |
|
57 |
this.title = PluginServices.getText(this, "create_portable_view"); |
|
58 |
this.group = |
|
59 |
ProjectManager.getInstance().addDocumentActionGroup( |
|
60 |
"PortableViewActions", "Portable View actions", null, 0); |
|
61 |
editorManager = PortableViewEditorLocator.getManager(); |
|
62 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
|
63 |
} |
|
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 | 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 |
}
|
|
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 | 72 |
|
73 |
/** {@inheridDoc} */ |
|
74 |
public boolean isAvailable(Document document, List<Document> documents) { |
|
75 |
return true; |
|
76 |
} |
|
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 |
} |
|
77 | 86 |
|
78 |
/** {@inheridDoc} */ |
|
79 |
public void execute(Document document, List<Document> documents) { |
|
80 |
final ViewDocument viewDoc; |
|
81 |
if (document != null) { |
|
82 |
viewDoc = (ViewDocument) document; |
|
83 |
} else { |
|
84 |
if (documents.size() != 1) { |
|
85 |
return; |
|
86 |
} |
|
87 |
viewDoc = (ViewDocument) documents.get(0); |
|
88 |
} |
|
87 |
if (doc instanceof ViewDocument) { |
|
88 |
MapContext mapContenxt = ((ViewDocument) doc).getMapContext(); |
|
89 |
if(mapContenxt.getLayers().getLayersCount() > 0){ |
|
90 |
return true; |
|
91 |
} |
|
92 |
} |
|
89 | 93 |
|
90 |
SwingUtilities.invokeLater(new Runnable() { |
|
94 |
return false; |
|
95 |
} |
|
91 | 96 |
|
92 |
public void run() { |
|
93 |
try { |
|
94 |
editorManager |
|
95 |
.createPortableViewFromView(viewDoc, null, true); |
|
96 |
} catch (Exception ex) { |
|
97 |
NotificationManager.addError( |
|
98 |
swingManager |
|
99 |
.getTranslation("problems_creating_portable_view_from_a_view"), |
|
100 |
ex); |
|
101 |
} |
|
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 |
} |
|
102 | 108 |
|
103 |
} |
|
104 |
}); |
|
105 |
} |
|
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 |
} |
|
106 | 125 |
} |
Also available in: Unified diff