Example usage for org.apache.wicket Component add

List of usage examples for org.apache.wicket Component add

Introduction

In this page you can find the example usage for org.apache.wicket Component add.

Prototype

public Component add(final Behavior... behaviors) 

Source Link

Document

Adds a behavior modifier to the component.

Usage

From source file:org.sakaiproject.scorm.ui.ResourceNavigator.java

License:Educational Community License

public void displayResource(final SessionBean sessionBean, Object target) {
    if (null == sessionBean)
        return;/*from  w  w  w.j  a  v  a 2  s .  c  o m*/

    if (sessionBean.isEnded() && target != null) {
        ((AjaxRequestTarget) target).appendJavascript(
                "window.location.href='" + sessionBean.getCompletionUrl() + "';initResizing();");
    }

    String url = getUrl(sessionBean);

    // Don't bother to display anything if a null url is returned. 
    if (null == url)
        return;

    if (log.isDebugEnabled())
        log.debug("Going to " + url);

    Component component = getFrameComponent();

    WebRequest webRequest = (WebRequest) component.getRequest();
    HttpServletRequest servletRequest = webRequest.getHttpServletRequest();

    String fullUrl = new StringBuilder(servletRequest.getContextPath()).append("/").append(url).toString();

    if (useLocationRedirect()) {
        component.add(new AttributeModifier("src", new Model(fullUrl)));

        if (target != null) {
            ((AjaxRequestTarget) target).addComponent(component);
            ((AjaxRequestTarget) target).appendJavascript("initResizing();");
        }
    } else if (target != null) {
        // It's critical to the proper functioning of the tool that this logic be maintained for SjaxCall 
        // This is due to a bug in Firefox's handling of Javascript when an iframe has control of the XMLHttpRequest
        ((AjaxRequestTarget) target)
                .appendJavascript("parent.scormContent.location.href='" + fullUrl + "';initResizing();");
    }

}

From source file:org.syncope.console.pages.BasePage.java

License:Apache License

private void pageSetup() {
    ((SyncopeApplication) getApplication()).setupNavigationPane(this, xmlRolesReader, true, version);

    feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);/*from ww w .  j  a  v a 2  s.  com*/

    final String kind = getClass().getSimpleName().toLowerCase();
    final BookmarkablePageLink kindLink = (BookmarkablePageLink) get(kind);
    if (kindLink != null) {
        kindLink.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {

                tag.put("class", kind);
            }
        });

        Component kindIcon = kindLink.get(0);
        if (kindIcon != null) {
            kindIcon.add(new Behavior() {

                private static final long serialVersionUID = 1469628524240283489L;

                @Override
                public void onComponentTag(final Component component, final ComponentTag tag) {

                    tag.put("src",
                            "../.." + SyncopeApplication.IMG_PREFIX + kind + SyncopeApplication.IMG_SUFFIX);
                }
            });
        }
    }

    // Modal window for editing user profile
    final ModalWindow editProfileModalWin = new ModalWindow("editProfileModal");
    editProfileModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    editProfileModalWin.setInitialHeight(EDIT_PROFILE_WIN_HEIGHT);
    editProfileModalWin.setInitialWidth(EDIT_PROFILE_WIN_WIDTH);
    editProfileModalWin.setCookieName("edit-profile-modal");
    add(editProfileModalWin);

    add(new Label("username", SyncopeSession.get().getUserId()));

    Fragment editProfileFrag;
    if ("admin".equals(SyncopeSession.get().getUserId())) {
        editProfileFrag = new Fragment("editProfile", "adminEmptyFrag", this);
    } else {
        final UserTO userTO = SyncopeSession.get().isAuthenticated() ? profileRestClient.readProfile()
                : new UserTO();

        editProfileFrag = new Fragment("editProfile", "editProfileFrag", this);

        AjaxLink editProfileLink = new IndicatingAjaxLink("link") {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target) {
                editProfileModalWin.setPageCreator(new ModalWindow.PageCreator() {

                    @Override
                    public Page createPage() {
                        return new UserRequestModalPage(BasePage.this.getPageReference(), editProfileModalWin,
                                userTO);
                    }
                });

                editProfileModalWin.show(target);
            }
        };
        editProfileLink.add(new Label("linkTitle", getString("editProfile")));

        Panel panel = new LinkPanel("editProfile", new ResourceModel("editProfile"));
        panel.add(editProfileLink);
        editProfileFrag.add(panel);
    }
    add(editProfileFrag);
}

From source file:org.ujorm.wicket.component.grid.KeyColumnBoolean.java

License:Apache License

/** Append css class */
@Override//from  www . ja  va 2s. c o m
protected void appendCssClass(Component value, UJO ujo) {
    super.appendCssClass(value, ujo);

    if (cssOkClass != null && Boolean.TRUE.equals(keySerializable.getFirstValue(ujo))) {
        value.add(new CssAppender(cssOkClass));
    }
}

From source file:org.ujorm.wicket.component.tabs.UjoTabbedPanel.java

License:Apache License

/** Assign a selected tab and add a user CSS class.
 * <br/>{@inheritDoc}//from   ww  w.j a va 2s.c  o m
 */
