Example usage for org.apache.wicket.markup.html WebMarkupContainer isVisible

List of usage examples for org.apache.wicket.markup.html WebMarkupContainer isVisible

Introduction

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

Prototype

public boolean isVisible() 

Source Link

Document

Gets whether this component and any children are visible.

Usage

From source file:by.grodno.ss.rentacar.webapp.page.admin.panel.UserEditPanel.java

@Override
public void onInitialize() {
    super.onInitialize();
    UserEditPanel.this.setOutputMarkupId(true);

    Form<UserProfile> form = new Form<UserProfile>("form", new CompoundPropertyModel<UserProfile>(userProfile));

    TextField<String> created = new TextField<String>("created");
    created.setEnabled(false);/*w  w w . j  av a2s .  c o  m*/
    form.add(created);

    TextField<String> email = new TextField<String>("email", new PropertyModel<>(userCredentials, "email"));
    email.setRequired(true);
    email.add(StringValidator.maximumLength(100));
    email.add(StringValidator.minimumLength(3));
    email.add(EmailAddressValidator.getInstance());
    form.add(email);

    DropDownChoice<UserRole> roleDropDown = new DropDownChoice<>("role",
            new PropertyModel<>(userCredentials, "role"), Arrays.asList(UserRole.values()),
            UserRoleChoiceRenderer.INSTANCE);
    roleDropDown.setRequired(true);
    form.add(roleDropDown);

    TextField<String> firstName = new TextField<String>("firstName");
    firstName.setRequired(true);
    firstName.add(StringValidator.maximumLength(100));
    firstName.add(StringValidator.minimumLength(2));
    firstName.add(new PatternValidator("[A-Za-z]+"));
    form.add(firstName);

    TextField<String> lastName = new TextField<String>("lastName");
    lastName.setRequired(true);
    lastName.add(StringValidator.maximumLength(100));
    lastName.add(StringValidator.minimumLength(2));
    lastName.add(new PatternValidator("[A-Za-z]+"));
    form.add(lastName);

    TextField<String> phone = new TextField<String>("phoneNumber");
    phone.setRequired(true);
    phone.add(StringValidator.maximumLength(100));
    phone.add(StringValidator.minimumLength(2));
    phone.add(new PatternValidator("[0-9+()-]+"));
    form.add(phone);

    TextField<String> licNumber = new TextField<String>("licenseNumber");
    licNumber.add(StringValidator.maximumLength(100));
    licNumber.add(StringValidator.minimumLength(2));
    licNumber.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(licNumber);

    DateTextFieldConfig config = new DateTextFieldConfig();
    config.withLanguage(AuthorizedSession.get().getLocale().getLanguage());
    config.withFormat("dd.MM.yyyy");
    DateTextField dateBirth = new DateTextField("birthDay", config);
    form.add(dateBirth);

    TextField<String> address = new TextField<String>("address");
    address.add(StringValidator.maximumLength(100));
    address.add(StringValidator.minimumLength(2));
    address.add(new PatternValidator("[A-Za-z0-9 /-]+"));
    form.add(address);

    TextField<String> city = new TextField<String>("city");
    city.add(StringValidator.maximumLength(100));
    city.add(StringValidator.minimumLength(2));
    city.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(city);

    TextField<String> region = new TextField<String>("region");
    region.add(StringValidator.maximumLength(100));
    region.add(StringValidator.minimumLength(2));
    region.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(region);

    TextField<String> zip = new TextField<String>("zipCode");
    zip.add(StringValidator.maximumLength(20));
    zip.add(StringValidator.minimumLength(2));
    zip.add(new PatternValidator("[0-9]+"));
    form.add(zip);

    WebMarkupContainer passTable = new WebMarkupContainer("pass-table");
    passTable.setOutputMarkupId(true);

    WebMarkupContainer trPass = new WebMarkupContainer("pass");
    WebMarkupContainer trCpass = new WebMarkupContainer("cpass");
    if (userProfile.getId() == null) {
        trPass.setVisible(true);
        trCpass.setVisible(true);
    } else {
        trPass.setVisible(false);
        trCpass.setVisible(false);
    }
    trPass.setOutputMarkupId(true);
    trCpass.setOutputMarkupId(true);

    PasswordTextField password = new PasswordTextField("password",
            new PropertyModel<>(userCredentials, "password"));
    trPass.add(password);
    PasswordTextField cpassword = new PasswordTextField("cpassword", Model.of(""));
    trCpass.add(cpassword);

    passTable.add(trPass);
    passTable.add(trCpass);
    form.add(passTable);
    form.add(new EqualPasswordInputValidator(password, cpassword));

    AjaxLink<Void> changePass = new AjaxLink<Void>("change-password") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (!trPass.isVisible()) {
                trPass.setVisible(true);
                trCpass.setVisible(true);
                passTable.add(trPass);
                passTable.add(trCpass);
            } else {
                trPass.setVisible(false);
                trCpass.setVisible(false);
            }
            if (target != null) {
                target.add(passTable);
            }
        }
    };
    if (userProfile.getId() == null) {
        changePass.setVisible(false);
    }
    form.add(changePass);

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

        @Override
        public void onSubmit() {
            if (userProfile.getId() == null) {
                userService.register(userProfile, userCredentials);
            } else {
                userService.update(userProfile);
                userService.update(userCredentials);
            }
            info("User was saved");
        }
    });

    boolean a = (AuthorizedSession.get().isSignedIn()
            && AuthorizedSession.get().getLoggedUser().getRole().equals(UserRole.ADMIN));
    form.setEnabled(a);
    add(form);

    add(new AjaxLink<Void>("back") {
        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            Component newPanel = new UserListPanel(UserEditPanel.this.getId(), filter);
            UserEditPanel.this.replaceWith(newPanel);
            if (target != null) {
                target.add(newPanel);
            }
        }
    });
}

