Example usage for org.apache.wicket.markup.html.form CheckBoxMultipleChoice CheckBoxMultipleChoice

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

Introduction

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

Prototype

public CheckBoxMultipleChoice(String id, IModel<? extends Collection<T>> model,
        IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) 

Source Link

Document

Constructor

Usage

From source file:au.org.theark.arkcalendar.component.dataentry.CheckGroupDataEntryPanel.java

License:Open Source License

/**
 * NumberDataEntryPanel Constructor/*from  w  w w  .  j  a v  a 2s .  c o  m*/
 * @param id - component id
 * @param dataModel - must be a model for a String dataValue
 * @param labelModel - field-specific String label model to be used for feedback
 * @param allChoicesList - list of choices for the Dropdown
 */
public CheckGroupDataEntryPanel(String id, IModel<String> dataModel, IModel<String> labelModel,
        final ArrayList<EncodedValueVO> allChoicesList, ChoiceRenderer<EncodedValueVO> renderer) {
    super(id, labelModel);
    missingValueVo = null;
    underlyingDataModel = dataModel;
    //      dataValueModel = new Model<ArrayList<EncodedValueVO>>(selectedList); 
    dataValueModel = new Model<ArrayList<EncodedValueVO>>() {
        private static final long serialVersionUID = 1L;

        public ArrayList<EncodedValueVO> getObject() {

            String textDataValue = underlyingDataModel.getObject();
            ArrayList selectedEvvos = new ArrayList<EncodedValueVO>();
            if (textDataValue != null && !textDataValue.isEmpty()) {
                List<String> encodeKeyValueList = Arrays.asList(textDataValue.split(";"));
                for (String keyValue : encodeKeyValueList) {
                    //            if(key is in the list of our keys in allPossibilities))       then add it to out list to return         
                    for (EncodedValueVO evvo : allChoicesList) {
                        if (keyValue.equalsIgnoreCase(evvo.getKey())) {
                            selectedEvvos.add(evvo);
                        }
                    }
                }
            }
            return selectedEvvos;
        }

        public void setObject(ArrayList<EncodedValueVO> object) {
            String keyConcat = "";
            if (object == null || object.isEmpty()) {
                underlyingDataModel.setObject(null);
            } else {
                for (EncodedValueVO evvo : object) {
                    keyConcat += evvo.getKey() + ";";
                }
                underlyingDataModel.setObject(keyConcat);
            }
        }

    };

    checkBoxMultipleChoice = new CheckBoxMultipleChoice("checkGroupDataValue", dataValueModel, allChoicesList,
            renderer);
    //checkBoxMultipleChoice.setNullValid(true);   // nullValid allows you to set the "Choose One" option
    checkBoxMultipleChoice.setLabel(fieldLabelModel); // set the ${label} for feedback messages
    this.add(checkBoxMultipleChoice);
}

From source file:ch.bd.qv.quiz.panels.CheckQuestionPanel.java

License:Apache License

public CheckQuestionPanel(String inner, CheckQuestion bq) {
    super(inner, bq);
    this.checkQuestion = bq;
    add(new CheckBoxMultipleChoice<>("checkboxes", model,
            Lists.newArrayList(checkQuestion.getAnswerKeys().iterator()), new IChoiceRenderer<String>() {
                @Override/*from  w  w  w.  ja va  2s  .  c om*/
                public Object getDisplayValue(String object) {
                    return new StringResourceModel(object, CheckQuestionPanel.this, null).getObject();
                }

                @Override
                public String getIdValue(String object, int index) {
                    return new StringResourceModel(object, CheckQuestionPanel.this, null).getObject();
                }
            }).setRequired(true));
}

From source file:dk.teachus.frontend.components.form.CheckGroupElement.java

License:Apache License

@Override
protected Component newInputComponent(String wicketId, FeedbackPanel feedbackPanel) {
    checkGroup = new CheckBoxMultipleChoice<T>(wicketId, inputModel, choices, choiceRenderer) {
        private static final long serialVersionUID = 1L;

        @Override//from ww w  .ja v a 2s  .c  o  m
        public boolean isEnabled() {
            return isReadOnly() == false;
        }
    };
    checkGroup.setRequired(required);
    checkGroup.setLabel(new Model<String>(label));
    return checkGroup;
}

From source file:org.brixcms.rmiserver.web.admin.UserDtoEditor.java

License:Apache License

public UserDtoEditor(String id, IModel<UserDto> model, Mode mode) {
    super(id, model);

    add(new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(this)));

    Form<?> form = new Form<Void>("form");
    add(form);/*  w ww . j  a  va 2  s. c  o  m*/

    FormComponent<?> login = new TextField<String>("login", new PropertyModel<String>(model, "login"))
            .setRequired(true).add(StringValidator.lengthBetween(4, 32));
    login.setLabel(new Model<String>("Login"));
    login.setVisible(mode == Mode.CREATE || mode == Mode.EDIT);
    form.add(login);

    FormComponent<?> roles = new CheckBoxMultipleChoice<Role>("roles",
            new PropertyModel<Collection<Role>>(model, "roles"), new RoleCollection(), new RoleRenderer());
    roles.setVisible(mode == Mode.CREATE || mode == Mode.EDIT);
    form.add(roles);

    FormComponent<?> password1 = new PasswordTextField("password1",
            new PropertyModel<String>(model, "password")).setRequired(true)
                    .add(StringValidator.lengthBetween(4, 32)).setLabel(new Model<String>("Password"));
    password1.setVisible(mode == Mode.CREATE || mode == Mode.CHANGE_PASSWORD);
    FormComponent<?> password2 = new PasswordTextField("password2", new Model<String>());
    password2.setLabel(new Model<String>("Confirm Password"));
    form.add(password1, password2);
    password2.setVisible(mode == Mode.CREATE || mode == Mode.CHANGE_PASSWORD);
    form.add(new EqualPasswordInputValidator(password1, password2));

    form.add(new Button("ok") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            onOk(UserDtoEditor.this.getModelObject());
        }
    });

    form.add(new Link<Void>("cancel") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            onCancel();
        }
    });
}

From source file:org.cast.cwm.admin.EventLog.java

License:Open Source License

protected void addSiteFilter(Form<Object> form) {
    IModel<List<Site>> allSites = siteService.listSites();
    List<Site> sites = new ArrayList<Site>();
    sites.addAll(allSites.getObject());/*from   w w  w. j a v  a 2 s.  co  m*/
    numberOfSites = sites.size();
    showSitesM = new ListModel<Site>(sites);
    if (!allSites.getObject().isEmpty())
        form.add(new CheckBoxMultipleChoice<Site>("site", showSitesM, allSites,
                new ChoiceRenderer<Site>("name", "id")));
    else
        form.add(new WebMarkupContainer("site").setVisible(false));
}

