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:org.hippoecm.frontend.plugins.console.menu.refs.ReferencesDialog.java

License:Apache License

public ReferencesDialog(final ReferencesPlugin plugin) {
    final IModel<Node> nodeModel = (IModel<Node>) plugin.getDefaultModel();
    setModel(nodeModel);//  w w  w. ja  va  2 s.co  m

    add(new RefreshingView<Property>("references") {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<IModel<Property>> getItemModels() {
            List<IModel<Property>> refModels = new LinkedList<IModel<Property>>();
            Node node = ReferencesDialog.this.getModelObject();
            try {
                PropertyIterator refs = node.getReferences();
                while (refs.hasNext()) {
                    refModels.add(new JcrPropertyModel(refs.nextProperty()));
                }
            } catch (RepositoryException ex) {
                log.error(ex.getMessage());
            }
            return refModels.iterator();
        }

        @Override
        protected void populateItem(final Item<Property> item) {
            item.add(new Label("property", new PropertyModel(item.getModel(), "path")));
            AjaxLink link = new AjaxLink("reference") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    Property prop = item.getModelObject();
                    if (prop != null) {
                        try {
                            plugin.setModel(new JcrNodeModel(prop.getParent()));
                            closeDialog();
                        } catch (RepositoryException e) {
                            error(e.getMessage());
                            log.error(e.getMessage());
                        }
                    }
                }

            };
            link.add(new Label("name", new PropertyModel(item.getModel(), "parent.name")));
            item.add(link);
        }

    });
}

From source file:org.hippoecm.frontend.plugins.gotolink.GotolinkDocumentsShortcutPlugin.java

License:Apache License

public GotolinkDocumentsShortcutPlugin(final IPluginContext context, final IPluginConfig config) {
    super(context, config);

    AjaxLink link = new AjaxLink("link") {
        @Override//from ww  w. ja v a2  s  .com
        public void onClick(AjaxRequestTarget target) {
            final String browserId = config.getString("browser.id");
            final IBrowseService browseService = context.getService(browserId, IBrowseService.class);
            final String location = config.getString("option.location", "/content");
            if (browseService != null) {
                browseService.browse(new JcrNodeModel(location));
            } else {
                log.warn("no browse service found with id '{}', cannot browse to '{}'", browserId, location);
            }
        }
    };

    add(link);

    final HippoIcon icon = HippoIcon.fromSprite("gotolink-icon", Icon.FOLDER_OPEN, IconSize.XL);
    link.add(icon);
}

From source file:org.hippoecm.frontend.plugins.logout.LogoutLink.java

License:Apache License

public LogoutLink(final String id, final ILogoutService logoutService, final IDialogService dialogService) {
    super(id);/*from  w  w  w.  j  a v a 2  s .co m*/

    final AjaxLink logoutLink = new AjaxLink("logout-link") {
        @Override
        public void onClick(final AjaxRequestTarget target) {
            final UserSession userSession = UserSession.get();
            try {
                final Node rootNode = userSession.getRootNode();
                if (rootNode != null && rootNode.getSession().hasPendingChanges()) {
                    final LogoutDialog dialog = new LogoutDialog(logoutService);
                    dialogService.show(dialog);
                } else {
                    logoutService.logout();
                }
            } catch (final RepositoryException e) {
                log.error("Error while logging out", e);
            }
        }
    };

    add(logoutLink);
    logoutLink.add(new Label("logout-label", "Logout"));
}

From source file:org.hippoecm.frontend.plugins.reviewedactions.PublishAllShortcutPlugin.java

License:Apache License

public PublishAllShortcutPlugin(final IPluginContext context, final IPluginConfig config) {
    super(context, config);

    AjaxLink<String> link = new AjaxLink<String>("link") {
        @Override/*from w  w  w .j a  va  2 s.c o m*/
        public void onClick(AjaxRequestTarget target) {
            IDialogService dialogService = getDialogService();
            dialogService.show(new PublishAllShortcutPlugin.Dialog(config));
        }
    };
    link.setModel(new StringResourceModel(config.getString("label.link"), this, null));
    add(link);
    Label label = new Label("label");
    label.setDefaultModel(new StringResourceModel(config.getString("label.link"), this, null));
    link.add(label);
}

From source file:org.hippoecm.frontend.plugins.standards.browse.BreadcrumbPlugin.java

