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.
// 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
So this is a little tricky. What you need to do is call:
project.eResource().unload();
What this does is walk through all the children of project( and
project) and turns them all into proxies so that when they are accessed
again they are reloaded. The problem is that the reloaded objects
are new objects so if any objects retain references to the old projects,
maps, layers, etc... they will be referencing the wrong objects.
What I suggest is that you close all editors to maps within that project
before unloading the project, then unload the project... I suppose
there could be a problem though since the maps try to save the project
when being closed, seems like that would overwrite the
changes.
Thinking....
The easy way for me is for you to change you program so that you have
a central repository and get copies from the repository and run uDig on
those copies instead of directly against the repository projects.
Especially since you are bound to have read/write conflicts if you are
directly hacking the repository. Might be a good plan for you
anyhow. So how it might work is you can close your maps, unload the
project, get a new copy and then re-open you maps and project.
Otherwise I think I would have to put in make a change so that you
can turn off autosaving is a preference that can be turned off. But
if I do that then when would things be saved? I guess you would have
to implement that yourself and manage all the read/write transactions to
the repository anyhow. So maybe the suggestion is the least amount
of work for both of us...
I'm open to suggestions.
Jesse
On 11-May-06, at 6:16 AM, M.S.Bachler wrote:
Hi!
As part of my use of uDig, people are sharing .umap
files (now I have uniquely named them).
If a user downloads a .umap file it overwrite the
local file fine.
Q 1) But how to I get uDig to reload the .umap file
it is using in its project (eObject - structure etc), and redraw the map
/ Project View / Layer View etc to reflect any changes in the newly
downloaded file?
Any pointers for this would be great as I have a
feeling it will not be straight forward.
If the downloaded file does not exist, I want to
import it into the current project.
Q 2) How
would I do that?
Thanks
Michelle
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
_______________________________________________
User-friendly Desktop Internet GIS (uDig)