This looks fine to me, and I am doing this type of
thing in other places without this ODD side-effect.
The only difference this time is the way I have
obtained the map, layer and feature references from searching the
projects:
private void searchProjects(String sMapPath, String sLayer,
String sPoint) {
URI
mapURI = URI.createFileURI(sMapPath);
List projects =
ProjectRegistryImpl.getProjectRegistry().getProjects();
Project project = null;
boolean bFound = false;
Resource resource = null;
List list = null;
int
countk = 0;
int
countj = projects.size();
for
(int j= 0; j<countj; j++) {
bFound = false;
project = (Project)projects.get(j);
//
SEE IF THIS PROJECT HAS A MAP WITH THE CORRECT NAME
//
IF IT HAS THE CORRECT LAYER, THEN FOUND + TRUE
try
{
resource =
project.eResource().getResourceSet().getResource(mapURI, true);
if
(resource != null && resource instanceof Map) {
if
(processMap((Map)resource, sLayer, sPoint)) {
bFound = true;
}
}
}
catch (Exception io){} // getResource can throw
FileNotFoundException
//
ELSE SEARCH ALL MAPS FOR THE CORRECT LAYER
if
(!bFound) {
ResourceSet resources =
project.eResource().getResourceSet();
List elements = resources.getResources();
countk=elements.size();
for
(int k=0;k <countk; k++) {
resource =(Resource)elements.get(k);
list = resource.getContents();
if
(list != null && list.size() > 0) {
System.out.println("mapResourceContents="+(resource.getContents().get(0)).getClass().getName());
Object obj = resource.getContents().get(0);
if
(obj instanceof Map) {
processMap((Map)obj, sLayer, sPoint);
}
}
}
}
}
}
private boolean processMap(Map map, String sLayer, String
sPoint) {
boolean bLayerFound = false;
Layer layer = findLayer(map, sLayer);
if
(layer != null) {
Feature feature =
findPoint(layer, sPoint);
bLayerFound = true;
}
return bLayerFound;
}
private Layer findLayer(Map map, String sLayer)
{
Layer layer = null;
if
(map != null ) {
List layers = map.getLayersInternal();
int count =
layers.size();
for (int j= 0; j <
count; j++) {
layer =
(Layer)layers.get(j);
System.out.println("checking layer="+layer.getID());
if
((layer.getID().toString()).equals(sLayer)) {
nMatchCount++;
vtMapMatches.insertElementAt(map,
nMatchCount);
vtLayerMatches.insertElementAt(layer, nMatchCount);
vtFeatureMatches.insertElementAt("None", nMatchCount);
break;
} else {
layer = null;
}
}
}
return layer;
}
private Feature findPoint(Layer layer, String sPoint) {
Feature feature =
null;
String
sFeatureID = "";
FeatureIterator
featurReader = null;
FeatureCollection results =
null;
FeatureSource resource =
null;
IProgressMonitor monitor =
new NullProgressMonitor();
try {
resource =
layer.getResource(FeatureSource.class, monitor);
if
(resource != null) {
results =
resource.getFeatures();
featurReader =
results.features();
while
(featurReader.hasNext())
{
feature=featurReader.next();
sFeatureID =
(String)feature.getAttribute(1);
if
(sFeatureID.equals(sPoint)) {
vtFeatureMatches.removeElementAt(nMatchCount);
vtFeatureMatches.insertElementAt(feature, nMatchCount);
break;
}
}
featurReader.close();
}
} catch (IOException
e) {}
monitor.done();
return feature;
}
Can anyone see why obtaining the map, layer and
feature references this way would mean that when I update the feature
the Project Explorer View lists the project again (shows it
twice)?
I'm curious why you have to
do all the stuff with getResource() and so on? When you have a
project you should be able to call getProjectElement( IMap.class
). Which should give you the list of all the maps in the
project. I wouldn't be surprised if you were causing the system to
think that it has another project.