From source file:by.grodno.ss.rentacar.webapp.page.MyBooking.ProfileEditPanel.java

@Override
public void onInitialize() {
    super.onInitialize();
    final NotificationPanel feedback = new NotificationPanel("feedbackpanel");
    add(feedback);//from   w w w  .  j  av a 2  s.c o  m

    Form<UserProfile> form = new Form<UserProfile>("form", new CompoundPropertyModel<UserProfile>(userProfile));

    TextField<String> firstName = new TextField<String>("firstName");
    firstName.setRequired(true);
    firstName.add(StringValidator.maximumLength(100));
    firstName.add(StringValidator.minimumLength(2));
    firstName.add(new PatternValidator("[A-Za-z]+"));
    form.add(firstName);

    TextField<String> lastName = new TextField<String>("lastName");
    lastName.setRequired(true);
    lastName.add(StringValidator.maximumLength(100));
    lastName.add(StringValidator.minimumLength(2));
    lastName.add(new PatternValidator("[A-Za-z]+"));
    form.add(lastName);

    TextField<String> phone = new TextField<String>("phoneNumber");
    phone.setRequired(true);
    phone.add(StringValidator.maximumLength(100));
    phone.add(StringValidator.minimumLength(2));
    phone.add(new PatternValidator("[0-9+()-]+"));
    form.add(phone);

    TextField<String> licNumber = new TextField<String>("licenseNumber");
    licNumber.add(StringValidator.maximumLength(100));
    licNumber.add(StringValidator.minimumLength(2));
    licNumber.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(licNumber);

    DateTextFieldConfig config = new DateTextFieldConfig();
    config.withLanguage(AuthorizedSession.get().getLocale().getLanguage());
    config.withFormat("dd.MM.yyyy");
    DateTextField dateBirth = new DateTextField("birthDay", config);
    form.add(dateBirth);

    TextField<String> address = new TextField<String>("address");
    address.add(StringValidator.maximumLength(100));
    address.add(StringValidator.minimumLength(2));
    address.add(new PatternValidator("[A-Za-z0-9 /-]+"));
    form.add(address);

    TextField<String> city = new TextField<String>("city");
    city.add(StringValidator.maximumLength(100));
    city.add(StringValidator.minimumLength(2));
    city.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(city);

    TextField<String> region = new TextField<String>("region");
    region.add(StringValidator.maximumLength(100));
    region.add(StringValidator.minimumLength(2));
    region.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(region);

    TextField<String> zip = new TextField<String>("zipCode");
    zip.add(StringValidator.maximumLength(20));
    zip.add(StringValidator.minimumLength(2));
    zip.add(new PatternValidator("[0-9]+"));
    form.add(zip);

    Label email = new Label("email", new PropertyModel<>(userCredentials, "email"));
    form.add(email);

    WebMarkupContainer passTable = new WebMarkupContainer("pass-table");
    passTable.setOutputMarkupId(true);

    WebMarkupContainer trPass = new WebMarkupContainer("pass");
    WebMarkupContainer trCpass = new WebMarkupContainer("cpass");
    if (userProfile.getId() == null) {
        trPass.setVisible(true);
        trCpass.setVisible(true);
    } else {
        trPass.setVisible(false);
        trCpass.setVisible(false);
    }
    trPass.setOutputMarkupId(true);
    trCpass.setOutputMarkupId(true);

    PasswordTextField password = new PasswordTextField("password",
            new PropertyModel<>(userCredentials, "password"));
    trPass.add(password);
    PasswordTextField cpassword = new PasswordTextField("cpassword", Model.of(""));
    trCpass.add(cpassword);

    passTable.add(trPass);
    passTable.add(trCpass);
    form.add(passTable);
    form.add(new EqualPasswordInputValidator(password, cpassword));

    AjaxLink<Void> changePass = new AjaxLink<Void>("change-password") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (!trPass.isVisible()) {
                trPass.setVisible(true);
                trCpass.setVisible(true);
                passTable.add(trPass);
                passTable.add(trCpass);
            } else {
                trPass.setVisible(false);
                trCpass.setVisible(false);
            }
            if (target != null) {
                target.add(passTable);
            }
        }
    };
    if (userProfile.getId() == null) {
        changePass.setVisible(false);
    }
    form.add(changePass);

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

        @Override
        public void onSubmit() {
            if (userProfile.getId() == null) {
                error("saving error");
            } else {
                userService.update(userProfile);
                userService.update(userCredentials);
            }
            info("User was saved");
        }
    });
    add(form);

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

        @Override
        public void onClick() {
            setResponsePage(new MyBookingPage());
        }
    });
}

