Example usage for org.apache.wicket.markup.html.basic Label setEnabled

List of usage examples for org.apache.wicket.markup.html.basic Label setEnabled

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.basic Label setEnabled.

Prototype

public final Component setEnabled(final boolean enabled) 

Source Link

Document

Sets whether this component is enabled.

Usage

From source file:com.evolveum.midpoint.web.page.self.component.LinksPanel.java

License:Apache License

@Override
protected void initLayout() {

    final List<RichHyperlinkType> linksList = getModel().getObject();
    RepeatingView rowView = new RepeatingView(ID_LINKS_ROW);

    int linksListSize = linksList == null ? 0 : linksList.size();
    if (linksListSize > 0) {
        int currentColumn = 0;
        RepeatingView columnView = null;
        WebMarkupContainer row = null;/*from   w w  w  .j  ava 2s.com*/
        boolean isRowAdded = false;
        for (int i = 0; i < linksListSize; i++) {
            final RichHyperlinkType link = linksList.get(i);
            if (WebComponentUtil.isAuthorized(link.getAuthorization())) {
                if (currentColumn == 0) {
                    row = new WebMarkupContainer(rowView.newChildId());
                    isRowAdded = false;
                    columnView = new RepeatingView(ID_LINKS_COLUMN);
                }
                WebMarkupContainer column = new WebMarkupContainer(columnView.newChildId());
                Link linkItem = new Link(ID_LINK) {
                    @Override
                    public void onClick() {
                    }

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        super.onComponentTag(tag);
                        String rootContext = "";
                        //TODO: what is this for???
                        if (link.getTargetUrl() != null && !link.getTargetUrl().startsWith("http://")
                                && !link.getTargetUrl().startsWith("https://")
                                && !link.getTargetUrl().startsWith("www://")
                                && !link.getTargetUrl().startsWith("//")) {
                            WebApplication webApplication = WebApplication.get();
                            if (webApplication != null) {
                                ServletContext servletContext = webApplication.getServletContext();
                                if (servletContext != null) {
                                    rootContext = servletContext.getContextPath();
                                }
                            }
                        }
                        tag.put("href",
                                rootContext + (link.getTargetUrl() == null ? "#" : link.getTargetUrl()));
                    }
                };
                linkItem.add(new Label(ID_IMAGE) {
                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        super.onComponentTag(tag);
                        String cssClass = ICON_DEFAULT_CSS_CLASS;
                        if (link.getIcon() != null) {
                            cssClass = link.getIcon().getCssClass();
                        }
                        tag.put("class",
                                "info-box-icon "
                                        + (link.getColor() != null
                                                ? (link.getColor().startsWith("bg-") ? link.getColor()
                                                        : "bg-" + link.getColor())
                                                : "")
                                        + " " + cssClass);
                    }
                });

                linkItem.add(new Label(ID_LABEL, new Model<String>() {
                    public String getObject() {
                        return link.getLabel();
                    }
                }));
                Label description = new Label(ID_DESCRIPTION, new Model<String>() {
                    public String getObject() {
                        return link.getDescription();
                    }
                });
                description.setEnabled(false);
                linkItem.add(description);

                column.add(linkItem);
                columnView.add(column);
                if (currentColumn == 1 || (linksList.indexOf(link) == linksListSize - 1)) {
                    row.add(columnView);
                    rowView.add(row);
                    currentColumn = 0;
                    isRowAdded = true;
                } else {
                    currentColumn++;
                }
            } else {
                LOGGER.trace("Link {} not authorized, skipping", link);
            }
        }
        if (row != null && columnView != null && !isRowAdded) {
            row.add(columnView);
            rowView.add(row);
        }
    }
    add(rowView);
}

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

License:Apache License

protected Component addComponentForCompact() {
    Fragment compactFragment = getCompactFragment(CompactType.SPAN);
    final Label label = new Label(ID_SCALAR_IF_COMPACT, newTextFieldValueModel()) {
        @Override/*from ww w  .  j a  v a 2s.  c o m*/
        public <C> IConverter<C> getConverter(Class<C> type) {
            return (IConverter<C>) converter;
        }
    };
    label.setEnabled(false);

    // adding an amount because seemed to truncate in tables in certain circumstances
    final int lengthAdjust = getLengthAdjustHint() != null ? getLengthAdjustHint() : 1;
    final String dateTimePattern = converter.getDateTimePattern(getLocale());
    final int length = dateTimePattern.length() + lengthAdjust;
    label.add(new AttributeModifier("size", Model.of("" + length)));

    compactFragment.add(label);

    scalarTypeContainer.addOrReplace(compactFragment);
    return label;
}

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

License:Apache License

protected Component addComponentForCompact() {
    Fragment compactFragment = getCompactFragment(CompactType.SPAN);
    final Label label = new Label(ID_SCALAR_IF_COMPACT, newTextFieldValueModel()) {
        @Override//from   ww w. ja  va 2s. co m
        public <C> IConverter<C> getConverter(Class<C> type) {
            return (IConverter<C>) converter;
        }
    };

    label.setEnabled(false);

    compactFragment.add(label);
    scalarTypeContainer.addOrReplace(compactFragment);
    return label;
}

From source file:org.obiba.onyx.wicket.action.ActionDefinitionPanel.java

