Issue #2033 fix plots working with multiple plotModels dirs contributed

by different plugins

Change-Id: I2d1ff75c62395ead5154398002610401faa4388d

Former-commit-id: 0ed68f5ec6b2b2f3413f7de5f9c7b15291afb85c
This commit is contained in:
Nate Jensen 2013-11-20 17:33:53 -06:00
parent 0bdb25bf43
commit 2b6799712d

View file

@ -29,7 +29,6 @@ import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Formatter;
import java.util.HashMap;
@ -58,7 +57,6 @@ import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
@ -90,6 +88,7 @@ import com.raytheon.viz.pointdata.rsc.PlotResourceData;
* Aug 09, 2012 1085 jkorman Corrected data construction.
* Sep 05, 2013 2316 bsteffen Unify pirep and ncpirep.
* Sep 05, 2013 2307 dgilling Use better PythonScript constructor.
* Nov 20, 2013 2033 njensen Fix detecting plotModels dirs from multiple plugins
*
* </pre>
*
@ -100,7 +99,7 @@ public class PlotModelFactory2 {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PlotModelFactory2.class);
private static final String plotmodelDir = "plotModels";
private static final String PLOT_MODEL_DIR = "plotModels";
private static final String DM_ATTRIBUTE = "plotMode";
@ -122,6 +121,8 @@ public class PlotModelFactory2 {
private static final String REQUIRED = "required";
private static String cachedIncludePath;
private final SimpleDateFormat SAMPLE_DATE = new SimpleDateFormat("HHmm");
// Need to include attribute and code to allow for String2String lookups and
@ -1305,35 +1306,39 @@ public class PlotModelFactory2 {
}
private PlotPythonScript createScript() throws JepException {
PlotPythonScript script;
Map<LocalizationLevel, LocalizationFile> map = PathManagerFactory
.getPathManager().getTieredLocalizationFile(
LocalizationType.CAVE_STATIC, plotmodelDir);
ArrayList<LocalizationLevel> keys = new ArrayList<LocalizationLevel>(
map.keySet());
Collections.sort(keys);
Collections.reverse(keys);
StringBuilder includePath = new StringBuilder();
for (LocalizationLevel ll : keys) {
LocalizationFile lf = map.get(ll);
if (includePath.length() > 0) {
includePath.append(File.pathSeparator);
synchronized (PlotModelFactory2.class) {
if (cachedIncludePath == null) {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationFile[] files = pm
.listFiles(
pm.getLocalSearchHierarchy(LocalizationType.CAVE_STATIC),
PLOT_MODEL_DIR, null, false, false);
StringBuilder includePath = new StringBuilder();
for (LocalizationFile lf : files) {
if (lf.exists() && lf.isDirectory()) {
if (includePath.length() > 0) {
includePath.append(File.pathSeparator);
}
includePath.append(lf.getFile().getAbsolutePath());
}
}
cachedIncludePath = includePath.toString();
}
includePath.append(lf.getFile().getAbsolutePath());
}
File baseFile = PathManagerFactory.getPathManager().getStaticFile(
plotmodelDir + IPathManager.SEPARATOR
PLOT_MODEL_DIR + IPathManager.SEPARATOR
+ "PlotModelInterface.py");
script = new PlotPythonScript(baseFile.getAbsolutePath(),
includePath.toString(), plotDelegateName);
PlotPythonScript localScript = new PlotPythonScript(
baseFile.getAbsolutePath(), cachedIncludePath,
plotDelegateName);
if (scriptText != null) {
script.evaluate(scriptText);
localScript.evaluate(scriptText);
}
script.executePlotDelegateMethod("init", "plotModelFactory",
localScript.executePlotDelegateMethod("init", "plotModelFactory",
PlotModelFactory2.this);
return script;
return localScript;
}
}
@ -1375,7 +1380,7 @@ public class PlotModelFactory2 {
private File getTableFile(String fileName) {
File rval = PathManagerFactory.getPathManager().getStaticFile(
plotmodelDir + IPathManager.SEPARATOR + fileName);
PLOT_MODEL_DIR + IPathManager.SEPARATOR + fileName);
return rval;
}