From source file:info.jtrac.wicket.ExcelImportColumnPage.java

License:Apache License

public ExcelImportColumnPage(final ExcelImportPage previous, final int index) {

    add(new FeedbackPanel("feedback"));

    space = previous.getSpace();//from  w  ww .j ava  2 s.com
    excelFile = previous.getExcelFile();
    this.index = index;
    column = excelFile.getColumns().get(index).getClone();
    columnCells = excelFile.getColumnCellsCloned(index);
    final Map<Name, String> labelsMap = BasePage.getLocalizedLabels(this);

    Form form = new Form("form");

    add(form);

    DropDownChoice columnChoice = new DropDownChoice("column");
    columnChoice.setChoices(new AbstractReadOnlyModel() {
        @Override
        public Object getObject() {
            // avoid lazy init problem
            Space s = getJtrac().loadSpace(space.getId());
            List<ColumnHeading> list = ColumnHeading.getColumnHeadings(s);
            list.remove(new ColumnHeading(Name.ID));
            list.remove(new ColumnHeading(Name.SPACE));
            return list;
        }
    });
    columnChoice.setChoiceRenderer(new IChoiceRenderer() {
        @Override
        public Object getDisplayValue(Object o) {
            ColumnHeading ch = (ColumnHeading) o;
            if (ch.isField()) {
                return ch.getLabel();
            }
            return labelsMap.get(ch.getName());
        }

        @Override
        public String getIdValue(Object o, int i) {
            ColumnHeading ch = (ColumnHeading) o;
            return ch.getNameText();
        }
    });
    columnChoice.setModel(new PropertyModel(column, "columnHeading"));
    columnChoice.setNullValid(true);

    form.add(columnChoice);

    Button previewButton = new Button("preview") {
        @Override
        public void onSubmit() {
            if (column.getColumnHeading() == null) {
                return;
            }
        }
    };

    form.add(previewButton);

    form.add(new Link("cancel") {
        @Override
        public void onClick() {
            setResponsePage(previous);
        }
    });

    final WebMarkupContainer columnCellsContainer = new WebMarkupContainer("columnCells") {
        @Override
        public boolean isVisible() {
            return column.getColumnHeading() != null;
        }
    };

    form.add(columnCellsContainer);

    final WebMarkupContainer distinctCellsContainer = new WebMarkupContainer("distinctCells") {
        @Override
        public boolean isVisible() {
            ColumnHeading ch = column.getColumnHeading();
            return ch != null && ch.isDropDownType();
        }
    };

    columnCellsContainer.add(new Label("header", new PropertyModel(column, "label")));
    columnCellsContainer.add(new ReadOnlyRefreshingView<Cell>("rows") {
        @Override
        public List<Cell> getObjectList() {
            return columnCells;
        }

        @Override
        protected void populateItem(Item item) {
            if (item.getIndex() % 2 == 1) {
                item.add(CLASS_ALT);
            }
            item.add(new Label("index", item.getIndex() + 1 + ""));
            Cell cell = (Cell) item.getModelObject();
            Label label = new Label("cell", new PropertyModel(cell, "valueAsString"));
            label.setEscapeModelStrings(false);
            if (!cell.isValid(column.getColumnHeading())) {
                label.add(CLASS_ERROR_BACK);
            }
            item.add(label);
            if (mappedDisplayValues != null && distinctCellsContainer.isVisible() && cell.getKey() != null) {
                String mapped = mappedDisplayValues.get(cell.getKey());
                item.add(new Label("mapped", mapped));
            } else {
                item.add(new WebMarkupContainer("mapped"));
            }
        }
    });

    form.add(distinctCellsContainer);

    distinctCellsContainer.add(new DistinctCellsView("rows"));

    Button updateButton = new Button("update") {
        @Override
        public void onSubmit() {
            if (distinctCellsContainer.isVisible()) {
                for (Cell cell : columnCells) {
                    IModel model = mappedKeys.get(cell.getValueAsString());
                    Object o = model.getObject();
                    cell.setKey(o);
                }
            }
        }

        @Override
        public boolean isVisible() {
            return distinctCellsContainer.isVisible();
        }
    };

    form.add(updateButton);

    Button submitButton = new Button("submit") {
        @Override
        public void onSubmit() {
            ColumnHeading ch = column.getColumnHeading();
            for (Cell cell : columnCells) {
                if (!cell.isValid(ch)) {
                    error(localize("excel_view.error.invalidValue"));
                    return;
                }
            }
            if (ch.isField()) {
                column.setLabel(ch.getLabel());
            } else {
                column.setLabel(labelsMap.get(column.getColumnHeading().getName()));
            }
            excelFile.getColumns().set(index, column);
            if (distinctCellsContainer.isVisible()) {
                for (Cell cell : columnCells) {
                    cell.setValue(mappedDisplayValues.get(cell.getKey()));
                }
                excelFile.setColumnCells(index, columnCells);
            }
            setResponsePage(previous);
        }

        @Override
        public boolean isVisible() {
            return columnCellsContainer.isVisible();
        }
    };

    form.add(submitButton);

}

