[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [udig-devel] PlatformGIS functions do not work
|
I am extremely confused as to why that snippet doesn't work because I
have used it a number of times and I know that it works...
I have just used this code try it and see if it works. If not then
there is something wrong with your environment... :(
try{
//For some reason, getting the active workbench doesn't seem
to work??!! So looping
// through all the workbenches and all their pages was the
slow way to go...
//IEditorReference[] editors =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
IWorkbenchWindow[] wWindows =
PlatformUI.getWorkbench().getWorkbenchWindows();
List<IMap> maps = new ArrayList<IMap>();
for ( IWorkbenchWindow wWindow : wWindows ) {
IWorkbenchPage[] wPages = wWindow.getPages();
for ( IWorkbenchPage wPage : wPages ) {
IEditorReference[] editors =
wPage.getEditorReferences();
for ( IEditorReference editor : editors ) {
IEditorPart editor2 = editor.getEditor(false);
if( editor2 instanceof MapEditor ){
maps.add(((MapEditor)editor2).getMap());
}
}
}
}
if (maps.size() == 0)
return null;
return maps;
}catch(NullPointerException e){
return null;
}
Jesse
Bas Retsios wrote:
Hello,
Thank you for your response. However, it did not solve my problem.
In the code snippet below, the condition "editor instanceof MapEditor"
is always false, regardless of the value of variable "editor" (thus
also when in the debugger I clearly see that variable "editor" is a
MapEditor). How is this possible?
Up to now I was suspecting a classloader problem (whereby two versions
of the MapEditor class appear). After struggling several days trying
to get a unique set of .jar files (see "things I already tried"), I
realised I wouldn't be able to solve this problem by myself.
Any other ideas?
Bas.
Jesse Eichar wrote:
OK Here's a code snippet that will get you all the open maps. Its
not pretty but it is what PlatformGIS.getMaps() is supposed to do.
IEditorReference[] refs =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
ArrayList<IMap> maps=new ArrayList<IMap>();
for( IEditorReference reference : refs ) {
IEditorPart editor = reference.getEditor(false);
if( editor instanceof MapEditor )
maps.add(((MapEditor)editor).getMap());
}
maps will have all the open maps.
I'm sorry that PlatformGIS is buggy. I'll fix it.
Jesse
Bas Retsios wrote:
Hello,
I am developing a plug-in for uDig (class MyView extends ViewPart).
In one of the functions of this plug-in I am trying to reach the
IMap items that correspond to opened maps in uDig.
Using uDig version 1.0.5 (SDK version) I figured (guessed) two ways
to do it:
1.
List <IMap> maps = PlatformGIS.getMaps();
2.
IProject prj = PlatformGIS.getActiveProject();
List<IMap> maps = prj.getElements(IMap.class);
Both methods do not work, and I can not find why.
In the first case, getMaps() always returns null (regardless of the
project / maps loaded). By tracing the getMaps() code, I found that
the following expression always returns false:
if( editor.getEditor(false) instanceof MapEditor )
which results in no maps being returned by getMaps().
In the second case, getActiveProject() gives a NullPointerException
Things I already tried:
- (re-)install Eclipse 3.1.0 and 3.1.2
- (re-)install uDig 1.0.5 (SDK) and uDig 1.0.6 (latest stable release)
- turn on/off plugins in Eclipse->Window->Preferences->Plug-in
development->Target Platform
- add all possible .jar files (net.refractions.*, org.eclipse.*) to
the Java Build Path->Libraries of my eclipse project
Thanks in advance,
Bas.
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel