net.refractions.udig.project.ui
Class ApplicationGIS

java.lang.Object
  extended by net.refractions.udig.project.ui.ApplicationGIS

public class ApplicationGIS
extends java.lang.Object

A facade into udig to simplify operations such as getting the active map and openning a map editor.

Since:
0.9.0
Author:
jeichar

Nested Class Summary
static class ApplicationGIS.DrawMapParameter
          Parameter class for drawMap(net.refractions.udig.project.ui.ApplicationGIS.DrawMapParameter)
 
Field Summary
static Map NO_MAP
           
 
Constructor Summary
ApplicationGIS()
           
 
Method Summary
static java.util.List<? extends ILayer> addLayersToMap(IMap map, java.util.List<IGeoResource> resourceList, int startPosition)
          Make layers from the resourceList and adds the layers to the map.
static java.util.List<? extends ILayer> addLayersToMap(IMap map2, java.util.List<IGeoResource> resourceList, int startPosition2, IProject project2, boolean wait)
          Make layers from the resourceList and adds the layers to the map.
static java.util.List<? extends ILayer> addLayersToMap(IMap map, java.util.List<IGeoResource> resourceList, int startPosition, Project project)
          Deprecated.  
static java.util.List<? extends ILayer> addLayersToMap(IProject project, java.util.List<IGeoResource> resourceList)
          Make layers from the resourceList, creates a new map, adds layers to map and adds map to the project.
static RenderContext configureMapForRendering(Map map, java.awt.Dimension destinationSize, int dpi, BoundsStrategy boundsStrategy, ReferencedEnvelope baseMapBounds)
          Creates a ViewportModel and RenderManager; configures them correctly and sets them on the RenderContext.
static IMap copyMap(IMap mapToCopy)
          Performs a deep copy of a map.
static void createAndOpenMap(java.util.List<IGeoResource> resources)
          creates a map and opens an editor for the map.
static void createAndOpenMap(java.util.List<IGeoResource> resources, IProject owner)
          creates a map and opens an editor for the map.
static void createAndOpenMap(java.util.List<IGeoResource> resources, IProject owner, boolean wait)
          creates a map and opens an editor for the map.
static IToolContext createContext(IMap map)
          Creates a Tools Context out of Map.
static ProjectElementAdapter createGeneralProjectElement(IProject project, java.lang.Class<? extends IGenericProjectElement> typeToCreate, java.lang.String extensionId)
          Creates an instance of the typeToCreate and wraps it with the ProjectElementAdapter.
static ProjectElementAdapter createGeneralProjectElement(IProject project, java.lang.String elementName, java.lang.Class<? extends IGenericProjectElement> typeToCreate, java.lang.String extensionId)
          Creates an instance of the typeToCreate and wraps it with the ProjectElementAdapter.
static IMap drawMap(ApplicationGIS.DrawMapParameter drawMapParams)
          Renders the provided map on to the provided graphics2D object.
static IMap getActiveMap()
          Returns the active map.
static IProject getActiveProject()
          Obtains the current project.
static java.util.List<UDIGEditorInputDescriptor> getEditorInputs(IProjectElement projectElement)
          Returns an editor input for the type passed in.
static UDIGEditorInput getInput(IProjectElement element)
          Returns the IEditorInput instance that wraps the element argument.
static java.util.Collection<? extends IMap> getOpenMaps()
          Returns all open maps.
static java.util.List<? extends IProject> getProjects()
          Return all Projects.
static IToolManager getToolManager()
          Returns the ToolManager singleton.
static IViewPart getView(boolean show, java.lang.String id)
          Gets a reference to a view.
static java.util.Collection<? extends IMap> getVisibleMaps()
          Returns all visible maps.
static IProjectElement loadProjectElement(java.net.URL url, IProject project)
          Loads the project element indicated by the url and adds the map to the provided project.
static void openMap(IMap map)
          Opens a Map editor for the provided map, This is a non-blocking call.
static void openMap(IMap map, boolean wait)
          Opens a Map editor for the provided map.
static void openProjectElement(IProjectElement obj, boolean wait)
          Opens a IProjectElement for editing/viewing.
static void run(ISafeRunnable request)
          Runs the given runnable in a protected mode.
static void setActiveMapTracker(ActiveMapTracker activeMapTrackerToSet)
          This method should only be called by uDig.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MAP

public static final Map NO_MAP
Constructor Detail

ApplicationGIS

public ApplicationGIS()
Method Detail

getActiveProject

public static IProject getActiveProject()
Obtains the current project.

Returns:
The current active project

getProjects

public static java.util.List<? extends IProject> getProjects()
Return all Projects. The list is unmodifiable.

Returns:
all Projects.

getActiveMap

public static IMap getActiveMap()
Returns the active map. Returns NO_MAP if there is no open map.

Returns:
the map contained by the current MapEditor or null if the active editor is not a map editor.

getOpenMaps

