Example usage for org.apache.wicket.util.string Strings isEmpty

List of usage examples for org.apache.wicket.util.string Strings isEmpty

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings isEmpty.

Prototype

public static boolean isEmpty(final CharSequence string) 

Source Link

Document

Checks whether the string is considered empty.

Usage

From source file:de.invesdwin.nowicket.component.palette.component.Recorder.java

License:Apache License

protected void updateIds(final String value) {
    getSelectedIds().clear();//from www  .  ja  va2 s  .c  o m

    if (!Strings.isEmpty(value)) {
        for (final String id : Strings.split(value, ',')) {
            getSelectedIds().add(id);
        }
    }
}

From source file:de.jetwick.ui.util.MyAutoCompleteBehavior.java

License:Apache License

@Override
public void renderHead(IHeaderResponse response) {
    // do not insert duplicate javascript files
    response.renderJavascriptReference(AUTOCOMPLETE_JS);
    final String elementId = getComponent().getMarkupId();

    String indicatorId = findIndicatorId();
    if (Strings.isEmpty(indicatorId)) {
        indicatorId = "null";
    } else {//from w w  w .  ja  v a  2s  .c  om
        indicatorId = "'" + indicatorId + "'";
    }

    String initJS = String.format("new Wicket.AutoComplete('%s','%s',%s,%s);", elementId, getCallbackUrl(),
            constructSettingsJS(), indicatorId);
    response.renderOnDomReadyJavascript(initJS);
}

From source file:de.smf.timetracker.panel.form.SignInPage.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();

    StatelessForm form = new StatelessForm("form") {
        @Override//from  w  w  w  .ja va2s .  c  o  m
        protected void onSubmit() {
            if (Strings.isEmpty(username) || Strings.isEmpty(password))
                return;

            boolean authResult = AuthenticatedWebSession.get().signIn(username, password);

            if (authResult)
                continueToOriginalDestination();
        }
    };

    form.setDefaultModel(new CompoundPropertyModel(this));

    form.add(new TextField("username"));
    form.add(new PasswordTextField("password"));

    add(form);
}

From source file:dk.frankbille.scoreboard.ScoreBoardSession.java

License:Open Source License

public ScoreBoardSession(Request request) {
    super(request);
    Injector.get().inject(this);

    CookieUtils cookieUtils = new CookieUtils();
    String loginUsername = cookieUtils.load("loginUsername");
    String loginPassword = cookieUtils.load("loginPassword");
    if (false == Strings.isEmpty(loginUsername) && false == Strings.isEmpty(loginPassword)) {
        authenticate(loginUsername, loginPassword);
    }//w  w  w .  java2s . com
}

From source file:dk.teachus.frontend.components.calendar.PeriodsCalendarPanel.java

License:Apache License

@Override
protected final List<String> getTimeSlotContent(final DateMidnight date,
        final TimeSlot<PeriodBookingTimeSlotPayload> timeSlot,
        final ListItem<TimeSlot<PeriodBookingTimeSlotPayload>> timeSlotItem) {
    // Click action
    timeSlotItem.add(new AjaxEventBehavior("onclick") { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override//from  www.java2s. co  m
        protected void onEvent(AjaxRequestTarget target) {
            onTimeSlotClicked(timeSlot, timeSlot.getStartTime().toDateTime(date), target);

            target.add(timeSlotItem);
        }

        @Override
        public boolean isEnabled(Component component) {
            return isTimeSlotBookable(timeSlot);
        }
    });

    timeSlotItem.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getTimeSlotClass(timeSlot);
        }
    }));

    List<String> contentLines = new ArrayList<String>();
    Period period = timeSlot.getPayload().getPeriod();

    // Time line
    DateTime startTime = timeSlot.getStartTime().toDateTime(date);
    DateTime endTime = timeSlot.getEndTime().toDateTime(date);
    org.joda.time.Period minutesDuration = new org.joda.time.Period(startTime, endTime, PeriodType.minutes());
    String timePriceLine = TIME_FORMAT.print(startTime) + "-" + TIME_FORMAT.print(endTime) + " - " //$NON-NLS-1$//$NON-NLS-2$
            + Math.round(minutesDuration.getMinutes()) + "m"; //$NON-NLS-1$
    if (period.getPrice() > 0) {
        timePriceLine += " - " + Formatters.getFormatCurrency().format(period.getPrice()); //$NON-NLS-1$
    }
    contentLines.add(timePriceLine);

    // Period
    if (Strings.isEmpty(period.getLocation()) == false) {
        contentLines.add(period.getLocation());
    }

    appendToTimeSlotContent(contentLines, timeSlot);

    return contentLines;
}

From source file:dk.teachus.frontend.components.ConfirmClickBehavior.java

License:Apache License

public ConfirmClickBehavior(String confirmText) {
    if (Strings.isEmpty(confirmText) == false) {
        StringBuilder b = new StringBuilder();
        b.append("return confirm('");
        b.append(JavaScriptUtils.escapeQuotes(confirmText));
        b.append("');");

        this.confirmScript = b.toString();
    } else {/*from  www  .j a  v a 2  s  .  c  o  m*/
        this.confirmScript = null;
    }
}

From source file:dk.teachus.frontend.components.ConfirmClickBehavior.java

License:Apache License

@Override
public boolean isEnabled(Component component) {
    return component.isEnabled() && Strings.isEmpty(confirmScript) == false;
}

From source file:dk.teachus.frontend.components.person.PersonPanel.java

License:Apache License

public PersonPanel(String id, final PersonModel<? extends Person> personModel) {
    super(id, personModel);

    if (allowUserEditing(TeachUsSession.get().getPerson(), personModel.getObject()) == false) {
        throw new RestartResponseAtInterceptPageException(Application.get().getHomePage());
    }//www . ja v  a  2  s  .  c om

    FormPanel formPanel = new FormPanel("form"); //$NON-NLS-1$
    add(formPanel);

    // Name
    StringTextFieldElement nameField = new StringTextFieldElement(
            TeachUsSession.get().getString("General.name"), new PropertyModel<String>(personModel, "name"), //$NON-NLS-1$//$NON-NLS-2$
            true, 32);
    nameField.add(StringValidator.lengthBetween(2, 100));
    formPanel.addElement(nameField);

    // Email
    StringTextFieldElement emailField = new StringTextFieldElement(
            TeachUsSession.get().getString("General.email"), new PropertyModel<String>(personModel, "email"), //$NON-NLS-1$//$NON-NLS-2$
            true, 50);
    emailField.add(EmailAddressValidator.getInstance());
    formPanel.addElement(emailField);

    // Phone number
    formPanel.addElement(new IntegerFieldElement(TeachUsSession.get().getString("General.phoneNumber"), //$NON-NLS-1$
            new PropertyModel<Integer>(personModel, "phoneNumber"), 10)); //$NON-NLS-1$

    // Username
    if (isUsernameEnabled()) {
        StringTextFieldElement usernameField = new StringTextFieldElement(
                TeachUsSession.get().getString("General.username"), //$NON-NLS-1$
                new PropertyModel<String>(personModel, "username"), true); //$NON-NLS-1$
        usernameField.add(StringValidator.lengthBetween(3, 50));

        // Validate the username for correct content
        usernameField.add(new PatternValidator("^[a-zA-Z0-9-_]+$") { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            @Override
            public void error(IValidatable<String> validatable) {
                ValidationError validationError = new ValidationError();
                validationError.setMessage(TeachUsSession.get().getString("PersonPanel.usernameCharacters"));
                validatable.error(validationError); //$NON-NLS-1$
            }
        });

        // validate the username checking for dublicates
        usernameField.add(new IValidator<String>() {
            private static final long serialVersionUID = 1L;

            public void validate(IValidatable<String> validatable) {
                PersonDAO personDAO = TeachUsApplication.get().getPersonDAO();
                String username = validatable.getValue();

                Person existingPerson = personDAO.usernameExists(username);

                if (existingPerson != null
                        && existingPerson.getId().equals(personModel.getPersonId()) == false) {
                    String localeString = TeachUsSession.get().getString("PersonPanel.userAlreadyExists"); //$NON-NLS-1$
                    localeString = localeString.replace("${username}", username); //$NON-NLS-1$
                    ValidationError validationError = new ValidationError();
                    validationError.setMessage(localeString);
                    validatable.error(validationError);
                }
            }
        });
        formPanel.addElement(usernameField);
    } else {
        formPanel.addElement(new ReadOnlyElement(TeachUsSession.get().getString("General.username"), //$NON-NLS-1$
                new PropertyModel<Object>(personModel, "username"))); //$NON-NLS-1$
    }

    // Password 1
    if (isPasswordVisible()) {
        final PasswordFieldElement password1Field = new PasswordFieldElement(
                TeachUsSession.get().getString("General.password"), //$NON-NLS-1$
                new PropertyModel<String>(this, "password1"), personModel.getPersonId() == null); //$NON-NLS-1$
        password1Field.add(StringValidator.lengthBetween(4, 32));
        formPanel.addElement(password1Field);

        // Password 2
        final PasswordFieldElement password2Field = new PasswordFieldElement(
                TeachUsSession.get().getString("PersonPanel.repeatPassword"), //$NON-NLS-1$
                new PropertyModel<String>(this, "password2")); //$NON-NLS-1$
        formPanel.addElement(password2Field);

        // Password validator
        formPanel.addValidator(new FormValidator() {
            private static final long serialVersionUID = 1L;

            public IFormValidator getFormValidator() {
                return new EqualInputValidator(password1Field.getFormComponent(),
                        password2Field.getFormComponent());
            }
        });
    }

    // Locale
    if (isLocaleVisible()) {
        List<Locale> availableLocales = TeachUsApplication.get().getAvailableLocales();
        formPanel.addElement(new DropDownElement<Locale>(TeachUsSession.get().getString("General.locale"), //$NON-NLS-1$
                new PropertyModel<Locale>(personModel, "locale"), availableLocales, //$NON-NLS-1$
                new LocaleChoiceRenderer()));
    }

    if (isCurrencyVisible()) {
        StringTextFieldElement currencyField = new StringTextFieldElement(
                TeachUsSession.get().getString("General.currency"), //$NON-NLS-1$
                new PropertyModel<String>(personModel, "currency"), 4); //$NON-NLS-1$
        currencyField.add(StringValidator.lengthBetween(0, 10));
        formPanel.addElement(currencyField); //$NON-NLS-1$ //$NON-NLS-2$
    }

    // Theme
    if (isThemeVisible()) {
        List<Theme> themes = Arrays.asList(Theme.values());
        formPanel.addElement(new DropDownElement<Theme>(TeachUsSession.get().getString("General.theme"), //$NON-NLS-1$
                new PropertyModel<Theme>(personModel, "theme"), themes, new ThemeChoiceRenderer())); //$NON-NLS-1$
    }

    // Teacher
    if (isTeacherVisible()) {
        formPanel.addElement(new ReadOnlyElement(TeachUsSession.get().getString("General.teacher"), //$NON-NLS-1$
                new PropertyModel<Object>(personModel, "teacher.name"))); //$NON-NLS-1$
    }

    // iCalendar URL
    formPanel.addElement(
            new ReadOnlyElement(TeachUsSession.get().getString("Ical.label"), new IcalUrlModel(personModel)));

    // Additional elements
    appendElements(formPanel);

    // Notes
    if (isNotesVisible()) {
        formPanel.addElement(new TextAreaElement("Notes", new PropertyModel<String>(personModel, "notes")));
    }

    // Buttons
    formPanel.addElement(new ButtonPanelElement() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onCancel() {
            getRequestCycle().setResponsePage(getPersonsPageClass());
        }

        @Override
        protected void onSave(AjaxRequestTarget target) {
            if (Strings.isEmpty(password1) == false) {
                personModel.setPassword(password1);
            }

            personModel.save();

            PersonPanel.this.onSave(personModel.getObject());

            getRequestCycle().setResponsePage(getPersonsPageClass());
        }
    });
}

