Added javadoc + comments about missing javadoc svn changeset:11455/svn branch:6.3_ddtags/6.7.0.beta1
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public interface Transferable { | public interface Transferable { | ||||
public Object getData(String dataFlawor); | |||||
public Object getData(String dataFlavor); | |||||
public void setData(String dataFlawor, Object value); | |||||
public void setData(String dataFlavor, Object value); | |||||
public Collection<String> getDataFlawors(); | |||||
public Collection<String> getDataFlavors(); | |||||
/** | /** | ||||
* @return the component that created the Transferable | * @return the component that created the Transferable |
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public class TransferableImpl implements Transferable { | public class TransferableImpl implements Transferable { | ||||
private Map<String, Object> rawVariables = new HashMap<String, Object>(); | private Map<String, Object> rawVariables = new HashMap<String, Object>(); | ||||
private Component sourceComponent; | private Component sourceComponent; | ||||
return sourceComponent; | return sourceComponent; | ||||
} | } | ||||
public Object getData(String dataFlawor) { | |||||
return rawVariables.get(dataFlawor); | |||||
public Object getData(String dataFlavor) { | |||||
return rawVariables.get(dataFlavor); | |||||
} | } | ||||
public void setData(String dataFlawor, Object value) { | |||||
rawVariables.put(dataFlawor, value); | |||||
public void setData(String dataFlavor, Object value) { | |||||
rawVariables.put(dataFlavor, value); | |||||
} | } | ||||
public Collection<String> getDataFlawors() { | |||||
public Collection<String> getDataFlavors() { | |||||
return rawVariables.keySet(); | return rawVariables.keySet(); | ||||
} | } | ||||
import com.vaadin.event.Transferable; | import com.vaadin.event.Transferable; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
public class DragAndDropEvent implements Serializable { | public class DragAndDropEvent implements Serializable { | ||||
private static final long serialVersionUID = -2232591107911385564L; | private static final long serialVersionUID = -2232591107911385564L; | ||||
private Transferable transferable; | private Transferable transferable; | ||||
private DropTargetDetails dropDetails; | |||||
private DropTargetDetails dropTargetDetails; | |||||
public DragAndDropEvent(Transferable tr, DropTargetDetails details) { | |||||
transferable = tr; | |||||
dropDetails = details; | |||||
public DragAndDropEvent(Transferable transferable, | |||||
DropTargetDetails dropTargetDetails) { | |||||
this.transferable = transferable; | |||||
this.dropTargetDetails = dropTargetDetails; | |||||
} | } | ||||
public Transferable getTransferable() { | public Transferable getTransferable() { | ||||
return transferable; | return transferable; | ||||
} | } | ||||
public DropTargetDetails getDropTargetData() { | |||||
return dropDetails; | |||||
public DropTargetDetails getDropTargetDetails() { | |||||
return dropTargetDetails; | |||||
} | } | ||||
} | } |
import com.vaadin.event.Transferable; | import com.vaadin.event.Transferable; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
public interface DragSource extends Serializable { | public interface DragSource extends Serializable { | ||||
/** | /** | ||||
* DragSource may convert client side variables to meaningful values on | * DragSource may convert client side variables to meaningful values on | ||||
* server side. For example in Selects we convert item identifiers to | |||||
* generated string keys for the client side. Translators in Selects should | |||||
* convert them back to item identifiers. | |||||
* server side. For example Tree converts item identifiers to generated | |||||
* string keys for the client side. Translators in Selects should convert | |||||
* them back to item identifiers. | |||||
* | |||||
* <p> | * <p> | ||||
* Translator should remove variables it handled from rawVariables. All non | * Translator should remove variables it handled from rawVariables. All non | ||||
* handled variables are added to Transferable automatically by terminal. | * handled variables are added to Transferable automatically by terminal. | ||||
* </p> | |||||
* | * | ||||
* <p> | * <p> | ||||
* | * | ||||
* @since 6.3 | |||||
* @param rawVariables | * @param rawVariables | ||||
* @return the drag source related transferable | * @return the drag source related transferable | ||||
*/ | */ |
import com.vaadin.event.dd.acceptCriteria.AcceptAll; | import com.vaadin.event.dd.acceptCriteria.AcceptAll; | ||||
import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
public interface DropHandler extends Serializable { | public interface DropHandler extends Serializable { | ||||
public void drop(DragAndDropEvent dropEvent); | public void drop(DragAndDropEvent dropEvent); |
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
/** | /** | ||||
* DropTarget is a marker interface for components supporting drop operations. A | |||||
* DropTarget is an interface for components supporting drop operations. A | |||||
* component that wants to receive drop events should implement this interface | * component that wants to receive drop events should implement this interface | ||||
* and provide a DropHandler which will handle the actual drop event. | * and provide a DropHandler which will handle the actual drop event. | ||||
* | * | ||||
* @since 6.3 | |||||
*/ | */ | ||||
public interface DropTarget extends Component { | public interface DropTarget extends Component { | ||||
public DropHandler getDropHandler(); | public DropHandler getDropHandler(); | ||||
/** | /** | ||||
* Called before a drop operation to translate the drop data provided by the | |||||
* client widget. Should return a DropData implementation with the new | |||||
* values. If null is returned the terminal implementation will | |||||
* automatically create a {@link DropTargetDetails} with all the client | |||||
* variables. | |||||
* <p> | |||||
* If this method returns null the data from client side will be passed | |||||
* through as-is without conversion. | |||||
* Called before a drop operation to translate the drop target details | |||||
* provided by the client widget (drop target). Should return a DropData | |||||
* implementation with the new values. If null is returned the terminal | |||||
* implementation will automatically create a {@link DropTargetDetails} with | |||||
* all the client variables. | |||||
* | * | ||||
* @param rawVariables | * @param rawVariables | ||||
* Parameters passed from the client side widget. | * Parameters passed from the client side widget. | ||||
* @return A DropData object with the translated data or null. | |||||
* @return A DropTargetDetails object with the translated data or null to | |||||
* use a default implementation. | |||||
*/ | */ | ||||
public DropTargetDetails translateDragDropDetails( | |||||
public DropTargetDetails translateDropTargetDetails( | |||||
Map<String, Object> clientVariables); | Map<String, Object> clientVariables); | ||||
} | } |
import java.io.Serializable; | import java.io.Serializable; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
public interface DropTargetDetails extends Serializable { | public interface DropTargetDetails extends Serializable { | ||||
public Object getData(String key); | public Object getData(String key); |
import com.vaadin.terminal.gwt.server.DragAndDropService; | import com.vaadin.terminal.gwt.server.DragAndDropService; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
public class DropTargetDetailsImpl implements DropTargetDetails { | public class DropTargetDetailsImpl implements DropTargetDetails { | ||||
private HashMap<String, Object> data = new HashMap<String, Object>(); | private HashMap<String, Object> data = new HashMap<String, Object>(); |
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VAcceptAll; | import com.vaadin.terminal.gwt.client.ui.dd.VAcceptAll; | ||||
/** | |||||
* Criterion that accepts all drops anywhere on the component. | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VAcceptAll.class) | @ClientCriterion(VAcceptAll.class) | ||||
public final class AcceptAll extends ClientSideCriterion { | public final class AcceptAll extends ClientSideCriterion { | ||||
import com.vaadin.terminal.PaintException; | import com.vaadin.terminal.PaintException; | ||||
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
public interface AcceptCriterion extends Serializable { | public interface AcceptCriterion extends Serializable { | ||||
/** | /** |
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
/** | /** | ||||
* TODO consider replacing this with Union | |||||
* Criterion that joins two {@link ClientSideCriterion} together and validates | |||||
* if both sub criterion validate. | |||||
* | |||||
* @since 6.3 | |||||
* | * | ||||
*/ | */ | ||||
@ClientCriterion(com.vaadin.terminal.gwt.client.ui.dd.VAnd.class) | @ClientCriterion(com.vaadin.terminal.gwt.client.ui.dd.VAnd.class) | ||||
public class And extends ClientSideCriterion { | public class And extends ClientSideCriterion { | ||||
/** | |||||
* | |||||
*/ | |||||
private static final long serialVersionUID = 1L; | |||||
private AcceptCriterion f1; | private AcceptCriterion f1; | ||||
private AcceptCriterion f2; | private AcceptCriterion f2; | ||||
this.f2 = f2; | this.f2 = f2; | ||||
} | } | ||||
// @Override | |||||
// public boolean isClientSideVerifiable() { | |||||
// boolean a1 = f1 instanceof AcceptCriterion ? (f1) | |||||
// .isClientSideVerifiable() : false; | |||||
// boolean a2 = f2 instanceof AcceptCriterion ? (f2) | |||||
// .isClientSideVerifiable() : false; | |||||
// return a1 && a2; | |||||
// } | |||||
@Override | @Override | ||||
public void paintContent(PaintTarget target) throws PaintException { | public void paintContent(PaintTarget target) throws PaintException { | ||||
super.paintContent(target); | super.paintContent(target); | ||||
(f1).paint(target); | |||||
(f2).paint(target); | |||||
f1.paint(target); | |||||
f2.paint(target); | |||||
} | } | ||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { |
/** | /** | ||||
* TODO | * TODO | ||||
* | * | ||||
* @since 6.2 | |||||
* @since 6.3 | |||||
*/ | */ | ||||
@Retention(RetentionPolicy.RUNTIME) | @Retention(RetentionPolicy.RUNTIME) | ||||
@Target(ElementType.TYPE) | @Target(ElementType.TYPE) |
import com.vaadin.terminal.PaintException; | import com.vaadin.terminal.PaintException; | ||||
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
/** | |||||
* Parent class for criteria that can be completely validated on client side. | |||||
* All classes that provide criteria that can be completely validated on client | |||||
* side should extend this class. | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public abstract class ClientSideCriterion implements Serializable, | public abstract class ClientSideCriterion implements Serializable, | ||||
AcceptCriterion { | |||||
AcceptCriterion { | |||||
/** | |||||
/* | |||||
* All criteria that extend this must be completely validatable on client | |||||
* side. | |||||
* | * | ||||
* (non-Javadoc) | |||||
* | |||||
* @see | |||||
* com.vaadin.event.dd.acceptCriteria.AcceptCriterion#isClientSideVerifiable | |||||
* () | |||||
*/ | */ | ||||
private static final long serialVersionUID = 1L; | |||||
public final boolean isClientSideVerifiable() { | |||||
return true; | |||||
} | |||||
public void paint(PaintTarget target) throws PaintException { | |||||
target.startTag("-ac"); | |||||
target.addAttribute("name", getIdentifier()); | |||||
paintContent(target); | |||||
target.endTag("-ac"); | |||||
} | |||||
public void paintContent(PaintTarget target) throws PaintException { | |||||
} | |||||
protected String getIdentifier() { | |||||
return getClass().getCanonicalName(); | |||||
} | |||||
public final void paintResponse(PaintTarget target) throws PaintException { | |||||
// NOP, nothing to do as this is client side verified criterion | |||||
} | |||||
public final boolean isClientSideVerifiable() { | |||||
return true; | |||||
} | |||||
public void paint(PaintTarget target) throws PaintException { | |||||
target.startTag("-ac"); | |||||
target.addAttribute("name", getIdentifier()); | |||||
paintContent(target); | |||||
target.endTag("-ac"); | |||||
} | |||||
protected void paintContent(PaintTarget target) throws PaintException { | |||||
} | |||||
protected String getIdentifier() { | |||||
return getClass().getCanonicalName(); | |||||
} | |||||
public final void paintResponse(PaintTarget target) throws PaintException { | |||||
// NOP, nothing to do as this is client side verified criterion | |||||
} | |||||
} | } |
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.terminal.PaintException; | import com.vaadin.terminal.PaintException; | ||||
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VContainsDataFlawor; | |||||
import com.vaadin.terminal.gwt.client.ui.dd.VContainsDataFlavor; | |||||
@ClientCriterion(VContainsDataFlawor.class) | |||||
public final class ContainsDataFlawor extends ClientSideCriterion { | |||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VContainsDataFlavor.class) | |||||
public final class ContainsDataFlavor extends ClientSideCriterion { | |||||
private String dataFlaworId; | |||||
private String dataFlavorId; | |||||
/** | /** | ||||
* TODO should support basic UIDL data types | * TODO should support basic UIDL data types | ||||
* @param dataFlawor | * @param dataFlawor | ||||
* @param value | * @param value | ||||
*/ | */ | ||||
public ContainsDataFlawor(String dataFlawor) { | |||||
dataFlaworId = dataFlawor; | |||||
public ContainsDataFlavor(String dataFlawor) { | |||||
dataFlavorId = dataFlawor; | |||||
} | } | ||||
@Override | @Override | ||||
public void paintContent(PaintTarget target) throws PaintException { | public void paintContent(PaintTarget target) throws PaintException { | ||||
super.paintContent(target); | super.paintContent(target); | ||||
target.addAttribute("p", dataFlaworId); | |||||
target.addAttribute("p", dataFlavorId); | |||||
} | } | ||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { | ||||
return dragEvent.getTransferable().getDataFlawors().contains( | |||||
dataFlaworId); | |||||
return dragEvent.getTransferable().getDataFlavors().contains( | |||||
dataFlavorId); | |||||
} | } | ||||
} | } |
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VDropDetailEquals; | import com.vaadin.terminal.gwt.client.ui.dd.VDropDetailEquals; | ||||
/** | |||||
* Criteria for checking if drop target details contain the specific property | |||||
* with the specific value. | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VDropDetailEquals.class) | @ClientCriterion(VDropDetailEquals.class) | ||||
public final class DropDetailEquals extends ClientSideCriterion { | |||||
public final class DropTargetDetailEquals extends ClientSideCriterion { | |||||
private String propertyName; | private String propertyName; | ||||
private String value; | private String value; | ||||
* @param propertyName | * @param propertyName | ||||
* @param value | * @param value | ||||
*/ | */ | ||||
public DropDetailEquals(String propertyName, String value) { | |||||
public DropTargetDetailEquals(String propertyName, String value) { | |||||
this.propertyName = propertyName; | this.propertyName = propertyName; | ||||
this.value = value; | this.value = value; | ||||
} | } | ||||
} | } | ||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { | ||||
Object data = dragEvent.getDropTargetData().getData(propertyName); | |||||
Object data = dragEvent.getDropTargetDetails().getData(propertyName); | |||||
return value.equals(data); | return value.equals(data); | ||||
} | } | ||||
} | } |
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VDataBound; | import com.vaadin.terminal.gwt.client.ui.dd.VDataBound; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VDataBound.class) | @ClientCriterion(VDataBound.class) | ||||
public final class IsDatabound extends ClientSideCriterion { | |||||
private static IsDatabound singleton = new IsDatabound(); | |||||
public final class IsDataBound extends ClientSideCriterion { | |||||
private static IsDataBound singleton = new IsDataBound(); | |||||
private IsDatabound() { | |||||
private IsDataBound() { | |||||
} | } | ||||
public static IsDatabound get() { | |||||
public static IsDataBound get() { | |||||
return singleton; | return singleton; | ||||
} | } | ||||
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.terminal.PaintException; | import com.vaadin.terminal.PaintException; | ||||
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VComponentFilter; | |||||
import com.vaadin.terminal.gwt.client.ui.dd.VIsDragSource; | |||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
@ClientCriterion(VComponentFilter.class) | |||||
public class ComponentFilter extends ClientSideCriterion { | |||||
/** | |||||
* Client side criteria that checks if the drag source is one of the given | |||||
* components. | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
@ClientCriterion(VIsDragSource.class) | |||||
public class IsDragSource extends ClientSideCriterion { | |||||
private Component[] component; | private Component[] component; | ||||
public ComponentFilter(Component... component) { | |||||
public IsDragSource(Component... component) { | |||||
this.component = component; | this.component = component; | ||||
} | } | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VSourceIsSameAsTarget; | import com.vaadin.terminal.gwt.client.ui.dd.VSourceIsSameAsTarget; | ||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VSourceIsSameAsTarget.class) | @ClientCriterion(VSourceIsSameAsTarget.class) | ||||
public class SourceIsSameAsTarget extends ClientSideCriterion { | |||||
public class IsSameSourceAndTarget extends ClientSideCriterion { | |||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { | ||||
if (dragEvent.getTransferable() instanceof TransferableImpl) { | if (dragEvent.getTransferable() instanceof TransferableImpl) { | ||||
Component sourceComponent = ((TransferableImpl) dragEvent | Component sourceComponent = ((TransferableImpl) dragEvent | ||||
.getTransferable()).getSourceComponent(); | .getTransferable()).getSourceComponent(); | ||||
DropTarget target = dragEvent.getDropTargetData().getTarget(); | |||||
DropTarget target = dragEvent.getDropTargetDetails().getTarget(); | |||||
return sourceComponent == target; | return sourceComponent == target; | ||||
} | } | ||||
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VNot; | import com.vaadin.terminal.gwt.client.ui.dd.VNot; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VNot.class) | @ClientCriterion(VNot.class) | ||||
public class Not extends ClientSideCriterion { | public class Not extends ClientSideCriterion { | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VOr; | import com.vaadin.terminal.gwt.client.ui.dd.VOr; | ||||
/** | /** | ||||
* TODO consider replacing this with intersection | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | * | ||||
*/ | */ | ||||
@ClientCriterion(VOr.class) | @ClientCriterion(VOr.class) |
/** | |||||
* | |||||
*/ | |||||
package com.vaadin.event.dd.acceptCriteria; | |||||
import com.vaadin.event.dd.DragAndDropEvent; | |||||
import com.vaadin.terminal.gwt.client.ui.dd.VOverTreeNode; | |||||
import com.vaadin.ui.Tree; | |||||
import com.vaadin.ui.Tree.Location; | |||||
import com.vaadin.ui.Tree.TreeDropDetails; | |||||
/** | |||||
* Accepts transferable only on tree Node (middle of the node + can has child) | |||||
* | |||||
* TODO relocate close to {@link Tree} as this is tree specifif | |||||
* | |||||
*/ | |||||
@ClientCriterion(VOverTreeNode.class) | |||||
public class OverTreeNode extends ClientSideCriterion { | |||||
private static final long serialVersionUID = 1L; | |||||
public boolean accepts(DragAndDropEvent dragEvent) { | |||||
try { | |||||
// must be over tree node and in the middle of it (not top or bottom | |||||
// part) | |||||
TreeDropDetails eventDetails = (TreeDropDetails) dragEvent | |||||
.getDropTargetData(); | |||||
Object itemIdOver = eventDetails.getItemIdOver(); | |||||
if (!eventDetails.getTarget().areChildrenAllowed(itemIdOver)) { | |||||
return false; | |||||
} | |||||
return eventDetails.getDropLocation() == Location.MIDDLE; | |||||
} catch (Exception e) { | |||||
return false; | |||||
} | |||||
} | |||||
} |
import com.vaadin.terminal.PaintTarget; | import com.vaadin.terminal.PaintTarget; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VServerAccept; | import com.vaadin.terminal.gwt.client.ui.dd.VServerAccept; | ||||
/** | |||||
* TODO Javadoc | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
@ClientCriterion(VServerAccept.class) | @ClientCriterion(VServerAccept.class) | ||||
public abstract class ServerSideCriterion implements Serializable, | public abstract class ServerSideCriterion implements Serializable, | ||||
AcceptCriterion { | AcceptCriterion { | ||||
/** | |||||
* | |||||
*/ | |||||
private static final long serialVersionUID = 1L; | |||||
public final boolean isClientSideVerifiable() { | public final boolean isClientSideVerifiable() { | ||||
return false; | return false; | ||||
} | } |
import com.vaadin.terminal.gwt.client.UIDL; | import com.vaadin.terminal.gwt.client.UIDL; | ||||
final public class VContainsDataFlawor extends VAcceptCriterion { | |||||
final public class VContainsDataFlavor extends VAcceptCriterion { | |||||
@Override | @Override | ||||
public boolean validates(VDragEvent drag, UIDL configuration) { | public boolean validates(VDragEvent drag, UIDL configuration) { | ||||
String name = configuration.getStringAttribute("p"); | String name = configuration.getStringAttribute("p"); | ||||
return drag.getTransferable().getDataFlawors().contains(name); | |||||
return drag.getTransferable().getDataFlavors().contains(name); | |||||
} | } | ||||
} | } |
/** | |||||
* | |||||
*/ | |||||
package com.vaadin.terminal.gwt.client.ui.dd; | package com.vaadin.terminal.gwt.client.ui.dd; | ||||
import com.vaadin.terminal.gwt.client.Paintable; | import com.vaadin.terminal.gwt.client.Paintable; | ||||
import com.vaadin.terminal.gwt.client.UIDL; | import com.vaadin.terminal.gwt.client.UIDL; | ||||
final public class VComponentFilter extends VAcceptCriterion { | |||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
final public class VIsDragSource extends VAcceptCriterion { | |||||
@Override | @Override | ||||
public boolean validates(VDragEvent drag, UIDL configuration) { | public boolean validates(VDragEvent drag, UIDL configuration) { |
variables.put(dataFlawor, value); | variables.put(dataFlawor, value); | ||||
} | } | ||||
public Collection<String> getDataFlawors() { | |||||
public Collection<String> getDataFlavors() { | |||||
return variables.keySet(); | return variables.keySet(); | ||||
} | } | ||||
.get("evt"); | .get("evt"); | ||||
DropTargetDetails dropData = dropTarget | DropTargetDetails dropData = dropTarget | ||||
.translateDragDropDetails(rawDragDropDetails); | |||||
.translateDropTargetDetails(rawDragDropDetails); | |||||
if (dropData == null) { | if (dropData == null) { | ||||
// Create a default DragDropDetails with all the raw variables | // Create a default DragDropDetails with all the raw variables |
import com.vaadin.data.Property; | import com.vaadin.data.Property; | ||||
import com.vaadin.data.util.IndexedContainer; | import com.vaadin.data.util.IndexedContainer; | ||||
import com.vaadin.event.DataBoundTransferable; | import com.vaadin.event.DataBoundTransferable; | ||||
import com.vaadin.event.Transferable; | |||||
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.event.dd.DropTargetDetailsImpl; | import com.vaadin.event.dd.DropTargetDetailsImpl; | ||||
import com.vaadin.event.dd.acceptCriteria.ClientCriterion; | import com.vaadin.event.dd.acceptCriteria.ClientCriterion; | ||||
} | } | ||||
/** | /** | ||||
* Criterion for selects that support drop (Tree and Table). With this | |||||
* criterion drop is accepted on given identifier or set of identifiers. | |||||
* Criterion which accepts a drop only if the drop target is (one of) the | |||||
* given item identifier(s). Meaningful only for drop targets that extends | |||||
* AbstractSelect. | |||||
* | |||||
* @since 6.3 | |||||
*/ | */ | ||||
@ClientCriterion(VIsOverId.class) | @ClientCriterion(VIsOverId.class) | ||||
public static class IsOverId extends AbstractItemSetCriterion { | |||||
public static class DropTargetItemId extends AbstractItemSetCriterion { | |||||
public IsOverId(AbstractSelect select, Object... itemId) { | |||||
public DropTargetItemId(AbstractSelect select, Object... itemId) { | |||||
super(select, itemId); | super(select, itemId); | ||||
} | } | ||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { | ||||
AbstractSelectDropDetails dropTargetData = (AbstractSelectDropDetails) dragEvent | |||||
.getDropTargetData(); | |||||
AbstractSelectDropTargetDetails dropTargetData = (AbstractSelectDropTargetDetails) dragEvent | |||||
.getDropTargetDetails(); | |||||
return itemIds.contains(dropTargetData.getItemIdOver()); | return itemIds.contains(dropTargetData.getItemIdOver()); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
* | |||||
*/ | |||||
private static abstract class AbstractItemSetCriterion extends | private static abstract class AbstractItemSetCriterion extends | ||||
ClientSideCriterion { | ClientSideCriterion { | ||||
protected final Collection<Object> itemIds = new HashSet<Object>(); | protected final Collection<Object> itemIds = new HashSet<Object>(); | ||||
} | } | ||||
/** | /** | ||||
* Criterion for selects that support drop (Tree and Table). With this | |||||
* criterion drop is accepted only if {@link Transferable} (from this | |||||
* {@link AbstractSelect}) contains given item identifier or identifiers. | |||||
* Criterion which accepts a drop only if the transferable contains the | |||||
* given item identifier(s). The item ids relate to the drag source | |||||
* (AbstractSelect). | |||||
* | |||||
* @since 6.3 | |||||
*/ | */ | ||||
@ClientCriterion(VItemIdIs.class) | @ClientCriterion(VItemIdIs.class) | ||||
public static class ItemIdIs extends AbstractItemSetCriterion { | |||||
public ItemIdIs(AbstractSelect select, Object... itemId) { | |||||
public static class TransferableContainsItemId extends | |||||
AbstractItemSetCriterion { | |||||
public TransferableContainsItemId(AbstractSelect select, | |||||
Object... itemId) { | |||||
super(select, itemId); | super(select, itemId); | ||||
} | } | ||||
} | } | ||||
public class AbstractSelectDropDetails extends DropTargetDetailsImpl { | |||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public class AbstractSelectDropTargetDetails extends DropTargetDetailsImpl { | |||||
private Object idOver; | private Object idOver; | ||||
AbstractSelectDropDetails(Map<String, Object> rawVariables) { | |||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
*/ | |||||
AbstractSelectDropTargetDetails(Map<String, Object> rawVariables) { | |||||
super(rawVariables); | super(rawVariables); | ||||
// eagar fetch itemid, mapper may be emptied | // eagar fetch itemid, mapper may be emptied | ||||
String keyover = (String) getData("itemIdOver"); | String keyover = (String) getData("itemIdOver"); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
*/ | |||||
public Object getItemIdOver() { | public Object getItemIdOver() { | ||||
return idOver; | return idOver; | ||||
} | } | ||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public Location getDropLocation() { | public Location getDropLocation() { | ||||
String s = (String) getData("detail"); | String s = (String) getData("detail"); | ||||
if ("TOP".equals(s)) { | if ("TOP".equals(s)) { |
requestRepaint(); | requestRepaint(); | ||||
} | } | ||||
public DropTargetDetails translateDragDropDetails( | |||||
public DropTargetDetails translateDropTargetDetails( | |||||
Map<String, Object> clientVariables) { | Map<String, Object> clientVariables) { | ||||
return new WrapperDropDetails(clientVariables); | return new WrapperDropDetails(clientVariables); | ||||
} | } |
public static class ImportPrettyMuchAnything implements DropHandler { | public static class ImportPrettyMuchAnything implements DropHandler { | ||||
public void drop(DragAndDropEvent event) { | public void drop(DragAndDropEvent event) { | ||||
DragDropPane pane = (DragDropPane) event.getDropTargetData() | |||||
DragDropPane pane = (DragDropPane) event.getDropTargetDetails() | |||||
.getTarget(); | .getTarget(); | ||||
DragEventDetails ed = (DragEventDetails) event.getDropTargetData(); | |||||
DragEventDetails ed = (DragEventDetails) event.getDropTargetDetails(); | |||||
Transferable transferable = event.getTransferable(); | Transferable transferable = event.getTransferable(); | ||||
if (transferable instanceof TransferableImpl) { | if (transferable instanceof TransferableImpl) { | ||||
TransferableImpl ctr = (TransferableImpl) transferable; | TransferableImpl ctr = (TransferableImpl) transferable; | ||||
} | } | ||||
public DropTargetDetails translateDragDropDetails( | |||||
public DropTargetDetails translateDropTargetDetails( | |||||
Map<String, Object> clientVariables) { | Map<String, Object> clientVariables) { | ||||
return new DragEventDetails(clientVariables); | return new DragEventDetails(clientVariables); | ||||
} | } |
this.dropHandler = dropHandler; | this.dropHandler = dropHandler; | ||||
} | } | ||||
public AbstractSelectDropDetails translateDragDropDetails( | |||||
public AbstractSelectDropTargetDetails translateDropTargetDetails( | |||||
Map<String, Object> clientVariables) { | Map<String, Object> clientVariables) { | ||||
return new AbstractSelectDropDetails(clientVariables); | |||||
return new AbstractSelectDropTargetDetails(clientVariables); | |||||
} | } | ||||
} | } |
import com.vaadin.event.dd.DropHandler; | import com.vaadin.event.dd.DropHandler; | ||||
import com.vaadin.event.dd.DropTarget; | import com.vaadin.event.dd.DropTarget; | ||||
import com.vaadin.event.dd.acceptCriteria.ClientCriterion; | 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.ServerSideCriterion; | ||||
import com.vaadin.terminal.KeyMapper; | import com.vaadin.terminal.KeyMapper; | ||||
import com.vaadin.terminal.PaintException; | import com.vaadin.terminal.PaintException; | ||||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | import com.vaadin.terminal.gwt.client.MouseEventDetails; | ||||
import com.vaadin.terminal.gwt.client.ui.VTree; | import com.vaadin.terminal.gwt.client.ui.VTree; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers; | import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers; | ||||
import com.vaadin.terminal.gwt.client.ui.dd.VOverTreeNode; | |||||
/** | /** | ||||
* Tree component. A Tree can be used to select an item (or multiple items) from | * Tree component. A Tree can be used to select an item (or multiple items) from | ||||
} | } | ||||
class TreeTransferable extends DataBoundTransferable { | |||||
public TreeTransferable(Component sourceComponent, | |||||
Map<String, Object> rawVariables) { | |||||
super(sourceComponent, rawVariables); | |||||
} | |||||
@Override | |||||
public Object getItemId() { | |||||
return getData("itemId"); | |||||
} | |||||
@Override | |||||
public Object getPropertyId() { | |||||
return getItemCaptionPropertyId(); | |||||
} | |||||
} | |||||
public Transferable getTransferable(Map<String, Object> payload) { | |||||
TreeTransferable transferable = new TreeTransferable(this, payload); | |||||
// updating drag source variables | |||||
Object object = payload.get("itemId"); | |||||
if (object != null) { | |||||
transferable.setData("itemId", itemIdMapper.get((String) object)); | |||||
} | |||||
return transferable; | |||||
} | |||||
/* Tree constructors */ | /* Tree constructors */ | ||||
/** | /** | ||||
TOP, BOTTOM, MIDDLE; | TOP, BOTTOM, MIDDLE; | ||||
} | } | ||||
public class TreeDropDetails extends AbstractSelectDropDetails { | |||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public class TreeDropTargetDetails extends AbstractSelectDropTargetDetails { | |||||
TreeDropDetails(Map<String, Object> rawVariables) { | |||||
TreeDropTargetDetails(Map<String, Object> rawVariables) { | |||||
super(rawVariables); | super(rawVariables); | ||||
} | } | ||||
} | } | ||||
public TreeDropDetails translateDragDropDetails( | |||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public TreeDropTargetDetails translateDropTargetDetails( | |||||
Map<String, Object> clientVariables) { | Map<String, Object> clientVariables) { | ||||
return new TreeDropDetails(clientVariables); | |||||
return new TreeDropTargetDetails(clientVariables); | |||||
} | } | ||||
/** | /** | ||||
return itemIdMapper.key(itemId); | return itemIdMapper.key(itemId); | ||||
} | } | ||||
/** | |||||
* TODO Javadoc! | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
public class TreeTransferable extends DataBoundTransferable { | |||||
public TreeTransferable(Component sourceComponent, | |||||
Map<String, Object> rawVariables) { | |||||
super(sourceComponent, rawVariables); | |||||
} | |||||
@Override | |||||
public Object getItemId() { | |||||
return getData("itemId"); | |||||
} | |||||
@Override | |||||
public Object getPropertyId() { | |||||
return getItemCaptionPropertyId(); | |||||
} | |||||
} | |||||
/* | |||||
* (non-Javadoc) | |||||
* | |||||
* @see com.vaadin.event.dd.DragSource#getTransferable(java.util.Map) | |||||
*/ | |||||
public Transferable getTransferable(Map<String, Object> payload) { | |||||
TreeTransferable transferable = new TreeTransferable(this, payload); | |||||
// updating drag source variables | |||||
Object object = payload.get("itemId"); | |||||
if (object != null) { | |||||
transferable.setData("itemId", itemIdMapper.get((String) object)); | |||||
} | |||||
return transferable; | |||||
} | |||||
/** | /** | ||||
* An example of lazy initializing criterion. Initially pretty much no data | * An example of lazy initializing criterion. Initially pretty much no data | ||||
* is sent to client, on first accepts set (per drag request) the client | * is sent to client, on first accepts set (per drag request) the client | ||||
* .event.dd.DragAndDropEvent) | * .event.dd.DragAndDropEvent) | ||||
*/ | */ | ||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { | ||||
AbstractSelectDropDetails dropTargetData = (AbstractSelectDropDetails) dragEvent | |||||
.getDropTargetData(); | |||||
tree = (Tree) dragEvent.getDropTargetData().getTarget(); | |||||
AbstractSelectDropTargetDetails dropTargetData = (AbstractSelectDropTargetDetails) dragEvent | |||||
.getDropTargetDetails(); | |||||
tree = (Tree) dragEvent.getDropTargetDetails().getTarget(); | |||||
allowedItemIds = getAllowedItemIds(dragEvent, tree); | allowedItemIds = getAllowedItemIds(dragEvent, tree); | ||||
return allowedItemIds.contains(dropTargetData.getItemIdOver()); | return allowedItemIds.contains(dropTargetData.getItemIdOver()); | ||||
} | } | ||||
/** | |||||
* Accepts transferable only on tree Node (middle of the node + can has | |||||
* child) | |||||
* | |||||
* @since 6.3 | |||||
*/ | |||||
@ClientCriterion(VOverTreeNode.class) | |||||
public static class OverTreeNode extends ClientSideCriterion { | |||||
private static final long serialVersionUID = 1L; | |||||
public boolean accepts(DragAndDropEvent dragEvent) { | |||||
try { | |||||
// must be over tree node and in the middle of it (not top or | |||||
// bottom part) | |||||
TreeDropTargetDetails eventDetails = (TreeDropTargetDetails) dragEvent | |||||
.getDropTargetDetails(); | |||||
Object itemIdOver = eventDetails.getItemIdOver(); | |||||
if (!eventDetails.getTarget().areChildrenAllowed(itemIdOver)) { | |||||
return false; | |||||
} | |||||
return eventDetails.getDropLocation() == Location.MIDDLE; | |||||
} catch (Exception e) { | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
} | } |
public void drop(DragAndDropEvent event) { | public void drop(DragAndDropEvent event) { | ||||
WrapperDropDetails ed = (WrapperDropDetails) event | WrapperDropDetails ed = (WrapperDropDetails) event | ||||
.getDropTargetData(); | |||||
.getDropTargetDetails(); | |||||
Transferable transferable = event.getTransferable(); | Transferable transferable = event.getTransferable(); | ||||
TransferableImpl ctr = (TransferableImpl) transferable; | TransferableImpl ctr = (TransferableImpl) transferable; | ||||
Component component = ctr.getSourceComponent(); | Component component = ctr.getSourceComponent(); |
}; | }; | ||||
} | } | ||||
public DropTargetDetails translateDragDropDetails( | |||||
public DropTargetDetails translateDropTargetDetails( | |||||
Map<String, Object> clientVariables) { | Map<String, Object> clientVariables) { | ||||
// If component has some special drop details that it needs to | // If component has some special drop details that it needs to | ||||
// translate for server side use, developer must return a | // translate for server side use, developer must return a |
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.event.dd.DropHandler; | import com.vaadin.event.dd.DropHandler; | ||||
import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | ||||
import com.vaadin.event.dd.acceptCriteria.IsDatabound; | |||||
import com.vaadin.event.dd.acceptCriteria.IsDataBound; | |||||
import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; | import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; | ||||
import com.vaadin.terminal.ExternalResource; | import com.vaadin.terminal.ExternalResource; | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.Link; | import com.vaadin.ui.Link; | ||||
import com.vaadin.ui.Table; | import com.vaadin.ui.Table; | ||||
import com.vaadin.ui.Tree; | import com.vaadin.ui.Tree; | ||||
import com.vaadin.ui.AbstractSelect.AbstractSelectDropDetails; | |||||
import com.vaadin.ui.AbstractSelect.AbstractSelectDropTargetDetails; | |||||
import com.vaadin.ui.Table.DragModes; | import com.vaadin.ui.Table.DragModes; | ||||
import com.vaadin.ui.Tree.Location; | import com.vaadin.ui.Tree.Location; | ||||
} | } | ||||
public void drop(DragAndDropEvent event) { | public void drop(DragAndDropEvent event) { | ||||
AbstractSelectDropDetails details = (AbstractSelectDropDetails) event | |||||
.getDropTargetData(); | |||||
AbstractSelectDropTargetDetails details = (AbstractSelectDropTargetDetails) event | |||||
.getDropTargetDetails(); | |||||
// TODO set properties, so same sorter could be used in Table | // TODO set properties, so same sorter could be used in Table | ||||
Transferable transferable = event.getTransferable(); | Transferable transferable = event.getTransferable(); | ||||
if (transferable instanceof DataBoundTransferable) { | if (transferable instanceof DataBoundTransferable) { | ||||
public AcceptCriterion getAcceptCriterion() { | public AcceptCriterion getAcceptCriterion() { | ||||
// TODO should actually check that source is same as target | // TODO should actually check that source is same as target | ||||
return IsDatabound.get(); | |||||
return IsDataBound.get(); | |||||
} | } | ||||
}; | }; |
import com.vaadin.event.dd.DropHandler; | import com.vaadin.event.dd.DropHandler; | ||||
import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | ||||
import com.vaadin.event.dd.acceptCriteria.And; | import com.vaadin.event.dd.acceptCriteria.And; | ||||
import com.vaadin.event.dd.acceptCriteria.ComponentFilter; | |||||
import com.vaadin.event.dd.acceptCriteria.IsDatabound; | |||||
import com.vaadin.event.dd.acceptCriteria.IsDragSource; | |||||
import com.vaadin.event.dd.acceptCriteria.IsDataBound; | |||||
import com.vaadin.event.dd.acceptCriteria.Or; | import com.vaadin.event.dd.acceptCriteria.Or; | ||||
import com.vaadin.event.dd.acceptCriteria.OverTreeNode; | |||||
import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; | import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; | ||||
import com.vaadin.terminal.Resource; | import com.vaadin.terminal.Resource; | ||||
import com.vaadin.terminal.ThemeResource; | import com.vaadin.terminal.ThemeResource; | ||||
import com.vaadin.ui.Table; | import com.vaadin.ui.Table; | ||||
import com.vaadin.ui.Tree; | import com.vaadin.ui.Tree; | ||||
import com.vaadin.ui.Window; | import com.vaadin.ui.Window; | ||||
import com.vaadin.ui.AbstractSelect.AbstractSelectDropDetails; | |||||
import com.vaadin.ui.Tree.TreeDropDetails; | |||||
import com.vaadin.ui.AbstractSelect.AbstractSelectDropTargetDetails; | |||||
import com.vaadin.ui.Tree.OverTreeNode; | |||||
import com.vaadin.ui.Tree.TreeDropTargetDetails; | |||||
public class DDTest2 extends TestBase { | public class DDTest2 extends TestBase { | ||||
final AcceptCriterion crit = new ServerSideCriterion() { | final AcceptCriterion crit = new ServerSideCriterion() { | ||||
public boolean accepts(DragAndDropEvent dragEvent) { | public boolean accepts(DragAndDropEvent dragEvent) { | ||||
TreeDropDetails dropTargetData = (TreeDropDetails) dragEvent | |||||
.getDropTargetData(); | |||||
TreeDropTargetDetails dropTargetData = (TreeDropTargetDetails) dragEvent | |||||
.getDropTargetDetails(); | |||||
Object itemIdOver = dropTargetData.getItemIdOver(); | Object itemIdOver = dropTargetData.getItemIdOver(); | ||||
data = "-no Text data flawor-"; | data = "-no Text data flawor-"; | ||||
} | } | ||||
tree3.addItem(data); | tree3.addItem(data); | ||||
AbstractSelect.AbstractSelectDropDetails dropTargetData = (AbstractSelect.AbstractSelectDropDetails) dropEvent | |||||
.getDropTargetData(); | |||||
AbstractSelect.AbstractSelectDropTargetDetails dropTargetData = (AbstractSelect.AbstractSelectDropTargetDetails) dropEvent | |||||
.getDropTargetDetails(); | |||||
tree3.setParent(data, dropTargetData.getItemIdOver()); | tree3.setParent(data, dropTargetData.getItemIdOver()); | ||||
} | } | ||||
table.setDragMode(Table.DragModes.ROWS); | table.setDragMode(Table.DragModes.ROWS); | ||||
OverTreeNode onNode = new OverTreeNode(); | OverTreeNode onNode = new OverTreeNode(); | ||||
ComponentFilter fromTable = new ComponentFilter(table); | |||||
IsDragSource fromTable = new IsDragSource(table); | |||||
ComponentFilter fromTree = new ComponentFilter(tree1); | |||||
IsDragSource fromTree = new IsDragSource(tree1); | |||||
final Or fromTree1OrTable = new Or(fromTable, fromTree); | final Or fromTree1OrTable = new Or(fromTable, fromTree); | ||||
final And and = new And(fromTree1OrTable, onNode); | final And and = new And(fromTree1OrTable, onNode); | ||||
* As we also accept only drops on folders, we know dropDetails | * As we also accept only drops on folders, we know dropDetails | ||||
* is from Tree and it contains itemIdOver. | * is from Tree and it contains itemIdOver. | ||||
*/ | */ | ||||
AbstractSelectDropDetails details = (AbstractSelectDropDetails) event | |||||
.getDropTargetData(); | |||||
AbstractSelectDropTargetDetails details = (AbstractSelectDropTargetDetails) event | |||||
.getDropTargetDetails(); | |||||
Object idOver = details.getItemIdOver(); | Object idOver = details.getItemIdOver(); | ||||
tree1.setParent(itemId, idOver); | tree1.setParent(itemId, idOver); | ||||
dropHandler = new DropHandler() { | dropHandler = new DropHandler() { | ||||
public void drop(DragAndDropEvent event) { | public void drop(DragAndDropEvent event) { | ||||
AbstractSelectDropDetails details = (AbstractSelectDropDetails) event | |||||
.getDropTargetData(); | |||||
AbstractSelectDropTargetDetails details = (AbstractSelectDropTargetDetails) event | |||||
.getDropTargetDetails(); | |||||
Transferable transferable = event.getTransferable(); | Transferable transferable = event.getTransferable(); | ||||
if (transferable instanceof DataBoundTransferable) { | if (transferable instanceof DataBoundTransferable) { | ||||
} | } | ||||
public AcceptCriterion getAcceptCriterion() { | public AcceptCriterion getAcceptCriterion() { | ||||
return IsDatabound.get(); | |||||
return IsDataBound.get(); | |||||
} | } | ||||
}; | }; | ||||
import com.vaadin.event.dd.DragAndDropEvent; | import com.vaadin.event.dd.DragAndDropEvent; | ||||
import com.vaadin.event.dd.DropHandler; | import com.vaadin.event.dd.DropHandler; | ||||
import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | ||||
import com.vaadin.event.dd.acceptCriteria.ComponentFilter; | |||||
import com.vaadin.event.dd.acceptCriteria.IsDragSource; | |||||
import com.vaadin.terminal.ThemeResource; | import com.vaadin.terminal.ThemeResource; | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
import com.vaadin.ui.Table; | import com.vaadin.ui.Table; | ||||
import com.vaadin.ui.Tree; | import com.vaadin.ui.Tree; | ||||
import com.vaadin.ui.Window; | import com.vaadin.ui.Window; | ||||
import com.vaadin.ui.AbstractSelect.AbstractSelectDropDetails; | |||||
import com.vaadin.ui.AbstractSelect.AbstractSelectDropTargetDetails; | |||||
import com.vaadin.ui.Tree.Location; | import com.vaadin.ui.Tree.Location; | ||||
public class DDTest4 extends TestBase { | public class DDTest4 extends TestBase { | ||||
table.setDropHandler(new DropHandler() { | table.setDropHandler(new DropHandler() { | ||||
// accept only drags from this table | // accept only drags from this table | ||||
AcceptCriterion crit = new ComponentFilter(table); | |||||
AcceptCriterion crit = new IsDragSource(table); | |||||
public AcceptCriterion getAcceptCriterion() { | public AcceptCriterion getAcceptCriterion() { | ||||
return crit; | return crit; | ||||
} | } | ||||
public void drop(DragAndDropEvent dropEvent) { | public void drop(DragAndDropEvent dropEvent) { | ||||
AbstractSelectDropDetails dropTargetData = (AbstractSelectDropDetails) dropEvent | |||||
.getDropTargetData(); | |||||
AbstractSelectDropTargetDetails dropTargetData = (AbstractSelectDropTargetDetails) dropEvent | |||||
.getDropTargetDetails(); | |||||
DataBoundTransferable transferable = (DataBoundTransferable) dropEvent | DataBoundTransferable transferable = (DataBoundTransferable) dropEvent | ||||
.getTransferable(); | .getTransferable(); | ||||
Object itemIdOver = dropTargetData.getItemIdOver(); | Object itemIdOver = dropTargetData.getItemIdOver(); |
Component draggedComponent = transferable | Component draggedComponent = transferable | ||||
.getDraggedComponent(); | .getDraggedComponent(); | ||||
DropTarget target = dropEvent.getDropTargetData() | |||||
DropTarget target = dropEvent.getDropTargetDetails() | |||||
.getTarget(); | .getTarget(); | ||||
WrappedLabel wrappedLabel = new WrappedLabel( | WrappedLabel wrappedLabel = new WrappedLabel( | ||||
cssLayout.removeComponent(sourceComponent); | cssLayout.removeComponent(sourceComponent); | ||||
wrappedLabel = (WrappedLabel) sourceComponent; | wrappedLabel = (WrappedLabel) sourceComponent; | ||||
} | } | ||||
if (dropEvent.getDropTargetData().getData( | |||||
if (dropEvent.getDropTargetDetails().getData( | |||||
"verticalLocation").equals("TOP")) { | "verticalLocation").equals("TOP")) { | ||||
// before reference if dropped on topmost part | // before reference if dropped on topmost part | ||||
i--; | i--; |
import com.vaadin.event.dd.DropTargetDetails; | import com.vaadin.event.dd.DropTargetDetails; | ||||
import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; | ||||
import com.vaadin.event.dd.acceptCriteria.And; | import com.vaadin.event.dd.acceptCriteria.And; | ||||
import com.vaadin.event.dd.acceptCriteria.DropDetailEquals; | |||||
import com.vaadin.event.dd.acceptCriteria.DropTargetDetailEquals; | |||||
import com.vaadin.event.dd.acceptCriteria.Not; | import com.vaadin.event.dd.acceptCriteria.Not; | ||||
import com.vaadin.event.dd.acceptCriteria.SourceIsSameAsTarget; | |||||
import com.vaadin.event.dd.acceptCriteria.IsSameSourceAndTarget; | |||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
import com.vaadin.ui.DragAndDropWrapper; | import com.vaadin.ui.DragAndDropWrapper; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
} | } | ||||
private DropHandler dh = new DropHandler() { | private DropHandler dh = new DropHandler() { | ||||
AcceptCriterion crit = new And(new DropDetailEquals( | |||||
AcceptCriterion crit = new And(new DropTargetDetailEquals( | |||||
"horizontalLocation", "LEFT"), new Not( | "horizontalLocation", "LEFT"), new Not( | ||||
new SourceIsSameAsTarget())); | |||||
new IsSameSourceAndTarget())); | |||||
public AcceptCriterion getAcceptCriterion() { | public AcceptCriterion getAcceptCriterion() { | ||||
return crit; | return crit; | ||||
.getComponentIterator(); | .getComponentIterator(); | ||||
Component next = componentIterator.next(); | Component next = componentIterator.next(); | ||||
DropTargetDetails dropTargetData = dropEvent | DropTargetDetails dropTargetData = dropEvent | ||||
.getDropTargetData(); | |||||
.getDropTargetDetails(); | |||||
DropTarget target = dropTargetData.getTarget(); | DropTarget target = dropTargetData.getTarget(); | ||||
while (next != target) { | while (next != target) { | ||||
if (next != sourceComponent) { | if (next != sourceComponent) { |
.getComponentIterator(); | .getComponentIterator(); | ||||
Component next = componentIterator.next(); | Component next = componentIterator.next(); | ||||
DropTargetDetails dropTargetData = dropEvent | DropTargetDetails dropTargetData = dropEvent | ||||
.getDropTargetData(); | |||||
.getDropTargetDetails(); | |||||
DropTarget target = dropTargetData.getTarget(); | DropTarget target = dropTargetData.getTarget(); | ||||
while (next != target) { | while (next != target) { | ||||
if (next != sourceComponent) { | if (next != sourceComponent) { |