Example usage for org.apache.wicket.ajax.markup.html AjaxLink add

List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink add

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html AjaxLink add.

Prototype

public MarkupContainer add(final Component... children) 

Source Link

Document

Adds the child component(s) to this container.

Usage

From source file:com.senacor.wbs.web.project.LinkPanel.java

License:Apache License

public LinkPanel(String id, ResourceReference resourceReference, final TreeNode node) {
    super(id);//  ww  w .j  a  va2  s . co m
    AjaxLink link = new AjaxLink("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            handle(node, target);
        }
    };
    link.add(new Image("image", resourceReference));
    add(link);
    setVisible(show());
}

From source file:com.swordlord.gozer.components.wicket.action.button.modal.GWModalAction.java

License:Open Source License

public GWModalAction(String id, GozerController gc, GWContext context, DataBinding binding,
        PackageResourceReference resource) {
    super(id);/*from w w  w . j  ava2s.c  o m*/

    _gc = gc;
    _binding = binding;
    _context = context;

    AjaxLink<?> link = new AjaxLink<Object>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            // add some checks!!
            GozerModalWindow window = getModalWindow();

            // HACK:
            // Oh my, what a hack... clean this up...
            if (window != null) {
                boolean bIsOK = isOK();

                if (bIsOK) {
                    DataViewBase dv = _binding.getDataBindingManager()
                            .getDataView(_binding.getDataBindingMember());
                    window.setSelectedRow(dv.getCurrentRow());
                }
                window.close(target, bIsOK);
            }
        }
    };

    _image = new Image("image", resource);

    link.add(_image);

    add(link);
}

From source file:com.swordlord.gozer.ui.modal.action.ModalAction.java

License:Open Source License

public ModalAction(String id, PackageResourceReference resource, final ModalWindowEx mw) {
    super(id);/*from w w  w  .ja  v a2s . c  om*/

    AjaxLink<?> link = new AjaxLink<Object>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            // HACK:
            // Oh my, what a hack... clean this up...
            if (mw != null) {
                boolean bIsOK = isOK();

                if (bIsOK) {
                    //window.setSelectedRow(dv.getCurrentRow());
                }
                mw.close(target, bIsOK);
            }
        }
    };

    _image = new Image("image", resource);

    link.add(_image);

    add(link);
}

From source file:com.tysanclan.site.projectewok.components.OtterSniperPanel.java

License:Open Source License

public OtterSniperPanel(String id, int otterNumber) {
    super(id);//from www.j  ava 2s. c o  m
    this.otterId = otterNumber;

    if (otterNumber > otters.length) {
        otterId = 0;
    } else if (otterNumber < 0) {
        otterId = 0;
    } else {
        otterId = otterNumber;
    }

    User currentUser = null;
    if (TysanSession.get() != null) {
        currentUser = TysanSession.get().getUser();
    }

    OtterSightingFilter filter = new OtterSightingFilter();
    filter.setUser(currentUser);
    filter.setOtterNumber(otterNumber);

    boolean hasSighting = otterSightDao.countByFilter(filter) > 0;

    AjaxLink<User> otterLink = new AjaxLink<User>("otterLink", ModelMaker.wrap(currentUser)) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            User user = getModelObject();

            if (user != null) {
                humorService.otterSighted(TysanSession.get().getUser(), otterId);
                livingGnomeContainer.setVisible(false);
                deadGnomeContainer.setVisible(true);
                target.add(deadGnomeContainer);
                target.add(livingGnomeContainer);
            }
        }
    };

    otterLink.add(new ContextImage("gnome", "images/blah/" + otters[otterId]));

    livingGnomeContainer = new WebMarkupContainer("livingGnomeContainer");
    livingGnomeContainer.setOutputMarkupPlaceholderTag(true);
    livingGnomeContainer.add(otterLink);
    livingGnomeContainer.setVisible(currentUser != null && !hasSighting);

    deadGnomeContainer = new WebMarkupContainer("deadGnomeContainer");
    deadGnomeContainer.setOutputMarkupPlaceholderTag(true);
    deadGnomeContainer.add(new ContextImage("otter", "images/blah/welldonesir.png"));
    deadGnomeContainer.setVisible(false);
    add(livingGnomeContainer);
    add(deadGnomeContainer);

    this.setVisible(globalSetting.getGlobalSetting(GlobalSettings.BLAH).getValue().equals("allhailblah"));
}

From source file:com.tysanclan.site.projectewok.components.TysanMemberPanel.java

License:Open Source License