License:Apache License

private ListView<NodeItem> getListView(JcrNodeModel model) {
    nodeitems = new LinkedList<NodeItem>();
    if (model != null) {
        //add current folder as disabled
        nodeitems.add(new NodeItem(model, false));
        if (!roots.contains(model.getItemModel().getPath())) {
            model = model.getParentModel();
            while (model != null) {
                nodeitems.add(new NodeItem(model, true));
                if (roots.contains(model.getItemModel().getPath())) {
                    model = null;/*from   w  ww.  jav  a 2s.co  m*/
                } else {
                    model = model.getParentModel();
                }
            }
        }
    }
    Collections.reverse(nodeitems);
    ListView<NodeItem> listview = new ListView<NodeItem>("crumbs", nodeitems) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<NodeItem> item) {
            AjaxLink<NodeItem> link = new AjaxLink<NodeItem>("link", item.getModel()) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    folderReference.setModel(getModelObject().model);
                }

            };

            link.add(new Label("name", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    NodeItem nodeItem = item.getModelObject();
                    return (nodeItem.name != null ? format.parse(nodeItem.name) : null);
                }

            }));
            link.add(new AttributeAppender("title", true, new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                    return item.getModelObject().getName();
                }
            }, " "));

            link.setEnabled(item.getModelObject().enabled);
            item.add(link);

            IModel<String> css = new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                    String css = item.getModelObject().enabled ? "enabled" : "disabled";

                    if (nodeitems.size() == 1) {
                        css += " firstlast";
                    } else if (item.getIndex() == 0) {
                        css += " first";
                    } else if (item.getIndex() == (nodeitems.size() - 1)) {
                        css += " last";
                    }
                    return css;
                }
            };
            item.add(new AttributeAppender("class", css, " "));

            //CMS7-8008: Just show the last part of the breadcrumb
            item.setVisible(item.getIndex() >= (nodeitems.size() - maxNumberOfCrumbs));
        }
    };
    return listview;
}

From source file:org.hippoecm.frontend.plugins.yui.datetime.YuiDateTimeField.java

License:Apache License

public YuiDateTimeField(String id, IModel<Date> model, YuiDatePickerSettings settings) {
    super(id, model);

    if (settings == null) {
        settings = new YuiDatePickerSettings();
        settings.setLanguage(getLocale().getLanguage());
    }//  ww w . j  a v a  2 s  .c  om
    this.settings = settings;

    setOutputMarkupId(true);

    final DateTextField dateField = (DateTextField) get("date");
    dateField.setLabel(Model.of(getString(DATE_LABEL)));

    // Remove existing behaviors from dateField
    dateField.getBehaviors().forEach(dateField::remove);
    // And add our own YuiDatePicker instead
    dateField.add(new YuiDatePicker(settings));

    // Restrict the size of the input field to match the date pattern
    final int dateLength = calculateDateLength();

    dateField.add(AttributeModifier.replace("size", dateLength));
    dateField.add(AttributeModifier.replace("maxlength", dateLength));

    final TextField hoursField = (TextField) get("hours");
    hoursField.setLabel(Model.of(getString(HOURS_LABEL)));

    final TextField minutesField = (TextField) get("minutes");
    minutesField.setLabel(Model.of(getString(MINUTES_LABEL)));

    //add "Now" link
    AjaxLink<Date> today;
    add(today = new AjaxLink<Date>("today") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            YuiDateTimeField.this.setDefaultModelObject(new Date());
            dateField.clearInput();
            hoursField.clearInput();
            minutesField.clearInput();
            if (target != null) {
                target.add(YuiDateTimeField.this);
            }
        }

        @Override
        public boolean isVisible() {
            return todayLinkVisible;
        }
    });

    today.add(HippoIcon.fromSprite("current-date-icon", Icon.RESTORE));

    //Add change behavior to super fields
    for (String name : new String[] { "date", "hours", "minutes", "amOrPmChoice" }) {
        get(name).add(new AjaxFormComponentUpdatingBehavior("onChange") {

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                updateDateTime();
                send(YuiDateTimeField.this, Broadcast.BUBBLE, new UpdateFeedbackInfo(target));
            }

            @Override
            protected void onError(AjaxRequestTarget target, RuntimeException e) {
                super.onError(target, e);
                send(YuiDateTimeField.this, Broadcast.BUBBLE, new UpdateFeedbackInfo(target));
            }
        });
    }
}