From source file:dk.teachus.frontend.models.ApplicationConfigurationModel.java

License:Apache License

public ApplicationConfigurationModel(String configurationKey) {
    if (Strings.isEmpty(configurationKey)) {
        throw new IllegalArgumentException("Configuration key must not be null.");
    }//from  w ww.  j  av  a 2 s. c  o m

    this.configurationKey = configurationKey;
}

From source file:dk.teachus.frontend.pages.messages.SendNewPasswordPage.java

License:Apache License

public SendNewPasswordPage(Long pupilId) {
    super(UserLevel.TEACHER, true);

    if (pupilId == null) {
        throw new IllegalArgumentException("Must provide a valid pupilId"); //$NON-NLS-1$
    }/*w  w w.  j  a v a  2  s.  co  m*/

    final PupilModel pupilModel = new PupilModel(pupilId);

    // Find intro message from teachers attributes
    WelcomeIntroductionTeacherAttribute welcomeIntroduction = TeachUsSession.get()
            .getTeacherAttribute(WelcomeIntroductionTeacherAttribute.class);
    if (welcomeIntroduction != null) {
        setIntroMessage(welcomeIntroduction.getValue());
    }

    String title = TeachUsSession.get().getString("SendNewPasswordPage.title"); //$NON-NLS-1$
    title = title.replace("{pupilname}", pupilModel.getObject().getName()); //$NON-NLS-1$
    add(new Label("newPasswordTitle", title)); //$NON-NLS-1$

    FormPanel formPanel = new FormPanel("passwordForm"); //$NON-NLS-1$
    add(formPanel);

    // Password 1
    final PasswordFieldElement password1Field = new PasswordFieldElement(
            TeachUsSession.get().getString("General.password"), new PropertyModel(this, "password1"), true); //$NON-NLS-1$ //$NON-NLS-2$
    password1Field.add(StringValidator.lengthBetween(4, 32));
    formPanel.addElement(password1Field);

    // Password 2
    final PasswordFieldElement password2Field = new PasswordFieldElement(
            TeachUsSession.get().getString("PersonPanel.repeatPassword"), new PropertyModel(this, "password2"), //$NON-NLS-1$//$NON-NLS-2$
            true);
    formPanel.addElement(password2Field);

    // Password validator
    formPanel.addValidator(new FormValidator() {
        private static final long serialVersionUID = 1L;

        public IFormValidator getFormValidator() {
            return new EqualInputValidator(password1Field.getFormComponent(),
                    password2Field.getFormComponent());
        }
    });

    // Password generator
    formPanel.addElement(new GeneratePasswordElement("", pupilModel.getObject().getUsername()) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void passwordGenerated(AjaxRequestTarget target, String password) {
            setPassword1(password);
            setPassword2(password);

            target.addComponent(password1Field.getFormComponent());
            target.addComponent(password1Field.getFeedbackPanel());
            target.addComponent(password2Field.getFormComponent());
            target.addComponent(password2Field.getFeedbackPanel());
        }
    });

    // Text
    formPanel.addElement(new TextAreaElement(TeachUsSession.get().getString("SendNewPasswordPage.introMessage"), //$NON-NLS-1$
            new PropertyModel(this, "introMessage"))); //$NON-NLS-1$

    // Buttons
    formPanel.addElement(new ButtonPanelElement(TeachUsSession.get().getString("General.send")) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void onCancel() {
            getRequestCycle().setResponsePage(PupilsPage.class);
        }

        @Override
        protected void onSave(AjaxRequestTarget target) {
            PersonDAO personDAO = TeachUsApplication.get().getPersonDAO();
            MessageDAO messageDAO = TeachUsApplication.get().getMessageDAO();

            // Update pupil
            final Pupil pupil = pupilModel.getObject();
            pupil.setPassword(getPassword1());
            personDAO.save(pupil);

            // Create mail message
            Message message = new MailMessage();
            message.setSender(pupil.getTeacher());
            message.setRecipient(pupil);
            message.setState(MessageState.FINAL);

            String subject = TeachUsSession.get().getString("NewPasswordMail.subject"); //$NON-NLS-1$
            message.setSubject(subject);

            String body = TeachUsSession.get().getString("NewPasswordMail.body"); //$NON-NLS-1$
            body = body.replace("${username}", pupil.getUsername()); //$NON-NLS-1$
            body = body.replace("${password}", getPassword1()); //$NON-NLS-1$
            String serverUrl = TeachUsApplication.get().getServerUrl();
            body = body.replace("${server}", serverUrl); //$NON-NLS-1$
            String im = getIntroMessage();
            if (Strings.isEmpty(im) == false) {
                im += "\n\n"; //$NON-NLS-1$
            }
            body = body.replace("${introMessage}", im); //$NON-NLS-1$
            message.setBody(body);

            messageDAO.save(message);

            getRequestCycle().setResponsePage(PupilsPage.class);
        }
    });
}