Search in sources :

Example 1 with JSDNDEvent

use of com.servoy.j2db.dnd.JSDNDEvent in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method createScriptEvent.

public JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
    JSDNDEvent jsEvent = new JSDNDEvent();
    jsEvent.setType(type);
    jsEvent.setFormName(getDragFormName());
    if (dragSource instanceof IDataRenderer) {
        IDataRenderer dr = (IDataRenderer) dragSource;
        FormController fct = dr.getDataAdapterList().getFormController();
        jsEvent.setSource(fct.getFormScope());
    } else {
        jsEvent.setSource(dragSource);
        if (dragSource != null) {
            if (dragSource instanceof Component) {
                WebCellBasedViewListItem listItem = ((Component) dragSource).findParent(WebCellBasedViewListItem.class);
                if (listItem != null) {
                    IRecordInternal dragRecord = listItem.getModelObject();
                    if (dragRecord instanceof Record)
                        jsEvent.setRecord((Record) dragRecord);
                }
            }
            String dragSourceName = dragSource.getName();
            if (dragSourceName == null)
                dragSourceName = dragSource.getId();
            jsEvent.setElementName(dragSourceName);
        }
    }
    if (xy != null)
        jsEvent.setLocation(xy);
    jsEvent.setModifiers(modifiers);
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) Record(com.servoy.j2db.dataprocessing.Record) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 2 with JSDNDEvent

use of com.servoy.j2db.dnd.JSDNDEvent in project servoy-client by Servoy.

the class WebDataRenderer method createScriptEvent.

private JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
    JSDNDEvent jsEvent = new JSDNDEvent();
    jsEvent.setType(type);
    jsEvent.setFormName(getDragFormName());
    IRecordInternal dragRecord = getDragRecord(xy);
    if (dragRecord instanceof Record)
        jsEvent.setRecord((Record) dragRecord);
    if (dragSource instanceof IDataRenderer) {
        IDataRenderer dr = (IDataRenderer) dragSource;
        FormController fct = dr.getDataAdapterList().getFormController();
        jsEvent.setSource(fct.getFormScope());
    } else {
        jsEvent.setSource(dragSource);
        if (dragSource != null) {
            String dragSourceName = dragSource.getName();
            if (dragSourceName == null)
                dragSourceName = dragSource.getId();
            jsEvent.setElementName(dragSourceName);
        }
    }
    if (xy != null)
        jsEvent.setLocation(xy);
    jsEvent.setModifiers(modifiers);
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) Record(com.servoy.j2db.dataprocessing.Record)

Example 3 with JSDNDEvent

use of com.servoy.j2db.dnd.JSDNDEvent 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);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DraggableBehavior(com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IComponent(com.servoy.j2db.ui.IComponent) Point(java.awt.Point) Point(java.awt.Point)

Example 4 with JSDNDEvent

use of com.servoy.j2db.dnd.JSDNDEvent in project servoy-client by Servoy.

the class JSDNDEventType method fromJSON.

@Override
public JSDNDEvent fromJSON(Object newJSONValue, JSDNDEvent previousSabloValue, PropertyDescription pd, IBrowserConverterContext dataConverterContext, ValueReference<Boolean> returnValueAdjustedIncommingValue) {
    JSDNDEvent event = null;
    if (newJSONValue instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) newJSONValue;
        // $NON-NLS-1$
        event = getReference(jsonObject.optString("jseventhash"));
        if (event == null) {
            BaseWebObject webObject = dataConverterContext.getWebObject();
            event = new JSDNDEvent();
            JSEventType.fillJSEvent(event, jsonObject, webObject, null);
        }
    }
    return event;
}
Also used : JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) JSONObject(org.json.JSONObject) BaseWebObject(org.sablo.BaseWebObject)

Example 5 with JSDNDEvent

use of com.servoy.j2db.dnd.JSDNDEvent 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);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DraggableBehavior(com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IComponent(com.servoy.j2db.ui.IComponent) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

JSDNDEvent (com.servoy.j2db.dnd.JSDNDEvent)5 IComponent (com.servoy.j2db.ui.IComponent)3 FormController (com.servoy.j2db.FormController)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 Record (com.servoy.j2db.dataprocessing.Record)2 DraggableBehavior (com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior)2 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)2 Point (java.awt.Point)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)1 Component (org.apache.wicket.Component)1 JSONObject (org.json.JSONObject)1 BaseWebObject (org.sablo.BaseWebObject)1