From source file:org.cast.cwm.admin.UserContentLogPage.java

License:Open Source License

protected void addSiteFilter(Form<Object> form) {
    IModel<List<Site>> allSites = siteService.listSites();
    List<Site> sites = new ArrayList<Site>();
    sites.addAll(allSites.getObject());//w  w  w . j av a 2 s  . c  om
    showSitesM = new ListModel<Site>(sites);
    numberOfSites = sites.size();
    if (!allSites.getObject().isEmpty())
        form.add(new CheckBoxMultipleChoice<Site>("site", showSitesM, allSites,
                new ChoiceRenderer<Site>("name", "id")));
    else
        form.add(new WebMarkupContainer("site").setVisible(false));
}

From source file:org.dcm4chee.wizard.edit.CreateOrEditApplicationEntityPage.java

License:LGPL

public CreateOrEditApplicationEntityPage(final ModalWindow window, final ApplicationEntityModel aeModel,
        final ConfigTreeNode deviceNode) {
    super();/*from w  w w. j av  a  2 s .c  o m*/

    add(new WebMarkupContainer("create-applicationEntity-title").setVisible(aeModel == null));
    add(new WebMarkupContainer("edit-applicationEntity-title").setVisible(aeModel != null));

    setOutputMarkupId(true);
    final ExtendedForm form = new ExtendedForm("form");
    form.setResourceIdPrefix("dicom.edit.applicationEntity.");
    add(form);

    installedRendererChoices = new ArrayList<String>();
    installedRendererChoices
            .add(new ResourceModel("dicom.installed.true.text").wrapOnAssignment(this).getObject());
    installedRendererChoices
            .add(new ResourceModel("dicom.installed.false.text").wrapOnAssignment(this).getObject());

    ArrayList<ConnectionModel> connectionReferences = new ArrayList<ConnectionModel>();

    try {
        oldAETitle = aeModel == null ? null : aeModel.getApplicationEntity().getAETitle();

        isProxy = (((DeviceModel) deviceNode.getModel()).getDevice()
                .getDeviceExtension(ProxyDeviceExtension.class) != null);

        hl7Applications = Arrays.asList(ConfigTreeProvider.get().getUniqueHL7ApplicationNames());

        connectionReferencesModel = new Model<ArrayList<ConnectionModel>>();
        connectionReferencesModel.setObject(new ArrayList<ConnectionModel>());
        for (Connection connection : ((DeviceModel) deviceNode.getModel()).getDevice().listConnections()) {
            ConnectionModel connectionReference = new ConnectionModel(connection, 0);
            connectionReferences.add(connectionReference);
            if (aeModel != null && aeModel.getApplicationEntity().getConnections().contains(connection))
                connectionReferencesModel.getObject().add(connectionReference);
        }

        proxyPIXConsumerApplicationModel = Model.of();
        remotePIXManagerApplicationModel = Model.of();
        fallbackDestinationAETModel = Model.of();
        if (aeModel == null) {
            aeTitleModel = Model.of();
            associationAcceptorModel = Model.of();
            associationInitiatorModel = Model.of();

            acceptDataOnFailedNegotiationModel = Model.of(false);
            enableAuditLogModel = Model.of(false);
            spoolDirectoryModel = Model.of();
            deleteFailedDataWithoutRetryConfigurationModel = Model.of(false);
            mergeStgCmtMessagesUsingANDLogicModel = Model.of(false);

            applicationClustersModel = new StringArrayModel(null);
            descriptionModel = Model.of();
            installedModel = Model.of();
            calledAETitlesModel = new StringArrayModel(null);
            callingAETitlesModel = new StringArrayModel(null);
            supportedCharacterSetsModel = new StringArrayModel(null);
            vendorDataModel = Model.of("size 0");
        } else {
            ProxyAEExtension proxyAEExtension = aeModel.getApplicationEntity()
                    .getAEExtension(ProxyAEExtension.class);

            aeTitleModel = Model.of(aeModel.getApplicationEntity().getAETitle());
            associationAcceptorModel = Model.of(aeModel.getApplicationEntity().isAssociationAcceptor());
            associationInitiatorModel = Model.of(aeModel.getApplicationEntity().isAssociationInitiator());

            acceptDataOnFailedNegotiationModel = Model
                    .of(isProxy ? proxyAEExtension.isAcceptDataOnFailedAssociation() : false);
            enableAuditLogModel = Model.of(isProxy ? proxyAEExtension.isEnableAuditLog() : false);
            spoolDirectoryModel = Model.of(isProxy ? proxyAEExtension.getSpoolDirectory() : null);
            deleteFailedDataWithoutRetryConfigurationModel = Model
                    .of(isProxy ? proxyAEExtension.isDeleteFailedDataWithoutRetryConfiguration() : false);
            mergeStgCmtMessagesUsingANDLogicModel = Model
                    .of(isProxy ? proxyAEExtension.isMergeStgCmtMessagesUsingANDLogic() : false);

            applicationClustersModel = new StringArrayModel(
                    aeModel.getApplicationEntity().getApplicationClusters());
            descriptionModel = Model.of(aeModel.getApplicationEntity().getDescription());
            installedModel = Model.of(aeModel.getApplicationEntity().getInstalled());
            calledAETitlesModel = new StringArrayModel(
                    aeModel.getApplicationEntity().getPreferredCalledAETitles());
            callingAETitlesModel = new StringArrayModel(
                    aeModel.getApplicationEntity().getPreferredCallingAETitles());
            supportedCharacterSetsModel = new StringArrayModel(
                    aeModel.getApplicationEntity().getSupportedCharacterSets());
            vendorDataModel = Model.of("size " + aeModel.getApplicationEntity().getVendorData().length);

            if (isProxy) {
                proxyPIXConsumerApplicationModel = Model.of(proxyAEExtension.getProxyPIXConsumerApplication());
                remotePIXManagerApplicationModel = Model.of(proxyAEExtension.getRemotePIXManagerApplication());
                fallbackDestinationAETModel = Model.of(proxyAEExtension.getFallbackDestinationAET());
            }
        }
    } catch (ConfigurationException ce) {
        log.error(this.getClass().toString() + ": " + "Error retrieving application entity data: "
                + ce.getMessage());
        log.debug("Exception", ce);
        throw new ModalWindowRuntimeException(ce.getLocalizedMessage());
    }

    form.add(new Label("aeTitle.label", new ResourceModel("dicom.edit.applicationEntity.aeTitle.label")))
            .add(new TextField<String>("aeTitle", aeTitleModel)
                    .add(new AETitleValidator(aeTitleModel.getObject())).setRequired(true)
                    .add(FocusOnLoadBehavior.newFocusAndSelectBehaviour()));

    form.add(new Label("associationAcceptor.label",
            new ResourceModel("dicom.edit.applicationEntity.associationAcceptor.label")))
            .add(new CheckBox("associationAcceptor", associationAcceptorModel));
    form.add(new Label("associationInitiator.label",
            new ResourceModel("dicom.edit.applicationEntity.associationInitiator.label")))
            .add(new CheckBox("associationInitiator", associationInitiatorModel));

    form.add(new CheckBoxMultipleChoice<ConnectionModel>("connections", connectionReferencesModel,
            new Model<ArrayList<ConnectionModel>>(connectionReferences),
            new IChoiceRenderer<ConnectionModel>() {

                private static final long serialVersionUID = 1L;

                public Object getDisplayValue(ConnectionModel connectionReference) {
                    Connection connection = null;
                    try {
                        connection = connectionReference.getConnection();
                    } catch (Exception e) {
                        log.error(this.getClass().toString() + ": " + "Error obtaining connection: "
                                + e.getMessage());
                        log.debug("Exception", e);
                        throw new ModalWindowRuntimeException(e.getLocalizedMessage());
                    }
                    String location = connection.getHostname()
                            + (connection.getPort() == -1 ? "" : ":" + connection.getPort());
                    return connection.getCommonName() != null
                            ? connection.getCommonName() + " (" + location + ")"
                            : location;
                }

                public String getIdValue(ConnectionModel model, int index) {
                    return String.valueOf(index);
                }
            }).add(new ConnectionReferenceValidator())
                    .add(new ConnectionProtocolValidator(Connection.Protocol.DICOM)));

    WebMarkupContainer proxyContainer = new WebMarkupContainer("proxy") {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isProxy;
        }
    };
    form.add(proxyContainer);

    proxyContainer
            .add(new Label("acceptDataOnFailedNegotiation.label",
                    new ResourceModel("dicom.edit.applicationEntity.proxy.acceptDataOnFailedNegotiation.label"))
                            .setVisible(isProxy))
            .add(new CheckBox("acceptDataOnFailedNegotiation", acceptDataOnFailedNegotiationModel)
                    .setVisible(isProxy));

    proxyContainer
            .add(new Label("enableAuditLog.label",
                    new ResourceModel("dicom.edit.applicationEntity.proxy.enableAuditLog.label"))
                            .setVisible(isProxy))
            .add(new CheckBox("enableAuditLog", enableAuditLogModel).setVisible(isProxy));

    proxyContainer
            .add(new Label("spoolDirectory.label",
                    new ResourceModel("dicom.edit.applicationEntity.proxy.spoolDirectory.label"))
                            .setVisible(isProxy))
            .add(new TextField<String>("spoolDirectory", spoolDirectoryModel).setRequired(true)
                    .setVisible(isProxy));

    proxyContainer
            .add(new Label("deleteFailedDataWithoutRetryConfiguration.label", new ResourceModel(
                    "dicom.edit.applicationEntity.proxy.deleteFailedDataWithoutRetryConfiguration.label")))
            .add(new CheckBox("deleteFailedDataWithoutRetryConfiguration",
                    deleteFailedDataWithoutRetryConfigurationModel));

    proxyContainer
            .add(new Label("mergeStgCmtMessagesUsingANDLogic.label",
                    new ResourceModel(
                            "dicom.edit.applicationEntity.proxy.mergeStgCmtMessagesUsingANDLogic.label")))
            .add(new CheckBox("mergeStgCmtMessagesUsingANDLogic", mergeStgCmtMessagesUsingANDLogicModel));

    final WebMarkupContainer optionalContainer = new WebMarkupContainer("optional");
    form.add(optionalContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true).setVisible(false));

    optionalContainer
            .add(new Label("applicationClusters.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.applicationClusters.label")))
            .add(new TextArea<String>("applicationClusters", applicationClustersModel));

    optionalContainer
            .add(new Label("description.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.description.label")))
            .add(new TextField<String>("description", descriptionModel));

    optionalContainer
            .add(new Label("installed.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.installed.label")))
            .add(new DropDownChoice<Boolean>("installed", installedModel,
                    Arrays.asList(new Boolean[] { new Boolean(true), new Boolean(false) }),
                    new IChoiceRenderer<Boolean>() {

                        private static final long serialVersionUID = 1L;

                        public String getDisplayValue(Boolean object) {
                            return object.booleanValue() ? installedRendererChoices.get(0)
                                    : installedRendererChoices.get(1);
                        }

                        public String getIdValue(Boolean object, int index) {
                            return String.valueOf(index);
                        }
                    }).setNullValid(true));

    optionalContainer
            .add(new Label("calledAETitles.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.calledAETitles.label")))
            .add(new TextArea<String>("calledAETitles", calledAETitlesModel));

    optionalContainer
            .add(new Label("callingAETitles.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.callingAETitles.label")))
            .add(new TextArea<String>("callingAETitles", callingAETitlesModel));

    optionalContainer
            .add(new Label("supportedCharacterSets.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.supportedCharacterSets.label")))
            .add(new TextArea<String>("supportedCharacterSets", supportedCharacterSetsModel));

    optionalContainer
            .add(new Label("vendorData.label",
                    new ResourceModel("dicom.edit.applicationEntity.optional.vendorData.label")))
            .add(new Label("vendorData", vendorDataModel));

    WebMarkupContainer optionalProxyContainer = new WebMarkupContainer("proxy");
    optionalContainer.add(optionalProxyContainer.setVisible(isProxy));

    final DropDownChoice<String> proxyPIXConsumerApplicationDropDownChoice = new DropDownChoice<String>(
            "proxyPIXConsumerApplication", proxyPIXConsumerApplicationModel, hl7Applications);
    optionalProxyContainer
            .add(new Label("proxyPIXConsumerApplication.label",
                    new ResourceModel(
                            "dicom.edit.applicationEntity.optional.proxy.proxyPIXConsumerApplication.label")))
            .add(proxyPIXConsumerApplicationDropDownChoice.setNullValid(true).setOutputMarkupId(true)
                    .setOutputMarkupPlaceholderTag(true));

    final TextField<String> proxyPIXConsumerApplicationTextField = new TextField<String>(
            "proxyPIXConsumerApplication.freetext", proxyPIXConsumerApplicationModel);
    optionalProxyContainer.add(proxyPIXConsumerApplicationTextField.setVisible(false).setOutputMarkupId(true)
            .setOutputMarkupPlaceholderTag(true));

    final Model<Boolean> toggleProxyPIXConsumerApplicationModel = Model.of(false);
    if (aeModel != null && proxyPIXConsumerApplicationModel.getObject() != null
            && !hl7Applications.contains(proxyPIXConsumerApplicationModel.getObject())) {
        toggleProxyPIXConsumerApplicationModel.setObject(true);
        proxyPIXConsumerApplicationTextField.setVisible(true);
        proxyPIXConsumerApplicationDropDownChoice.setVisible(false);
    }

    optionalProxyContainer
            .add(new AjaxCheckBox("toggleProxyPIXConsumerApplication", toggleProxyPIXConsumerApplicationModel) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    proxyPIXConsumerApplicationDropDownChoice
                            .setVisible(!toggleProxyPIXConsumerApplicationModel.getObject());
                    proxyPIXConsumerApplicationTextField
                            .setVisible(toggleProxyPIXConsumerApplicationModel.getObject());
                    target.add(proxyPIXConsumerApplicationDropDownChoice);
                    target.add(proxyPIXConsumerApplicationTextField);
                }
            });

    final DropDownChoice<String> remotePIXManagerApplicationDropDownChoice = new DropDownChoice<String>(
            "remotePIXManagerApplication", remotePIXManagerApplicationModel, hl7Applications);
    optionalProxyContainer
            .add(new Label("remotePIXManagerApplication.label",
                    new ResourceModel(
                            "dicom.edit.applicationEntity.optional.proxy.remotePIXManagerApplication.label")))
            .add(remotePIXManagerApplicationDropDownChoice.setNullValid(true).setOutputMarkupId(true)
                    .setOutputMarkupPlaceholderTag(true));

    final TextField<String> remotePIXManagerApplicationTextField = new TextField<String>(
            "remotePIXManagerApplication.freetext", remotePIXManagerApplicationModel);
    optionalProxyContainer.add(remotePIXManagerApplicationTextField.setVisible(false).setOutputMarkupId(true)
            .setOutputMarkupPlaceholderTag(true));

    final Model<Boolean> toggleRemotePIXManagerApplicationModel = Model.of(false);
    if (aeModel != null && remotePIXManagerApplicationModel.getObject() != null
            && !hl7Applications.contains(remotePIXManagerApplicationModel.getObject())) {
        toggleRemotePIXManagerApplicationModel.setObject(true);
        remotePIXManagerApplicationTextField.setVisible(true);
        remotePIXManagerApplicationDropDownChoice.setVisible(false);
    }

    optionalProxyContainer
            .add(new AjaxCheckBox("toggleRemotePIXManagerApplication", toggleRemotePIXManagerApplicationModel) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    remotePIXManagerApplicationDropDownChoice
                            .setVisible(!toggleRemotePIXManagerApplicationModel.getObject());
                    remotePIXManagerApplicationTextField
                            .setVisible(toggleRemotePIXManagerApplicationModel.getObject());
                    target.add(remotePIXManagerApplicationDropDownChoice);
                    target.add(remotePIXManagerApplicationTextField);
                }
            });

    List<String> uniqueAETitles = null;
    if (isProxy)
        try {
            uniqueAETitles = Arrays.asList(ConfigTreeProvider.get().getUniqueAETitles());
            Collections.sort(uniqueAETitles);
        } catch (ConfigurationException ce) {
            log.error(this.getClass().toString() + ": " + "Error retrieving unique ae titles: "
                    + ce.getMessage());
            log.debug("Exception", ce);
            throw new ModalWindowRuntimeException(ce.getLocalizedMessage());
        }

    final DropDownChoice<String> fallbackDestinationAETDropDownChoice = new DropDownChoice<String>(
            "fallbackDestinationAET", fallbackDestinationAETModel, uniqueAETitles);
    optionalProxyContainer
            .add(new Label("fallbackDestinationAET.label",
                    new ResourceModel(
                            "dicom.edit.applicationEntity.optional.proxy.fallbackDestinationAET.label")))
            .add(fallbackDestinationAETDropDownChoice.setNullValid(true).setOutputMarkupId(true)
                    .setOutputMarkupPlaceholderTag(true));

    final TextField<String> fallbackDestinationAETTextField = new TextField<String>(
            "fallbackDestinationAET.freetext", fallbackDestinationAETModel);
    optionalProxyContainer.add(fallbackDestinationAETTextField.setVisible(false).setOutputMarkupId(true)
            .setOutputMarkupPlaceholderTag(true));

    final Model<Boolean> toggleFallbackDestinationAETModel = Model.of(false);
    if (aeModel != null && fallbackDestinationAETModel.getObject() != null
            && !uniqueAETitles.contains(fallbackDestinationAETModel.getObject())) {
        toggleFallbackDestinationAETModel.setObject(true);
        fallbackDestinationAETTextField.setVisible(true);
        fallbackDestinationAETDropDownChoice.setVisible(false);
    }

    optionalProxyContainer
            .add(new AjaxCheckBox("toggleFallbackDestinationAET", toggleFallbackDestinationAETModel) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    fallbackDestinationAETDropDownChoice
                            .setVisible(!toggleFallbackDestinationAETModel.getObject());
                    fallbackDestinationAETTextField.setVisible(toggleFallbackDestinationAETModel.getObject());
                    target.add(fallbackDestinationAETDropDownChoice);
                    target.add(fallbackDestinationAETTextField);
                }
            });

    form.add(new Label("toggleOptional.label", new ResourceModel("dicom.edit.toggleOptional.label")))
            .add(new AjaxCheckBox("toggleOptional", new Model<Boolean>()) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(optionalContainer.setVisible(this.getModelObject()));
                }
            });

    form.add(new IndicatingAjaxButton("submit", new ResourceModel("saveBtn"), form) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                ApplicationEntity applicationEntity = aeModel == null
                        ? new ApplicationEntity(aeTitleModel.getObject())
                        : aeModel.getApplicationEntity();

                applicationEntity.setAETitle(aeTitleModel.getObject());
                applicationEntity.setAssociationAcceptor(associationAcceptorModel.getObject());
                applicationEntity.setAssociationInitiator(associationInitiatorModel.getObject());
                applicationEntity.getConnections().clear();
                for (ConnectionModel connectionReference : connectionReferencesModel.getObject())
                    for (Connection connection : ((DeviceModel) deviceNode.getModel()).getDevice()
                            .listConnections())
                        if (connectionReference.getConnection().getHostname().equals(connection.getHostname())
                                && connectionReference.getConnection().getPort() == connection.getPort())
                            applicationEntity.addConnection(connection);

                applicationEntity.setApplicationClusters(applicationClustersModel.getArray());
                applicationEntity.setDescription(descriptionModel.getObject());
                applicationEntity.setInstalled(installedModel.getObject());
                applicationEntity.setPreferredCalledAETitles(calledAETitlesModel.getArray());
                applicationEntity.setPreferredCallingAETitles(callingAETitlesModel.getArray());
                applicationEntity.setSupportedCharacterSets(supportedCharacterSetsModel.getArray());

                if (isProxy) {
                    ProxyAEExtension proxyAEExtension = applicationEntity
                            .getAEExtension(ProxyAEExtension.class);
                    if (proxyAEExtension == null) {
                        proxyAEExtension = new ProxyAEExtension();
                        applicationEntity.addAEExtension(proxyAEExtension);
                    }
                    proxyAEExtension
                            .setAcceptDataOnFailedAssociation(acceptDataOnFailedNegotiationModel.getObject());
                    proxyAEExtension.setEnableAuditLog(enableAuditLogModel.getObject());
                    proxyAEExtension.setSpoolDirectory(spoolDirectoryModel.getObject());
                    proxyAEExtension.setDeleteFailedDataWithoutRetryConfiguration(
                            deleteFailedDataWithoutRetryConfigurationModel.getObject());
                    proxyAEExtension
                            .setProxyPIXConsumerApplication(proxyPIXConsumerApplicationModel.getObject());
                    proxyAEExtension
                            .setRemotePIXManagerApplication(remotePIXManagerApplicationModel.getObject());
                    proxyAEExtension.setFallbackDestinationAET(fallbackDestinationAETModel.getObject());
                    proxyAEExtension.setMergeStgCmtMessagesUsingANDLogic(
                            mergeStgCmtMessagesUsingANDLogicModel.getObject());

                    TransferCapabilitiesUtils.addTCsToAE(applicationEntity);
                }
                if (aeModel != null) {
                    if (!"*".equals(oldAETitle))
                        ConfigTreeProvider.get().unregisterAETitle(oldAETitle);
                } else
                    ((DeviceModel) deviceNode.getModel()).getDevice().addApplicationEntity(applicationEntity);
                ConfigTreeProvider.get().mergeDevice(applicationEntity.getDevice());
                if (!"*".equals(applicationEntity.getAETitle()))
                    ConfigTreeProvider.get().registerAETitle(applicationEntity.getAETitle());
                window.close(target);
            } catch (Exception e) {
                log.error(this.getClass().toString() + ": " + "Error modifying application entity: "
                        + e.getMessage());
                log.debug("Exception", e);
                throw new ModalWindowRuntimeException(e.getLocalizedMessage());
            }
        }

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

    form.add(new AjaxFallbackButton("cancel", new ResourceModel("cancelBtn"), form) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            window.close(target);
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {
        }
    }.setDefaultFormProcessing(false));
}

