Commit bb97d1b2 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

[maven-release-plugin] copy for tag ohoui-0.1

parents 2c610ca0 d45026de
......@@ -27,6 +27,11 @@
<artifactId>xstream</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>RELEASE691</version>
</dependency>
</dependencies>
<!-- ************************************************************* -->
......@@ -34,7 +39,7 @@
<!-- ************************************************************* -->
<name>${project.artifactId} ${project.version}</name>
<description></description>
<description />
<url>http://trac.clermont.cemagref.fr/projets/LISC/wiki/JavaObservation</url>
<licenses>
......@@ -52,8 +57,8 @@
<packaging>jar</packaging>
<scm>
<connection>scm:svn:http://trac.clermont.cemagref.fr/svn/LISC/OhOUI/branches/0.1</connection>
<url>http://trac.clermont.cemagref.fr/projets/LISC/browser/OhOUI/branches/0.1</url>
<connection>scm:svn:http://trac.clermont.cemagref.fr/svn/LISC/OhOUI/tags/ohoui-0.1</connection>
<url>http://trac.clermont.cemagref.fr/projets/LISC/browser/OhOUI/tags/ohoui-0.1</url>
</scm>
<build>
<plugins>
......@@ -95,10 +100,13 @@
<distributionManagement>
<repository>
<id>trac.clermont.cemagref.fr</id>
<name>Lisc maven repository</name>
<url>scp://trac.clermont.cemagref.fr/var/www/maven/repo/</url>
<id>trac.clermont.cemagref.fr.nexus</id>
<url>http://trac.clermont.cemagref.fr/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>trac.clermont.cemagref.fr.nexus</id>
<url>http://trac.clermont.cemagref.fr/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
......
package fr.cemagref.ohoui.core;
import fr.cemagref.commons.modulesloader.ModulesLoader;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openide.util.Lookup;
public abstract class AbstractCollectionPanel<C> extends AbstractOUIPanel<C> {
protected IntrospectionContext collectionContext;
protected IntrospectionContext itemsContext;
protected Class itemClass;
protected Class[] availableTypesForItems;
protected List<AbstractOUIPanel<C>> ouiPanels;
public AbstractCollectionPanel(Object object) {
......@@ -31,22 +24,23 @@ public abstract class AbstractCollectionPanel<C> extends AbstractOUIPanel<C> {
public AbstractCollectionPanel(IntrospectionContext collectionContext) {
this(collectionContext.getObject());
this.collectionContext = collectionContext;
if (collectionContext.getObjectDeclaredType() == null)
if (collectionContext.getObjectDeclaredType() == null) {
itemClass = getItemClass(collectionContext.getField().getGenericType());
else
} else {
itemClass = getItemClass(collectionContext.getObjectDeclaredType());
}
this.itemsContext = new IntrospectionContext(collectionContext).setObjectDeclaredType(itemClass);
availableTypesForItems = ModulesLoader.getPlugins(itemClass).toArray(new Class[] {});
availableTypesForItems = new ArrayList<Class>(Lookup.getDefault().lookupResult(itemClass).allClasses()).toArray(new Class[]{});
ouiPanels = new ArrayList<AbstractOUIPanel<C>>();
IntrospectionContext itemContext;
AbstractOUIPanel<C> buff;
for (Object element : (Collection) collectionContext.getObject()) {
itemContext = new IntrospectionContext(this.itemsContext).setObject(element);
buff = AbstractOhOUI.getProducerLookup().lookupProducer(itemContext.getObject().getClass())
.getPanel(itemContext);
if (buff != null)
buff = AbstractOhOUI.getProducerLookup().lookupProducer(itemContext.getObject().getClass()).getPanel(itemContext);
if (buff != null) {
ouiPanels.add(buff);
}
}
}
......@@ -79,28 +73,31 @@ public abstract class AbstractCollectionPanel<C> extends AbstractOUIPanel<C> {
// Collection are suposed to have only one parametrized type
assert ((ParameterizedType) gtype).getActualTypeArguments().length == 1;
Type type = ((ParameterizedType) gtype).getActualTypeArguments()[0];
if (type instanceof WildcardType) {
if (type instanceof ParameterizedType) {
result = (Class) ((ParameterizedType) type).getRawType();
} else if (type instanceof WildcardType) {
// case with wildcard
if (((WildcardType) type).getLowerBounds().length > 0)
if (((WildcardType) type).getLowerBounds().length > 0) {
result = (Class) ((WildcardType) type).getLowerBounds()[0];
else if (((WildcardType) type).getUpperBounds().length > 0)
} else if (((WildcardType) type).getUpperBounds().length > 0) {
result = (Class) ((WildcardType) type).getUpperBounds()[0];
}
} else if (type instanceof TypeVariable) {
Type bound = ((TypeVariable) type).getBounds()[0];
if (bound instanceof ParameterizedType) {
// if the parameter is again parametrized
result = (Class)((ParameterizedType)bound).getRawType();
result = (Class) ((ParameterizedType) bound).getRawType();
} else if (bound instanceof Class) {
result = (Class) bound;
}
} else if (type instanceof Class)
// classical case
} else if (type instanceof Class) // classical case
{
result = (Class) type;
}
}
} catch (Exception e) {
// if error, fall to Object.class
}
return result;
}
}
package fr.cemagref.ohoui.core;
import fr.cemagref.commons.modulesloader.ModulesLoader;
import fr.cemagref.ohoui.annotations.Description;
import fr.cemagref.ohoui.annotations.NoRecursive;
import fr.cemagref.ohoui.annotations.XStreamable;
......@@ -10,8 +9,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.util.Lookup;
/**
* <code>AbstractDefaultObjectProducer</code> is used to produce graphical
......@@ -19,6 +20,7 @@ import java.util.List;
*/
public abstract class AbstractDefaultObjectProducer<C> implements OUIPanelProducer<C> {
@Override
public Class[] getCompatibleTypes() {
return null;
}
......@@ -35,8 +37,9 @@ public abstract class AbstractDefaultObjectProducer<C> implements OUIPanelProduc
protected AbstractOUIPanel<C> getPanel(IntrospectionContext context, AbstractObjectOUIPanel<C> objectPanel) {
assert context.getObject() != null;
// This object must not be parsed an other time
if (context.getStack().search(context.getObject()) >= 0)
if (context.getStack().search(context.getObject()) >= 0) {
return null;
}
context.getStack().push(context.getObject());
// The index of panels corresponding to inner fields is used for
// rebuilding a nested panel
......@@ -59,14 +62,19 @@ public abstract class AbstractDefaultObjectProducer<C> implements OUIPanelProduc
// Now, we build a panel for each field
AbstractOUIPanel<C> fieldPanel;
IntrospectionContext fieldContext;
fieldsLoop: for (Field innerField : fields) {
if (!innerField.isAccessible())
fieldsLoop:
for (Field innerField : fields) {
if (!innerField.isAccessible()) {
innerField.setAccessible(true);
// if one filter fails, we jump to the next field
// if one filter fails, we jump to the next field
}
for (FieldFilter fieldFilter : context.getFieldFilters()) {
if (!fieldFilter.accept(innerField))
if (!fieldFilter.accept(innerField)) {
continue fieldsLoop;
}
}
Logger.getLogger(AbstractDefaultObjectProducer.class.getName()).log(Level.FINER, "Introspecting a field: {0}.{1}",
new Object[]{innerField.getDeclaringClass().getName(), innerField.getName()});
fieldContext = new IntrospectionContext(context);
// updating the context
fieldContext.setField(innerField);
......@@ -85,18 +93,22 @@ public abstract class AbstractDefaultObjectProducer<C> implements OUIPanelProduc
return null;
}
// building the panel
Collection<Class> modules = ModulesLoader.getPlugins(fieldContext.getField().getType());
List<Class> modules = new ArrayList<Class>(Lookup.getDefault().lookupResult(fieldContext.getField().getType()).allClasses());
Class[] moduleArray;
if (modules == null)
moduleArray = new Class[] { fieldContext.getField().getType() };
else
moduleArray = modules.toArray(new Class[] {});
if (modules == null) {
moduleArray = new Class[]{fieldContext.getField().getType()};
} else {
moduleArray = modules.toArray(new Class[]{});
}
fieldPanel = buildFieldPanel(objectPanel, context, fieldContext, moduleArray, indexOfCurrentNestedPanel);
// if the field is final, it couldn't be edited
if (fieldPanel != null) {
// TODO : add an explicit icon beside the field
if (Modifier.isFinal(innerField.getModifiers()))
if (Modifier.isFinal(innerField.getModifiers())) {
fieldPanel.setEnabled(false);
}
objectPanel.registerField(innerField, fieldPanel);
objectPanel.addFieldPanel(fieldPanel);
indexOfCurrentNestedPanel++;
......@@ -104,15 +116,16 @@ public abstract class AbstractDefaultObjectProducer<C> implements OUIPanelProduc
}
objectPanel.validateOUI();
context.getStack().pop();
if (indexOfCurrentNestedPanel == 0)
completeEmptyPanel(objectPanel);
if (indexOfCurrentNestedPanel == 0) {
completeEmptyPanel(objectPanel);
}
return objectPanel;
}
protected abstract void completeEmptyPanel(AbstractObjectOUIPanel<C> objectPanel);
/**
/**
* <code>buildFieldPanel</code> builds graphical controls for a field.
*
* @param parentOUIPanel
......@@ -240,5 +253,4 @@ public abstract class AbstractDefaultObjectProducer<C> implements OUIPanelProduc
parentOUIPanel.addFieldPanelAt(fieldPanel, indexOfCurrentNestedPanel);
parentOUIPanel.registerField(fieldContext.getField(), fieldPanel);
}
}
......@@ -16,10 +16,12 @@ public class BooleanProducer implements OUIPanelProducer<JComponent> {
private static Class[] ty = new Class[] { Boolean.class, boolean.class };
@Override
public Class[] getCompatibleTypes() {
return ty;
}
@Override
public OUIPanel getPanel(IntrospectionContext context) {
BooleanOUIPanel ouiPanel = new BooleanOUIPanel(context.getObject());
ouiPanel.getPanel().setLayout(new FlowLayout(FlowLayout.LEFT));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment