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.apache.isis.viewer.wicket.ui.components.header.HeaderPanel.java

License:Apache License

private void addMenuBar(final MarkupContainer container, final String id,
        final DomainServiceLayout.MenuBar menuBar) {
    final ServiceActionsModel model = new ServiceActionsModel(menuBar);
    Component menuBarComponent = getComponentFactoryRegistry().createComponent(ComponentType.SERVICE_ACTIONS,
            id, model);//from w  w w  .j  av a 2 s.com
    menuBarComponent.add(AttributeAppender.append("class", menuBar.name().toLowerCase(Locale.ENGLISH)));
    container.add(menuBarComponent);

}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract2.java

License:Apache License

private void addFormComponentBehaviourToUpdateSubscribers() {
    Component scalarValueComponent = getScalarValueComponent();
    if (scalarValueComponent == null) {
        return;/*from  www .  j a v  a 2s . co  m*/
    }
    for (Behavior b : scalarValueComponent.getBehaviors(ScalarUpdatingBehavior.class)) {
        scalarValueComponent.remove(b);
    }
    scalarValueComponent.add(new ScalarUpdatingBehavior(this));
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.XEditableBehavior2.java

License:Apache License

@Override
public void bind(Component component) {
    super.bind(component);
    validateListener = newSaveListener();
    component.add(validateListener);
}

From source file:org.apache.isis.viewer.wicket.ui.pages.PageAbstract.java

License:Apache License

/**
 * Convenience for subclasses//from  w w  w . j  av a2  s.  c  o m
 */
protected void addBookmarkedPages(final MarkupContainer container) {
    Component bookmarks = getComponentFactoryRegistry().createComponent(ComponentType.BOOKMARKED_PAGES,
            ID_BOOKMARKED_PAGES, getBookmarkedPagesModel());
    container.add(bookmarks);
    bookmarks.add(new Behavior() {
        @Override
        public void onConfigure(Component component) {
            super.onConfigure(component);

            PageParameters parameters = getPageParameters();
            component.setVisible(parameters.get(PageParametersUtils.ISIS_NO_HEADER_PARAMETER_NAME).isNull());
        }
    });
}

From source file:org.apache.isis.viewer.wicket.ui.panels.PanelAbstract.java

License:Apache License

protected void addConfirmationDialogIfAreYouSureSemantics(final Component component,
        final SemanticsOf semanticsOf) {
    if (!semanticsOf.isAreYouSure()) {
        return;//from   w w w .  j a v  a2  s  .c o m
    }

    final TranslationService translationService = getPersistenceSession().getServicesInjector()
            .lookupService(TranslationService.class);

    ConfirmationConfig confirmationConfig = new ConfirmationConfig();

    final String context = IsisSystem.class.getName();
    final String areYouSure = translationService.translate(context, IsisSystem.MSG_ARE_YOU_SURE);
    final String confirm = translationService.translate(context, IsisSystem.MSG_CONFIRM);
    final String cancel = translationService.translate(context, IsisSystem.MSG_CANCEL);

    confirmationConfig.withTitle(areYouSure).withBtnOkLabel(confirm).withBtnCancelLabel(cancel)
            .withPlacement(TooltipConfig.Placement.right).withBtnOkClass("btn btn-danger")
            .withBtnCancelClass("btn btn-default");

    component.add(new ConfirmationBehavior(confirmationConfig));
}

From source file:org.apache.isis.viewer.wicket.ui.selector.links.LinksSelectorPanelAbstract.java

License:Apache License

private void addUnderlyingViews(final String underlyingIdPrefix, final T model,
        final ComponentFactory factory) {
    final List<ComponentFactory> componentFactories = findOtherComponentFactories(model, factory);

    final int selected = determineInitialFactory(componentFactories, model);

    final LinksSelectorPanelAbstract<T> selectorPanel = LinksSelectorPanelAbstract.this;

    // create all, hide the one not selected
    final Component[] underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS];
    int i = 0;/*from w  w  w  . j a v  a 2s  .c  o m*/
    final T emptyModel = dummyOf(model);
    for (ComponentFactory componentFactory : componentFactories) {
        final String underlyingId = underlyingIdPrefix + "-" + i;

        Component underlyingView = componentFactory.createComponent(underlyingId,
                i == selected ? model : emptyModel);
        underlyingViews[i++] = underlyingView;
        selectorPanel.addOrReplace(underlyingView);
    }

    // hide any unused placeholders
    while (i < MAX_NUM_UNDERLYING_VIEWS) {
        String underlyingId = underlyingIdPrefix + "-" + i;
        permanentlyHide(underlyingId);
        i++;
    }

    // selector
    if (componentFactories.size() <= 1) {
        permanentlyHide(ID_VIEWS);
    } else {
        final Model<ComponentFactory> componentFactoryModel = new Model<ComponentFactory>();

        selectorPanel.selectedComponentFactory = componentFactories.get(selected);
        componentFactoryModel.setObject(selectorPanel.selectedComponentFactory);

        final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS);

        final WebMarkupContainer container = new WebMarkupContainer(ID_VIEW_LIST);

        views.addOrReplace(container);
        views.setOutputMarkupId(true);

        this.setOutputMarkupId(true);

        final ListView<ComponentFactory> listView = new ListView<ComponentFactory>(ID_VIEW_ITEM,
                componentFactories) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<ComponentFactory> item) {

                final int underlyingViewNum = item.getIndex();

                final ComponentFactory componentFactory = item.getModelObject();
                final AbstractLink link = new AjaxLink<Void>(ID_VIEW_LINK) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {

                        final T dummyModel = dummyOf(model);
                        for (int i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
                            final Component component = underlyingViews[i];
                            if (component == null) {
                                continue;
                            }
                            final boolean isSelected = i == underlyingViewNum;
                            applyCssVisibility(component, isSelected);
                            component.setDefaultModel(isSelected ? model : dummyModel);
                        }
                        selectorPanel.selectedComponentFactory = componentFactory;
                        selectorPanel.selectedComponent = underlyingViews[underlyingViewNum];
                        selectorPanel.onSelect(target);
                        target.add(selectorPanel, views);
                    }
                };
                String name = nameFor(componentFactory);
                Label viewTitleLabel = new Label(ID_VIEW_TITLE, name);
                viewTitleLabel.add(new CssClassAppender(StringExtensions.asLowerDashed(name)));
                link.add(viewTitleLabel);
                item.add(link);

                link.setEnabled(componentFactory != selectorPanel.selectedComponentFactory);
            }

            private String nameFor(final ComponentFactory componentFactory) {
                return componentFactory instanceof CollectionContentsAsUnresolvedPanelFactory ? "hide"
                        : componentFactory.getName();
            }
        };
        container.add(listView);
        addOrReplace(views);
    }

    for (i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
        Component component = underlyingViews[i];
        if (component != null) {
            if (i != selected) {
                component.add(new AttributeAppender("class", " " + INVISIBLE_CLASS));
            } else {
                selectedComponent = component;
            }
        }
    }
}

