Example usage for org.apache.wicket.markup.html.link AbstractLink setVisible

List of usage examples for org.apache.wicket.markup.html.link AbstractLink setVisible

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.link AbstractLink setVisible.

Prototype

public final Component setVisible(final boolean visible) 

Source Link

Document

Sets whether this component and any children are visible.

Usage

From source file:org.apache.isis.viewer.wicket.ui.components.collection.selector.CollectionSelectorPanel.java

License:Apache License

private void addDropdown() {
    final List<ComponentFactory> componentFactories = selectorHelper.getComponentFactories();
    final String selected = selectorHelper.honourViewHintElseDefault(this);

    // selector//from  w w w .j a  v a  2  s  . c o  m
    if (componentFactories.size() <= 1) {
        permanentlyHide(ID_VIEWS);
    } else {
        final Model<ComponentFactory> componentFactoryModel = new Model<>();

        this.selectedComponentFactory = selectorHelper.find(selected);
        componentFactoryModel.setObject(this.selectedComponentFactory);

        final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS);

        final Label viewButtonTitle = new Label(ID_VIEW_BUTTON_TITLE, "Hidden");
        views.addOrReplace(viewButtonTitle);

        final Label viewButtonIcon = new Label(ID_VIEW_BUTTON_ICON, "");
        views.addOrReplace(viewButtonIcon);

        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 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) {
                        CollectionSelectorPanel linksSelectorPanel = CollectionSelectorPanel.this;
                        linksSelectorPanel.setViewHintAndBroadcast(componentFactory.getName(), target);

                        linksSelectorPanel.selectedComponentFactory = componentFactory;
                        componentHintKey.set(domainObjectBookmarkIfAny(), componentFactory.getName());
                        target.add(linksSelectorPanel, views);
                    }

                    Bookmark domainObjectBookmarkIfAny() {
                        final EntityCollectionModel entityCollectionModel = CollectionSelectorPanel.this
                                .getModel();
                        final EntityModel entityModel = entityCollectionModel.getEntityModel();
                        return entityModel != null ? entityModel.getObjectAdapterMemento().asBookmark() : null;
                    }

                    @Override
                    protected void onComponentTag(ComponentTag tag) {
                        super.onComponentTag(tag);
                        Buttons.fixDisabledState(this, tag);
                    }
                };

                IModel<String> title = nameFor(componentFactory);
                Label viewItemTitleLabel = new Label(ID_VIEW_ITEM_TITLE, title);
                link.add(viewItemTitleLabel);

                Label viewItemIcon = new Label(ID_VIEW_ITEM_ICON, "");
                link.add(viewItemIcon);

                final boolean selected = componentFactory == CollectionSelectorPanel.this.selectedComponentFactory;
                if (selected) {
                    viewButtonTitle.setDefaultModel(title);
                    IModel<String> cssClass = cssClassFor(componentFactory, viewButtonIcon);
                    viewButtonIcon
                            .add(AttributeModifier.replace("class", "ViewLinkItem " + cssClass.getObject()));
                    link.setVisible(false);
                } else {
                    IModel<String> cssClass = cssClassFor(componentFactory, viewItemIcon);
                    viewItemIcon.add(new CssClassAppender(cssClass));
                }

                item.add(link);
            }

            private IModel<String> cssClassFor(final ComponentFactory componentFactory, Label viewIcon) {
                IModel<String> cssClass = null;
                if (componentFactory instanceof CollectionContentsAsFactory) {
                    CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory;
                    cssClass = collectionContentsAsFactory.getCssClass();
                    viewIcon.setDefaultModelObject("");
                    viewIcon.setEscapeModelStrings(true);
                }
                if (cssClass == null) {
                    String name = componentFactory.getName();
                    cssClass = Model.of(StringExtensions.asLowerDashed(name));
                    // Small hack: if there is no specific CSS class then we assume that background-image is used
                    // the span.ViewItemLink should have some content to show it
                    // FIX: find a way to do this with CSS (width and height don't seems to help)
                    viewIcon.setDefaultModelObject("&#160;&#160;&#160;&#160;&#160;");
                    viewIcon.setEscapeModelStrings(false);
                }
                return cssClass;
            }

            private IModel<String> nameFor(final ComponentFactory componentFactory) {
                IModel<String> name = null;
                if (componentFactory instanceof CollectionContentsAsFactory) {
                    CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory;
                    name = collectionContentsAsFactory.getTitleLabel();
                }
                if (name == null) {
                    name = Model.of(componentFactory.getName());
                }
                return name;
            }
        };
        container.add(listView);
        addOrReplace(views);
    }
}