From source file:org.hippoecm.frontend.widgets.breadcrumb.BreadcrumbLink.java

License:Apache License

public BreadcrumbLink(final String id, final IModel<String> name, final OnClickHandler onClickHandler) {
    super(id);/*from w  ww  .  j a va  2 s  .c o  m*/

    setCssClass("breadcrumb-link");

    AjaxLink link = new AjaxLink("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            if (onClickHandler != null) {
                onClickHandler.onClick(target);
            }
        }
    };
    link.add(new Label("name", name).setRenderBodyOnly(true));
    link.add(TitleAttribute.append(name));
    add(link);
}

From source file:org.hippoecm.frontend.widgets.ContextMenuTree.java

License:Apache License

protected MarkupContainer newContextLink(final MarkupContainer parent, String id, final TreeNode node,
        MarkupContainer content) {/* w  w w .j  a  v a2 s .com*/
    AjaxLink<Void> link = new ContextLink(id, content, parent) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            // It was a agreed decision that the node being operated upon was not to be selected
            // getTreeState().selectNode(node, !getTreeState().isNodeSelected(node));
            updateTree(target);
            content.setVisible(true);
            target.add(parent);
            IContextMenuManager menuManager = findParent(IContextMenuManager.class);
            if (menuManager != null) {
                menuManager.showContextMenu(this);
                onContextLinkClicked(content, target);
                dirty = true;
            }
        }

        @Override
        public void collapse(final AjaxRequestTarget target) {
            // mouseLeave is never triggered when opening the context menu. Because of this the tree has to be
            // marked dirty so that the mouse listeners on the current item are reset
            dirty = true;
            super.collapse(target);
        }
    };
    setOutputMarkupId(true);
    content.setOutputMarkupId(true);
    content.setVisible(false);
    link.add(newMenuIcon(link, "menuimage", node));
    return link;
}

From source file:org.hippoecm.frontend.widgets.NameUriField.java

License:Apache License

private Component createUrlAction() {
    final AjaxLink<Boolean> uriAction = new AjaxLink<Boolean>("uriAction") {
        @Override/*from  ww  w . j a  v a2 s .  c om*/
        public void onClick(final AjaxRequestTarget target) {
            urlIsEditable = !urlIsEditable;

            urlComponent.modelChanging();
            urlModel.setObject(getName());
            urlComponent.modelChanged();

            final Form<?> form = urlComponent.getForm();
            if (form.hasFeedbackMessage()) {
                form.getFeedbackMessages().clear();
            }

            if (!urlComponent.isValid()) {

                urlComponent.validate();
            }

            target.add(this);
            target.add(urlComponent);
            target.focusComponent(urlIsEditable ? urlComponent : nameComponent);
        }
    };

    uriAction.add(new Label("uriActionLabel",
            ReadOnlyModel.of(() -> getString(urlIsEditable ? "url-reset" : "url-edit"))));
    return uriAction;
}

From source file:org.jaulp.wicket.behaviors.examples.HomePage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 *
 * @param parameters//  w  w  w  .j  ava  2  s  .  c o  m
 *            Page parameters
 */
public HomePage(final PageParameters parameters) {
    StringResourceModel mailtoAddresModel = new StringResourceModel("mailtoAddresModel.value", this, null);
    StringResourceModel mailtoViewModel = new StringResourceModel("mailtoViewModel.value", this, null);
    MailtoModel mailtoModel = new MailtoModel(mailtoAddresModel, mailtoViewModel);

    add(new MailtoLabel("mailtoLabel", mailtoModel));

    Button button = new Button("button") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {

        }

    };
    add(new AddJsResourceReferenceBehavior(this.getClass(), "functions.js", "func"));
    add(new AddJavascriptBehavior("alertnow();", "xy"));

    add(new Link<String>("focusRequestExamplePage") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(FocusRequestExamplePage.class);
        }
    });

    add(button);
    add(new FaviconBehavior());

    AjaxLink<Void> link01 = new AjaxLink<Void>("link01") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

        }
    };
    link01.add(new AttributeAppender("class", "navbarlink"));
    add(link01);
    AjaxLink<Void> link02 = new AjaxLink<Void>("link02") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

        }
    };
    add(link02);

}