From source file:jp.go.nict.langrid.management.web.view.page.language.service.composite.component.form.panel.ServiceInvocationListFormPanel.java

License:Open Source License

/**
 * /*from  w ww  . jav a2s .  c o m*/
 * 
 */
public List<InvocationModel> getInvocations(String ownerServiceId) throws ServiceManagerException {
    List<InvocationModel> invocations = new ArrayList<InvocationModel>();
    Iterator ite = repeating.iterator();
    while (ite.hasNext()) {
        WebMarkupContainer wmc = (WebMarkupContainer) ite.next();
        WebMarkupContainer serviceSelect = (WebMarkupContainer) wmc.get("serviceSelect");

        TextField<String> name = (TextField<String>) wmc.get("invocationName");
        ServiceTypeDropDownChoice typeChoice = (ServiceTypeDropDownChoice) wmc.get("serviceTypeChoice");
        ServiceDropDownChoice serviceChoice = (ServiceDropDownChoice) serviceSelect.get("serviceChoice");

        InvocationModel invocation = new InvocationModel();
        invocation.setOwnerServiceGridId(gridId);
        invocation.setOwnerServiceId(ownerServiceId);

        invocation.setInvocationName(name.getModelObject());

        if (serviceSelect.isVisible()) { // Other Type
            ServiceModel model = serviceChoice.getSelectedService();
            invocation.setServiceTypeId(null);
            if (model != null) {
                invocation.setServiceGridId(model.getGridId());
                if (!model.getServiceId().isEmpty()) {
                    invocation.setServiceId(model.getServiceId());
                }
                if (!model.getServiceName().isEmpty()) {
                    invocation.setServiceName(model.getServiceName());
                }
            } else {
                invocation.setServiceId(null);
                invocation.setServiceName(null);
            }
        } else {
            ServiceTypeModel model = typeChoice.getSelectedType();
            invocation.setServiceGridId(gridId);
            invocation.setDomainId(model == null ? null : model.getDomainId());
            invocation.setServiceTypeId(model == null ? null : model.getTypeId());
        }
        invocations.add(invocation);
    }
    return invocations;
}