From source file:org.apache.isis.viewer.wicket.ui.components.entity.selector.links.EntityLinksSelectorPanel.java

License:Apache License

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

    final int selected = honourViewHintElseDefault(componentFactories, model);

    final EntityLinksSelectorPanel selectorPanel = this;

    // create all, hide the one not selected
    final Component[] underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS];
    int i = 0;/*ww w  .j  av a 2 s  . com*/
    final EntityModel 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<>();

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

        final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS);

        final Label viewButtonTitle = new Label(ID_VIEW_BUTTON_TITLE, "Hidden");
        views.addOrReplace(viewButtonTitle);

        final Label viewButtonIcon = new Label(ID_VIEW_BUTTON_ICON, "");
        views.addOrReplace(viewButtonIcon);

        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) {
                        EntityLinksSelectorPanel linksSelectorPanel = EntityLinksSelectorPanel.this;
                        linksSelectorPanel.setViewHintAndBroadcast(underlyingViewNum, target);

                        final EntityModel 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);
                    }

                    @Override
                    protected void onComponentTag(ComponentTag tag) {
                        super.onComponentTag(tag);
                        Buttons.fixDisabledState(this, tag);
                    }
                };

                IModel<String> title = nameFor(componentFactory);
                Label viewItemTitleLabel = new Label(ID_VIEW_ITEM_TITLE, title);
                link.add(viewItemTitleLabel);

                Label viewItemIcon = new Label(ID_VIEW_ITEM_ICON, "");
                link.add(viewItemIcon);

                boolean isEnabled = componentFactory != selectorPanel.selectedComponentFactory;
                if (!isEnabled) {
                    viewButtonTitle.setDefaultModel(title);
                    IModel<String> cssClass = cssClassFor(componentFactory, viewButtonIcon);
                    viewButtonIcon
                            .add(AttributeModifier.replace("class", "ViewLinkItem " + cssClass.getObject()));
                    link.setVisible(false);
                } else {
                    IModel<String> cssClass = cssClassFor(componentFactory, viewItemIcon);
                    viewItemIcon.add(new CssClassAppender(cssClass));
                }

                item.add(link);
            }

            private IModel<String> cssClassFor(final ComponentFactory componentFactory, Label viewIcon) {
                IModel<String> cssClass = null;
                if (componentFactory instanceof CollectionContentsAsFactory) {
                    CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory;
                    cssClass = collectionContentsAsFactory.getCssClass();
                    viewIcon.setDefaultModelObject("");
                    viewIcon.setEscapeModelStrings(true);
                }
                if (cssClass == null) {
                    String name = componentFactory.getName();
                    cssClass = Model.of(StringExtensions.asLowerDashed(name));
                    // Small hack: if there is no specific CSS class then we assume that background-image is used
                    // the span.ViewItemLink should have some content to show it
                    // FIX: find a way to do this with CSS (width and height don't seems to help)
                    viewIcon.setDefaultModelObject("&#160;&#160;&#160;&#160;&#160;");
                    viewIcon.setEscapeModelStrings(false);
                }
                return cssClass;
            }

            private IModel<String> nameFor(final ComponentFactory componentFactory) {
                IModel<String> name = null;
                if (componentFactory instanceof CollectionContentsAsFactory) {
                    CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory;
                    name = collectionContentsAsFactory.getTitleLabel();
                }
                if (name == null) {
                    name = Model.of(componentFactory.getName());
                }
                return name;
            }
        };
        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 CssClassAppender(INVISIBLE_CLASS));
            } else {
                selectedComponent = component;
            }
        }
    }
}

From source file:org.apache.syncope.client.console.wicket.markup.html.form.ActionPanel.java