License:Open Source License

public ActionDefinitionPanel(String id, ActionDefinition definition, AjaxRequestTarget target) {
    super(id);/*from   w  ww .  j  av a 2  s.  c o  m*/

    Action action = new Action(definition);
    setDefaultModel(new Model<Action>(action));

    add(feedback = new FeedbackWindow("feedback"));
    feedback.setOutputMarkupId(true);

    add(new Label("operator", userSessionService.getUserName()));

    // password field
    User operatorTemplate = new User();
    PasswordTextField password = new PasswordTextField("password",
            new PropertyModel<String>(operatorTemplate, "password"));
    password.setRequired(definition.isAskPassword());
    password.add(new IValidator<String>() {

        public void validate(IValidatable<String> validatable) {
            if (userSessionService.authenticate(validatable.getValue()) == false) {
                validatable.error(new UserValidationError());
            }
        }
    });
    add(password.setEnabled(definition.isAskPassword()));

    // participant barcode field
    Participant participantTemplate = new Participant();
    TextField<String> barcode = new TextField<String>("ParticipantCode",
            new PropertyModel<String>(participantTemplate, "barcode"));
    barcode.setRequired(definition.isAskParticipantId());
    barcode.add(new IValidator<String>() {

        public void validate(IValidatable<String> validatable) {
            if (!activeInterviewService.getParticipant().getBarcode().equals(validatable.getValue())) {
                validatable.error(new ParticipantValidationError());
            }
        }

    });
    add(barcode.setEnabled(definition.isAskParticipantId()));

    Object commentNoteKey = new PropertyModel<Object>(definition, "commentNote").getObject();
    String defaultNote = new StringResourceModel("AnonymousComments", this, null).getString();
    Label commentNoteLabel = new Label("commentNote",
            new SpringStringResourceModel(commentNoteKey != null ? commentNoteKey.toString() : "", defaultNote)
                    .getString());
    add(commentNoteLabel.setEnabled(definition.isAskComment()));

    TextArea<String> commentArea = new TextArea<String>("comment",
            new PropertyModel<String>(this, "action.comment"));
    commentArea.setRequired(definition.isAskComment() && definition.isCommentMandatory());
    commentArea.add(new StringValidator.MaximumLengthValidator(2000));
    add(commentArea.setEnabled(definition.isAskComment()));

    // request for focus on first field
    if (password.isEnabled()) {
        password.setOutputMarkupId(true);
        target.focusComponent(password);
    } else if (barcode.isEnabled()) {
        barcode.setOutputMarkupId(true);
        target.focusComponent(barcode);
    } else if (commentArea.isEnabled()) {
        commentArea.setOutputMarkupId(true);
        target.focusComponent(commentArea);
    }

    action.setEventReason(definition.getDefaultReason());
    DropDownChoice<String> reasonsDropDown = new DropDownChoice<String>("reasonsSelect",
            new PropertyModel<String>(ActionDefinitionPanel.this, "action.eventReason"),
            definition.getReasons(), new IChoiceRenderer<String>() {
                public Object getDisplayValue(String object) {
                    return new SpringStringResourceModel(object).getString();
                }

                public String getIdValue(String object, int index) {
                    return object;
                }
            });
    reasonsDropDown.setLabel(new ResourceModel("Reason"));
    reasonsDropDown.setRequired(definition.isReasonMandatory());
    reasonsDropDown.setEnabled(definition.getReasons().size() > 0);
    add(reasonsDropDown);
}

From source file:ro.nextreports.server.web.schedule.time.MonthlyJobPanel.java

License:Apache License

private void enableComponents(int monthlyType, Label label, TextField<Integer> minuteText,
        IntervalFieldPanel hoursPanel, IntervalFieldPanel monthsPanel, DropDownChoice<Integer> noChoice,
        DropDownChoice<String> dayChoice, Label everyLabel) {
    if (ScheduleConstants.MONTHLY_GENERAL_TYPE == monthlyType) {
        label.setEnabled(true);
        minuteText.setEnabled(true);/* w  w w. j a v a 2 s  .  c o m*/
        hoursPanel.setEnabled(true);
        daysPanel.setEnabled(true);
        monthsPanel.setEnabled(true);
        weekdaysPanel.setEnabled(true);

        noChoice.setEnabled(false);
        dayChoice.setEnabled(false);
        everyLabel.setEnabled(false);
    } else if (ScheduleConstants.MONTHLY_DAY_OF_WEEK_TYPE == monthlyType) {
        label.setEnabled(false);
        minuteText.setEnabled(false);
        hoursPanel.setEnabled(false);
        daysPanel.setEnabled(false);
        monthsPanel.setEnabled(false);
        weekdaysPanel.setEnabled(false);

        noChoice.setEnabled(true);
        dayChoice.setEnabled(true);
        everyLabel.setEnabled(true);
    } else {
        label.setEnabled(false);
        minuteText.setEnabled(false);
        hoursPanel.setEnabled(false);
        daysPanel.setEnabled(false);
        monthsPanel.setEnabled(false);
        weekdaysPanel.setEnabled(false);

        noChoice.setEnabled(false);
        dayChoice.setEnabled(false);
        everyLabel.setEnabled(false);
    }
}