From source file:org.atricore.idbus.capabilities.sso.ui.page.BasePage.java

License:Open Source License

@Override
protected void onInitialize() {
    super.onInitialize();
    getSession().bind();/*from  w w  w .  j a v a 2  s .  com*/

    // ---------------------------------------------------------------------
    // Resolve variation (branding)
    // ---------------------------------------------------------------------
    BaseWebApplication app = (BaseWebApplication) getApplication();
    WebBranding branding = app.getBranding();

    String variation = resolveVariation(branding);
    setVariation(variation);

    final SSOWebSession session = (SSOWebSession) getSession();

    // ---------------------------------------------------------------------
    // Utility box (current user, logout)
    // ---------------------------------------------------------------------
    WebMarkupContainer utilityBox = new WebMarkupContainer("utilityBox") {
        @Override
        public boolean isVisible() {
            return (session).isAuthenticated();
        };
    };

    if (session.isAuthenticated())
        utilityBox.add(new Label("username", session.getPrincipal()));

    add(utilityBox);

    // ---------------------------------------------------------------------
    // Navigation Bar
    // ---------------------------------------------------------------------
    // Do not display the menu for the IdBus ERROR PAGE
    WebMarkupContainer navBar = new WebMarkupContainer("navbar") {
        @Override
        public boolean isVisible() {
            return session.isAuthenticated();
        };
    };

    if (navBar.isVisible()) {
        // Select the proper section on the navbar (alter css class)

        // Dashboard
        if (this instanceof DashboardPage)
            navBar.add(new BookmarkablePageLink<Void>("dashboard", resolvePage("SS/HOME"))
                    .add(new AttributeAppender("class", "gt-active")));
        else
            navBar.add(new BookmarkablePageLink<Void>("dashboard", resolvePage("SS/HOME")));

        // Profile
        if (this instanceof ProfilePage)
            navBar.add(new BookmarkablePageLink<Void>("profile", resolvePage("SS/PROFILE"))
                    .add(new AttributeAppender("class", "gt-active")));
        else
            navBar.add(new BookmarkablePageLink<Void>("profile", resolvePage("SS/PROFILE")));

        // Change Password
        if (this instanceof PwdChangePage)
            navBar.add(new BookmarkablePageLink<Void>("pwdChange", resolvePage("SS/PWDCHANGE"))
                    .add(new AttributeAppender("class", "gt-active")));
        else
            navBar.add(new BookmarkablePageLink<Void>("pwdChange", resolvePage("SS/PWDCHANGE")));

        // Logout 1
        navBar.add(new BookmarkablePageLink<Void>("logout", resolvePage("AGENT/LOGOUT")));

        // Logout 2
    }

    add(navBar);

}

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.  ja  v  a2s. co m*/

    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.geoserver.web.data.resource.FeatureResourceConfigurationPanel.java

