use of com.servoy.j2db.dnd.IFormDataDragNDrop in project servoy-client by Servoy.
the class WebEventExecutor method generateDragAttach.
/**
* @param component2
* @param response
*/
@SuppressWarnings("nls")
public static void generateDragAttach(Component component, IHeaderResponse response) {
DraggableBehavior draggableBehavior = null;
Component behaviorComponent = component;
if ((behaviorComponent instanceof IComponent) && !(behaviorComponent instanceof IFormDataDragNDrop)) {
behaviorComponent = (Component) component.findParent(IFormDataDragNDrop.class);
}
if (behaviorComponent != null) {
Iterator<IBehavior> behaviors = behaviorComponent.getBehaviors().iterator();
Object behavior;
while (behaviors.hasNext()) {
behavior = behaviors.next();
if (behavior instanceof DraggableBehavior) {
draggableBehavior = (DraggableBehavior) behavior;
break;
}
}
}
if (draggableBehavior == null)
return;
boolean bUseProxy = draggableBehavior.isUseProxy();
boolean bResizeProxyFrame = draggableBehavior.isResizeProxyFrame();
boolean bXConstraint = draggableBehavior.isXConstraint();
boolean bYConstraint = draggableBehavior.isYConstraint();
CharSequence dragUrl = draggableBehavior.getCallbackUrl();
String jsCode = null;
if (behaviorComponent instanceof IFormDataDragNDrop) {
final StringBuilder sbAttachDrag = new StringBuilder(100);
sbAttachDrag.append("Servoy.DD.attachDrag([");
final StringBuilder sbAttachDrop = new StringBuilder(100);
sbAttachDrop.append("Servoy.DD.attachDrop([");
final boolean hasDragEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragMethodID() > 0 || ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragOverMethodID() > 0;
final boolean hasDropEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDropMethodID() > 0;
if (component instanceof WebDataRenderer || component instanceof WebCellBasedView) {
if (hasDragEvent)
sbAttachDrag.append('\'').append(component.getMarkupId()).append("',");
if (hasDropEvent)
sbAttachDrop.append('\'').append(component.getMarkupId()).append("',");
if (component instanceof WebDataRenderer) {
Iterator<? extends Component> dataRendererIte = ((WebDataRenderer) component).iterator();
Object dataRendererChild;
while (dataRendererIte.hasNext()) {
dataRendererChild = dataRendererIte.next();
if (dataRendererChild instanceof IWebFormContainer)
continue;
if (dataRendererChild instanceof WrapperContainer)
dataRendererChild = ((WrapperContainer) dataRendererChild).getDelegate();
if (dataRendererChild instanceof IComponent && ((IComponent) dataRendererChild).isEnabled()) {
updateDragAttachOutput(dataRendererChild, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
}
} else if (component instanceof WebCellBasedView) {
ListView<IRecordInternal> table = ((WebCellBasedView) component).getTable();
table.visitChildren(new IVisitor<Component>() {
public Object component(Component comp) {
if (comp instanceof IComponent && comp.isEnabled()) {
updateDragAttachOutput(comp, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
return null;
}
});
}
} else if (component != null && component.isEnabled()) {
updateDragAttachOutput(component, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
if (sbAttachDrag.length() > 25) {
sbAttachDrag.setLength(sbAttachDrag.length() - 1);
sbAttachDrag.append("],'");
sbAttachDrag.append(dragUrl);
sbAttachDrag.append("', ");
sbAttachDrag.append(bUseProxy);
sbAttachDrag.append(", ");
sbAttachDrag.append(bResizeProxyFrame);
sbAttachDrag.append(", ");
sbAttachDrag.append(bXConstraint);
sbAttachDrag.append(", ");
sbAttachDrag.append(bYConstraint);
sbAttachDrag.append(");");
jsCode = sbAttachDrag.toString();
}
if (sbAttachDrop.length() > 25) {
sbAttachDrop.setLength(sbAttachDrop.length() - 1);
sbAttachDrop.append("],'");
sbAttachDrop.append(dragUrl);
sbAttachDrop.append("');");
if (jsCode != null)
jsCode += '\n' + sbAttachDrop.toString();
else
jsCode = sbAttachDrop.toString();
}
if (jsCode != null) {
if (response == null) {
jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
Response cyleResponse = RequestCycle.get().getResponse();
cyleResponse.write(jsCode);
} else
response.renderOnDomReadyJavascript(jsCode);
}
} else // default handling
{
jsCode = "Servoy.DD.attachDrag(['" + component.getMarkupId() + "'],'" + dragUrl + "', " + bUseProxy + ", " + bResizeProxyFrame + ", " + bXConstraint + ", " + bYConstraint + ")";
if (response == null) {
jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
Response cyleResponse = RequestCycle.get().getResponse();
cyleResponse.write(jsCode);
} else
response.renderOnDomReadyJavascript(jsCode);
}
}
Aggregations