From source file:org.apache.isis.viewer.wicket.ui.selector.links.LinksSelectorPanelAbstract.java

License:Apache License

protected static void applyCssVisibility(final Component component, final boolean visible) {
    final AttributeModifier modifier = visible ? new AttributeModifier("class",
            String.valueOf(component.getMarkupAttributes().get("class")).replaceFirst(INVISIBLE_CLASS, ""))
            : new AttributeAppender("class", " " + INVISIBLE_CLASS);
    component.add(modifier);
}

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

License:Apache License

public BasePage(final PageParameters parameters) {
    super(parameters);

    // Native WebSocket
    add(new WebSocketBehavior() {

        private static final long serialVersionUID = 3109256773218160485L;

        @Override/*from w  w w . j  a  va2 s  . c om*/
        protected void onConnect(final ConnectedMessage message) {
            super.onConnect(message);

            SyncopeConsoleSession.get().scheduleAtFixedRate(new ApprovalsWidget.ApprovalInfoUpdater(message), 0,
                    30, TimeUnit.SECONDS);

            if (BasePage.this instanceof Dashboard) {
                SyncopeConsoleSession.get().scheduleAtFixedRate(new JobWidget.JobInfoUpdater(message), 0, 10,
                        TimeUnit.SECONDS);
                SyncopeConsoleSession.get().scheduleAtFixedRate(
                        new ReconciliationWidget.ReconciliationJobInfoUpdater(message), 0, 10,
                        TimeUnit.SECONDS);
            }
        }

    });

    body = new WebMarkupContainer("body");
    Serializable leftMenuCollapse = SyncopeConsoleSession.get()
            .getAttribute(SyncopeConsoleSession.MENU_COLLAPSE);
    if ((leftMenuCollapse instanceof Boolean) && ((Boolean) leftMenuCollapse)) {
        body.add(new AttributeAppender("class", " sidebar-collapse"));
    }
    add(body);

    notificationPanel = new NotificationPanel(Constants.FEEDBACK);
    body.addOrReplace(notificationPanel.setOutputMarkupId(true));

    // header, footer
    body.add(new Label("version", SyncopeConsoleApplication.get().getVersion()));
    body.add(new Label("username", SyncopeConsoleSession.get().getSelfTO().getUsername()));

    body.add(new ApprovalsWidget("approvalsWidget", getPageReference()).setRenderBodyOnly(true));

    // right sidebar
    SystemInfo systemInfo = SyncopeConsoleSession.get().getSystemInfo();
    body.add(new Label("hostname", systemInfo.getHostname()));
    body.add(new Label("processors", systemInfo.getAvailableProcessors()));
    body.add(new Label("os", systemInfo.getOs()));
    body.add(new Label("jvm", systemInfo.getJvm()));

    Link<Void> dbExportLink = new Link<Void>("dbExportLink") {

        private static final long serialVersionUID = -4331619903296515985L;

        @Override
        public void onClick() {
            try {
                HttpResourceStream stream = new HttpResourceStream(new ConfigurationRestClient().dbExport());

                ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
                rsrh.setFileName(
                        stream.getFilename() == null ? SyncopeConsoleSession.get().getDomain() + "Content.xml"
                                : stream.getFilename());
                rsrh.setContentDisposition(ContentDisposition.ATTACHMENT);

                getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh);
            } catch (Exception e) {
                SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
            }
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(dbExportLink, WebPage.ENABLE,
            StandardEntitlement.CONFIGURATION_EXPORT);
    body.add(dbExportLink);

    // menu
    WebMarkupContainer liContainer = new WebMarkupContainer(getLIContainerId("dashboard"));
    body.add(liContainer);
    liContainer.add(BookmarkablePageLinkBuilder.build("dashboard", Dashboard.class));

    liContainer = new WebMarkupContainer(getLIContainerId("realms"));
    body.add(liContainer);
    BookmarkablePageLink<? extends BasePage> link = BookmarkablePageLinkBuilder.build("realms", Realms.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.REALM_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("topology"));
    body.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("topology", Topology.class);
    StringBuilder bld = new StringBuilder();
    bld.append(StandardEntitlement.CONNECTOR_LIST).append(",").append(StandardEntitlement.RESOURCE_LIST)
            .append(",");
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, bld.toString());
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("reports"));
    body.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("reports", Reports.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.REPORT_LIST);
    liContainer.add(link);

    WebMarkupContainer confLIContainer = new WebMarkupContainer(getLIContainerId("configuration"));
    body.add(confLIContainer);
    WebMarkupContainer confULContainer = new WebMarkupContainer(getULContainerId("configuration"));
    confLIContainer.add(confULContainer);

    liContainer = new WebMarkupContainer(getLIContainerId("workflow"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("workflow", Workflow.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.WORKFLOW_DEF_READ);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("audit"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("audit", Audit.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.AUDIT_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("logs"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("logs", Logs.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.LOG_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("securityquestions"));
    confULContainer.add(liContainer);
    bld = new StringBuilder();
    bld.append(StandardEntitlement.SECURITY_QUESTION_CREATE).append(",")
            .append(StandardEntitlement.SECURITY_QUESTION_DELETE).append(",")
            .append(StandardEntitlement.SECURITY_QUESTION_UPDATE);
    link = BookmarkablePageLinkBuilder.build("securityquestions", SecurityQuestions.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, bld.toString());
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("types"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("types", Types.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.SCHEMA_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("roles"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("roles", Roles.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.ROLE_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("policies"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("policies", Policies.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.POLICY_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("notifications"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("notifications", Notifications.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.NOTIFICATION_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("parameters"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("parameters", Parameters.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.CONFIGURATION_LIST);
    liContainer.add(link);

    body.add(new AjaxLink<Void>("collapse") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            SyncopeConsoleSession.get().setAttribute(SyncopeConsoleSession.MENU_COLLAPSE,
                    SyncopeConsoleSession.get().getAttribute(SyncopeConsoleSession.MENU_COLLAPSE) == null ? true
                            : !(Boolean) SyncopeConsoleSession.get()
                                    .getAttribute(SyncopeConsoleSession.MENU_COLLAPSE));
        }
    });
    body.add(new Label("domain", SyncopeConsoleSession.get().getDomain()));
    body.add(new BookmarkablePageLink<Page>("logout", Logout.class));

    // set 'active' menu item for everything but extensions
    // 1. check if current class is set to top-level menu
    Component containingLI = body.get(getLIContainerId(getClass().getSimpleName().toLowerCase()));
    // 2. if not, check if it is under 'Configuration'
    if (containingLI == null) {
        containingLI = confULContainer.get(getLIContainerId(getClass().getSimpleName().toLowerCase()));
    }
    // 3. when found, set CSS coordinates for menu
    if (containingLI != null) {
        containingLI.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {
                tag.put("class", "active");
            }
        });

        if (confULContainer.getId().equals(containingLI.getParent().getId())) {
            confULContainer.add(new Behavior() {

                private static final long serialVersionUID = 3109256773218160485L;

                @Override
                public void onComponentTag(final Component component, final ComponentTag tag) {
                    tag.put("class", "treeview-menu menu-open");
                    tag.put("style", "display: block;");
                }

            });

            confLIContainer.add(new Behavior() {

                private static final long serialVersionUID = 3109256773218160485L;

                @Override
                public void onComponentTag(final Component component, final ComponentTag tag) {
                    tag.put("class", "treeview active");
                }
            });
        }
    }

    // Extensions
    ClassPathScanImplementationLookup classPathScanImplementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication
            .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP);
    List<Class<? extends BaseExtPage>> extPageClasses = classPathScanImplementationLookup.getExtPageClasses();

    WebMarkupContainer extensionsLI = new WebMarkupContainer(getLIContainerId("extensions"));
    extensionsLI.setOutputMarkupPlaceholderTag(true);
    extensionsLI.setVisible(!extPageClasses.isEmpty());
    body.add(extensionsLI);

    ListView<Class<? extends BaseExtPage>> extPages = new ListView<Class<? extends BaseExtPage>>("extPages",
            extPageClasses) {

        private static final long serialVersionUID = 4949588177564901031L;

        @Override
        protected void populateItem(final ListItem<Class<? extends BaseExtPage>> item) {
            WebMarkupContainer containingLI = new WebMarkupContainer("extPageLI");
            item.add(containingLI);
            if (item.getModelObject().equals(BasePage.this.getClass())) {
                containingLI.add(new Behavior() {

                    private static final long serialVersionUID = 1469628524240283489L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        tag.put("class", "active");
                    }
                });
            }

            ExtPage ann = item.getModelObject().getAnnotation(ExtPage.class);

            BookmarkablePageLink<Page> link = new BookmarkablePageLink<>("extPage", item.getModelObject());
            link.add(new Label("extPageLabel", ann.label()));
            MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, ann.listEntitlement());
            containingLI.add(link);

            Label extPageIcon = new Label("extPageIcon");
            extPageIcon.add(new AttributeModifier("class", "fa " + ann.icon()));
            link.add(extPageIcon);
        }
    };
    extPages.setOutputMarkupId(true);
    extensionsLI.add(extPages);

    if (getPage() instanceof BaseExtPage) {
        extPages.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {
                tag.put("class", "treeview-menu menu-open");
                tag.put("style", "display: block;");
            }

        });

        extensionsLI.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {
                tag.put("class", "treeview active");
            }
        });
    }
}

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

License:Apache License

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

    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//from   w w  w.java2 s.  com
            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 + Constants.PNG_EXT);
                }
            });
        }
    }

    ((SyncopeApplication) getApplication()).setupEditProfileModal(this, userSelfRestClient);
}

From source file:org.artifactory.addon.wicket.disabledaddon.DisableLinkBehavior.java

License:Open Source License

@Override
public void bind(Component component) {
    component.add(new CssClass("disabled"));
}