From source file:org.dcm4chee.wizard.edit.CreateOrEditAuditLoggerPage.java

License:LGPL

public CreateOrEditAuditLoggerPage(final ModalWindow window, final AuditLoggerModel auditLoggerModel,
        final ConfigTreeNode deviceNode) {
    super();/*from  w  w  w  . j  a  v a2s .  com*/

    add(new WebMarkupContainer("create-audit-logger-title").setVisible(auditLoggerModel == null));
    add(new WebMarkupContainer("edit-audit-logger-title").setVisible(auditLoggerModel != null));

    setOutputMarkupId(true);
    final ExtendedForm form = new ExtendedForm("form");
    form.setResourceIdPrefix("dicom.edit.audit-logger.");
    add(form);

    installedRendererChoices = new ArrayList<String>();
    installedRendererChoices
            .add(new ResourceModel("dicom.installed.true.text").wrapOnAssignment(this).getObject());
    installedRendererChoices
            .add(new ResourceModel("dicom.installed.false.text").wrapOnAssignment(this).getObject());

    ArrayList<ConnectionModel> connectionReferences = new ArrayList<ConnectionModel>();
    List<String> deviceList = null;

    try {
        connectionReferencesModel = new Model<ArrayList<ConnectionModel>>();
        connectionReferencesModel.setObject(new ArrayList<ConnectionModel>());
        for (Connection connection : ((DeviceModel) deviceNode.getModel()).getDevice().listConnections()) {
            ConnectionModel connectionReference = new ConnectionModel(connection, 0);
            connectionReferences.add(connectionReference);
            if (auditLoggerModel != null
                    && auditLoggerModel.getAuditLogger().getConnections().contains(connection))
                connectionReferencesModel.getObject().add(connectionReference);
        }

        deviceList = ((WizardApplication) getApplication()).getDicomConfigurationManager().listDevices();
        Collections.sort(deviceList);

        arrDeviceNameModel = Model.of();
        if (auditLoggerModel == null) {
            applicationNameModel = Model.of();
            auditEnterpriseSiteIDModel = Model.of();
            auditSourceIDModel = Model.of();
            auditSourceTypeCodesModel = new StringArrayModel(null);
            encodingModel = Model.of("UTF-8");
            facilityModel = Model.of(AuditLogger.Facility.authpriv);
            formatXMLModel = Model.of();
            includeBOMModel = Model.of();
            installedModel = Model.of();
            majorFailureSeverityModel = Model.of(AuditLogger.Severity.crit);
            messageIDModel = Model.of(AuditLogger.MESSAGE_ID);
            minorFailureSeverityModel = Model.of(AuditLogger.Severity.warning);
            schemaURIModel = Model.of();
            seriousFailureSeverityModel = Model.of(AuditLogger.Severity.err);
            successSeverityModel = Model.of(AuditLogger.Severity.notice);
            timestampInUTCModel = Model.of();
        } else {
            AuditLogger auditLogger = auditLoggerModel.getAuditLogger();
            applicationNameModel = Model.of(auditLogger.getApplicationName());
            auditEnterpriseSiteIDModel = Model.of(auditLogger.getAuditEnterpriseSiteID());
            if (auditLogger.getAuditRecordRepositoryDevice() != null)
                arrDeviceNameModel = Model.of(auditLogger.getAuditRecordRepositoryDevice().getDeviceName());
            Collections.sort(deviceList);
            auditSourceIDModel = Model.of(auditLogger.getAuditSourceID());
            auditSourceTypeCodesModel = new StringArrayModel(auditLogger.getAuditSourceTypeCodes());
            encodingModel = Model.of(auditLogger.getEncoding());
            facilityModel = Model.of(auditLogger.getFacility());
            formatXMLModel = Model.of(auditLogger.isFormatXML());
            includeBOMModel = Model.of(auditLogger.isIncludeBOM());
            installedModel = Model.of(auditLogger.getInstalled());
            majorFailureSeverityModel = Model.of(auditLogger.getMajorFailureSeverity());
            messageIDModel = Model.of(auditLogger.getMessageID());
            minorFailureSeverityModel = Model.of(auditLogger.getMinorFailureSeverity());
            schemaURIModel = Model.of(auditLogger.getSchemaURI());
            seriousFailureSeverityModel = Model.of(auditLogger.getSeriousFailureSeverity());
            successSeverityModel = Model.of(auditLogger.getSuccessSeverity());
            timestampInUTCModel = Model.of(auditLogger.isTimestampInUTC());
        }
    } catch (ConfigurationException ce) {
        log.error(this.getClass().toString() + ": " + "Error retrieving audit logger data: " + ce.getMessage());
        log.debug("Exception", ce);
        throw new ModalWindowRuntimeException(ce.getLocalizedMessage());
    }

    form.add(new Label("applicationName.label",
            new ResourceModel("dicom.edit.audit-logger.applicationName.label")))
            .add(new TextField<String>("applicationName", applicationNameModel).setRequired(true)
                    .add(FocusOnLoadBehavior.newFocusAndSelectBehaviour()));

    form.add(new CheckBoxMultipleChoice<ConnectionModel>("connections", connectionReferencesModel,
            new Model<ArrayList<ConnectionModel>>(connectionReferences),
            new IChoiceRenderer<ConnectionModel>() {

                private static final long serialVersionUID = 1L;

                public Object getDisplayValue(ConnectionModel connectionReference) {
                    Connection connection = null;
                    try {
                        connection = connectionReference.getConnection();
                    } catch (Exception e) {
                        log.error(this.getClass().toString() + ": " + "Error obtaining connection: "
                                + e.getMessage());
                        log.debug("Exception", e);
                        throw new ModalWindowRuntimeException(e.getLocalizedMessage());
                    }
                    String location = connection.getHostname()
                            + (connection.getPort() == -1 ? "" : ":" + connection.getPort());
                    return connection.getCommonName() != null
                            ? connection.getCommonName() + " (" + location + ")"
                            : location;
                }

                public String getIdValue(ConnectionModel model, int index) {
                    return String.valueOf(index);
                }
            }).add(new ConnectionReferenceValidator()).add(new ConnectionProtocolValidator(
                    Connection.Protocol.SYSLOG_TLS, Connection.Protocol.SYSLOG_UDP)));

    DeviceListValidator deviceListValidator = null;
    if (arrDeviceNameModel.getObject() != null && !deviceList.contains(arrDeviceNameModel.getObject())) {
        deviceList.add(0, arrDeviceNameModel.getObject());
        deviceListValidator = new DeviceListValidator();
    }

    DropDownChoice<String> arrDeviceNameDropDownChoice;
    form.add(new Label("arrDeviceName.label", new ResourceModel("dicom.edit.audit-logger.arrDeviceName.label")))
            .add((arrDeviceNameDropDownChoice = new DropDownChoice<String>("arrDeviceName", arrDeviceNameModel,
                    deviceList)).setNullValid(false).setRequired(true));
    if (arrDeviceNameModel.getObject() == null)
        arrDeviceNameModel.setObject(deviceList.get(0));
    if (deviceListValidator != null)
        arrDeviceNameDropDownChoice.add(deviceListValidator);

    final WebMarkupContainer optionalContainer = new WebMarkupContainer("optional");
    form.add(optionalContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true).setVisible(false));

    form.add(new Label("toggleOptional.label", new ResourceModel("dicom.edit.toggleOptional.label")))
            .add(new AjaxCheckBox("toggleOptional", new Model<Boolean>()) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(optionalContainer.setVisible(this.getModelObject()));
                }
            });

    optionalContainer
            .add(new Label("auditEnterpriseSiteID.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.auditEnterpriseSiteID.label")))
            .add(new TextField<String>("auditEnterpriseSiteID", auditEnterpriseSiteIDModel));

    optionalContainer
            .add(new Label("auditSourceID.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.auditSourceID.label")))
            .add(new TextField<String>("auditSourceID", auditSourceIDModel));

    optionalContainer
            .add(new Label("auditSourceTypeCodes.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.auditSourceTypeCodes.label")))
            .add(new TextArea<String>("auditSourceTypeCodes", auditSourceTypeCodesModel));

    optionalContainer
            .add(new Label("encoding.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.encoding.label")))
            .add(new TextField<String>("encoding", encodingModel).setRequired(true));

    optionalContainer
            .add(new Label("facility.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.facility.label")))
            .add(new DropDownChoice<Facility>("facility", facilityModel,
                    Arrays.asList(AuditLogger.Facility.values())));

    optionalContainer
            .add(new Label("formatXML.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.formatXML.label")))
            .add(new CheckBox("formatXML", formatXMLModel));

    optionalContainer
            .add(new Label("includeBOM.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.includeBOM.label")))
            .add(new CheckBox("includeBOM", includeBOMModel));

    optionalContainer
            .add(new Label("installed.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.installed.label")))
            .add(new DropDownChoice<Boolean>("installed", installedModel,
                    Arrays.asList(new Boolean[] { new Boolean(true), new Boolean(false) }),
                    new IChoiceRenderer<Boolean>() {

                        private static final long serialVersionUID = 1L;

                        public String getDisplayValue(Boolean object) {
                            return object.booleanValue() ? installedRendererChoices.get(0)
                                    : installedRendererChoices.get(1);
                        }

                        public String getIdValue(Boolean object, int index) {
                            return String.valueOf(index);
                        }
                    }).setNullValid(true));

    optionalContainer
            .add(new Label("messageID.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.messageID.label")))
            .add(new TextField<String>("messageID", messageIDModel).setRequired(true));

    optionalContainer
            .add(new Label("schemaURI.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.schemaURI.label")))
            .add(new TextField<String>("schemaURI", schemaURIModel));

    optionalContainer
            .add(new Label("timestampInUTC.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.timestampInUTC.label")))
            .add(new CheckBox("timestampInUTC", timestampInUTCModel));

    List<Severity> severities = Arrays.asList(AuditLogger.Severity.values());

    optionalContainer
            .add(new Label("majorFailureSeverity.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.majorFailureSeverity.label")))
            .add(new DropDownChoice<Severity>("majorFailureSeverity", majorFailureSeverityModel, severities));

    optionalContainer
            .add(new Label("minorFailureSeverity.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.minorFailureSeverity.label")))
            .add(new DropDownChoice<Severity>("minorFailureSeverity", minorFailureSeverityModel, severities));

    optionalContainer
            .add(new Label("seriousFailureSeverity.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.seriousFailureSeverity.label")))
            .add(new DropDownChoice<Severity>("seriousFailureSeverity", seriousFailureSeverityModel,
                    severities));

    optionalContainer
            .add(new Label("successSeverity.label",
                    new ResourceModel("dicom.edit.audit-logger.optional.successSeverity.label")))
            .add(new DropDownChoice<Severity>("successSeverity", successSeverityModel, severities));

    form.add(new AjaxFallbackButton("submit", new ResourceModel("saveBtn"), form) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                AuditLogger auditLogger = auditLoggerModel == null ? new AuditLogger()
                        : auditLoggerModel.getAuditLogger();

                auditLogger.setApplicationName(applicationNameModel.getObject());
                auditLogger.getConnections().clear();
                for (ConnectionModel connectionReference : connectionReferencesModel.getObject())
                    for (Connection connection : ((DeviceModel) deviceNode.getModel()).getDevice()
                            .listConnections())
                        if (connectionReference.getConnection().getHostname().equals(connection.getHostname())
                                && connectionReference.getConnection().getPort() == connection.getPort())
                            auditLogger.addConnection(connection);

                auditLogger.setAuditRecordRepositoryDevice(
                        ((WizardApplication) getApplication()).getDicomConfigurationManager()
                                .getDicomConfiguration().findDevice(arrDeviceNameModel.getObject()));

                if (optionalContainer.isVisible()) {
                    auditLogger.setAuditEnterpriseSiteID(auditEnterpriseSiteIDModel.getObject());
                    auditLogger.setAuditSourceID(auditSourceIDModel.getObject());
                    auditLogger.setAuditSourceTypeCodes(auditSourceTypeCodesModel.getArray());
                    if (encodingModel.getObject() != null)
                        auditLogger.setEncoding(encodingModel.getObject());
                    auditLogger.setFacility(facilityModel.getObject());
                    auditLogger.setFormatXML(formatXMLModel.getObject());
                    auditLogger.setIncludeBOM(includeBOMModel.getObject());
                    auditLogger.setInstalled(installedModel.getObject());
                    auditLogger.setMessageID(messageIDModel.getObject());
                    auditLogger.setSchemaURI(schemaURIModel.getObject());
                    auditLogger.setTimestampInUTC(timestampInUTCModel.getObject());
                    auditLogger.setSeriousFailureSeverity(seriousFailureSeverityModel.getObject());
                    auditLogger.setMajorFailureSeverity(majorFailureSeverityModel.getObject());
                    auditLogger.setMinorFailureSeverity(minorFailureSeverityModel.getObject());
                    auditLogger.setSuccessSeverity(successSeverityModel.getObject());
                }

                Device device = ((DeviceModel) deviceNode.getModel()).getDevice();
                if (auditLoggerModel == null)
                    device.addDeviceExtension(auditLogger);
                ConfigTreeProvider.get().mergeDevice(device);
                window.close(target);
            } catch (Exception e) {
                log.error(this.getClass().toString() + ": " + "Error modifying HL7 application: "
                        + e.getMessage());
                if (log.isDebugEnabled())
                    e.printStackTrace();
                throw new ModalWindowRuntimeException(e.getLocalizedMessage());
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            if (target != null)
                target.add(form);
        }
    });
    form.add(new AjaxFallbackButton("cancel", new ResourceModel("cancelBtn"), form) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            window.close(target);
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {
        }
    }.setDefaultFormProcessing(false));
}

