Created
May 14, 2013 21:47
-
-
Save mbruch/5579865 to your computer and use it in GitHub Desktop.
Extension Point für FormFields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='UTF-8'?> | |
<!-- Schema file written by PDE --> | |
<schema targetNamespace="com.example.miniscout.client" xmlns="http://www.w3.org/2001/XMLSchema"> | |
<annotation> | |
<appinfo> | |
<meta.schema plugin="com.example.miniscout.client" id="fields" name="Form Fields"/> | |
</appinfo> | |
<documentation> | |
</documentation> | |
</annotation> | |
<element name="extension"> | |
<annotation> | |
<appinfo> | |
<meta.element /> | |
</appinfo> | |
</annotation> | |
<complexType> | |
<sequence minOccurs="1" maxOccurs="unbounded"> | |
<element ref="Field"/> | |
</sequence> | |
<attribute name="point" type="string" use="required"> | |
<annotation> | |
<documentation> | |
</documentation> | |
</annotation> | |
</attribute> | |
<attribute name="id" type="string"> | |
<annotation> | |
<documentation> | |
</documentation> | |
</annotation> | |
</attribute> | |
<attribute name="name" type="string"> | |
<annotation> | |
<documentation> | |
</documentation> | |
<appinfo> | |
<meta.attribute translatable="true"/> | |
</appinfo> | |
</annotation> | |
</attribute> | |
</complexType> | |
</element> | |
<element name="Field"> | |
<complexType> | |
<attribute name="name" type="string"> | |
<annotation> | |
<documentation> | |
</documentation> | |
</annotation> | |
</attribute> | |
<attribute name="class" type="string"> | |
<annotation> | |
<documentation> | |
</documentation> | |
<appinfo> | |
<meta.attribute kind="java" basedOn="com.example.miniscout.client.fields.FormField:"/> | |
</appinfo> | |
</annotation> | |
</attribute> | |
<attribute name="type" type="string" use="required"> | |
<annotation> | |
<documentation> | |
</documentation> | |
</annotation> | |
</attribute> | |
</complexType> | |
</element> | |
</schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.miniscout.client.fields; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.eclipse.core.runtime.CoreException; | |
import org.eclipse.core.runtime.IConfigurationElement; | |
import org.eclipse.core.runtime.IExtensionRegistry; | |
import org.eclipse.core.runtime.Platform; | |
import com.google.common.base.Throwables; | |
public class Fields { | |
private static Map<String /* type */, IConfigurationElement> fields = new HashMap<String, IConfigurationElement>(); | |
private static Map<String, IConfigurationElement> getFields() { | |
IExtensionRegistry registry = Platform.getExtensionRegistry(); | |
IConfigurationElement[] elements = registry | |
.getConfigurationElementsFor("com.example.miniscout.client.fields"); | |
for (IConfigurationElement e : elements) { | |
fields.put(e.getAttribute("type"), e); | |
} | |
return fields; | |
} | |
public static FormField newField(String type) { | |
try { | |
Map<String, IConfigurationElement> f = getFields(); | |
IConfigurationElement e = f.get(type); | |
return (FormField) e.createExecutableExtension("class"); | |
} catch (CoreException e) { | |
throw Throwables.propagate(e); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?eclipse version="3.4"?> | |
<plugin> | |
<extension-point id="fields" name="Form Fields" schema="schema/fields.exsd"/> | |
<!-- skipped previous content --> | |
<extension | |
point="com.example.miniscout.client.fields"> | |
<Field | |
class="com.example.miniscout.client.fields.StringFormField" | |
name="String Form Field" | |
type="string"> | |
</Field> | |
<Field | |
class="com.example.miniscout.client.fields.IntFormField" | |
name="Integer Form Field" | |
type="int"> | |
</Field> | |
</extension> | |
</plugin> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment