Example usage for org.apache.wicket.markup.html.form Form setVisibilityAllowed

List of usage examples for org.apache.wicket.markup.html.form Form setVisibilityAllowed

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form setVisibilityAllowed.

Prototype

public final Component setVisibilityAllowed(boolean allowed) 

Source Link

Document

Sets whether or not this component is allowed to be visible.

Usage

From source file:com.gitblit.wicket.panels.SshKeysPanel.java

License:Apache License

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

    setOutputMarkupId(true);/*from w  w  w  .  j av  a2 s  .c o  m*/

    final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
    final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
    final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<SshKey> item) {
            final SshKey key = item.getModelObject();
            item.add(new Label("comment", key.getComment()));
            item.add(new Label("fingerprint", key.getFingerprint()));
            item.add(new Label("permission", key.getPermission().toString()));
            item.add(new Label("algorithm", key.getAlgorithm()));

            AjaxLink<Void> delete = new AjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (app().keys().removeKey(user.username, key)) {
                        // reset the keys list
                        keys.clear();
                        keys.addAll(app().keys().getKeys(user.username));

                        // update the panel
                        target.add(SshKeysPanel.this);
                    }
                }
            };
            if (!canWriteKeys) {
                delete.setVisibilityAllowed(false);
            }
            item.add(delete);
        }
    };
    add(keysView);

    Form<Void> addKeyForm = new Form<Void>("addKeyForm");

    final IModel<String> keyData = Model.of("");
    addKeyForm.add(new TextAreaOption("addKeyData", getString("gb.key"), null, "span5", keyData));

    final IModel<AccessPermission> keyPermission = Model.of(AccessPermission.PUSH);
    addKeyForm.add(new ChoiceOption<AccessPermission>("addKeyPermission", getString("gb.permission"),
            getString("gb.sshKeyPermissionDescription"), keyPermission,
            Arrays.asList(AccessPermission.SSHPERMISSIONS)));

    final IModel<String> keyComment = Model.of("");
    addKeyForm.add(new TextOption("addKeyComment", getString("gb.comment"),
            getString("gb.sshKeyCommentDescription"), "span5", keyComment));

    addKeyForm.add(new AjaxButton("addKeyButton") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {

            UserModel user = GitBlitWebSession.get().getUser();
            String data = keyData.getObject();
            if (StringUtils.isEmpty(data)) {
                // do not submit empty key
                return;
            }

            SshKey key = new SshKey(data);
            try {
                key.getPublicKey();
            } catch (Exception e) {
                // failed to parse the key
                return;
            }

            AccessPermission permission = keyPermission.getObject();
            key.setPermission(permission);

            String comment = keyComment.getObject();
            if (!StringUtils.isEmpty(comment)) {
                key.setComment(comment);
            }

            if (app().keys().addKey(user.username, key)) {
                // reset add key fields
                keyData.setObject("");
                keyPermission.setObject(AccessPermission.PUSH);
                keyComment.setObject("");

                // reset the keys list
                keys.clear();
                keys.addAll(app().keys().getKeys(user.username));

                // update the panel
                target.add(SshKeysPanel.this);
            }
        }
    });

    if (!canWriteKeys) {
        addKeyForm.setVisibilityAllowed(false);
    }

    add(addKeyForm);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentOptParamValueFormPage.java

License:Apache License