License:Open Source License

public FeatureResourceConfigurationPanel(String id, final IModel model) {
    super(id, model);

    CheckBox circularArcs = new CheckBox("circularArcPresent");
    add(circularArcs);//from  w w  w . j  av  a2 s .co m

    TextField<Measure> tolerance = new TextField<Measure>("linearizationTolerance", Measure.class);
    add(tolerance);

    attributePanel = new Fragment("attributePanel", "attributePanelFragment", this);
    attributePanel.setOutputMarkupId(true);
    add(attributePanel);

    // We need to use the resourcePool directly because we're playing with an edited
    // FeatureTypeInfo and the info.getFeatureType() and info.getAttributes() will hit
    // the resource pool without the modified properties (since it passes "this" into calls
    // to the ResourcePoool

    // just use the direct attributes, this is not editable atm
    attributes = new ListView("attributes", new AttributeListModel()) {
        @Override
        protected void populateItem(ListItem item) {

            // odd/even style
            item.add(new SimpleAttributeModifier("class", item.getIndex() % 2 == 0 ? "even" : "odd"));

            // dump the attribute information we have
            AttributeTypeInfo attribute = (AttributeTypeInfo) item.getModelObject();
            item.add(new Label("name", attribute.getName()));
            item.add(new Label("minmax", attribute.getMinOccurs() + "/" + attribute.getMaxOccurs()));
            try {
                // working around a serialization issue
                FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject();
                final ResourcePool resourcePool = GeoServerApplication.get().getCatalog().getResourcePool();
                final FeatureType featureType = resourcePool.getFeatureType(typeInfo);
                org.opengis.feature.type.PropertyDescriptor pd = featureType.getDescriptor(attribute.getName());
                String typeName = "?";
                String nillable = "?";
                try {
                    typeName = pd.getType().getBinding().getSimpleName();
                    nillable = String.valueOf(pd.isNillable());
                } catch (Exception e) {
                    LOGGER.log(Level.INFO, "Could not find attribute " + attribute.getName()
                            + " in feature type " + featureType, e);
                }
                item.add(new Label("type", typeName));
                item.add(new Label("nillable", nillable));
            } catch (IOException e) {
                item.add(new Label("type", "?"));
                item.add(new Label("nillable", "?"));
            }
        }

    };
    attributePanel.add(attributes);

    TextArea<String> cqlFilter = new TextArea<String>("cqlFilter");
    cqlFilter.add(new CqlFilterValidator(model));
    add(cqlFilter);

    // reload links
    WebMarkupContainer reloadContainer = new WebMarkupContainer("reloadContainer");
    attributePanel.add(reloadContainer);
    GeoServerAjaxFormLink reload = new GeoServerAjaxFormLink("reload") {
        @Override
        protected void onClick(AjaxRequestTarget target, Form form) {
            GeoServerApplication app = (GeoServerApplication) getApplication();

            FeatureTypeInfo ft = (FeatureTypeInfo) getResourceInfo();
            app.getCatalog().getResourcePool().clear(ft);
            app.getCatalog().getResourcePool().clear(ft.getStore());
            target.addComponent(attributePanel);
        }
    };
    reloadContainer.add(reload);

    GeoServerAjaxFormLink warning = new GeoServerAjaxFormLink("reloadWarning") {
        @Override
        protected void onClick(AjaxRequestTarget target, Form form) {
            reloadWarningDialog.show(target);
        }
    };
    reloadContainer.add(warning);

    add(reloadWarningDialog = new ModalWindow("reloadWarningDialog"));
    reloadWarningDialog.setPageCreator(new ModalWindow.PageCreator() {
        public Page createPage() {
            return new ReloadWarningDialog(new StringResourceModel("featureTypeReloadWarning",
                    FeatureResourceConfigurationPanel.this, null));
        }
    });
    reloadWarningDialog.setTitle(new StringResourceModel("warning", (Component) null, null));
    reloadWarningDialog.setInitialHeight(100);
    reloadWarningDialog.setInitialHeight(200);

    // sql view handling
    WebMarkupContainer sqlViewContainer = new WebMarkupContainer("editSqlContainer");
    attributePanel.add(sqlViewContainer);
    sqlViewContainer.add(new Link("editSql") {

        @Override
        public void onClick() {
            FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject();
            try {
                setResponsePage(new SQLViewEditPage(typeInfo, ((ResourceConfigurationPage) this.getPage())));
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Failure opening the sql view edit page", e);
                error(e.toString());
            }
        }

    });

    // which one do we show, reload or edit?
    FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject();
    reloadContainer.setVisible(
            typeInfo.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class) == null);
    sqlViewContainer.setVisible(!reloadContainer.isVisible());

    // Cascaded Stored Query
    WebMarkupContainer cascadedStoredQueryContainer = new WebMarkupContainer(
            "editCascadedStoredQueryContainer");
    attributePanel.add(cascadedStoredQueryContainer);
    cascadedStoredQueryContainer.add(new Link("editCascadedStoredQuery") {
        @Override
        public void onClick() {
            FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject();
            try {
                setResponsePage(new CascadedWFSStoredQueryEditPage(typeInfo,
                        ((ResourceConfigurationPage) this.getPage())));
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Failure opening the sql view edit page", e);
                error(e.toString());
            }
        }
    });
    cascadedStoredQueryContainer.setVisible(typeInfo.getMetadata()
            .get(FeatureTypeInfo.STORED_QUERY_CONFIGURATION, StoredQueryConfiguration.class) != null);
}