public static java.util.Collection<? extends IMap> getOpenMaps()
Returns all open maps.

Returns:
a Collection of maps contained.

getVisibleMaps

public static java.util.Collection<? extends IMap> getVisibleMaps()
Returns all visible maps.

Returns:
a Collection of maps contained.

openMap

public static void openMap(IMap map)
Opens a Map editor for the provided map, This is a non-blocking call. Equivalent to openMap(map, false);

Parameters:
map - the map to open. Must be an instance of Map.

openMap

public static void openMap(IMap map,
                           boolean wait)
Opens a Map editor for the provided map.

Parameters:
map - the map to open. Must be an instance of Map.
wait - indicates whether to wait for the map to open before returning.

createAndOpenMap

public static void createAndOpenMap(java.util.List<IGeoResource> resources)
creates a map and opens an editor for the map.

Parameters:
a - list of IGeoResources. Each resource will be a layer in the created map.

createAndOpenMap

public static void createAndOpenMap(java.util.List<IGeoResource> resources,
                                    IProject owner)
creates a map and opens an editor for the map.

Parameters:
a - list of IGeoResources. Each resource will be a layer in the created map.
owner - the project that will contain the map. owner must be an instance of Project. If it is obtained using the framework then this will always be the case.

createAndOpenMap

public static void createAndOpenMap(java.util.List<IGeoResource> resources,
                                    IProject owner,
                                    boolean wait)
creates a map and opens an editor for the map.

Parameters:
a - list of IGeoResources. Each resource will be a layer in the created map.
owner - the project that will contain the map. owner must be an instance of Project. If it is obtained using the framework then this will always be the case.
wait - indicates whether to wait for the map to open before returning.

getView

public static IViewPart getView(boolean show,
                                java.lang.String id)
Gets a reference to a view. If the view has not been opened previously then the view will be opened.

Parameters:
show - whether to show the view or not.
id - the id of the view to show.
Returns:
returns the view or null if the view does not exist

run

public static void run(ISafeRunnable request)
Runs the given runnable in a protected mode. Exceptions thrown in the runnable are logged and passed to the runnable's exception handler. Such exceptions are not rethrown by this method.


getEditorInputs

public static java.util.List<UDIGEditorInputDescriptor> getEditorInputs(IProjectElement projectElement)
Returns an editor input for the type passed in. Processes the editorInputs extension point.

Parameters:
type -
Returns:
an editor input for the type passed in.

getToolManager

public static IToolManager getToolManager()
Returns the ToolManager singleton.

Returns:
the ToolManager singleton.

getInput

public static UDIGEditorInput getInput(IProjectElement element)
Returns the IEditorInput instance that wraps the element argument.

Returns:
the IEditorInput instance that wraps the element argument.

createContext

public static IToolContext createContext(IMap map)
Creates a Tools Context out of Map.

Parameters:
map - that the context interacts with
Returns:
a ToolContext
See Also:
ToolContext

addLayersToMap

public static java.util.List<? extends ILayer> addLayersToMap(IMap map,
                                                              java.util.List<IGeoResource> resourceList,
                                                              int startPosition)
Make layers from the resourceList and adds the layers to the map.