public ExperimentOptParamValueFormPage(final PageParameters parameters) {

    setPageTitle(ResourceUtils.getModel("pageTitle.addExperimentOptionalParameter"));

    add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));
    final Experiment experiment = experimentFacade.read(parseParameters(parameters));

    boolean allowed = true;
    if ((!securityFacade.userIsOwnerOrCoexperimenter(experiment.getExperimentId()))
            && (!securityFacade.isAdmin())) {
        warn(ResourceUtils.getString("error.mustBeOwnerOfExperimentOrCoexperimenter"));
        allowed = false;/*from   w  ww . j  av a2 s.co  m*/
    }

    final CompoundPropertyModel<ExperimentOptParamVal> model = new CompoundPropertyModel<ExperimentOptParamVal>(
            new ExperimentOptParamVal());
    final Form<ExperimentOptParamVal> form = new Form<ExperimentOptParamVal>("form");
    TextField<String> textField = new TextField<String>("paramValue");
    textField.setLabel(ResourceUtils.getModel("label.parameterValue"));
    textField.setRequired(true);
    form.add(textField);
    form.setOutputMarkupId(true);
    form.setModel(model);
    form.setVisibilityAllowed(allowed);

    List<ExperimentOptParamDef> paramList = facade
            .getRecordsByGroup(experiment.getResearchGroup().getResearchGroupId());
    ChoiceRenderer<ExperimentOptParamDef> renderer = new ChoiceRenderer<ExperimentOptParamDef>("paramName",
            "experimentOptParamDefId");
    final DropDownChoice<ExperimentOptParamDef> paramChoice = new DropDownChoice<ExperimentOptParamDef>(
            "paramChoice", new Model<ExperimentOptParamDef>(), paramList, renderer);

    paramChoice.setLabel(ResourceUtils.getModel("label.parameterType"));
    paramChoice.add(new AjaxFormComponentUpdatingBehavior("OnChange") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            int experimentOptParamDefId = paramChoice.getModelObject().getExperimentOptParamDefId();
            ExperimentOptParamValId id = new ExperimentOptParamValId(experiment.getExperimentId(),
                    experimentOptParamDefId);

            ExperimentOptParamVal entity = facade.read(id);
            form.setModelObject(entity == null ? new ExperimentOptParamVal() : entity);

            target.add(form);
        }
    });
    paramChoice.setRequired(true);
    form.add(paramChoice);

    form.add(new AjaxButton("submit", ResourceUtils.getModel("button.addExperimentOptionalParameter")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(getFeedback());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            ExperimentOptParamVal newValue = model.getObject();
            ExperimentOptParamDef experimentOptParamDef = paramChoice.getModelObject();
            ExperimentOptParamValId id = new ExperimentOptParamValId(experiment.getExperimentId(),
                    experimentOptParamDef.getExperimentOptParamDefId());
            newValue.setExperiment(experiment);

            ExperimentOptParamVal val = facade.read(id);

            if (newValue.getId() == null) {
                if (val != null) { // field already exists
                    error(ResourceUtils.getString("invalid.paramIdAlreadyInserted"));
                } else {
                    newValue.setId(id);
                    facade.create(newValue);
                }
            } else {
                facade.update(newValue);
            }

            setResponsePage(ExperimentsDetailPage.class, parameters);
        }

    });

    add(form);
}

From source file:org.sakaiproject.attendance.tool.panels.AttendanceRecordFormDataPanel.java

License:Educational Community License

private Form<AttendanceRecord> createRecordInputForm() {
    Form<AttendanceRecord> recordForm = new Form<AttendanceRecord>("attendanceRecord", this.recordIModel) {
        protected void onSubmit() {
            AttendanceRecord aR = (AttendanceRecord) getDefaultModelObject();
            if (aR.getStatus() == null) {
                aR.setStatus(Status.UNKNOWN);
            }/* w ww  . j  a v a2s  .  c om*/
            boolean result = attendanceLogic.updateAttendanceRecord(aR, oldStatus);
            String[] resultMsgVars = new String[] { sakaiProxy.getUserSortName(aR.getUserID()),
                    aR.getAttendanceEvent().getName(), getStatusString(aR.getStatus()) };
            StringResourceModel temp;
            if (result) {
                temp = new StringResourceModel("attendance.record.save.success", null, resultMsgVars);
                getSession().info(temp.getString());
                oldStatus = aR.getStatus();
            } else {
                temp = new StringResourceModel("attendance.record.save.failure", null, resultMsgVars);
                getSession().error(temp.getString());
            }
        }

        @Override
        public boolean isEnabled() {
            return !recordIModel.getObject().getAttendanceEvent().getAttendanceSite().getIsSyncing();
        }
    };

    createStatusRadio(recordForm);
    createCommentBox(recordForm);

    boolean noRecordBool = recordForm.getModelObject().getStatus().equals(Status.UNKNOWN) && restricted;
    recordForm.setVisibilityAllowed(!noRecordBool);

    WebMarkupContainer noRecordContainer = new WebMarkupContainer("no-record");
    noRecordContainer.setVisibilityAllowed(noRecordBool);
    add(noRecordContainer);

    return recordForm;
}