001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.internal;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import net.refractions.udig.project.IProjectElement;
023: import net.refractions.udig.project.ui.UDIGEditorInput;
024:
025: import org.eclipse.core.runtime.CoreException;
026: import org.eclipse.core.runtime.IConfigurationElement;
027:
028: /**
029: * UDIGEditorInputDescriptor objects create IEditorInput objects that wrap IProjectElements objects.
030: * <p>
031: * Since IProjectElements are not editor inputs and cannot be since they are model objects and not
032: * UI objects an extensible system of turning IProjectElement objects into IEditorInput objects are
033: * needed. The mapping between a IProjectElements and IEditorInput types are defined by
034: * net.refractions.udig.project.ui.editorInputs extensions.
035: * </p>
036: *
037: * @author jones
038: * @since 0.3
039: */
040: public class UDIGEditorInputDescriptor {
041: protected String editorID;
042: protected String name;
043: protected Class type;
044: protected IConfigurationElement extensionElement;
045: protected Map<IProjectElement, UDIGEditorInput> instances = new HashMap<IProjectElement, UDIGEditorInput>();
046:
047: /**
048: * Creates a UDIGEditorInput
049: *
050: * @param element
051: * @return the EditorInput
052: * @throws CoreException
053: */
054: public UDIGEditorInput createInput(IProjectElement element) {
055: if (!instances.containsKey(element)) {
056: UDIGEditorInput input;
057: try {
058: input = (UDIGEditorInput) extensionElement
059: .createExecutableExtension("class"); //$NON-NLS-1$
060: input.setEditorId(editorID);
061: } catch (CoreException e) {
062: ProjectUIPlugin.log("Error creating input type", e); //$NON-NLS-1$
063: return null;
064: } //$NON-NLS-1$
065: input.setProjectElement(element);
066: instances.put(element, input);
067: }
068: return (UDIGEditorInput) instances.get(element);
069:
070: }
071:
072: /**
073: * @return Returns the type.
074: */
075: public Class getType() {
076: return type;
077: }
078:
079: /**
080: * @param type The type to set.
081: */
082: public void setType(Class type) {
083: this .type = type;
084: }
085:
086: /**
087: * @return Returns the editorID.
088: */
089: public String getEditorID() {
090: return editorID;
091: }
092:
093: /**
094: * @param editorID The editorID to set.
095: */
096: public void setEditorID(String editorID) {
097: this .editorID = editorID;
098: }
099:
100: /**
101: * @return Returns the name.
102: */
103: public String getName() {
104: return name;
105: }
106:
107: /**
108: * @param name The name to set.
109: */
110: public void setName(String name) {
111: this .name = name;
112: }
113:
114: /**
115: * @return Returns the extensionElement.
116: */
117: public IConfigurationElement getExtensionElement() {
118: return extensionElement;
119: }
120:
121: /**
122: * @param extensionElement The extensionElement to set.
123: */
124: public void setExtensionElement(
125: IConfigurationElement extensionElement) {
126: this.extensionElement = extensionElement;
127: }
128:
129: }
|