Search in sources :

Example 1 with DDLayoutState

use of com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DDLayoutState in project cuba by cuba-platform.

the class VDragCaptionProvider method getDragCaptionElement.

public Element getDragCaptionElement(Widget w) {
    ComponentConnector component = Util.findConnectorFor(w);
    DDLayoutState state = ((DragAndDropAwareState) root.getState()).getDragAndDropState();
    DragCaptionInfo dci = state.dragCaptions.get(component);
    Document document = Document.get();
    Element dragCaptionImage = document.createDivElement();
    Element dragCaption = document.createSpanElement();
    String dragCaptionText = dci.caption;
    if (dragCaptionText != null) {
        if (dci.contentMode == ContentMode.TEXT) {
            dragCaption.setInnerText(dragCaptionText);
        } else if (dci.contentMode == ContentMode.HTML) {
            dragCaption.setInnerHTML(dragCaptionText);
        } else if (dci.contentMode == ContentMode.PREFORMATTED) {
            PreElement preElement = document.createPreElement();
            preElement.setInnerText(dragCaptionText);
            dragCaption.appendChild(preElement);
        }
    }
    String dragIconKey = state.dragCaptions.get(component).iconKey;
    if (dragIconKey != null) {
        String resourceUrl = root.getResourceUrl(dragIconKey);
        Icon icon = component.getConnection().getIcon(resourceUrl);
        dragCaptionImage.appendChild(icon.getElement());
    }
    dragCaptionImage.appendChild(dragCaption);
    return dragCaptionImage;
}
Also used : DDLayoutState(com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DDLayoutState) ComponentConnector(com.vaadin.client.ComponentConnector) PreElement(com.google.gwt.dom.client.PreElement) PreElement(com.google.gwt.dom.client.PreElement) Element(com.google.gwt.dom.client.Element) DragAndDropAwareState(com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DragAndDropAwareState) Icon(com.vaadin.client.ui.Icon) Document(com.google.gwt.dom.client.Document)

Example 2 with DDLayoutState

use of com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DDLayoutState in project cuba by cuba-platform.

the class DDUtil method onBeforeClientResponse.

public static void onBeforeClientResponse(HasComponents layout, DragAndDropAwareState state) {
    DDLayoutState dragAndDropState = state.getDragAndDropState();
    Iterator<Component> componentIterator = layout.iterator();
    dragAndDropState.draggable = new ArrayList<>();
    dragAndDropState.referenceImageComponents = new HashMap<>();
    dragAndDropState.nonGrabbable = new ArrayList<>();
    dragAndDropState.dragCaptions = new HashMap<>();
    if (layout instanceof AbstractClientConnector) {
        for (DragCaptionInfo dci : dragAndDropState.dragCaptions.values()) {
            if (dci.iconKey != null) {
                ((AbstractClientConnector) layout).setConnectorResource(dci.iconKey, null);
            }
        }
    }
    KeyMapper<Resource> keyMapper = new KeyMapper<>();
    while (componentIterator.hasNext()) {
        Component c = componentIterator.next();
        if (layout instanceof DragFilterSupport && ((DragFilterSupport) layout).getDragFilter().isDraggable(c)) {
            dragAndDropState.draggable.add(c);
        }
        if (layout instanceof DragGrabFilterSupport) {
            DragGrabFilter dragGrabFilter = ((DragGrabFilterSupport) layout).getDragGrabFilter();
            if (dragGrabFilter != null) {
                addNonGrabbedComponents(dragAndDropState.nonGrabbable, c, dragGrabFilter);
            }
        }
        if (layout instanceof HasDragCaptionProvider) {
            DragCaptionProvider dragCaptionProvider = ((HasDragCaptionProvider) layout).getDragCaptionProvider();
            if (dragCaptionProvider != null) {
                DragCaption dragCaption = dragCaptionProvider.getDragCaption(c);
                if (dragCaption != null) {
                    String dragIconKey = null;
                    if (dragCaption.getIcon() != null && layout instanceof AbstractClientConnector) {
                        dragIconKey = keyMapper.key(dragCaption.getIcon());
                        ((AbstractClientConnector) layout).setConnectorResource(dragIconKey, dragCaption.getIcon());
                    }
                    DragCaptionInfo dci = new DragCaptionInfo();
                    dci.caption = dragCaption.getCaption();
                    dci.contentMode = dragCaption.getContentMode();
                    dci.iconKey = dragIconKey;
                    dragAndDropState.dragCaptions.put(c, dci);
                }
            }
        }
        if (layout instanceof DragImageReferenceSupport) {
            DragImageProvider provider = ((DragImageReferenceSupport) layout).getDragImageProvider();
            if (provider != null) {
                Component dragImage = provider.getDragImage(c);
                if (dragImage != null) {
                    dragAndDropState.referenceImageComponents.put(c, dragImage);
                }
            }
        }
    }
}
Also used : DDLayoutState(com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DDLayoutState) KeyMapper(com.vaadin.server.KeyMapper) Resource(com.vaadin.server.Resource) AbstractClientConnector(com.vaadin.server.AbstractClientConnector) DragCaptionInfo(com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.DragCaptionInfo) Component(com.vaadin.ui.Component)

Aggregations

DDLayoutState (com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DDLayoutState)2 Document (com.google.gwt.dom.client.Document)1 Element (com.google.gwt.dom.client.Element)1 PreElement (com.google.gwt.dom.client.PreElement)1 DragCaptionInfo (com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.DragCaptionInfo)1 DragAndDropAwareState (com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.interfaces.DragAndDropAwareState)1 ComponentConnector (com.vaadin.client.ComponentConnector)1 Icon (com.vaadin.client.ui.Icon)1 AbstractClientConnector (com.vaadin.server.AbstractClientConnector)1 KeyMapper (com.vaadin.server.KeyMapper)1 Resource (com.vaadin.server.Resource)1 Component (com.vaadin.ui.Component)1