License:Apache License

public ActionPanel(final String componentId, final IModel<T> model, final Action<T> action) {
    super(componentId);
    setOutputMarkupId(true);//  w w w  . j  a  v  a2 s.c o  m
    this.action = action;

    final T obj;
    if (model == null) {
        obj = null;
    } else {
        obj = model.getObject();
    }

    final boolean enabled;
    final AbstractLink actionLink;

    if (action.getLink() == null || action.getType() == ActionType.NOT_FOUND) {
        enabled = true;
        actionLink = new IndicatingAjaxLink<Void>("action") {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public boolean isEnabled() {
                return false;
            }

            @Override
            public void onClick(final AjaxRequestTarget target) {
            }
        };
    } else if (action.getType() == ActionType.WORKFLOW_MODELER) {
        enabled = action.getLink().isEnabled(obj);
        actionLink = new BookmarkablePageLink<>("action", action.getLink().getPageClass(),
                action.getLink().getPageParameters())
                        .setPopupSettings(new VeilPopupSettings().setHeight(600).setWidth(800));
    } else {
        enabled = action.getLink().isEnabled(obj);

        actionLink = action.isOnConfirm() ? new IndicatingOnConfirmAjaxLink<Void>("action", enabled) {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target) {
                beforeOnClick(target);
                action.getLink().onClick(target, obj);
            }

            @Override
            public String getAjaxIndicatorMarkupId() {
                return disableIndicator || !action.getLink().isIndicatorEnabled() ? StringUtils.EMPTY
                        : Constants.VEIL_INDICATOR_MARKUP_ID;
            }
        } : new IndicatingAjaxLink<Void>("action") {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target) {
                beforeOnClick(target);
                action.getLink().onClick(target, obj);
            }

            @Override
            public String getAjaxIndicatorMarkupId() {
                return disableIndicator || !action.getLink().isIndicatorEnabled() ? StringUtils.EMPTY
                        : Constants.VEIL_INDICATOR_MARKUP_ID;
            }
        };
    }

    if (SyncopeConsoleSession.get().owns(action.getEntitlements(), action.getRealm())) {
        MetaDataRoleAuthorizationStrategy.authorizeAll(actionLink, RENDER);
    } else {
        MetaDataRoleAuthorizationStrategy.unauthorizeAll(actionLink, RENDER);
    }

    actionLink.setVisible(enabled);

    actionIcon = new Label("actionIcon", "");
    actionLink.add(actionIcon);

    final String clazz = action.getType().name().toLowerCase() + ".class";
    actionIcon.add(new AttributeModifier("class", new ResourceModel(clazz, clazz)));

    final String title = action.getType().name().toLowerCase() + ".title";
    final IModel<String> titleModel = new ResourceModel(title, title);
    actionIcon.add(new AttributeModifier("title", titleModel));

    final String alt = action.getType().name().toLowerCase() + ".alt";
    actionIcon.add(new AttributeModifier("alt", new ResourceModel(alt, alt)));

    actionLabel = new Label("label", titleModel);
    actionLink.add(actionLabel);
    add(actionLink);

    // ---------------------------
    // Action configuration
    // ---------------------------
    actionLabel.setVisible(action.isVisibleLabel());

    if (action.getLabel() != null) {
        actionLabel.setDefaultModel(action.getLabel());
    }

    if (action.getTitle() != null) {
        actionIcon.add(new AttributeModifier("title", action.getTitle()));
    }

    if (action.getAlt() != null) {
        actionIcon.add(new AttributeModifier("alt", action.getAlt()));
    }

    if (action.getIcon() != null) {
        actionIcon.add(new AttributeModifier("class", action.getIcon()));
    }

    this.disableIndicator = !action.hasIndicator();
    // ---------------------------
}

From source file:org.dcm4chee.web.war.folder.webviewer.Webviewer.java

License:LGPL

