use of com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior in project servoy-client by Servoy.
the class WebDataRenderer method addDragNDropBehavior.
private void addDragNDropBehavior() {
DraggableBehavior dragBehavior = new DraggableBehavior() {
private IComponent hoverComponent;
private boolean isHoverAcceptDrop;
@Override
protected void onDragEnd(String id, int x, int y, int m, AjaxRequestTarget ajaxRequestTarget) {
if (getCurrentDragOperation() != DRAGNDROP.NONE) {
JSDNDEvent event = WebDataRenderer.this.createScriptEvent(EventType.onDragEnd, getDragComponent(), null, m);
event.setData(getDragData());
event.setDataMimeType(getDragDataMimeType());
event.setDragResult(getDropResult() ? getCurrentDragOperation() : DRAGNDROP.NONE);
WebDataRenderer.this.onDragEnd(event);
}
super.onDragEnd(id, x, y, m, ajaxRequestTarget);
}
@Override
protected boolean onDragStart(final String id, int x, int y, int m, AjaxRequestTarget ajaxRequestTarget) {
IComponent comp = getBindedComponentChild(id);
JSDNDEvent event = WebDataRenderer.this.createScriptEvent(EventType.onDrag, comp, new Point(x, y), m);
setDropResult(false);
int dragOp = WebDataRenderer.this.onDrag(event);
if (dragOp == DRAGNDROP.NONE)
return false;
setCurrentDragOperation(dragOp);
setDragComponent(comp);
setDragData(event.getData(), event.getDataMimeType());
hoverComponent = null;
isHoverAcceptDrop = false;
return true;
}
@Override
protected void onDrop(String id, final String targetid, int x, int y, int m, AjaxRequestTarget ajaxRequestTarget) {
if (getCurrentDragOperation() != DRAGNDROP.NONE) {
IComponent comp = getBindedComponentChild(targetid);
if (hoverComponent == comp && !isHoverAcceptDrop)
return;
WebDataRenderer renderer = WebDataRenderer.this;
JSDNDEvent event = renderer.createScriptEvent(EventType.onDrop, comp, new Point(x, y), m);
event.setData(getDragData());
event.setDataMimeType(getDragDataMimeType());
setDropResult(renderer.onDrop(event));
}
}
// private ISupportDragNDrop testTarget(ISupportDragNDrop ddComp, JSEvent event)
// {
// if (event.js_getSource() instanceof SpecialTabPanel)
// {
// SpecialTabPanel tabPanel = (SpecialTabPanel)event.js_getSource();
// Component selectedComponent = tabPanel.getEnclosingComponent().getSelectedComponent();
// if (selectedComponent instanceof FormLookupPanel)
// {
// FormController formControler = ((FormLookupPanel)selectedComponent).getFormPanel();
// event.setSource(null);
// event.setFormName(formControler.getName());
// event.setElementName(null);
// return (ISupportDragNDrop)formControler.getViewComponent();
// }
// }
// return ddComp;
// }
@Override
protected void onDropHover(String id, final String targetid, int m, AjaxRequestTarget ajaxRequestTarget) {
if (getCurrentDragOperation() != DRAGNDROP.NONE) {
IComponent comp = getBindedComponentChild(targetid);
JSDNDEvent event = WebDataRenderer.this.createScriptEvent(EventType.onDragOver, comp, null, m);
event.setData(getDragData());
event.setDataMimeType(getDragDataMimeType());
isHoverAcceptDrop = WebDataRenderer.this.onDragOver(event);
hoverComponent = comp;
}
}
@Override
public IComponent getBindedComponentChild(final String childId) {
IComponent comp = super.getBindedComponentChild(childId);
if (comp == null)
comp = WebDataRenderer.this;
return comp;
}
};
dragBehavior.setUseProxy(true);
add(dragBehavior);
}
use of com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior 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);
}
}
use of com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method addDragNDropBehavior.
private void addDragNDropBehavior() {
DraggableBehavior compDragBehavior = new DraggableBehavior() {
private IComponent hoverComponent;
private boolean isHoverAcceptDrop;
@Override
protected void onDragEnd(String id, int x, int y, int m, AjaxRequestTarget ajaxRequestTarget) {
if (getCurrentDragOperation() != DRAGNDROP.NONE) {
JSDNDEvent event = WebCellBasedView.this.createScriptEvent(EventType.onDragEnd, getDragComponent(), null, m);
event.setData(getDragData());
event.setDataMimeType(getDragDataMimeType());
event.setDragResult(getDropResult() ? getCurrentDragOperation() : DRAGNDROP.NONE);
WebCellBasedView.this.onDragEnd(event);
}
super.onDragEnd(id, x, y, m, ajaxRequestTarget);
}
@Override
protected boolean onDragStart(final String id, int x, int y, int m, AjaxRequestTarget ajaxRequestTarget) {
IComponent comp = getBindedComponentChild(id);
JSDNDEvent event = WebCellBasedView.this.createScriptEvent(EventType.onDrag, comp, new Point(x, y), m);
int dragOp = WebCellBasedView.this.onDrag(event);
if (dragOp == DRAGNDROP.NONE)
return false;
setCurrentDragOperation(dragOp);
setDragData(event.getData(), event.getDataMimeType());
setDragComponent(comp);
setDropResult(false);
hoverComponent = null;
isHoverAcceptDrop = false;
return true;
}
@Override
protected void onDrop(String id, final String targetid, int x, int y, int m, AjaxRequestTarget ajaxRequestTarget) {
if (getCurrentDragOperation() != DRAGNDROP.NONE) {
IComponent comp = getBindedComponentChild(targetid);
if (hoverComponent == comp && !isHoverAcceptDrop)
return;
JSDNDEvent event = WebCellBasedView.this.createScriptEvent(EventType.onDrop, comp, new Point(x, y), m);
event.setData(getDragData());
event.setDataMimeType(getDragDataMimeType());
setDropResult(WebCellBasedView.this.onDrop(event));
}
}
@Override
protected void onDropHover(String id, final String targetid, int m, AjaxRequestTarget ajaxRequestTarget) {
if (getCurrentDragOperation() != DRAGNDROP.NONE) {
IComponent comp = getBindedComponentChild(targetid);
JSDNDEvent event = WebCellBasedView.this.createScriptEvent(EventType.onDragOver, comp, null, m);
event.setData(getDragData());
event.setDataMimeType(getDragDataMimeType());
isHoverAcceptDrop = WebCellBasedView.this.onDragOver(event);
hoverComponent = comp;
}
}
@Override
public IComponent getBindedComponentChild(final String childId) {
IComponent comp = super.getBindedComponentChild(childId);
if (comp == null)
comp = WebCellBasedView.this;
return comp;
}
};
compDragBehavior.setUseProxy(true);
add(compDragBehavior);
}
Aggregations