From source file:org.headsupdev.agile.app.ci.Tests.java

License:Open Source License

public void layout() {
    super.layout();
    add(CSSPackageResource.getHeaderContribution(getClass(), "ci.css"));

    Project project = getProject();/*from w w  w .j  av a 2s.  com*/
    long id = getPageParameters().getLong("id");
    if (project == null || id < 0) {
        notFoundError();
        return;
    }

    Build build = CIApplication.getBuild(id, getProject());
    addLink(new BookmarkableMenuLink(getPageClass("builds/"), getProjectPageParameters(), "history"));
    addLink(new BookmarkableMenuLink(getPageClass("builds/view"), getPageParameters(), "view"));

    buildId = build.getId();
    add(new Label("project", build.getProject().getAlias()));
    add(new Label("tests", String.valueOf(build.getTests())));
    add(new Label("failures", String.valueOf(build.getFailures())));
    add(new Label("errors", String.valueOf(build.getErrors())));

    List<TestResultSet> sets = new LinkedList<TestResultSet>(build.getTestResults());
    Collections.sort(sets, new Comparator<TestResultSet>() {
        public int compare(TestResultSet t1, TestResultSet t2) {
            return t1.getName().compareToIgnoreCase(t2.getName());
        }
    });
    add(new ListView<TestResultSet>("set", sets) {
        protected void populateItem(ListItem<TestResultSet> listItem) {
            final TestResultSet set = listItem.getModelObject();

            listItem.add(new Label("name", set.getName()));
            String icon;
            if (set.getErrors() > 0) {
                icon = "error.png";
            } else if (set.getFailures() > 0) {
                icon = "failed.png";
            } else {
                icon = "passed.png";
            }
            listItem.add(new Image("status", new ResourceReference(View.class, icon)));

            listItem.add(new Label("tests", String.valueOf(set.getTests())));
            listItem.add(new Label("failures", String.valueOf(set.getFailures())));
            listItem.add(new Label("errors", String.valueOf(set.getErrors())));

            final WebMarkupContainer log = new WebMarkupContainer("log");
            log.add(new Label("output", new Model<String>() {
                String output = null;

                @Override
                public String getObject() {
                    if (output == null) {
                        output = set.getOutput();
                    }

                    return output;
                }
            }));
            listItem.add(log.setOutputMarkupId(true).setVisible(false).setOutputMarkupPlaceholderTag(true));

            AjaxLink logLink = new AjaxLink("log-link") {
                public void onClick(AjaxRequestTarget target) {
                    log.setVisible(!log.isVisible());
                    target.addComponent(log);
                }
            };
            logLink.add(new Image("log-icon", new ResourceReference(Tests.class, "log.png")));
            listItem.add(logLink.setVisible(set.getOutput() != null));

            listItem.add(new Label("time", new FormattedDurationModel(set.getDuration())));

            List<TestResult> results = new LinkedList<TestResult>(set.getResults());
            Collections.sort(results, new Comparator<TestResult>() {
                public int compare(TestResult r1, TestResult r2) {
                    if (r1.getStatus() == r2.getStatus()) {
                        return r1.getName().compareToIgnoreCase(r2.getName());
                    }

                    return r2.getStatus() - r1.getStatus();
                }
            });
            listItem.add(new ListView<TestResult>("test", results) {
                protected void populateItem(final ListItem<TestResult> listItem) {
                    AttributeModifier rowColor = new AttributeModifier("class", true, new Model<String>() {
                        public String getObject() {
                            if (listItem.getIndex() % 2 == 1) {
                                return "odd";
                            }

                            return "even";
                        }
                    });
                    final TestResult result = listItem.getModelObject();

                    WebMarkupContainer row1 = new WebMarkupContainer("row1");
                    row1.add(rowColor);
                    listItem.add(row1);

                    String icon;
                    switch (result.getStatus()) {
                    case TestResult.STATUS_ERROR:
                        icon = "error.png";
                        break;
                    case TestResult.STATUS_FAILED:
                        icon = "failed.png";
                        break;
                    default:
                        icon = "passed.png";
                    }
                    row1.add(new Image("status", new ResourceReference(View.class, icon)));

                    if (result.getMessage() != null && result.getMessage().length() > 0) {
                        if (result.getStatus() == TestResult.STATUS_FAILED) {
                            row1.add(new Label("name",
                                    result.getName() + " (failed: " + result.getMessage() + ")"));
                        } else {
                            row1.add(new Label("name",
                                    result.getName() + " (error: " + result.getMessage() + ")"));
                        }
                    } else {
                        row1.add(new Label("name", result.getName()));
                    }

                    boolean showOutput = result.getStatus() == TestResult.STATUS_ERROR
                            || result.getStatus() == TestResult.STATUS_FAILED;
                    showOutput = showOutput && result.getOutput() != null;

                    final WebMarkupContainer row2 = new WebMarkupContainer("row2");
                    row2.add(rowColor);
                    row2.add(new Label("output", new Model<String>() {
                        @Override
                        public String getObject() {
                            return result.getOutput();
                        }
                    }));
                    listItem.add(row2.setVisible(false).setOutputMarkupPlaceholderTag(true));

                    AjaxLink logLink = new AjaxLink("log-link") {
                        public void onClick(AjaxRequestTarget target) {
                            row2.setVisible(!row2.isVisible());
                            target.addComponent(row2);
                        }
                    };
                    logLink.add(new Image("log-icon", new ResourceReference(Tests.class, "log.png")));
                    row1.add(logLink.setVisible(showOutput));
                    row1.add(new Label("time", new FormattedDurationModel(result.getDuration())));
                }
            });
        }
    });
}