/**
*///from   w  w  w .j ava  2  s . c o  m
private Dialog addMembersOnlineLink() {
    Dialog window = new Dialog("onlinewindow");
    window.setTitle("Members online");
    window.setOutputMarkupId(true);
    window.setOutputMarkupPlaceholderTag(true);
    window.setWidth(400);

    window.add(new OtterSniperPanel("otterSniperPanel", 4));

    AjaxLink<Dialog> link = new AjaxLink<Dialog>("online", new Model<Dialog>(window)) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (target != null) {
                target.appendJavaScript(getModelObject().open().render().toString());
            }

        }

    };

    link.add(new Label("count", new MembersOnlineCountModel()).setOutputMarkupId(true));

    window.add(new ListView<User>("members", ModelMaker.wrap(userService.getMembersOnline())) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<User> item) {
            MemberListItem memberLink = new MemberListItem("link", item.getModelObject());

            item.add(memberLink);

        }

    });

    window.add(new ListView<MumbleServer>("servers", ModelMaker.wrap(serverDAO.findAll())) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<MumbleServer> item) {
            MumbleServer server = item.getModelObject();

            item.add(new WebMarkupContainer("server")
                    .add(AttributeModifier.replace("data-token", server.getApiToken()))
                    .add(AttributeModifier.replace("data-id", server.getServerID())));

            item.add(new ExternalLink("url", server.getUrl()).setBody(Model.of(server.getUrl())));
            item.add(new Label("password", server.getPassword()));

        }

    });

    add(link);
    add(window);
    return window;
}

From source file:com.tysanclan.site.projectewok.pages.member.RolesManagementPage.java

License:Open Source License

/**
 * /*from w w w . j a v  a  2  s . c om*/
 */
public RolesManagementPage() {
    super("Roles management");

    RoleFilter filter = new RoleFilter();
    filter.addOrderBy("roleType", true);
    filter.addOrderBy("name", true);

    List<Role> roles = roleDAO.findByFilter(filter);

    add(new ListView<Role>("roles", ModelMaker.wrap(roles)) {
        private static final long serialVersionUID = 1L;

        @SpringBean
        private UserDAO userDAO;

        @Override
        protected void populateItem(ListItem<Role> item) {
            Role role = item.getModelObject();

            item.add(new Label("name", role.getName()));

            if (role.getAssignedTo() != null) {
                item.add(new MemberListItem("member", role.getAssignedTo()));
            } else {
                item.add(new Label("member", "-"));
            }

            Dialog reassignDialog = new Dialog("assigndialog");

            Form<Role> reassignForm = new Form<Role>("assign", ModelMaker.wrap(role)) {
                private static final long serialVersionUID = 1L;

                @SpringBean
                private RoleService roleService;

                /**
                 * @see org.apache.wicket.markup.html.form.Form#onSubmit()
                 */
                @SuppressWarnings("unchecked")
                @Override
                protected void onSubmit() {
                    DropDownChoice<User> userChoice = (DropDownChoice<User>) get("user");

                    User user = userChoice.getModelObject();

                    if (user != null) {
                        roleService.assignTo(getUser().getId(), getModelObject().getId(), user.getId());
                        setResponsePage(new RolesManagementPage());
                    }
                }
            };

            reassignDialog.setAutoOpen(false);
            reassignDialog.setTitle("Assign role " + role.getName());

            UserFilter f = new UserFilter();
            f.addRank(Rank.CHANCELLOR);
            f.addRank(Rank.SENATOR);
            f.addRank(Rank.TRUTHSAYER);
            f.addRank(Rank.REVERED_MEMBER);
            f.addRank(Rank.SENIOR_MEMBER);
            f.addRank(Rank.FULL_MEMBER);

            List<User> users = userDAO.findByFilter(f);

            reassignForm.add(new DropDownChoice<User>("user", ModelMaker.wrap(users.get(0), true),
                    ModelMaker.wrap(users)).setNullValid(false));

            reassignDialog.add(reassignForm);

            item.add(reassignDialog);

            AjaxLink<Dialog> reassignLink = new AjaxLink<Dialog>("reassign",
                    new Model<Dialog>(reassignDialog)) {
                private static final long serialVersionUID = 1L;

                /**
                 * @see org.apache.wicket.ajax.markup.html.AjaxLink#onClick(org.apache.wicket.ajax.AjaxRequestTarget)
                 */
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Dialog dlg = getModelObject();

                    if (target != null) {
                        dlg.open(target);
                    }

                }

            };

            reassignLink.add(new ContextImage("icon", "images/icons/vcard.png"));

            reassignLink.setVisible(role.isReassignable());

            Link<Role> editLink = new Link<Role>("edit", ModelMaker.wrap(role)) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    setResponsePage(new EditRolePage(getModelObject()));

                }

            };

            editLink.add(new ContextImage("icon", "images/icons/vcard_edit.png"));

            editLink.setVisible(role.isReassignable());

            Dialog deletedialog = new Dialog("deletedialog");
            deletedialog.setTitle("Delete role " + role.getName());
            deletedialog.setAutoOpen(false);

            deletedialog.add(new Label("name", role.getName()));

            Link<Role> yesDeleteLink = new Link<Role>("yes", ModelMaker.wrap(role)) {
                private static final long serialVersionUID = 1L;

                @SpringBean
                private RoleService roleService;

                @Override
                public void onClick() {
                    roleService.deleteRole(getUser(), getModelObject());
                    setResponsePage(new RolesManagementPage());
                }

            };

            yesDeleteLink.add(new ContextImage("icon", "images/icons/tick.png"));

            deletedialog.add(yesDeleteLink);

            AjaxLink<Dialog> noDeleteLink = new AjaxLink<Dialog>("no", new Model<Dialog>(deletedialog)) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    Dialog dlg = getModelObject();

                    if (target != null) {
                        dlg.close(target);
                    }

                }

            };

            noDeleteLink.add(new ContextImage("icon", "images/icons/cross.png"));

            deletedialog.add(noDeleteLink);

            item.add(deletedialog);

            AjaxLink<Dialog> deleteLink = new AjaxLink<Dialog>("delete", new Model<Dialog>(deletedialog)) {
                private static final long serialVersionUID = 1L;

                /**
                 * @see org.apache.wicket.ajax.markup.html.AjaxLink#onClick(org.apache.wicket.ajax.AjaxRequestTarget)
                 */
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Dialog dlg = getModelObject();

                    if (target != null) {
                        dlg.open(target);
                    }
                }

            };

            deleteLink.add(new ContextImage("icon", "images/icons/vcard_delete.png"));

            deleteLink.setVisible(role.isReassignable());

            item.add(new WebMarkupContainer("nonreassignable").setVisible(!role.isReassignable()));
            item.add(new WebMarkupContainer("noneditable").setVisible(!role.isReassignable()));
            item.add(new WebMarkupContainer("nondeletable").setVisible(!role.isReassignable()));

            item.add(reassignLink);
            item.add(deleteLink);
            item.add(editLink);
        }

    });

    Form<Role> addRoleForm = new Form<Role>("addRoleForm") {
        private static final long serialVersionUID = 1L;

        @SpringBean
        private RoleService roleService;

        /**
         * @see org.apache.wicket.markup.html.form.Form#onSubmit()
         */
        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit() {
            TextField<String> nameField = (TextField<String>) get("name");
            TextArea<String> descriptionArea = (TextArea<String>) get("description");

            String name = nameField.getModelObject();
            String description = descriptionArea.getModelObject();

            roleService.createRole(getUser(), name, description, RoleType.NORMAL);

            setResponsePage(new RolesManagementPage());
        }

    };

    addRoleForm.add(new TextField<String>("name", new Model<String>("")));
    addRoleForm.add(new BBCodeTextArea("description", ""));

    add(addRoleForm);
}