From source file:org.dcm4chee.wizard.edit.CreateOrEditHL7ApplicationPage.java

License:LGPL

public CreateOrEditHL7ApplicationPage(final ModalWindow window, final HL7ApplicationModel hl7ApplicationModel,
        final ConfigTreeNode deviceNode) {
    super();//from   w  w w  .j  a v a 2s .c  o  m

    add(new WebMarkupContainer("create-hl7-application-title").setVisible(hl7ApplicationModel == null));
    add(new WebMarkupContainer("edit-hl7-application-title").setVisible(hl7ApplicationModel != null));

    setOutputMarkupId(true);
    final ExtendedForm form = new ExtendedForm("form");
    form.setResourceIdPrefix("dicom.edit.hl7-application.");
    add(form);

    installedRendererChoices = new ArrayList<String>();
    installedRendererChoices
            .add(new ResourceModel("dicom.installed.true.text").wrapOnAssignment(this).getObject());
    installedRendererChoices
            .add(new ResourceModel("dicom.installed.false.text").wrapOnAssignment(this).getObject());

    ArrayList<ConnectionModel> connectionReferences = new ArrayList<ConnectionModel>();

    try {
        connectionReferencesModel = new Model<ArrayList<ConnectionModel>>();
        connectionReferencesModel.setObject(new ArrayList<ConnectionModel>());
        for (Connection connection : ((DeviceModel) deviceNode.getModel()).getDevice().listConnections()) {
            ConnectionModel connectionReference = new ConnectionModel(connection, 0);
            connectionReferences.add(connectionReference);
            if (hl7ApplicationModel != null
                    && hl7ApplicationModel.getHL7Application().getConnections().contains(connection))
                connectionReferencesModel.getObject().add(connectionReference);
        }

        if (hl7ApplicationModel == null) {
            applicationNameModel = Model.of();
            acceptedMessageTypesModel = new StringArrayModel(null);
            acceptedSendingApplicationsModel = new StringArrayModel(null);
            defaultCharacterSetModel = Model.of();
            installedModel = Model.of();
        } else {
            HL7Application hl7Application = hl7ApplicationModel.getHL7Application();

            applicationNameModel = Model.of(hl7Application.getApplicationName());
            acceptedMessageTypesModel = new StringArrayModel(hl7Application.getAcceptedMessageTypes());
            acceptedSendingApplicationsModel = new StringArrayModel(
                    hl7Application.getAcceptedSendingApplications());
            defaultCharacterSetModel = Model.of(hl7Application.getHL7DefaultCharacterSet());
            installedModel = Model.of(hl7Application.getInstalled());
        }
    } catch (ConfigurationException ce) {
        log.error(this.getClass().toString() + ": " + "Error retrieving hl7 application data: "
                + ce.getMessage());
        log.debug("Exception", ce);
        throw new ModalWindowRuntimeException(ce.getLocalizedMessage());
    }

    form.add(new Label("applicationName.label",
            new ResourceModel("dicom.edit.hl7-application.applicationName.label")))
            .add(new TextField<String>("applicationName", applicationNameModel)
                    .add(new HL7NameValidator(applicationNameModel.getObject())).setRequired(true)
                    .add(FocusOnLoadBehavior.newFocusAndSelectBehaviour()));

    form.add(new CheckBoxMultipleChoice<ConnectionModel>("connections", connectionReferencesModel,
            new Model<ArrayList<ConnectionModel>>(connectionReferences),
            new IChoiceRenderer<ConnectionModel>() {

                private static final long serialVersionUID = 1L;

                public Object getDisplayValue(ConnectionModel connectionReference) {
                    Connection connection = null;
                    try {
                        connection = connectionReference.getConnection();
                    } catch (Exception e) {
                        log.error(this.getClass().toString() + ": " + "Error obtaining connection: "
                                + e.getMessage());
                        log.debug("Exception", e);
                        throw new ModalWindowRuntimeException(e.getLocalizedMessage());
                    }
                    String location = connection.getHostname()
                            + (connection.getPort() == -1 ? "" : ":" + connection.getPort());
                    return connection.getCommonName() != null
                            ? connection.getCommonName() + " (" + location + ")"
                            : location;
                }

                public String getIdValue(ConnectionModel model, int index) {
                    return String.valueOf(index);
                }
            }).add(new ConnectionReferenceValidator())
                    .add(new ConnectionProtocolValidator(Connection.Protocol.HL7)));

    final WebMarkupContainer optionalContainer = new WebMarkupContainer("optional");
    form.add(optionalContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true).setVisible(false));

    form.add(new Label("toggleOptional.label", new ResourceModel("dicom.edit.toggleOptional.label")))
            .add(new AjaxCheckBox("toggleOptional", new Model<Boolean>()) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(optionalContainer.setVisible(this.getModelObject()));
                }
            });

    optionalContainer
            .add(new Label("acceptedMessageTypes.label",
                    new ResourceModel("dicom.edit.hl7-application.optional.acceptedMessageTypes.label")))
            .add(new TextArea<String>("acceptedMessageTypes", acceptedMessageTypesModel));

    optionalContainer
            .add(new Label("acceptedSendingApplications.label",
                    new ResourceModel("dicom.edit.hl7-application.optional.acceptedSendingApplications.label")))
            .add(new TextArea<String>("acceptedSendingApplications", acceptedSendingApplicationsModel));

    optionalContainer
            .add(new Label("defaultCharacterSet.label",
                    new ResourceModel("dicom.edit.hl7-application.optional.defaultCharacterSet.label")))
            .add(new TextField<String>("defaultCharacterSet", defaultCharacterSetModel));

    optionalContainer
            .add(new Label("installed.label",
                    new ResourceModel("dicom.edit.hl7-application.optional.installed.label")))
            .add(new DropDownChoice<Boolean>("installed", installedModel,
                    Arrays.asList(new Boolean[] { new Boolean(true), new Boolean(false) }),
                    new IChoiceRenderer<Boolean>() {

                        private static final long serialVersionUID = 1L;

                        public String getDisplayValue(Boolean object) {
                            return object.booleanValue() ? installedRendererChoices.get(0)
                                    : installedRendererChoices.get(1);
                        }

                        public String getIdValue(Boolean object, int index) {
                            return String.valueOf(index);
                        }
                    }).setNullValid(true));

    form.add(new IndicatingAjaxButton("submit", new ResourceModel("saveBtn"), form) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                String oldName = hl7ApplicationModel == null ? null
                        : hl7ApplicationModel.getHL7Application().getApplicationName();

                HL7Application hl7Application = hl7ApplicationModel == null
                        ? new HL7Application(applicationNameModel.getObject())
                        : (HL7Application) hl7ApplicationModel.getHL7Application();

                hl7Application.setApplicationName(applicationNameModel.getObject());
                hl7Application.getConnections().clear();
                for (ConnectionModel connectionReference : connectionReferencesModel.getObject())
                    for (Connection connection : ((DeviceModel) deviceNode.getModel()).getDevice()
                            .listConnections())
                        if (connectionReference.getConnection().getHostname().equals(connection.getHostname())
                                && connectionReference.getConnection().getPort() == connection.getPort())
                            hl7Application.addConnection(connection);

                hl7Application.setAcceptedMessageTypes(acceptedMessageTypesModel.getArray());
                hl7Application.setAcceptedSendingApplications(acceptedSendingApplicationsModel.getArray());
                hl7Application.setHL7DefaultCharacterSet(defaultCharacterSetModel.getObject());
                hl7Application.setInstalled(installedModel.getObject());

                if (hl7ApplicationModel == null) {
                    HL7DeviceExtension hl7DeviceExtension = ((DeviceModel) deviceNode.getModel()).getDevice()
                            .getDeviceExtension(HL7DeviceExtension.class);
                    if (hl7DeviceExtension == null) {
                        hl7DeviceExtension = new HL7DeviceExtension();
                        ((DeviceModel) deviceNode.getModel()).getDevice()
                                .addDeviceExtension(hl7DeviceExtension);
                    }
                    hl7DeviceExtension.addHL7Application(hl7Application);
                } else
                    ConfigTreeProvider.get().unregisterHL7Application(oldName);
                ConfigTreeProvider.get().mergeDevice(hl7Application.getDevice());
                ConfigTreeProvider.get().registerHL7Application(applicationNameModel.getObject());
                window.close(target);
            } catch (Exception e) {
                log.error(this.getClass().toString() + ": " + "Error modifying HL7 application: "
                        + e.getMessage());
                log.debug("Exception", e);
                throw new ModalWindowRuntimeException(e.getLocalizedMessage());
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            if (target != null)
                target.add(form);
        }
    });
    form.add(new AjaxFallbackButton("cancel", new ResourceModel("cancelBtn"), form) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            window.close(target);
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {
        }
    }.setDefaultFormProcessing(false));
}

From source file:org.efaps.ui.wicket.components.gridx.filter.ListFilterPanel.java

License:Apache License

/**
 * Instantiates a new list filter panel.
 *
 * @param _wicketid the wicketid/*w  w  w  .j  ava2  s.c  om*/
 * @param _model the model
 */
public ListFilterPanel(final String _wicketid, final IModel<IListFilter> _model) {
    super(_wicketid, _model);
    final List<IOption> selected = _model.getObject().stream().filter(new Predicate<IOption>() {
        @Override
        public boolean test(final IOption _option) {
            return _option.isSelected();
        }
    }).collect(Collectors.toList());

    @SuppressWarnings({ "rawtypes", "unchecked" })
    final CheckBoxMultipleChoice<IOption> checkBoxes = new CheckBoxMultipleChoice("checkBoxes",
            Model.of(selected), (List) getModelObject(), new ChoiceRenderer());
    add(checkBoxes);
}