Example usage for org.apache.wicket.ajax.markup.html.form AjaxSubmitLink getMarkupId

List of usage examples for org.apache.wicket.ajax.markup.html.form AjaxSubmitLink getMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html.form AjaxSubmitLink getMarkupId.

Prototype

public String getMarkupId() 

Source Link

Document

Retrieves id by which this component is represented within the markup.

Usage

From source file:com.visural.stereotyped.ui.prototype.TreePanel.java

License:Mozilla Public License

public TreePanel(String id, final OperableTreeNode node) {
    super(id);/*  w ww. j a v a 2 s  .c  o  m*/
    WebMarkupContainer container = new WebMarkupContainer("container");
    add(container);
    if (node.getComponent() != null && !Stereotype.class.isAssignableFrom(node.getComponent().getClass())) {
        container.add(new DragSource(Operation.MOVE) {
            @Override
            public void onBeforeDrop(Component drag, Transfer transfer) throws Reject {
                if (!allowDragAndDrop()) {
                    transfer.reject();
                } else {
                    transfer.setData(node);
                }
            }
        }.drag("a"));
    }
    DropTarget componentDrop = null;
    if (node.getSlot() != null
            || (node.getComponent().getSlots() != null && node.getComponent().getSlots().size() == 1)) {
        DropTarget newDt = new DropTarget(Operation.MOVE) {
            @Override
            public void onDrop(AjaxRequestTarget target, Transfer transfer, Location location) throws Reject {
                Slot slot = node.getSlot() != null ? node.getSlot() : node.getComponent().getSlots().get(0);
                OperableTreeNode otn = transfer.getData();
                if (otn != null && otn.getComponent() != null && slot.acceptComponent(otn.getComponent())) {
                    if (otn.getComponent().contains(slot)) {
                        transfer.reject(); // drop component on self or child of self
                    } else {
                        com.visural.stereotyped.core.Component com = otn.getComponent();
                        com.delete();
                        slot.addComponent(com);
                        updateTree(target);
                        invokePreviewRefresh(target);
                    }
                } else {
                    transfer.reject();
                }
            }
        };
        if (node.getSlot() != null) {
            container.add(newDt.dropCenter("a"));
        } else {
            componentDrop = newDt;
        }
    }
    if (node.getComponent() != null && !Stereotype.class.isAssignableFrom(node.getComponent().getClass())) {
        final DropTarget dtComp = componentDrop;
        DropTarget dtNew = new DropTarget(Operation.MOVE) {
            @Override
            public void onDrop(AjaxRequestTarget target, Transfer transfer, Location location) throws Reject {
                Slot slot = node.getComponent().getParentSlot();
                if (location.getAnchor().equals(Anchor.CENTER)) {
                    dtComp.onDrop(target, transfer, location);
                } else {
                    OperableTreeNode otn = transfer.getData();
                    if (otn != null && otn.getComponent() != null && slot.acceptComponent(otn.getComponent())) {
                        com.visural.stereotyped.core.Component com = otn.getComponent();
                        if (com.getUuid().equals(node.getComponent().getUuid())) {
                            transfer.reject(); // drop component next to self
                        } else if (com.contains(slot)) {
                            transfer.reject(); // drop component on self or child of self
                        } else {
                            switch (location.getAnchor()) {
                            case TOP:
                            case LEFT: {
                                com.delete();
                                int idx = slot.getContent().indexOf(node.getComponent());
                                if (idx < 0) {
                                    throw new IllegalStateException("Drop component was not in expected slot.");
                                }
                                slot.addComponent(idx, com);
                                updateTree(target);
                                invokePreviewRefresh(target);
                            }
                                break;
                            case BOTTOM:
                            case RIGHT: {
                                com.delete();
                                int idx = slot.getContent().indexOf(node.getComponent());
                                if (idx < 0) {
                                    throw new IllegalStateException("Drop component was not in expected slot.");
                                }
                                if (idx == slot.getContent().size() - 1) {
                                    slot.addComponent(com);
                                } else {
                                    slot.addComponent(idx + 1, com);
                                }
                                updateTree(target);
                                invokePreviewRefresh(target);
                            }
                                break;
                            default:
                                transfer.reject();
                            }
                        }
                    } else {
                        transfer.reject();
                    }
                }
            }
        }.dropTopAndBottom("a");
        if (componentDrop != null) {
            dtNew.dropCenter("a");
        }
        container.add(dtNew);
    }

    AjaxSubmitLink link = new AjaxSubmitLink("link") {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            select(target);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (isSelected()) {
                tag.put("class", "selected");
            }
            tag.put("onmouseover",
                    "doHighlight('" + ComponentRenderer.STCOM_UUID_PREFIX + node.getUuid().toString() + "');");
            tag.put("onmouseout", "removeHighlight();");
        }
    };
    container.add(link);
    if (node.getComponent() != null) {
        link.add(new Image("icon", node.getComponent().getIcon()));
        link.add(new Label("label", new AbstractReadOnlyModel() {
            @Override
            public Object getObject() {
                return node.getComponent().getName() + (node.getComponent().isHide() ? " [hidden]" : "");
            }
        }));
    } else {
        link.add(new Image("icon", new SlotIcon()));
        link.add(new Label("label", new AbstractReadOnlyModel() {
            @Override
            public Object getObject() {
                return Function.nvl(node.getSlot().getDisplayName(), node.getSlot().getName());
            }
        }));
    }

    final Slot slot = node.getSlot() != null ? node.getSlot()
            : (node.getComponent() != null && node.getComponent().getSlots() != null
                    && node.getComponent().getSlots().size() == 1 ? node.getComponent().getSlots().get(0)
                            : null);

    if (slot == null) {
        container.add(new WebMarkupContainer("addComp").setVisible(false));
    } else {
        AjaxSubmitLink addComp;
        container.add(addComp = new AjaxSubmitLink("addComp") {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                invokeAdd(target, slot);
            }
        });
        addComp.setOutputMarkupId(true);
        container.add(
                new SimpleAttributeModifier("onmouseover", "jQuery('#" + addComp.getMarkupId() + "').show();"));
        container.add(
                new SimpleAttributeModifier("onmouseout", "jQuery('#" + addComp.getMarkupId() + "').hide();"));
    }
}