@SuppressWarnings("serial")
public static AbstractLink getLink(final AbstractDicomModel model, final WebviewerLinkProvider[] providers,
        final StudyPermissionHelper studyPermissionHelper, TooltipBehaviour tooltip, ModalWindow modalWindow,
        final WebviewerLinkClickedCallback callback) {
    final WebviewerLinkProvider[] p = { null };
    AbstractLink link = null;
    if (providers != null)
        for (int i = 0; i < providers.length; i++) {
            if (isLevelSupported(model, providers[i])) {
                if (p[0] == null) {
                    p[0] = providers[i];
                } else {
                    link = getWebviewerSelectionPageLink(model, providers, modalWindow, callback);
                    break;
                }//from   w  w  w. j  a v a  2s.  com
            }
        }
    if (p[0] == null) {
        link = new ExternalLink(WEBVIEW_ID, "http://dummy");
        link.setVisible(false);
    } else {
        if (link == null) {
            if (p[0].hasOwnWindow()) {
                String url = getUrlForModel(model, p[0]);
                link = new ExternalLink(WEBVIEW_ID, url);
                ((ExternalLink) link).setPopupSettings(getPopupSettingsForDirectGET(url));
            } else if (p[0].supportViewingAllSelection()) {
                link = new Link<Object>(WEBVIEW_ID) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick() {
                        try {
                            ExportDicomModel dicomModel = new ExportDicomModel(model);

                            RequestCycle.get().setRequestTarget(EmptyRequestTarget.getInstance());

                            HttpServletRequest request = ((WebRequestCycle) RequestCycle.get()).getWebRequest()
                                    .getHttpServletRequest();
                            HttpServletResponse response = ((WebResponse) getRequestCycle().getResponse())
                                    .getHttpServletResponse();
                            String result = p[0].viewAllSelection(dicomModel.getPatients(), request, response);
                            if (!p[0].notWebPageLinkTarget()) {
                                ViewerPage page = new ViewerPage();
                                page.add(new Label("viewer", new Model<String>(result))
                                        .setEscapeModelStrings(false));
                                this.setResponsePage(page);
                            }
                        } catch (Exception e) {
                            log.error("Cannot view the selection!", e);
                            if (p[0].notWebPageLinkTarget()) {
                                setResponsePage(getPage());
                            }
                        }
                    }
                };

                WebClientInfo clientInfo = (WebClientInfo) WebRequestCycle.get().getClientInfo();
                String browser = clientInfo.getUserAgent();

                if (!p[0].notWebPageLinkTarget() || (browser != null && browser.contains("Firefox"))) {
                    ((Link) link).setPopupSettings(new PopupSettings(PageMap.forName("webviewPage"),
                            PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS));
                }
            } else {
                link = new Link<Object>(WEBVIEW_ID) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick() {
                        setResponsePage(new WebviewerRedirectPage(model, p[0]));
                    }
                };
                ((Link) link).setPopupSettings(new PopupSettings(PageMap.forName("webviewPage"),
                        PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS));
            }
            if (callback != null) {
                link.add(new AjaxEventBehavior("onclick") {
                    @Override
                    public void onEvent(AjaxRequestTarget target) {
                        callback.linkClicked(target);
                    }

                    // just for the case, if the link is rendered as a <button> element
                    @Override
                    protected void onComponentTag(ComponentTag tag) {
                        String current = tag.getAttribute("onclick");

                        super.onComponentTag(tag);

                        if (current != null) {
                            tag.put("onclick",
                                    new StringBuilder(tag.getAttribute("onclick")).append(";").append(current));
                        }
                    }
                });
            }
        }
        if (model instanceof PatientModel) {
            link.setVisible(studyPermissionHelper.checkPermission(model.getDicomModelsOfNextLevel(),
                    StudyPermission.READ_ACTION, false));
        } else {
            link.setVisible(studyPermissionHelper.checkPermission(model, StudyPermission.READ_ACTION));
        }
    }
    Image image = new Image("webviewImg", ImageManager.IMAGE_FOLDER_VIEWER);
    image.add(new ImageSizeBehaviour("vertical-align: middle;"));
    if (tooltip != null)
        image.add(tooltip);
    link.add(image);
    return link;
}

From source file:org.dcm4chee.web.war.tc.TCViewBibliographyTab.java

License:LGPL