@Override
public final TabbedPanel<T> setSelectedTab(final int index) {
    TabbedPanel<T> result = super.setSelectedTab(index);
    final Component panel = super.get(TAB_PANEL_ID);
    panel.add(new CssAppender(getTabs().get(index).getCssClass()));
    return result;
}

From source file:org.wicketstuff.animator.Animator.java

License:Apache License

/**
 * Attaches the animator to the {@code component} (adds an AnimatorBehavior
 * to the component). The {@code action} is executed on the specified
 * {@code event}./* w w w  . j  a  v  a 2 s  .  c  o m*/
 * 
 * @param component
 *            the component to which the AnimatorBehavior should be attached
 *            to.
 * @param event
 *            the event on which the action should be executed.
 * @param action
 *            the action to be executed
 * @return the attached {@code AnimatorBehavior}
 */
public AnimatorBehavior attachTo(Component component, String event, Action action) {
    AnimatorBehavior behavior = new AnimatorBehavior(event, action.getScript());
    component.add(behavior);
    return behavior;
}

From source file:org.wicketstuff.dashboard.web.DashboardColumnPanel.java

License:Apache License

private void addSortableBehavior(Component component) {
    sortableAjaxBehavior = new SortableAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override/*from  ww  w .  j  a  va 2s . c  o  m*/
        public void onSort(AjaxRequestTarget target, Map<String, WidgetLocation> widgetLocations) {
            send(getPage(), Broadcast.BREADTH,
                    new DashboardEvent(target, DashboardEvent.EventType.WIDGETS_SORTED, widgetLocations));
        }

    };
    component.add(sortableAjaxBehavior);
}

From source file:org.wicketstuff.extjs.behavior.ExtTabbedPanelBehavior.java

License:Apache License

@Override
public void beforeRender(Component component) {
    super.beforeRender(component);

    if (autoTagComponents) {
        ((MarkupContainer) component).visitChildren(MarkupContainer.class, new IVisitor() {

            public Object component(Component child) {
                if (child instanceof AbstractRepeater) {
                    return null;
                }//w  w  w  . ja  v a  2s.  c o  m
                child.setOutputMarkupId(true);
                child.add(new AttributeAppender("class", new Model("x-tab"), " ") {
                    @Override
                    public boolean isTemporary() {
                        return true;
                    }
                });

                return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
            }
        });
    }
}

From source file:org.wicketstuff.extjs.behavior.ExtTabBehavior.java

License:Apache License

public void bind(Component component) {
    super.bind(component);
    component.setOutputMarkupId(true);/*from   w w  w.  j a  v  a  2  s. c o m*/
    component.add(new AttributeAppender("class", new Model("x-tab"), " "));
    if (title != null) {
        component.add(new AttributeModifier("title", true, new Model(title)));
    }
}

From source file:org.wicketstuff.extjs.Ext.java

License:Apache License

@Deprecated
public static void addContribution(final Component component) {
    IHeaderContributor[] contributions = bundle().getContributions();
    for (IHeaderContributor contrib : contributions) {
        component.add(new HeaderContributor(contrib));
    }//from   ww  w.  ja  va  2s.c o  m
}

From source file:org.wicketstuff.jmx.util.JmxUtil.java

License:Apache License

/**
 * This method is used to create an editor for the given
 * {@link MBeanAttributeInfo} based on properties like
 * {@link MBeanAttributeInfo#isReadable()},
 * {@link MBeanAttributeInfo#isWritable()} and
 * {@link MBeanAttributeInfo#getType()}. <br/>
 * The returned {@link Component} is created according to the accessibility
 * of the attribute://from  ww  w  .jav a2  s . c  o m
 * <ul>
 * <li>!read && !write: empty {@link Label}</li>
 * <li>read && !write: {@link Label} that renders the value of attribute</li>
 * <li>read && write: {@link EditorPanel}</li>
 * </ul>
 * 
 * @param id
 *            the id of the editor
 * @param mbean
 *            the {@link JmxMBeanWrapper}
 * @param attribute
 *            the {@link MBeanAttributeInfo} to process
 * @return a {@link Component} that may allow editing the attribute
 */
public static Component getEditor(String id, final JmxMBeanWrapper mbean, final MBeanAttributeInfo attribute) {
    Component editor;
    if (!attribute.isReadable()) {
        editor = new Label("editor");
    } else {
        // Create a model to bind the editor component to the bean.
        IModel model = newAttributeModel(mbean, attribute);

        // get the type of the attribute
        final Class<?> type = getType(attribute.getType());

        if (!(attribute.isWritable() && isWriteableType(type))) {
            editor = new Label(id, toString(model.getObject()));
        } else {
            editor = new EditorPanel("editor", model, new Model(attribute.getName()), type, true);
        }
    }
    editor.add(new AttributeModifier("class", true, new AbstractReadOnlyModel() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object getObject() {
            return attribute.isWritable() ? "writable" : "readonly";
        }
    }) {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled(Component component) {
            return attribute.isReadable() || attribute.isWritable();
        }
    });
    return editor;
}