From source file:com.userweave.components.navigation.breadcrumb.BreadcrumbLinkPanel.java

License:Open Source License

public BreadcrumbLinkPanel(String id, String displayName) {
    super(id);//from w ww.ja  v a  2 s  .co  m

    AjaxLink link = new AjaxLink("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            BreadcrumbLinkPanel.this.onClick(target);
        }
    };

    link.add(new Label("displayName", displayName));

    add(link);
}

From source file:com.userweave.pages.components.button.AddLink.java

License:Open Source License

/**
 * Initializes this panel with a link.//from www. ja v a2 s  .  c om
 * 
 * @param labelModel
 *       StringResourceModel for the label.
 */
private void initLink(StringResourceModel labelModel) {
    AjaxLink link = new AjaxLink("add") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddLink.this.onClick(target);
        }
    };

    add(link);

    link.add(new Label("message", labelModel));
}

From source file:com.userweave.pages.components.slidableajaxtabpanel.StudiesSlidableAjaxTabbedPanel.java

License:Open Source License

/**
 * Creates an ajax link to show an/*  w  w  w  .  j  a  v a2 s .co m*/
 * extra tab independent from the
 * tabbed panel to display configuration.
 * 
 * @return
 */
protected AjaxLink getConfigLink() {
    AjaxLink link = new AjaxLink(CONFIG_TAB_ID) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (StudiesSlidableAjaxTabbedPanel.this.get(TAB_PANEL_ID) == null) {
                StudiesSlidableAjaxTabbedPanel.this.add(getConfigTabPanel(TAB_PANEL_ID));
            } else {
                StudiesSlidableAjaxTabbedPanel.this.replace(getConfigTabPanel(TAB_PANEL_ID));
            }

            isTabPanelActive = false;

            this.add(configTabSelected);

            target.addComponent(this);
            target.addComponent(StudiesSlidableAjaxTabbedPanel.this);

            target.appendJavaScript(getTriggerScripts());
        }
    };

    link.add(new Label("configTabLabel",
            new StringResourceModel("config_label", StudiesSlidableAjaxTabbedPanel.this, null)));

    link.setOutputMarkupId(true);

    return link;
}

From source file:com.userweave.pages.components.slidableajaxtabpanel.StudiesSlidableAjaxTabbedPanel.java

License:Open Source License

/**
 * Creates an ajax link to show an/*from ww  w.  j  ava 2s .  c o  m*/
 * extra tab independent from the
 * tabbed panel to display results.
 * 
 * @return
 */
protected AjaxLink getResultLink() {
    AjaxLink link = new AjaxLink(CONFIG_TAB_ID) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            displayResultTab();

            target.addComponent(this);
            target.addComponent(StudiesSlidableAjaxTabbedPanel.this);

            target.appendJavaScript(getTriggerScripts());
        }
    };

    link.add(new Label("configTabLabel",
            new StringResourceModel("result_label", StudiesSlidableAjaxTabbedPanel.this, null)));

    return link;
}