root / org.gvsig.legend.urbanhorizontalsignage / trunk / org.gvsig.legend.urbanhorizontalsignage / org.gvsig.legend.urbanhorizontalsignage.app / org.gvsig.legend.urbanhorizontalsignage.app.mainplugin / src / main / java / org / gvsig / legend / urbanhorizontalsignage / app / UrbanHorizontalSignageExtension.java @ 5139
History | View | Annotate | Download (5.08 KB)
1 |
package org.gvsig.legend.urbanhorizontalsignage.app; |
---|---|
2 |
|
3 |
import javax.swing.JOptionPane; |
4 |
import org.gvsig.andami.IconThemeHelper; |
5 |
import org.gvsig.andami.plugins.Extension; |
6 |
import org.gvsig.app.ApplicationLocator; |
7 |
import org.gvsig.app.ApplicationManager; |
8 |
import org.gvsig.app.project.documents.view.ViewDocument; |
9 |
import org.gvsig.app.project.documents.view.ViewManager; |
10 |
import org.gvsig.fmap.dal.DALLocator; |
11 |
import org.gvsig.fmap.dal.DataManager; |
12 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
13 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.mapcontext.MapContext; |
16 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
17 |
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLegend; |
18 |
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator; |
19 |
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageManager; |
20 |
import org.gvsig.tools.ToolsLocator; |
21 |
import org.gvsig.tools.dispose.DisposeUtils; |
22 |
import org.gvsig.tools.i18n.I18nManager; |
23 |
import org.slf4j.Logger; |
24 |
import org.slf4j.LoggerFactory; |
25 |
|
26 |
public class UrbanHorizontalSignageExtension extends Extension { |
27 |
|
28 |
private static final Logger LOGGER = LoggerFactory.getLogger(UrbanHorizontalSignageExtension.class); |
29 |
|
30 |
@Override
|
31 |
public void initialize() { |
32 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-urbanhorizontalsignage", this); |
33 |
IconThemeHelper.registerIcon("action", "layer-modify-clipboard-copy-as-polygons", this); |
34 |
|
35 |
} |
36 |
|
37 |
@Override
|
38 |
public void execute(String actionCommand) { |
39 |
|
40 |
if (actionCommand.compareToIgnoreCase("layer-modify-clipboard-copy-as-polygons") != 0) { |
41 |
return;
|
42 |
} |
43 |
DataManager dataManager = DALLocator.getDataManager(); |
44 |
|
45 |
ApplicationManager application = ApplicationLocator.getManager(); |
46 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
47 |
if (viewdoc == null) { |
48 |
return;
|
49 |
} |
50 |
MapContext mapContext = viewdoc.getMapContext(); |
51 |
FLyrVect layer = mapContext.getLayers().getFirstActiveVectorLayer(); |
52 |
if (layer == null) { |
53 |
return;
|
54 |
} |
55 |
FeatureStore targetStore = null;
|
56 |
FeatureSet featureSet = null;
|
57 |
try {
|
58 |
UrbanHorizontalSignageManager uhsManager = UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager(); |
59 |
//TODO: Presentar formulario para pedir el targetLenghtFieldName
|
60 |
|
61 |
UrbanHorizontalSignageLegend legend = (UrbanHorizontalSignageLegend) layer.getLegend(); |
62 |
FeatureSelection selection = layer.getFeatureStore().getFeatureSelection(); |
63 |
targetStore = uhsManager.convertLinesToPolygons(selection, legend.getConfig(), null);
|
64 |
|
65 |
featureSet = targetStore.getFeatureSet(); |
66 |
|
67 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
68 |
int n = application.confirmDialog(
|
69 |
"_Number_of_geometries_to_be_copied_to_the_clipboard" + " " + featureSet.getSize() + "\n" + "_Do_you_want_to_continue", |
70 |
i18n.getTranslation("_Copy_selected_features_as_polygons_to_clipboard"),
|
71 |
JOptionPane.YES_NO_OPTION,
|
72 |
JOptionPane.QUESTION_MESSAGE);
|
73 |
if (n == JOptionPane.YES_OPTION) { |
74 |
dataManager.putFeaturesInClipboard(featureSet); |
75 |
} |
76 |
|
77 |
} catch (Exception e) { |
78 |
LOGGER.warn("Can't get the selection as JSON.", e);
|
79 |
} finally {
|
80 |
DisposeUtils.disposeQuietly(targetStore); |
81 |
DisposeUtils.disposeQuietly(featureSet); |
82 |
} |
83 |
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
public boolean isEnabled() { |
88 |
// it's enabled if there is exactly one vector layer in the active view
|
89 |
// and it has a selection
|
90 |
|
91 |
ApplicationManager application = ApplicationLocator.getManager(); |
92 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
93 |
if (viewdoc == null) { |
94 |
return false; |
95 |
} |
96 |
MapContext mapContext = viewdoc.getMapContext(); |
97 |
FLyrVect layer = mapContext.getLayers().getFirstActiveVectorLayer(); |
98 |
if (layer == null) { |
99 |
return false; |
100 |
} |
101 |
if (!layer.isAvailable()) {
|
102 |
// This can happen when opening a persisted project
|
103 |
// and there is a "slow" layer (GeoDB)
|
104 |
return false; |
105 |
} |
106 |
try {
|
107 |
FeatureStore store = layer.getFeatureStore(); |
108 |
FeatureSelection selection = store.getFeatureSelection(); |
109 |
if (selection.isEmpty()) {
|
110 |
return false; |
111 |
} |
112 |
return (layer.getLegend() instanceof UrbanHorizontalSignageLegend); |
113 |
// return !selection.isEmpty();
|
114 |
} catch (Exception ex) { |
115 |
LOGGER.warn("Can't get selection from layer '" + layer.getName() + "'.", ex); |
116 |
return false; |
117 |
} |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public boolean isVisible() { |
122 |
ApplicationManager application = ApplicationLocator.getManager(); |
123 |
return application.getActiveDocument(ViewManager.TYPENAME) != null; |
124 |
} |
125 |
|
126 |
} |