[udig-devel] Storing/Showing other project elements
Jesse Eichar
jeichar.w at gmail.com
Fri May 16 11:52:09 PDT 2008
Its been a while since we've done this. Basically you need to define
a EMF type that extends ProjectElement I believe. Here is a very
quick and incomplete example but hopefully enough to get you going. I
will try to turn it into a tutorial. Or maybe you can help get a
simple example going so you understand the principals and donate it
for the tutorials directory :).
Any how start with an interface that is the core of your model:
For example Element:
/**
* @model
*/
public interface Element extends ProjectElement{
/**
* @model
*/
Point getLocation();
/**
* @model
*/
Dimension getSize();
void execute.
}
The important part to note is:
1. It extends ProjectElement
2. The interface has @model
3. Each property also has @model
4. Non-property methods don't need @model
Next you have to EMF Model Wizard from the New... Other menu item.
Name is unimportant. Choose Annotated Java. More or less follow the
instructions. It will create a .ecore and a .genmodel file
(hopefully). Open the .genmodel and the from the Generate menu run
Generate All. It will create an basic implementation of the
interface(s) and a plugin with the UI code. Basically the UI code are
classes that extend classes implement ILabelProvider and
IContentProvider. You can modify then to provide a custom look in the
project view.
That "should" be it. All the generate methods will have a @generated
tag in the javadocs. If you modify the method and leave the
@generated the next time you generate from the .genmodel those changes
will be lost.
You also have to make an extension point
net.refractions.udig.project.projectElementFactories It is just a
factory for creating instances of you class. I no longer remember why
we needed this class but we did for opening editors.
You might also consider a editor extension point.
Jesse
On 16-May-08, at 6:47 PM, Dave S-B wrote:
> I did a post ages ago asking about how to add other types of
> elements to a project (other than maps). For example, I am creating
> analysis files which are associated with a project - they're not GIS-
> related at all. I'd like these to show in the project view under the
> project. I've been trying to get this to happen on and off over the
> past few weeks without success. The
> net.refractions.udig.project.projectElementFactories and
> net.refractions.udig.project.ui.editorInputs extension points look
> promising but I don't see how to set everything up to add
> IProjectElements to a project. The
> ApplicationGIS.loadProjectElement(url, project) method is the
> closest I could see - it looks like this...
>
> public static IProjectElement loadProjectElement( URL url, IProject
> project )
> throws IOException, IllegalArgumentException {
> URI uri = URI.createURI(url.toString());
>
> Resource mapResource;
> try {
> mapResource =
> ProjectRegistryImpl.getProjectRegistry().eResource().getResourceSet()
> .getResource(uri, true);
> } catch (Exception e) {
> throw new IOException(Messages.ApplicationGIS_loadError +
> uri);
> }
>
> Object obj;
> try {
> obj = mapResource.getContents().get(0);
> } catch (Exception e) {
> throw new IllegalArgumentException(
> Messages.ApplicationGIS_illegalArgumentPart1 + uri
> + Messages.ApplicationGIS_illegalArgumentPart2); }
> if (!(obj instanceof ProjectElement))
> throw new IllegalArgumentException(
> Messages.ApplicationGIS_noProjectElement +
> obj.getClass().getSimpleName());
>
> ProjectElement elem = (ProjectElement) obj;
> ((Project) project).getElementsInternal().add(elem);
>
> return elem;
> }
>
> ...so, even if (somehow) uDig was able to find my file and recognise
> that there exists the means to interact with it, one of my classes
> would have to implement ProjectElement, which is an internal class
> with lots of strange EMF stuff going on!
>
> Does anyone know the proper usage of the extension points I
> mentioned above? Or the proper method for adding IProjectElements to
> a project?
>
> Thanks once again
> Dave S-B
> Lledr Solutions
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.refractions.net/pipermail/udig-devel/attachments/20080516/3eeb33c0/attachment-0001.html
More information about the udig-devel
mailing list