Title: Message
OK,
 
After some trial and error I figured it out.
 
Thank you so much for this extension point.
It is really going to help with our group file sharing.
 
Thanks
 
Michelle
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of M.S.Bachler
Sent: 09 May 2006 12:19
To: User-friendly Desktop Internet GIS
Subject: RE: [udig-devel] ODD side-effect. Feature updatecreatingduplicateProject

Hi!
 
Ok I have downloaded the latest nightly build and found the extension point for
    net.refractions.udig.project.mapInterceptor
 
I have started to write my class.
The problem is the run method passes in the Map object, but then I am not really sure how to go about naming the umap file.
 
Is it not already created at this point?
Where  / how would I name it with my unique file name?
 
Thanks
 
Michelle
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jesse Eichar
Sent: 05 May 2006 17:14
To: User-friendly Desktop Internet GIS
Subject: Re: [udig-devel] ODD side-effect. Feature update creatingduplicateProject


On 5-May-06, at 1:29 AM, M.S.Bachler wrote:

Hi!
 
"I wouldn't be surprised if you were causing the system to think that it has another project.  "
 
Yes, that's what I suspected, but I was not sure how.
I have not really used these classes before, and was not really sure how to access them.
 
"getProjectElement( IMap.class )"
Ah, I will try that as a way of getting all maps, and see if it helps.
 
uDig is being passed, from my Compendium app, project/map/layer/feature identifiers and if the project or map are not found, it searches all projects and maps to find if the layer is used somewhere and then updates the point feature from there. Hence I do all the searching.
 
It is all part of my problem of not haveing unique map ids in uDig.
You mentioned adding an extension point to allow me to rename the umap files.
Is this still on the cards?
I've actually added that now.  It is the net.refractions.udig.project.mapInterceptor extension point.

Jesse
 
Thanks
 
Michelle
 
 
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Jesse Eichar
Sent: 04 May 2006 17:23
To: User-friendly Desktop Internet GIS
Subject: Re: [udig-devel] ODD side-effect. Feature update creating duplicateProject


On 4-May-06, at 8:30 AM, M.S.Bachler wrote:

Hi!

Somehow I have got my code into a strange position where when I update a point feature's data, it actually creates a duplicate project (+map/layer) listing in the Project Explorer View.

The update code is:

EditManager manager = (EditManager)map.getEditManager();
manager.setEditFeature(feature, layer);
String sData = (String)feature.getAttribute(7);

// code to process sData and create the sFinalData
 
feature.setAttribute(7, sFinalData);
manager.commitTransaction();


This snippet won't actually update the datastore.  The feature.setAttribute() will only affect the in-memory copy of the feature.  You have to use the FeatureStore API to modify the actual data.  The SetAttributeCommand encapsulates that functionality.  But

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.  

Jesse

_______________________________________________
User-friendly Desktop Internet GIS (uDig)

_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to