Revision 43610 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.timesupport.app/org.gvsig.timesupport.app.viewfilter/src/main/java/org/gvsig/timesupport/app/extension/TimeSupportExtension.java
TimeSupportExtension.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.timesupport.app.extension; |
23 | 23 |
|
24 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
|
24 |
import java.util.Collection; |
|
25 |
import java.util.Date; |
|
26 |
import java.util.Iterator; |
|
25 | 27 |
import org.gvsig.andami.plugins.Extension; |
26 | 28 |
import org.gvsig.app.ApplicationLocator; |
27 | 29 |
import org.gvsig.app.ApplicationManager; |
28 | 30 |
import org.gvsig.app.project.documents.view.ViewDocument; |
29 | 31 |
import org.gvsig.app.project.documents.view.ViewManager; |
30 | 32 |
import org.gvsig.fmap.dal.DataStore; |
33 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStoreTimeSupport; |
|
31 | 36 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
38 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
32 | 39 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
33 | 40 |
import org.gvsig.timesupport.AbsoluteIntervalTypeNotRegisteredException; |
41 |
import org.gvsig.timesupport.Interval; |
|
34 | 42 |
import org.gvsig.timesupport.swing.api.TimeSupportSwingException; |
35 | 43 |
import org.gvsig.timesupport.swing.api.TimeSupportSwingLocator; |
36 | 44 |
import org.gvsig.timesupport.swing.api.TimeSupportSwingManager; |
37 | 45 |
import org.gvsig.timesupport.swing.api.panel.TimeSelectorPanel; |
38 |
import org.gvsig.tools.exception.BaseException; |
|
39 | 46 |
import org.gvsig.tools.locator.LocatorException; |
40 | 47 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
41 | 48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
42 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
43 |
import org.gvsig.tools.visitor.Visitor; |
|
44 |
import org.slf4j.Logger; |
|
45 |
import org.slf4j.LoggerFactory; |
|
46 | 49 |
|
47 | 50 |
/** |
48 | 51 |
* Andami extension to show TimeSupport in the application. |
... | ... | |
51 | 54 |
* @version $Id$ |
52 | 55 |
*/ |
53 | 56 |
public class TimeSupportExtension extends Extension { |
54 |
|
|
55 |
private static final Logger logger = LoggerFactory.getLogger(TimeSupportExtension.class); |
|
56 |
|
|
57 |
|
|
58 |
@Override |
|
57 | 59 |
public void initialize() { |
58 | 60 |
// Do nothing |
59 | 61 |
} |
... | ... | |
63 | 65 |
super.postInitialize(); |
64 | 66 |
} |
65 | 67 |
|
68 |
@Override |
|
66 | 69 |
public void execute(String actionCommand) { |
67 | 70 |
try { |
68 | 71 |
showTimeSupport(); |
... | ... | |
72 | 75 |
} |
73 | 76 |
|
74 | 77 |
public void showTimeSupport() throws CloneNotSupportedException, LocatorException, TimeSupportSwingException, AbsoluteIntervalTypeNotRegisteredException { |
75 |
|
|
76 | 78 |
ApplicationManager application = ApplicationLocator.getManager(); |
77 | 79 |
ViewDocument viewDocument = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
78 | 80 |
if( viewDocument == null ) { |
79 | 81 |
return; |
80 |
} |
|
81 |
|
|
82 |
} |
|
82 | 83 |
TimeSupportSwingManager swingManager = TimeSupportSwingLocator.getSwingManager(); |
83 | 84 |
|
84 | 85 |
MapContext mapContext = viewDocument.getMapContext(); |
... | ... | |
94 | 95 |
windowManager.showWindow(timeSelectorPanel, viewDocument.getName(), WindowManager.MODE.TOOL); |
95 | 96 |
} |
96 | 97 |
|
97 |
public boolean isEnabled() {
|
|
98 |
|
|
98 |
@Override
|
|
99 |
public boolean isEnabled() { |
|
99 | 100 |
ApplicationManager application = ApplicationLocator.getManager(); |
100 | 101 |
ViewDocument viewDocument = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
101 | 102 |
if( viewDocument == null ) { |
102 | 103 |
return false; |
103 | 104 |
} |
104 |
final MutableBoolean enabled = new MutableBoolean(false); |
|
105 |
|
|
106 |
MapContext mapContext = viewDocument.getMapContext(); |
|
107 |
try { |
|
108 |
mapContext.getLayers().accept(new Visitor() { |
|
109 |
public void visit(Object layer) throws VisitCanceledException, BaseException { |
|
110 |
if (layer instanceof SingleLayer){ |
|
111 |
DataStore dataStore = ((SingleLayer)layer).getDataStore(); |
|
112 |
if (dataStore.getInterval() != null){ |
|
113 |
enabled.setValue(true); |
|
114 |
throw new VisitCanceledException(); |
|
115 |
} |
|
116 |
} |
|
105 |
FLayers layers = viewDocument.getMapContext().getLayers(); |
|
106 |
for( Iterator<FLayer> iterator = layers.deepiterator(); iterator.hasNext(); ) { |
|
107 |
FLayer layer = iterator.next(); |
|
108 |
if (layer instanceof SingleLayer){ |
|
109 |
DataStore dataStore = ((SingleLayer)layer).getDataStore(); |
|
110 |
if (dataStore.getInterval() != null){ |
|
111 |
return true; |
|
117 | 112 |
} |
118 |
}); |
|
119 |
} catch (Exception ex) { |
|
120 |
logger.warn("Unable to determine if there are layers with temporal information.",ex); |
|
113 |
} |
|
121 | 114 |
} |
122 |
|
|
123 |
return enabled.getValue(); |
|
115 |
return false; |
|
124 | 116 |
} |
125 | 117 |
|
118 |
@Override |
|
126 | 119 |
public boolean isVisible() { |
127 | 120 |
return true; |
128 | 121 |
} |
129 |
|
|
122 |
|
|
130 | 123 |
} |
Also available in: Unified diff