Example usage for com.vaadin.server KeyMapper KeyMapper

List of usage examples for com.vaadin.server KeyMapper KeyMapper

Introduction

In this page you can find the example usage for com.vaadin.server KeyMapper KeyMapper.

Prototype

public KeyMapper() 

Source Link

Document

Constructs a new mapper with trivial identifierGetter .

Usage

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDUtil.java

License:Apache License

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);
            }//from   www  .  j a  v a  2 s. c o m
        }
    }

    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);
                }
            }
        }
    }
}

From source file:org.vaadin.anna.gridactionrenderer.GridActionRenderer.java

License:Apache License

/**
 * Constructor. If the contents of the actions list given as a parameter are
 * changed after this constructor is called those changes won't be taken
 * into account. The visibility of each action can be determined by row (see
 * {@link GridActionRenderer} for further details).
 *
 * @param actions//from  w ww  . ja  v a2  s  .  co m
 *            all the actions that are to be displayed by this renderer
 */
public GridActionRenderer(final List<GridAction> actions) {
    super(String.class);

    actionKeyMapper = new KeyMapper<GridAction>();
    setActions(actions);

    registerRpc(new GridActionClickRpc() {
        @Override
        public void click(int rowIndex, String actionKey, MouseEventDetails mouseDetails) {
            GridAction action = actionKeyMapper.get(actionKey);
            Object itemId = getParentGrid().getContainerDataSource().getIdByIndex(rowIndex);
            fireEvent(new GridActionClickEvent(getParentGrid(), itemId, action, mouseDetails));
        }
    });
}