NOTE map may be null. If it is then the current open map will be used (see getActiveMap() or a new map will be created if that is null.

Parameters:
map - the map to add the layers to. If null the current active map will be used or a new one will be created
resourceList - Resources to add to the map.
startPosition - z-position of the layers to add. if -1 it will be added to the top of the map (0 is the bottom of the map and map.getMapLayer.size() is the top of the map).
Returns:
layers that were added.

addLayersToMap

public static java.util.List<? extends ILayer> addLayersToMap(IProject project,
                                                              java.util.List<IGeoResource> resourceList)
Make layers from the resourceList, creates a new map, adds layers to map and adds map to the project.

Parameters:
project - project that new map should be added to
resourceList - Resources to add to the map.
startPosition - z-position of the layers to add. if -1 it will be added to the top of the map (0 is the bottom of the map and map.getMapLayer.size() is the top of the map).
Returns:
layers that were added.

addLayersToMap

public static java.util.List<? extends ILayer> addLayersToMap(IMap map,
                                                              java.util.List<IGeoResource> resourceList,
                                                              int startPosition,
                                                              Project project)
Deprecated. 

Make layers from the resourceList and adds the layers to the map.

NOTE map may be null. If it is then the current open map will be used (see getActiveMap() or a new map will be created if that is null.

Parameters:
map - the map to add the layers to. If null the current active map will be used or a new one will be created
resourceList - Resources to add to the map.
startPosition - z-position of the layers to add. if -1 it will be added to the top of the map (0 is the bottom of the map and map.getMapLayer.size() is the top of the map).
project - project that map should be added to... Only used if there is no current map. If project is then the default project is used.
Returns:
layers that were added.

addLayersToMap

public static java.util.List<? extends ILayer> addLayersToMap(IMap map2,
                                                              java.util.List<IGeoResource> resourceList,
                                                              int startPosition2,
                                                              IProject project2,
                                                              boolean wait)
Make layers from the resourceList and adds the layers to the map.

NOTE map may be null. If it is then the current open map will be used (see getActiveMap() or a new map will be created if that is null.

Parameters:
map - the map to add the layers to. If null the current active map will be used or a new one will be created
resourceList - Resources to add to the map.
startPosition - z-position of the layers to add. if -1 it will be added to the top of the map (0 is the bottom of the map and map.getMapLayer.size() is the top of the map).
project - project that map should be added to... Only used if there is no current map. If project is then the default project is used.
wait - if true then method will block until map has been opened otherwise will return without blocking.

loadProjectElement

public static IProjectElement loadProjectElement(java.net.URL url,
                                                 IProject project)
                                          throws java.io.IOException,
                                                 java.lang.IllegalArgumentException
Loads the project element indicated by the url and adds the map to the provided project.

Parameters:
url - the project element to load
project - the project to add the project element to.
Returns:
returns the loaded project element.
Throws:
java.io.IOException - thrown if there is a problem reading the project element file
java.lang.IllegalArgumentException - thrown if the file indicated by the URL is not a project element file.

openProjectElement

public static void openProjectElement(IProjectElement obj,
                                      boolean wait)
Opens a IProjectElement for editing/viewing.

Parameters:
obj - object to open
wait - whether or not to perform the action asynchronously

drawMap

public static IMap drawMap(ApplicationGIS.DrawMapParameter drawMapParams)
                    throws RenderException
Renders the provided map on to the provided graphics2D object.

Parameters:
params - parameters that describe how and where to draw the map
Returns:
the map that was rendered. It will not be saved or and is not part of any project.
Throws:
RenderException - Thrown if an error occurs such as a unreachable server.

configureMapForRendering

public static RenderContext configureMapForRendering(Map map,
                                                     java.awt.Dimension destinationSize,
                                                     int dpi,
                                                     BoundsStrategy boundsStrategy,
                                                     ReferencedEnvelope baseMapBounds)
Creates a ViewportModel and RenderManager; configures them correctly and sets them on the RenderContext. The layer and the georesource still must be set on the context. Returns the Context.

Parameters:
map - the map
destinationSize - the size of the destination area
dpi - the dpi of the destination
boundsStrategy - the strategy to use for setting the bounds on the viewport model
baseMapBounds - the bounds of the reference map, depending on the boundsStrategy it may be null.
Returns:
a render context

setActiveMapTracker

public static void setActiveMapTracker(ActiveMapTracker activeMapTrackerToSet)
This method should only be called by uDig. If it is called by any one else an exception will be thrown.

Parameters:
activeMapTracker - the tracker that managers

copyMap

public static IMap copyMap(IMap mapToCopy)
Performs a deep copy of a map.

Parameters:
mapToCopy -
Returns:
a new instance of the map.

createGeneralProjectElement

public static ProjectElementAdapter createGeneralProjectElement(IProject project,
                                                                java.lang.Class<? extends IGenericProjectElement> typeToCreate,
                                                                java.lang.String extensionId)
                                                         throws java.lang.IllegalArgumentException
Creates an instance of the typeToCreate and wraps it with the ProjectElementAdapter. This is part of the mechanism for adding custom items to a Project without needing to learn the EMF framework. See the net.refractions.udig.project.element Extension Point. If the typeToCreate is NOT the same or a superclass of the object created or if an object cannot be created a IllegalArgumentException will be thrown

Parameters:
project -
typeToCreate - The type of object that is expected to be created. This is provided as a check to ensure that the correct type is returned.
extensionId - the extension to use to create a new instance.
Returns:
A ProjectElementAdapter that wraps/adapts the object created using the extension
Throws:
java.lang.IllegalArgumentException

createGeneralProjectElement

public static ProjectElementAdapter createGeneralProjectElement(IProject project,
                                                                java.lang.String elementName,
                                                                java.lang.Class<? extends IGenericProjectElement> typeToCreate,
                                                                java.lang.String extensionId)
                                                         throws java.lang.IllegalArgumentException
Creates an instance of the typeToCreate and wraps it with the ProjectElementAdapter. This is part of the mechanism for adding custom items to a Project without needing to learn the EMF framework. See the net.refractions.udig.project.element Extension Point. If the typeToCreate is NOT the same or a superclass of the object created or if an object cannot be created a IllegalArgumentException will be thrown

Parameters:
project - the project to add the newly created adapter to
elementName - the name of the project to create
typeToCreate - The type of object that is expected to be created. This is provided as a check to ensure that the correct type is returned.
extensionId - the extension to use to create a new instance.
Returns:
A ProjectElementAdapter that wraps/adapts the object created using the extension
Throws:
java.lang.IllegalArgumentException