public TCViewBibliographyTab(final String id, IModel<TCEditableObject> model,
        TCAttributeVisibilityStrategy attrVisibilityStrategy) {
    super(id, model, attrVisibilityStrategy);

    list = new ListView<String>("tc-view-bibliography-list", new ListModelWrapper()) {
        private static final long serialVersionUID = 1L;

        @Override/*from w ww.  j a v a2 s .c  om*/
        protected void populateItem(final ListItem<String> item) {
            //textarea
            final TextArea<String> area = new SelfUpdatingTextArea("tc-view-bibliography-text",
                    item.getModelObject()) {
                @Override
                protected void textUpdated(String text) {
                    ((ListModelWrapper) list.getModel()).setReference(item.getIndex(), text);
                }
            };
            area.setOutputMarkupId(true);
            area.setEnabled(isEditing());
            area.add(createTextInputCssClassModifier());

            //remove button
            final AbstractLink removeBtn = new AjaxLink<Void>("tc-view-bibliography-remove-btn") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    try {
                        ((ListModelWrapper) list.getModel()).removeReference(item.getIndex());

                        target.addComponent(title);
                        target.addComponent(listContainer);
                        target.appendJavascript("updateTCViewDialog();");

                        tabTitleChanged(target);

                        if (tabTitleComponent != null) {
                            target.addComponent(tabTitleComponent);
                        }
                    } catch (Exception e) {
                        log.error("Removing bibliographic reference from teaching-file failed!", e);
                    }
                }
            };
            removeBtn.add(new Image("tc-view-bibliography-remove-img", ImageManager.IMAGE_TC_CANCEL_MONO)
                    .add(new ImageSizeBehaviour("vertical-align: middle;")));
            removeBtn.add(new TooltipBehaviour("tc.view.bibliography", "remove"));
            removeBtn.setOutputMarkupId(true);
            removeBtn.setVisible(isEditing());
            removeBtn.add(new AttributeModifier("onmouseover", true,
                    new Model<String>("$(this).children('img').attr('src','"
                            + RequestCycle.get().urlFor(ImageManager.IMAGE_TC_CANCEL) + "');")));
            removeBtn.add(new AttributeModifier("onmouseout", true,
                    new Model<String>("$(this).children('img').attr('src','"
                            + RequestCycle.get().urlFor(ImageManager.IMAGE_TC_CANCEL_MONO) + "');")));

            item.setOutputMarkupId(true);
            item.add(area);
            item.add(removeBtn);
        }
    };

    listContainer = new WebMarkupContainer("tc-view-bibliography-container");
    listContainer.setOutputMarkupId(true);
    listContainer.setMarkupId("tc-view-bibliography-container");
    listContainer.add(list);

    title = new Label("tc-view-bibliography-title-text", new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            String s = title.getString("tc.view.bibliography.number.text");
            List<String> refs = list.getModelObject();
            return MessageFormat.format(s, refs != null ? refs.size() : 0);
        }
    });
    title.setOutputMarkupId(true);

    addBtn = new AjaxLink<Void>("tc-view-bibliography-add-btn") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            try {
                ((ListModelWrapper) list.getModel())
                        .addReference(addBtn.getString("tc.view.bibliography.reference.defaulttext"));

                target.addComponent(title);
                target.addComponent(listContainer);
                target.appendJavascript("updateTCViewDialog();");

                tabTitleChanged(target);

                if (tabTitleComponent != null) {
                    target.addComponent(tabTitleComponent);
                }
            } catch (Exception e) {
                log.error("Adding new bibliographic reference to teachign-file failed!", e);
            }
        }
    };
    addBtn.add(new Image("tc-view-bibliography-add-img", ImageManager.IMAGE_COMMON_ADD)
            .add(new ImageSizeBehaviour("vertical-align: middle;")));
    addBtn.add(new Label("tc-view-bibliography-add-text", new ResourceModel("tc.view.bibliography.add.text")));
    addBtn.add(new TooltipBehaviour("tc.view.bibliography", "add"));
    addBtn.setMarkupId("tc-view-bibliography-add-btn");

    title.setEnabled(isEditing());
    addBtn.setVisible(isEditing());
    listContainer.setEnabled(isEditing());

    add(title);
    add(addBtn);
    add(listContainer);
}