|
Hi!
Jesse,
OK,
after much contorsion I have got something to work.
(I
need to release a Beta version today so just as well!!)
When
the user selects to open the download dialog, I check to see if they have any
open maps. If thye do I put up a message that these need to be closed if that
OK.
I then
close them.
If the
users selects any files to actually download I then store the URI's for the
projects and maps loaded (I needs them for searching for the downlaoded files
positions, and where to put them) and I unload the projects and maps as I
go.
I can
then download the maps and place them in the appropraite places, over-writting
existing files.
The
most complicated bit was working out how to fix the then broken Project Explorer
tree.
Eventually I figured out:
ProjectExplorer.getProjectExplorer().getViewer().refresh();
I have
a question. If the user downloads a map file for a map they do not have already.
I want to load it into the default project (placing the maop in the correct
folder etc).
I
eventually worked out a tortuous way of doing this. But there must be an easier
way:
URI projectURI =
fproject.eResource().getURI();
String sPath =
projectURI.toString();
int ind = sPath.lastIndexOf("\\"); String sBase = sPath.substring(0, ind); String sURIBase = sBase; if (sBase.startsWith("file://")) { sBase = sBase.substring(7); } else if (sBase.startsWith("file:/")) { sBase = sBase.substring(6); } String sFilePath = sBase+EcosensusPlugin.sFS+sDownloadFileName; try { if (fetchFile(oConnectionData, sFilePath, fsFileName, fsType, fsDirectory)) { // downloads the file to the default projects directory URI uri = URI.createURI(sURIBase+"\\"+fsFileNameClean); //
This loads it into a non-existant
project!!
Resource mapResource = ProjectRegistryImpl.getProjectRegistry().eResource() .getResourceSet().getResource(uri, true); if (mapResource.getContents().get(0) instanceof Map) { Map map = (Map) mapResource.getContents().get(0); map.setName(fsMapName); // not sure I need this but I got some odd behaviour once and it created a different umap file, so I paniced.
map.eResource().setURI(URI.createURI(sURIBase+"\\"+fsFileNameClean));
// Actually set the map into the default project where I want it, not the
non-existant one it has been put in.
map.setProjectInternal(fproject); Resource resource = fproject.eResource(); Resource mapResource2 = resource.getResourceSet().createResource(uri); mapResource2.getContents().add(0, map); mapResource.setTrackingModification(true); mapResource.setModified(true); ProjectRegistryImpl.getProjectRegistry().getProject(projectURI); } } } catch (IOException ioe) { ioe.printStackTrace(); } Bascially the above code works, but it feels like it is panic code, and
not correct code.
Can you simplyfy how you load a map from a mapfile reference into a
project.
Thanks
Michelle
|
_______________________________________________ User-friendly Desktop Internet GIS (uDig) http://udig.refractions.net http://lists.refractions.net/mailman/listinfo/udig-devel
