package com.vaadin.event.dd.acceptcriteria;
import com.vaadin.event.dd.DragAndDropEvent;
-import com.vaadin.terminal.gwt.client.ui.dd.VAcceptAll;
/**
* Criterion that accepts all drops anywhere on the component.
* @since 6.3
*
*/
-@ClientCriterion(VAcceptAll.class)
public final class AcceptAll extends ClientSideCriterion {
private static final long serialVersionUID = 7406683402153141461L;
* @since 6.3
*
*/
-@ClientCriterion(com.vaadin.terminal.gwt.client.ui.dd.VAnd.class)
public class And extends ClientSideCriterion {
private static final long serialVersionUID = -5242574480825471748L;
+++ /dev/null
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.event.dd.acceptcriteria;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import com.vaadin.terminal.gwt.client.ui.dd.VAcceptCriterion;
-
-/**
- * An annotation type used to point the client side counterpart for server side
- * a {@link AcceptCriterion} class.
- * <p>
- * Annotations are used at GWT compilation phase, so remember to rebuild your
- * widgetset if you do changes for {@link ClientCriterion} mappings.
- *
- * @since 6.3
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface ClientCriterion {
- /**
- * @return the client side counterpart for the annotated criterion
- */
- Class<? extends VAcceptCriterion> value();
-}
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VContainsDataFlavor;
/**
* A Criterion that checks whether {@link Transferable} contains given data
*
* @since 6.3
*/
-@ClientCriterion(VContainsDataFlavor.class)
public class ContainsDataFlavor extends ClientSideCriterion {
private String dataFlavorId;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VNot;
/**
* Criterion that wraps another criterion and inverts its return value.
* @since 6.3
*
*/
-@ClientCriterion(VNot.class)
public class Not extends ClientSideCriterion {
private static final long serialVersionUID = 1131422338558613244L;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VOr;
/**
* A compound criterion that accepts the drag if any of its criterion accepts
* @since 6.3
*
*/
-@ClientCriterion(VOr.class)
public class Or extends ClientSideCriterion {
private static final long serialVersionUID = 1L;
private AcceptCriterion criteria[];
import com.vaadin.event.Transferable;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VServerAccept;
/**
* Parent class for criteria which are verified on the server side during a drag
*
* @since 6.3
*/
-@ClientCriterion(VServerAccept.class)
public abstract class ServerSideCriterion implements Serializable,
AcceptCriterion {
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VDragSourceIs;
import com.vaadin.ui.Component;
/**
* @since 6.3
*/
@SuppressWarnings("serial")
-@ClientCriterion(VDragSourceIs.class)
public class SourceIs extends ClientSideCriterion {
private Component[] components;
import com.vaadin.event.TransferableImpl;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VSourceIsTarget;
import com.vaadin.ui.Component;
import com.vaadin.ui.Table;
import com.vaadin.ui.Tree;
* @since 6.3
*
*/
-@ClientCriterion(VSourceIsTarget.class)
public class SourceIsTarget extends ClientSideCriterion {
private static final long serialVersionUID = -451399314705532584L;
import com.vaadin.event.dd.TargetDetails;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.dd.VTargetDetailIs;
/**
* Criterion for checking if drop target details contains the specific property
* TODO add support for other basic data types that we support in UIDL.
*
*/
-@ClientCriterion(VTargetDetailIs.class)
public class TargetDetailIs extends ClientSideCriterion {
private static final long serialVersionUID = 763165450054331246L;
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.ui.dd;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation type used to point the server side counterpart for client side
+ * a {@link VAcceptCriterion} class.
+ * <p>
+ * Annotations are used at GWT compilation phase, so remember to rebuild your
+ * widgetset if you do changes for {@link AcceptCriterion} mappings.
+ *
+ * Prior to Vaadin 7, the mapping was done with an annotation on server side
+ * classes.
+ *
+ * @since 7.0
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface AcceptCriterion {
+ /**
+ * @return the fully qualified class name of the server side counterpart for
+ * the annotated criterion
+ */
+ String value();
+
+}
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.AcceptAll")
final public class VAcceptAll extends VAcceptCriterion {
@Override
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.And")
final public class VAnd extends VAcceptCriterion implements VAcceptCallback {
private boolean b1;
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor")
final public class VContainsDataFlavor extends VAcceptCriterion {
@Override
*
* @since 6.3
*/
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.SourceIs")
final public class VDragSourceIs extends VAcceptCriterion {
@Override
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.ui.AbstractSelect.TargetItemIs")
final public class VIsOverId extends VAcceptCriterion {
@Override
import com.vaadin.terminal.gwt.client.ComponentConnector;
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.ui.AbstractSelect.AcceptItem")
final public class VItemIdIs extends VAcceptCriterion {
@Override
/**
*
*/
-final public class VLazyInitItemIdentifiers extends VAcceptCriterion {
+public class VLazyInitItemIdentifiers extends VAcceptCriterion {
private boolean loaded = false;
private HashSet<String> hashSet;
private VDragEvent lastDragEvent;
+ @AcceptCriterion("com.vaadin.ui.Table.TableDropCriterion")
+ final public static class VTableLazyInitItemIdentifiers extends
+ VLazyInitItemIdentifiers {
+ // all logic in superclass
+ }
+
+ @AcceptCriterion("com.vaadin.ui.Tree.TreeDropCriterion")
+ final public static class VTreeLazyInitItemIdentifiers extends
+ VLazyInitItemIdentifiers {
+ // all logic in superclass
+ }
+
@Override
public void accept(final VDragEvent drag, UIDL configuration,
final VAcceptCallback callback) {
* TODO implementation could now be simplified/optimized
*
*/
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.Not")
final public class VNot extends VAcceptCriterion {
private boolean b1;
private VAcceptCriterion crit1;
/**
*
*/
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.Or")
final public class VOr extends VAcceptCriterion implements VAcceptCallback {
private boolean accepted;
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.ServerSideCriterion")
final public class VServerAccept extends VAcceptCriterion {
@Override
public void accept(final VDragEvent drag, UIDL configuration,
import com.vaadin.terminal.gwt.client.ComponentConnector;
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.SourceIsTarget")
final public class VSourceIsTarget extends VAcceptCriterion {
@Override
import com.vaadin.terminal.gwt.client.UIDL;
+@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.TargetDetailIs")
final public class VTargetDetailIs extends VAcceptCriterion {
@Override
import com.vaadin.terminal.gwt.client.ui.tree.VTree;
import com.vaadin.terminal.gwt.client.ui.tree.VTree.TreeNode;
+@AcceptCriterion("com.vaadin.ui.Tree.TargetInSubtree")
final public class VTargetInSubtree extends VAcceptCriterion {
@Override
package com.vaadin.terminal.gwt.widgetsetutils;
import java.io.PrintWriter;
-import java.util.Collection;
import java.util.Date;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
-import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
-import com.vaadin.event.dd.acceptcriteria.ClientCriterion;
+import com.vaadin.terminal.gwt.client.ui.dd.AcceptCriterion;
import com.vaadin.terminal.gwt.client.ui.dd.VAcceptCriterion;
import com.vaadin.terminal.gwt.client.ui.dd.VAcceptCriterionFactory;
/**
* GWT generator to build {@link VAcceptCriterionFactory} implementation
- * dynamically based on {@link ClientCriterion} annotations available in
+ * dynamically based on {@link AcceptCriterion} annotations available in
* classpath.
*
*/
sourceWriter.println("name = name.intern();");
- Collection<Class<? extends AcceptCriterion>> clientSideVerifiableCriterion = ClassPathExplorer
- .getCriterion();
-
- for (Class<? extends AcceptCriterion> class1 : clientSideVerifiableCriterion) {
- logger.log(Type.INFO,
- "creating mapping for " + class1.getCanonicalName());
- String canonicalName = class1.getCanonicalName();
- Class<? extends VAcceptCriterion> clientClass = class1
- .getAnnotation(ClientCriterion.class).value();
- sourceWriter.print("if (\"");
- sourceWriter.print(canonicalName);
- sourceWriter.print("\" == name) return GWT.create(");
- sourceWriter.print(clientClass.getCanonicalName());
- sourceWriter.println(".class );");
- sourceWriter.print("else ");
+ JClassType criteriaType = context.getTypeOracle().findType(
+ VAcceptCriterion.class.getName());
+ for (JClassType clientClass : criteriaType.getSubtypes()) {
+ AcceptCriterion annotation = clientClass
+ .getAnnotation(AcceptCriterion.class);
+ if (annotation != null) {
+ String clientClassName = clientClass.getQualifiedSourceName();
+ String serverClassName = clientClass.getAnnotation(
+ AcceptCriterion.class).value();
+ logger.log(Type.INFO, "creating mapping for " + serverClassName);
+ sourceWriter.print("if (\"");
+ sourceWriter.print(serverClassName);
+ sourceWriter.print("\" == name) return GWT.create(");
+ sourceWriter.print(clientClassName);
+ sourceWriter.println(".class );");
+ sourceWriter.print("else ");
+ }
}
sourceWriter.println("return null;");
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
-import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
-import com.vaadin.event.dd.acceptcriteria.ClientCriterion;
-
/**
* Utility class to collect widgetset related information from classpath.
* Utility will seek all directories from classpaths, and jar files having
private ClassPathExplorer() {
}
- /**
- * Finds server side widgets with ClientWidget annotation on the class path
- * (entries that can contain widgets/widgetsets - see
- * getRawClasspathEntries()).
- *
- * As a side effect, also accept criteria are searched under the same class
- * path entries and added into the acceptCriterion collection.
- */
- public static void findAcceptCriteria() {
- final Logger logger = getLogger();
- logger.info("Searching for accept criteria..");
- long start = System.currentTimeMillis();
- Set<String> keySet = classpathLocations.keySet();
- for (String url : keySet) {
- logger.fine("Searching for accept criteria in "
- + classpathLocations.get(url));
- searchForPaintables(classpathLocations.get(url), url);
- }
- long end = System.currentTimeMillis();
-
- logger.info("Search took " + (end - start) + "ms");
-
- }
-
- /**
- * Finds all accept criteria having client side counterparts (classes with
- * the {@link ClientCriterion} annotation).
- *
- * @return Collection of AcceptCriterion classes
- */
- public static Collection<Class<? extends AcceptCriterion>> getCriterion() {
- if (acceptCriterion.isEmpty()) {
- // accept criterion are searched as a side effect, normally after
- // paintable detection
- findAcceptCriteria();
- }
- return acceptCriterion;
- }
-
/**
* Finds the names and locations of widgetsets available on the class path.
*
}
- /**
- * Searches for all paintable classes and accept criteria under a location
- * based on {@link ClientCriterion} annotations.
- *
- * Note that client criteria are updated directly to the
- * {@link #acceptCriterion} field, whereas paintables are added to the
- * paintables map given as a parameter.
- *
- * @param location
- * @param locationString
- */
- private final static void searchForPaintables(URL location,
- String locationString) {
-
- // Get a File object for the package
- File directory = new File(location.getFile());
-
- if (directory.exists() && !directory.isHidden()) {
- // Get the list of the files contained in the directory
- String[] files = directory.list();
- for (int i = 0; i < files.length; i++) {
- // we are only interested in .class files
- if (files[i].endsWith(".class")) {
- // remove the .class extension
- String classname = files[i].substring(0,
- files[i].length() - 6);
- String packageName = locationString
- .substring(locationString.lastIndexOf("/") + 1);
- classname = packageName + "." + classname;
- tryToAdd(classname);
- }
- }
- } else {
- try {
- // check files in jar file, entries will list all directories
- // and files in jar
-
- URLConnection openConnection = location.openConnection();
-
- if (openConnection instanceof JarURLConnection) {
- JarURLConnection conn = (JarURLConnection) openConnection;
-
- JarFile jarFile = conn.getJarFile();
-
- // Only scan for paintables in Vaadin add-ons
- if (!isVaadinAddon(jarFile)) {
- return;
- }
-
- Enumeration<JarEntry> e = jarFile.entries();
- while (e.hasMoreElements()) {
- JarEntry entry = e.nextElement();
- String entryname = entry.getName();
- if (!entry.isDirectory()
- && entryname.endsWith(".class")) {
- String classname = entryname.substring(0,
- entryname.length() - 6);
- if (classname.startsWith("/")) {
- classname = classname.substring(1);
- }
- classname = classname.replace('/', '.');
- tryToAdd(classname);
- }
- }
- }
- } catch (IOException e) {
- getLogger().warning(e.toString());
- }
- }
-
- }
-
- /**
- * A print stream that ignores all output.
- *
- * This is used to hide error messages from static initializers of classes
- * being inspected.
- */
- private static PrintStream devnull = new PrintStream(new OutputStream() {
- @Override
- public void write(int b) throws IOException {
- // NOP
- }
- });
-
- /**
- * Collection of all {@link AcceptCriterion} classes, updated as a side
- * effect of {@link #searchForPaintables(URL, String, Collection)} based on
- * {@link ClientCriterion} annotations.
- */
- private static Set<Class<? extends AcceptCriterion>> acceptCriterion = new HashSet<Class<? extends AcceptCriterion>>();
-
- /**
- * Checks a class for the {@link ClientCriterion} annotations, and adds it
- * to the appropriate collection.
- *
- * @param fullclassName
- */
- @SuppressWarnings("unchecked")
- private static void tryToAdd(final String fullclassName) {
- PrintStream out = System.out;
- PrintStream err = System.err;
- Throwable errorToShow = null;
- Level logLevel = null;
- try {
- System.setErr(devnull);
- System.setOut(devnull);
-
- Class<?> c = Class.forName(fullclassName);
-
- if (c.getAnnotation(ClientCriterion.class) != null) {
- acceptCriterion.add((Class<? extends AcceptCriterion>) c);
- }
- } catch (UnsupportedClassVersionError e) {
- // Inform the user about this as the class might contain a Paintable
- // Typically happens when using an add-on that is compiled using a
- // newer Java version.
- logLevel = Level.INFO;
- errorToShow = e;
- } catch (ClassNotFoundException e) {
- // Don't show to avoid flooding the user with irrelevant messages
- logLevel = Level.FINE;
- errorToShow = e;
- } catch (LinkageError e) {
- // Don't show to avoid flooding the user with irrelevant messages
- logLevel = Level.FINE;
- errorToShow = e;
- } catch (Exception e) {
- // Don't show to avoid flooding the user with irrelevant messages
- logLevel = Level.FINE;
- errorToShow = e;
- } finally {
- System.setErr(err);
- System.setOut(out);
- }
-
- // Must be done here after stderr and stdout have been reset.
- if (errorToShow != null && logLevel != null) {
- getLogger().log(
- logLevel,
- "Failed to load class " + fullclassName + ". "
- + errorToShow.getClass().getName() + ": "
- + errorToShow.getMessage());
- }
- }
-
/**
* Find and return the default source directory where to create new
* widgetsets.
return null;
}
- /**
- * Checks if the given jarFile is a Vaadin add-on.
- *
- * @param jarFile
- * @return true if the file is an add-on, false otherwise
- * @throws IOException
- */
- private static boolean isVaadinAddon(JarFile jarFile) throws IOException {
- Manifest manifest = jarFile.getManifest();
- if (manifest == null) {
- return false;
- }
- Attributes mainAttributes = manifest.getMainAttributes();
- if (mainAttributes == null) {
- return false;
- }
-
- return (mainAttributes.getValue(VAADIN_ADDON_VERSION_ATTRIBUTE) != null);
- }
-
/**
* Test method for helper tool
*/
public static void main(String[] args) {
- ClassPathExplorer.findAcceptCriteria();
- getLogger().info("Found client criteria:");
- for (Class<? extends AcceptCriterion> cls : acceptCriterion) {
- getLogger().info(cls.getCanonicalName());
- }
-
- getLogger().info("");
getLogger().info("Searching available widgetsets...");
Map<String, URL> availableWidgetSets = ClassPathExplorer
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropTarget;
import com.vaadin.event.dd.TargetDetailsImpl;
-import com.vaadin.event.dd.acceptcriteria.ClientCriterion;
import com.vaadin.event.dd.acceptcriteria.ClientSideCriterion;
import com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor;
import com.vaadin.event.dd.acceptcriteria.TargetDetailIs;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.Vaadin6Component;
-import com.vaadin.terminal.gwt.client.ui.dd.VIsOverId;
-import com.vaadin.terminal.gwt.client.ui.dd.VItemIdIs;
import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation;
import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
*
* @since 6.3
*/
- @ClientCriterion(VIsOverId.class)
public static class TargetItemIs extends AbstractItemSetCriterion {
/**
*
* @since 6.3
*/
- @ClientCriterion(VItemIdIs.class)
public static class AcceptItem extends AbstractItemSetCriterion {
/**
import com.vaadin.event.dd.DragSource;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.DropTarget;
-import com.vaadin.event.dd.acceptcriteria.ClientCriterion;
import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion;
import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.LegacyPaint;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers;
import com.vaadin.terminal.gwt.client.ui.table.VScrollTable;
/**
* initialized from server and no subsequent requests requests are needed
* during that drag and drop operation.
*/
- @ClientCriterion(VLazyInitItemIdentifiers.class)
public static abstract class TableDropCriterion extends ServerSideCriterion {
private Table table;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.DropTarget;
import com.vaadin.event.dd.TargetDetails;
-import com.vaadin.event.dd.acceptcriteria.ClientCriterion;
import com.vaadin.event.dd.acceptcriteria.ClientSideCriterion;
import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion;
import com.vaadin.event.dd.acceptcriteria.TargetDetailIs;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers;
-import com.vaadin.terminal.gwt.client.ui.dd.VTargetInSubtree;
import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation;
import com.vaadin.terminal.gwt.client.ui.tree.TreeConnector;
import com.vaadin.terminal.gwt.client.ui.tree.VTree;
* initialized from server and no subsequent requests requests are needed
* during that drag and drop operation.
*/
- @ClientCriterion(VLazyInitItemIdentifiers.class)
public static abstract class TreeDropCriterion extends ServerSideCriterion {
private Tree tree;
* <p>
* The root items is also consider to be valid target.
*/
- @ClientCriterion(VTargetInSubtree.class)
public class TargetInSubtree extends ClientSideCriterion {
private Object rootId;