Example usage for org.apache.wicket.extensions.ajax.markup.html IndicatingAjaxButton setDefaultFormProcessing

List of usage examples for org.apache.wicket.extensions.ajax.markup.html IndicatingAjaxButton setDefaultFormProcessing

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html IndicatingAjaxButton setDefaultFormProcessing.

Prototype

@Override
public final Button setDefaultFormProcessing(boolean defaultFormProcessing) 

Source Link

Document

Sets the defaultFormProcessing property.

Usage

From source file:org.apache.syncope.client.console.pages.ConnectorModalPage.java

License:Apache License

public ConnectorModalPage(final PageReference pageRef, final ModalWindow window,
        final ConnInstanceTO connInstanceTO) {

    super();//w  ww  . j  a  v a2  s .  c o m

    this.add(new Label("new",
            connInstanceTO.getKey() == 0 ? new ResourceModel("new") : new Model<>(StringUtils.EMPTY)));
    this.add(new Label("key", connInstanceTO.getKey() == 0 ? StringUtils.EMPTY : connInstanceTO.getKey()));

    // general data setup
    selectedCapabilities = new ArrayList<>(
            connInstanceTO.getKey() == 0 ? EnumSet.noneOf(ConnectorCapability.class)
                    : connInstanceTO.getCapabilities());

    mapConnBundleTOs = new HashMap<>();
    for (ConnBundleTO connBundleTO : restClient.getAllBundles()) {
        // by location
        if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) {
            mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>());
        }
        final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs
                .get(connBundleTO.getLocation());

        // by name
        if (!byLocation.containsKey(connBundleTO.getBundleName())) {
            byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>());
        }
        final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName());

        // by version
        if (!byName.containsKey(connBundleTO.getVersion())) {
            byName.put(connBundleTO.getVersion(), connBundleTO);
        }
    }

    bundleTO = getSelectedBundleTO(connInstanceTO);
    properties = fillProperties(bundleTO, connInstanceTO);

    // form - first tab
    final Form<ConnInstanceTO> connectorForm = new Form<>(FORM);
    connectorForm.setModel(new CompoundPropertyModel<>(connInstanceTO));
    connectorForm.setOutputMarkupId(true);
    add(connectorForm);

    propertiesContainer = new WebMarkupContainer("container");
    propertiesContainer.setOutputMarkupId(true);
    connectorForm.add(propertiesContainer);

    final Form<ConnInstanceTO> connectorPropForm = new Form<>("connectorPropForm");
    connectorPropForm.setModel(new CompoundPropertyModel<>(connInstanceTO));
    connectorPropForm.setOutputMarkupId(true);
    propertiesContainer.add(connectorPropForm);

    final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name",
            new PropertyModel<String>(connInstanceTO, "displayName"));
    displayName.setOutputMarkupId(true);
    displayName.addRequiredLabel();
    connectorForm.add(displayName);

    final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<>("location", "location",
            new Model<>(bundleTO == null ? null : bundleTO.getLocation()));
    ((DropDownChoice<String>) location.getField()).setNullValid(true);
    location.setStyleSheet("long_dynamicsize");
    location.setChoices(new ArrayList<>(mapConnBundleTOs.keySet()));
    location.setRequired(true);
    location.addRequiredLabel();
    location.setOutputMarkupId(true);
    location.setEnabled(connInstanceTO.getKey() == 0);
    location.getField().setOutputMarkupId(true);
    connectorForm.add(location);

    final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<>("connectorName",
            "connectorName", new Model<>(bundleTO == null ? null : bundleTO.getBundleName()));
    ((DropDownChoice<String>) connectorName.getField()).setNullValid(true);
    connectorName.setStyleSheet("long_dynamicsize");
    connectorName.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet()));
    connectorName.setRequired(true);
    connectorName.addRequiredLabel();
    connectorName.setEnabled(connInstanceTO.getLocation() != null);
    connectorName.setOutputMarkupId(true);
    connectorName.setEnabled(connInstanceTO.getKey() == 0);
    connectorName.getField().setOutputMarkupId(true);
    connectorForm.add(connectorName);

    final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version",
            new Model<>(bundleTO == null ? null : bundleTO.getVersion()));
    version.setStyleSheet("long_dynamicsize");
    version.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation())
                    .get(connInstanceTO.getBundleName()).keySet()));
    version.setRequired(true);
    version.addRequiredLabel();
    version.setEnabled(connInstanceTO.getBundleName() != null);
    version.setOutputMarkupId(true);
    version.addRequiredLabel();
    version.getField().setOutputMarkupId(true);
    connectorForm.add(version);

    final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<>("connRequestTimeout",
            "connRequestTimeout", Integer.class,
            new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null);
    connRequestTimeout.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(connRequestTimeout);

    if (connInstanceTO.getPoolConf() == null) {
        connInstanceTO.setPoolConf(new ConnPoolConfTO());
    }
    final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<>("poolMaxObjects",
            "poolMaxObjects", Integer.class,
            new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null);
    poolMaxObjects.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxObjects);
    final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<>("poolMinIdle", "poolMinIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null);
    poolMinIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMinIdle);
    final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<>("poolMaxIdle", "poolMaxIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null);
    poolMaxIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxIdle);
    final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<>("poolMaxWait", "poolMaxWait",
            Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null);
    poolMaxWait.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMaxWait);
    final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<>("poolMinEvictableIdleTime",
            "poolMinEvictableIdleTime", Long.class,
            new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null);
    poolMinEvictableIdleTime.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMinEvictableIdleTime);

    // form - first tab - onchange()
    location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) location.getField()).setNullValid(false);
            connInstanceTO.setLocation(location.getModelObject());
            target.add(location);

            connectorName.setChoices(new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()).keySet()));
            connectorName.setEnabled(true);
            connectorName.getField().setModelValue(null);
            target.add(connectorName);

            version.setChoices(new ArrayList<String>());
            version.getField().setModelValue(null);
            version.setEnabled(false);
            target.add(version);

            properties.clear();
            target.add(propertiesContainer);
        }
    });
    connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) connectorName.getField()).setNullValid(false);
            connInstanceTO.setBundleName(connectorName.getModelObject());
            target.add(connectorName);

            List<String> versions = new ArrayList<>(mapConnBundleTOs.get(location.getModelObject())
                    .get(connectorName.getModelObject()).keySet());
            version.setChoices(versions);
            version.setEnabled(true);
            if (versions.size() == 1) {
                selectVersion(target, connInstanceTO, version, versions.get(0));
                version.getField().setModelObject(versions.get(0));
            } else {
                version.getField().setModelValue(null);
                properties.clear();
                target.add(propertiesContainer);
            }
            target.add(version);
        }
    });
    version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            selectVersion(target, connInstanceTO, version, version.getModelObject());
        }
    });

    // form - second tab (properties)
    final ListView<ConnConfProperty> connPropView = new ConnConfPropertyListView("connectorProperties",
            new PropertyModel<List<ConnConfProperty>>(this, "properties"), true,
            connInstanceTO.getConfiguration());
    connPropView.setOutputMarkupId(true);
    connectorPropForm.add(connPropView);

    final AjaxButton check = new IndicatingAjaxButton("check", new ResourceModel("check")) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject();

            // ensure that connector bundle information is in sync
            conn.setBundleName(bundleTO.getBundleName());
            conn.setVersion(bundleTO.getVersion());
            conn.setConnectorName(bundleTO.getConnectorName());

            if (restClient.check(conn)) {
                info(getString("success_connection"));
            } else {
                error(getString("error_connection"));
            }

            feedbackPanel.refresh(target);
        }
    };
    connectorPropForm.add(check);

    // form - third tab (capabilities)
    final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<ConnectorCapability> load() {
            return Arrays.asList(ConnectorCapability.values());
        }
    };
    CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<>(
            "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"),
            capabilities);

    capabilitiesPalette.add(new AjaxFormChoiceComponentUpdatingBehavior() {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });

    connectorForm.add(capabilitiesPalette);

    // form - submit / cancel buttons
    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<>(getString(SUBMIT))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject();

            conn.setConnectorName(bundleTO.getConnectorName());
            conn.setBundleName(bundleTO.getBundleName());
            conn.setVersion(bundleTO.getVersion());
            conn.getConfiguration().clear();
            conn.getConfiguration().addAll(connPropView.getModelObject());

            // Set the model object's capabilities to capabilitiesPalette's converted Set
            conn.getCapabilities().clear();
            conn.getCapabilities()
                    .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class)
                            : EnumSet.copyOf(selectedCapabilities));

            // Reset pool configuration if all fields are null
            if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null
                    && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null
                    && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null
                    && conn.getPoolConf().getMinIdle() == null) {

                conn.setPoolConf(null);
            }

            try {
                if (connInstanceTO.getKey() == 0) {
                    restClient.create(conn);
                } else {
                    restClient.update(conn);
                }

                ((Resources) pageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientException e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                feedbackPanel.refresh(target);
                ((Resources) pageRef.getPage()).setModalResult(false);
                LOG.error("While creating or updating connector {}", conn, e);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };
    String roles = connInstanceTO.getKey() == 0 ? xmlRolesReader.getEntitlement("Connectors", "create")
            : xmlRolesReader.getEntitlement("Connectors", "update");
    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles);
    connectorForm.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            window.close(target);
        }
    };
    cancel.setDefaultFormProcessing(false);
    connectorForm.add(cancel);
}

From source file:org.apache.syncope.client.console.pages.MembershipModalPage.java

License:Apache License

public MembershipModalPage(final PageReference pageRef, final ModalWindow window,
        final MembershipTO membershipTO, final Mode mode) {

    final Form<MembershipTO> form = new Form<MembershipTO>("MembershipForm");

    final UserTO userTO = ((UserModalPage) pageRef.getPage()).getUserTO();

    form.setModel(new CompoundPropertyModel<MembershipTO>(membershipTO));

    submit = new AjaxButton(SUBMIT, new ResourceModel(SUBMIT)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override//w  w w  .j  a  v a  2  s.com
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {
            userTO.getMemberships().remove(membershipTO);
            userTO.getMemberships().add(membershipTO);

            ((UserModalPage) pageRef.getPage()).setUserTO(userTO);

            window.close(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };

    form.add(submit);
    form.setDefaultButton(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            ((UserModalPage) pageRef.getPage()).setUserTO(userTO);
            window.close(target);
        }

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

    cancel.setDefaultFormProcessing(false);
    form.add(cancel);

    //--------------------------------
    // Attributes panel
    //--------------------------------
    form.add(new PlainAttrsPanel("plainAttrs", membershipTO, form, mode));
    form.add(new AnnotatedBeanPanel("systeminformation", membershipTO));
    //--------------------------------

    //--------------------------------
    // Derived attributes container
    //--------------------------------
    form.add(new DerAttrsPanel("derAttrs", membershipTO));
    //--------------------------------

    //--------------------------------
    // Virtual attributes container
    //--------------------------------
    form.add(new VirAttrsPanel("virAttrs", membershipTO, mode == Mode.TEMPLATE));
    //--------------------------------

    add(form);
}

From source file:org.apache.syncope.client.console.pages.PolicyModalPage.java

License:Apache License

public PolicyModalPage(final PageReference pageRef, final ModalWindow window, final T policyTO) {
    super();/* w w w.  ja  v a2 s .  c o  m*/

    final Form<?> form = new Form<>(FORM);
    form.setOutputMarkupId(true);
    add(form);

    final AjaxTextFieldPanel policyid = new AjaxTextFieldPanel("key", "key",
            new PropertyModel<String>(policyTO, "key"));
    policyid.setEnabled(false);
    policyid.setStyleSheet("ui-widget-content ui-corner-all short_fixedsize");
    form.add(policyid);

    final AjaxTextFieldPanel description = new AjaxTextFieldPanel("description", "description",
            new PropertyModel<String>(policyTO, "description"));
    description.addRequiredLabel();
    description.setStyleSheet("ui-widget-content ui-corner-all medium_dynamicsize");
    form.add(description);

    final AjaxDropDownChoicePanel<PolicyType> type = new AjaxDropDownChoicePanel<>("type", "type",
            new PropertyModel<PolicyType>(policyTO, "type"));
    switch (policyTO.getType()) {
    case GLOBAL_ACCOUNT:
    case ACCOUNT:
        type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_ACCOUNT, PolicyType.ACCOUNT }));
        break;

    case GLOBAL_PASSWORD:
    case PASSWORD:
        type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_PASSWORD, PolicyType.PASSWORD }));
        break;

    case GLOBAL_SYNC:
    case SYNC:
        type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_SYNC, PolicyType.SYNC }));

    default:
    }
    type.setChoiceRenderer(new PolicyTypeRenderer());
    type.addRequiredLabel();
    form.add(type);

    // Authentication resources - only for AccountPolicyTO
    Fragment fragment;
    if (policyTO instanceof AccountPolicyTO) {
        fragment = new Fragment("forAccountOnly", "authResourcesFragment", form);

        final List<String> resourceNames = new ArrayList<>();
        for (ResourceTO resource : resourceRestClient.getAll()) {
            resourceNames.add(resource.getKey());
        }
        fragment.add(new AjaxPalettePanel<>("authResources",
                new PropertyModel<List<String>>(policyTO, "resources"), new ListModel<>(resourceNames)));
    } else {
        fragment = new Fragment("forAccountOnly", "emptyFragment", form);
    }
    form.add(fragment);
    //

    final PolicySpec policy = getPolicySpecification(policyTO);

    form.add(new PolicyBeanPanel("panel", policy));

    final ModalWindow mwindow = new ModalWindow("metaEditModalWin");
    mwindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    mwindow.setInitialHeight(WIN_HEIGHT);
    mwindow.setInitialWidth(WIN_WIDTH);
    mwindow.setCookieName("meta-edit-modal");
    add(mwindow);

    List<IColumn<String, String>> resColumns = new ArrayList<>();
    resColumns.add(new AbstractColumn<String, String>(new StringResourceModel("name", this, null, "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public void populateItem(final Item<ICellPopulator<String>> cellItem, final String componentId,
                final IModel<String> rowModel) {

            cellItem.add(new Label(componentId, rowModel.getObject()));
        }
    });
    resColumns.add(new AbstractColumn<String, String>(new StringResourceModel("actions", this, null, "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public String getCssClass() {
            return "action";
        }

        @Override
        public void populateItem(final Item<ICellPopulator<String>> cellItem, final String componentId,
                final IModel<String> model) {

            final String resource = model.getObject();

            final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference());
            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    mwindow.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new ResourceModalPage(PolicyModalPage.this.getPageReference(), mwindow,
                                    resourceRestClient.read(resource), false);
                        }
                    });

                    mwindow.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Resources");

            cellItem.add(panel);
        }
    });
    ISortableDataProvider<String, String> resDataProvider = new SortableDataProvider<String, String>() {

        private static final long serialVersionUID = 8263758912838836438L;

        @Override
        public Iterator<? extends String> iterator(final long first, final long count) {
            return policyTO.getKey() == 0 ? Collections.<String>emptyList().iterator()
                    : policyRestClient.getPolicy(policyTO.getKey()).getUsedByResources()
                            .subList((int) first, (int) first + (int) count).iterator();
        }

        @Override
        public long size() {
            return policyTO.getKey() == 0 ? 0
                    : policyRestClient.getPolicy(policyTO.getKey()).getUsedByResources().size();
        }

        @Override
        public IModel<String> model(final String object) {
            return new Model<>(object);
        }
    };
    final AjaxFallbackDefaultDataTable<String, String> resources = new AjaxFallbackDefaultDataTable<>(
            "resources", resColumns, resDataProvider, 10);
    form.add(resources);

    List<IColumn<GroupTO, String>> groupColumns = new ArrayList<>();
    groupColumns.add(new PropertyColumn<GroupTO, String>(new ResourceModel("key", "key"), "key", "key"));
    groupColumns.add(new PropertyColumn<GroupTO, String>(new ResourceModel("name", "name"), "name", "name"));
    groupColumns.add(new AbstractColumn<GroupTO, String>(new StringResourceModel("actions", this, null, "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public String getCssClass() {
            return "action";
        }

        @Override
        public void populateItem(final Item<ICellPopulator<GroupTO>> cellItem, final String componentId,
                final IModel<GroupTO> model) {

            final GroupTO group = model.getObject();

            final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference());
            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    mwindow.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new GroupModalPage(PolicyModalPage.this.getPageReference(), mwindow, group);
                        }
                    });

                    mwindow.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Groups");

            cellItem.add(panel);
        }
    });
    ISortableDataProvider<GroupTO, String> groupDataProvider = new SortableDataProvider<GroupTO, String>() {

        private static final long serialVersionUID = 8263758912838836438L;

        @Override
        public Iterator<? extends GroupTO> iterator(final long first, final long count) {
            List<GroupTO> groups = new ArrayList<>();

            if (policyTO.getKey() > 0) {
                for (Long groupId : policyRestClient.getPolicy(policyTO.getKey()).getUsedByGroups()
                        .subList((int) first, (int) first + (int) count)) {

                    groups.add(groupRestClient.read(groupId));
                }
            }

            return groups.iterator();
        }

        @Override
        public long size() {
            return policyTO.getKey() == 0 ? 0
                    : policyRestClient.getPolicy(policyTO.getKey()).getUsedByGroups().size();
        }

        @Override
        public IModel<GroupTO> model(final GroupTO object) {
            return new Model<>(object);
        }
    };
    final AjaxFallbackDefaultDataTable<GroupTO, String> groups = new AjaxFallbackDefaultDataTable<>("groups",
            groupColumns, groupDataProvider, 10);
    form.add(groups);

    mwindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            target.add(resources);
            target.add(groups);
            if (isModalResult()) {
                info(getString(Constants.OPERATION_SUCCEEDED));
                feedbackPanel.refresh(target);
                setModalResult(false);
            }
        }
    });

    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(APPLY)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            setPolicySpecification(policyTO, policy);

            try {
                if (policyTO.getKey() > 0) {
                    policyRestClient.updatePolicy(policyTO);
                } else {
                    policyRestClient.createPolicy(policyTO);
                }
                ((BasePage) pageRef.getPage()).setModalResult(true);

                window.close(target);
            } catch (Exception e) {
                LOG.error("While creating policy", e);

                error(getString(Constants.ERROR) + ": " + e.getMessage());
                ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target);
        }
    };
    form.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

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

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

From source file:org.apache.syncope.client.console.panels.ConnectorModal.java

License:Apache License

public ConnectorModal(final ModalWindow window, final PageReference pageRef,
        final ConnInstanceTO connInstanceTO) {

    super(window, pageRef);

    this.add(new Label("new",
            connInstanceTO.getKey() == 0 ? new ResourceModel("new") : new Model<>(StringUtils.EMPTY)));
    this.add(new Label("key", connInstanceTO.getKey() == 0 ? StringUtils.EMPTY : connInstanceTO.getKey()));

    // general data setup
    selectedCapabilities = new ArrayList<>(
            connInstanceTO.getKey() == 0 ? EnumSet.noneOf(ConnectorCapability.class)
                    : connInstanceTO.getCapabilities());

    mapConnBundleTOs = new HashMap<>();
    for (ConnBundleTO connBundleTO : connectorRestClient.getAllBundles()) {
        // by location
        if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) {
            mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>());
        }/*w  w w .  j  a  va 2 s  . co  m*/
        final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs
                .get(connBundleTO.getLocation());

        // by name
        if (!byLocation.containsKey(connBundleTO.getBundleName())) {
            byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>());
        }
        final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName());

        // by version
        if (!byName.containsKey(connBundleTO.getVersion())) {
            byName.put(connBundleTO.getVersion(), connBundleTO);
        }
    }

    bundleTO = getSelectedBundleTO(connInstanceTO);
    properties = fillProperties(bundleTO, connInstanceTO);

    // form - first tab
    final Form<ConnInstanceTO> connectorForm = new Form<>(FORM);
    connectorForm.setModel(new CompoundPropertyModel<>(connInstanceTO));
    connectorForm.setOutputMarkupId(true);
    add(connectorForm);

    propertiesContainer = new WebMarkupContainer("container");
    propertiesContainer.setOutputMarkupId(true);
    connectorForm.add(propertiesContainer);

    final Form<ConnInstanceTO> connectorPropForm = new Form<>("connectorPropForm");
    connectorPropForm.setModel(new CompoundPropertyModel<>(connInstanceTO));
    connectorPropForm.setOutputMarkupId(true);
    propertiesContainer.add(connectorPropForm);

    final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name",
            new PropertyModel<String>(connInstanceTO, "displayName"));
    displayName.setOutputMarkupId(true);
    displayName.addRequiredLabel();
    connectorForm.add(displayName);

    final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<>("location", "location",
            new Model<>(bundleTO == null ? null : bundleTO.getLocation()));
    ((DropDownChoice<String>) location.getField()).setNullValid(true);
    location.setStyleSheet("long_dynamicsize");
    location.setChoices(new ArrayList<>(mapConnBundleTOs.keySet()));
    location.setRequired(true);
    location.addRequiredLabel();
    location.setOutputMarkupId(true);
    location.setEnabled(connInstanceTO.getKey() == 0);
    location.getField().setOutputMarkupId(true);
    connectorForm.add(location);

    final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<>("connectorName",
            "connectorName", new Model<>(bundleTO == null ? null : bundleTO.getBundleName()));
    ((DropDownChoice<String>) connectorName.getField()).setNullValid(true);
    connectorName.setStyleSheet("long_dynamicsize");
    connectorName.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet()));
    connectorName.setRequired(true);
    connectorName.addRequiredLabel();
    connectorName.setEnabled(connInstanceTO.getLocation() != null);
    connectorName.setOutputMarkupId(true);
    connectorName.setEnabled(connInstanceTO.getKey() == 0);
    connectorName.getField().setOutputMarkupId(true);
    connectorForm.add(connectorName);

    final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version",
            new Model<>(bundleTO == null ? null : bundleTO.getVersion()));
    version.setStyleSheet("long_dynamicsize");
    version.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation())
                    .get(connInstanceTO.getBundleName()).keySet()));
    version.setRequired(true);
    version.addRequiredLabel();
    version.setEnabled(connInstanceTO.getBundleName() != null);
    version.setOutputMarkupId(true);
    version.addRequiredLabel();
    version.getField().setOutputMarkupId(true);
    connectorForm.add(version);

    final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<>("connRequestTimeout",
            "connRequestTimeout", Integer.class,
            new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null);
    connRequestTimeout.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(connRequestTimeout);

    if (connInstanceTO.getPoolConf() == null) {
        connInstanceTO.setPoolConf(new ConnPoolConfTO());
    }
    final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<>("poolMaxObjects",
            "poolMaxObjects", Integer.class,
            new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null);
    poolMaxObjects.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxObjects);
    final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<>("poolMinIdle", "poolMinIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null);
    poolMinIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMinIdle);
    final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<>("poolMaxIdle", "poolMaxIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null);
    poolMaxIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxIdle);
    final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<>("poolMaxWait", "poolMaxWait",
            Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null);
    poolMaxWait.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMaxWait);
    final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<>("poolMinEvictableIdleTime",
            "poolMinEvictableIdleTime", Long.class,
            new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null);
    poolMinEvictableIdleTime.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMinEvictableIdleTime);

    // form - first tab - onchange()
    location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) location.getField()).setNullValid(false);
            connInstanceTO.setLocation(location.getModelObject());
            target.add(location);

            connectorName.setChoices(new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()).keySet()));
            connectorName.setEnabled(true);
            connectorName.getField().setModelValue(null);
            target.add(connectorName);

            version.setChoices(new ArrayList<String>());
            version.getField().setModelValue(null);
            version.setEnabled(false);
            target.add(version);

            properties.clear();
            target.add(propertiesContainer);
        }
    });
    connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) connectorName.getField()).setNullValid(false);
            connInstanceTO.setBundleName(connectorName.getModelObject());
            target.add(connectorName);

            List<String> versions = new ArrayList<>(mapConnBundleTOs.get(location.getModelObject())
                    .get(connectorName.getModelObject()).keySet());
            version.setChoices(versions);
            version.setEnabled(true);
            if (versions.size() == 1) {
                selectVersion(target, connInstanceTO, version, versions.get(0));
                version.getField().setModelObject(versions.get(0));
            } else {
                version.getField().setModelValue(null);
                properties.clear();
                target.add(propertiesContainer);
            }
            target.add(version);
        }
    });
    version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            selectVersion(target, connInstanceTO, version, version.getModelObject());
        }
    });

    // form - second tab (properties)
    final ListView<ConnConfProperty> connPropView = new ConnConfPropertyListView("connectorProperties",
            new PropertyModel<List<ConnConfProperty>>(this, "properties"), true,
            connInstanceTO.getConfiguration());
    connPropView.setOutputMarkupId(true);
    connectorPropForm.add(connPropView);

    final AjaxButton check = new IndicatingAjaxButton("check", new ResourceModel("check")) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject();

            // ensure that connector bundle information is in sync
            conn.setBundleName(bundleTO.getBundleName());
            conn.setVersion(bundleTO.getVersion());
            conn.setConnectorName(bundleTO.getConnectorName());

            if (connectorRestClient.check(conn)) {
                info(getString("success_connection"));
            } else {
                error(getString("error_connection"));
            }

            feedbackPanel.refresh(target);
        }
    };
    connectorPropForm.add(check);

    // form - third tab (capabilities)
    final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<ConnectorCapability> load() {
            return Arrays.asList(ConnectorCapability.values());
        }
    };
    CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<>(
            "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"),
            capabilities);

    capabilitiesPalette.add(new AjaxFormChoiceComponentUpdatingBehavior() {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
        }
    });

    connectorForm.add(capabilitiesPalette);

    // form - submit / cancel buttons
    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<>(getString(SUBMIT))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject();

            conn.setConnectorName(bundleTO.getConnectorName());
            conn.setBundleName(bundleTO.getBundleName());
            conn.setVersion(bundleTO.getVersion());
            conn.getConfiguration().clear();
            conn.getConfiguration().addAll(connPropView.getModelObject());

            // Set the model object's capabilities to capabilitiesPalette's converted Set
            conn.getCapabilities().clear();
            conn.getCapabilities()
                    .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class)
                            : EnumSet.copyOf(selectedCapabilities));

            // Reset pool configuration if all fields are null
            if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null
                    && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null
                    && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null
                    && conn.getPoolConf().getMinIdle() == null) {

                conn.setPoolConf(null);
            }

            try {
                if (connInstanceTO.getKey() == 0) {
                    connectorRestClient.create(conn);
                } else {
                    connectorRestClient.update(conn);
                }

                ((BasePage) pageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientException e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                feedbackPanel.refresh(target);
                ((BasePage) pageRef.getPage()).setModalResult(false);
                LOG.error("While creating or updating connector {}", conn, e);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };
    String entitlements = connInstanceTO.getKey() == 0 ? Entitlement.CONNECTOR_CREATE
            : Entitlement.CONNECTOR_UPDATE;

    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, entitlements);
    connectorForm.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            window.close(target);
        }
    };
    cancel.setDefaultFormProcessing(false);
    connectorForm.add(cancel);
}

From source file:org.apache.syncope.client.console.panels.LayoutsPanel.java

License:Apache License

@SuppressWarnings("unchecked")
public LayoutsPanel(final String id, final AttrLayoutType attrLayoutType,
        final NotificationPanel feedbackPanel) {
    super(id);//  www .j  a  v a  2 s .  co  m

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);

    final Form<String> form = new Form<String>("form");
    form.setOutputMarkupId(true);

    final AttrTO attrLayout = confRestClient.readAttrLayout(attrLayoutType);
    form.setModel(new CompoundPropertyModel(attrLayout.getValues()));

    final List<String> fields = schemaRestClient.getPlainSchemaNames(attrLayoutType.getAttrType());
    final ListModel<String> selectedFields = new ListModel<String>(
            attrLayout.getValues().isEmpty() ? fields : attrLayout.getValues());
    final ListModel<String> availableFields = new ListModel<String>(fields);

    form.add(new AjaxPalettePanel<String>("fields", selectedFields, availableFields,
            new SelectChoiceRenderer<String>(), true, true));

    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(APPLY)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            try {
                confRestClient.set(attrLayout);
                info(getString(Constants.OPERATION_SUCCEEDED));
            } catch (Exception e) {
                LOG.error("While saving layout configuration", e);
                error(getString(Constants.ERROR) + ": " + e.getMessage());
            }
            feedbackPanel.refresh(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            error(getString(Constants.ERROR) + ": While saving layout configuration");
            feedbackPanel.refresh(target);
        }
    };

    form.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            target.add(container);
        }

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

    cancel.setDefaultFormProcessing(false);
    form.add(cancel);
    container.add(form);
    add(container);
}

From source file:org.apache.syncope.console.pages.ConnectorModalPage.java

License:Apache License

public ConnectorModalPage(final PageReference pageRef, final ModalWindow window,
        final ConnInstanceTO connInstanceTO) {

    super();/*  w ww  .ja va 2 s  . co m*/

    // general data setup
    selectedCapabilities = new ArrayList<ConnectorCapability>(
            connInstanceTO.getId() == 0 ? EnumSet.noneOf(ConnectorCapability.class)
                    : connInstanceTO.getCapabilities());

    mapConnBundleTOs = new HashMap<String, Map<String, Map<String, ConnBundleTO>>>();
    for (ConnBundleTO connBundleTO : restClient.getAllBundles()) {
        // by location
        if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) {
            mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>());
        }
        final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs
                .get(connBundleTO.getLocation());

        // by name
        if (!byLocation.containsKey(connBundleTO.getBundleName())) {
            byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>());
        }
        final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName());

        // by version
        if (!byName.containsKey(connBundleTO.getVersion())) {
            byName.put(connBundleTO.getVersion(), connBundleTO);
        }
    }

    bundleTO = getSelectedBundleTO(connInstanceTO);
    properties = fillProperties(bundleTO, connInstanceTO);

    // form - first tab
    final Form<ConnInstanceTO> connectorForm = new Form<ConnInstanceTO>(FORM);
    connectorForm.setModel(new CompoundPropertyModel<ConnInstanceTO>(connInstanceTO));
    connectorForm.setOutputMarkupId(true);
    add(connectorForm);

    propertiesContainer = new WebMarkupContainer("container");
    propertiesContainer.setOutputMarkupId(true);
    connectorForm.add(propertiesContainer);

    final Form<ConnInstanceTO> connectorPropForm = new Form<ConnInstanceTO>("connectorPropForm");
    connectorPropForm.setModel(new CompoundPropertyModel<ConnInstanceTO>(connInstanceTO));
    connectorPropForm.setOutputMarkupId(true);
    propertiesContainer.add(connectorPropForm);

    final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name",
            new PropertyModel<String>(connInstanceTO, "displayName"));
    displayName.setOutputMarkupId(true);
    displayName.addRequiredLabel();
    connectorForm.add(displayName);

    final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<String>("location", "location",
            new Model<String>(bundleTO == null ? null : bundleTO.getLocation()));
    ((DropDownChoice<String>) location.getField()).setNullValid(true);
    location.setStyleSheet("long_dynamicsize");
    location.setChoices(new ArrayList<String>(mapConnBundleTOs.keySet()));
    location.setRequired(true);
    location.addRequiredLabel();
    location.setOutputMarkupId(true);
    location.setEnabled(connInstanceTO.getId() == 0);
    location.getField().setOutputMarkupId(true);
    connectorForm.add(location);

    final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<String>("connectorName",
            "connectorName", new Model<String>(bundleTO == null ? null : bundleTO.getBundleName()));
    ((DropDownChoice<String>) connectorName.getField()).setNullValid(true);
    connectorName.setStyleSheet("long_dynamicsize");
    connectorName.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<String>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet()));
    connectorName.setRequired(true);
    connectorName.addRequiredLabel();
    connectorName.setEnabled(connInstanceTO.getLocation() != null);
    connectorName.setOutputMarkupId(true);
    connectorName.setEnabled(connInstanceTO.getId() == 0);
    connectorName.getField().setOutputMarkupId(true);
    connectorForm.add(connectorName);

    final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<String>("version", "version",
            new Model<String>(bundleTO == null ? null : bundleTO.getVersion()));
    version.setStyleSheet("long_dynamicsize");
    version.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<String>(mapConnBundleTOs.get(connInstanceTO.getLocation())
                    .get(connInstanceTO.getBundleName()).keySet()));
    version.setRequired(true);
    version.addRequiredLabel();
    version.setEnabled(connInstanceTO.getBundleName() != null);
    version.setOutputMarkupId(true);
    version.addRequiredLabel();
    version.getField().setOutputMarkupId(true);
    connectorForm.add(version);

    final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<Integer>("connRequestTimeout",
            "connRequestTimeout", Integer.class,
            new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null);
    connRequestTimeout.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(connRequestTimeout);

    if (connInstanceTO.getPoolConf() == null) {
        connInstanceTO.setPoolConf(new ConnPoolConfTO());
    }
    final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<Integer>("poolMaxObjects",
            "poolMaxObjects", Integer.class,
            new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null);
    poolMaxObjects.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxObjects);
    final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<Integer>("poolMinIdle", "poolMinIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null);
    poolMinIdle.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMinIdle);
    final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<Integer>("poolMaxIdle", "poolMaxIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null);
    poolMaxIdle.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxIdle);
    final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<Long>("poolMaxWait", "poolMaxWait",
            Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null);
    poolMaxWait.getField().add(new RangeValidator<Long>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMaxWait);
    final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<Long>(
            "poolMinEvictableIdleTime", "poolMinEvictableIdleTime", Long.class,
            new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null);
    poolMinEvictableIdleTime.getField().add(new RangeValidator<Long>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMinEvictableIdleTime);

    // form - first tab - onchange()
    location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) location.getField()).setNullValid(false);
            connInstanceTO.setLocation(location.getModelObject());
            target.add(location);

            connectorName.setChoices(
                    new ArrayList<String>(mapConnBundleTOs.get(location.getModelObject()).keySet()));
            connectorName.setEnabled(true);
            connectorName.getField().setModelValue(null);
            target.add(connectorName);

            version.setChoices(new ArrayList<String>());
            version.getField().setModelValue(null);
            version.setEnabled(false);
            target.add(version);

            properties.clear();
            target.add(propertiesContainer);
        }
    });
    connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) connectorName.getField()).setNullValid(false);
            connInstanceTO.setBundleName(connectorName.getModelObject());
            target.add(connectorName);

            List<String> versions = new ArrayList<String>(mapConnBundleTOs.get(location.getModelObject())
                    .get(connectorName.getModelObject()).keySet());
            version.setChoices(versions);
            version.setEnabled(true);
            if (versions.size() == 1) {
                selectVersion(target, connInstanceTO, version, versions.get(0));
                version.getField().setModelObject(versions.get(0));
            } else {
                version.getField().setModelValue(null);
                properties.clear();
                target.add(propertiesContainer);
            }
            target.add(version);
        }
    });
    version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            selectVersion(target, connInstanceTO, version, version.getModelObject());
        }
    });

    // form - second tab (properties)
    final ListView<ConnConfProperty> connPropView = new AltListView<ConnConfProperty>("connectorProperties",
            new PropertyModel<List<ConnConfProperty>>(this, "properties")) {

        private static final long serialVersionUID = 9101744072914090143L;

        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        protected void populateItem(final ListItem<ConnConfProperty> item) {
            final ConnConfProperty property = item.getModelObject();

            final Label label = new Label("connPropAttrSchema",
                    StringUtils.isBlank(property.getSchema().getDisplayName()) ? property.getSchema().getName()
                            : property.getSchema().getDisplayName());
            item.add(label);

            final FieldPanel field;
            boolean required = false;
            boolean isArray = false;
            if (property.getSchema().isConfidential()
                    || Constants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
                    || Constants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {

                field = new AjaxPasswordFieldPanel("panel", label.getDefaultModelObjectAsString(),
                        new Model<String>());

                ((PasswordTextField) field.getField()).setResetPassword(false);

                required = property.getSchema().isRequired();
            } else {
                Class<?> propertySchemaClass;

                try {
                    propertySchemaClass = ClassUtils.forName(property.getSchema().getType(),
                            ClassUtils.getDefaultClassLoader());
                    if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
                        propertySchemaClass = org.apache.commons.lang3.ClassUtils
                                .primitiveToWrapper(propertySchemaClass);
                    }
                } catch (Exception e) {
                    LOG.error("Error parsing attribute type", e);
                    propertySchemaClass = String.class;
                }
                if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
                    field = new SpinnerFieldPanel<Number>("panel", label.getDefaultModelObjectAsString(),
                            (Class<Number>) propertySchemaClass, new Model<Number>(), null, null);

                    required = property.getSchema().isRequired();
                } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
                    field = new AjaxCheckBoxPanel("panel", label.getDefaultModelObjectAsString(),
                            new Model<Boolean>());
                } else {
                    field = new AjaxTextFieldPanel("panel", label.getDefaultModelObjectAsString(),
                            new Model<String>());

                    required = property.getSchema().isRequired();
                }

                if (propertySchemaClass.isArray()) {
                    isArray = true;
                }
            }

            field.setTitle(property.getSchema().getHelpMessage());

            if (required) {
                field.addRequiredLabel();
            }

            if (isArray) {
                if (property.getValues().isEmpty()) {
                    property.getValues().add(null);
                }

                item.add(new MultiFieldPanel<String>("panel",
                        new PropertyModel<List<String>>(property, "values"), field));
            } else {
                field.setNewModel(property.getValues());
                item.add(field);
            }

            final AjaxCheckBoxPanel overridable = new AjaxCheckBoxPanel("connPropAttrOverridable",
                    "connPropAttrOverridable", new PropertyModel<Boolean>(property, "overridable"));

            item.add(overridable);
            connInstanceTO.getConfiguration().add(property);
        }
    };
    connPropView.setOutputMarkupId(true);
    connectorPropForm.add(connPropView);

    final AjaxLink<String> check = new IndicatingAjaxLink<String>("check", new ResourceModel("check")) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            connInstanceTO.setBundleName(bundleTO.getBundleName());
            connInstanceTO.setVersion(bundleTO.getVersion());
            connInstanceTO.setConnectorName(bundleTO.getConnectorName());

            if (restClient.check(connInstanceTO)) {
                info(getString("success_connection"));
            } else {
                error(getString("error_connection"));
            }

            feedbackPanel.refresh(target);
        }
    };
    connectorPropForm.add(check);

    // form - third tab (capabilities)
    final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<ConnectorCapability> load() {
            return Arrays.asList(ConnectorCapability.values());
        }
    };
    CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<ConnectorCapability>(
            "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"),
            capabilities);
    connectorForm.add(capabilitiesPalette);

    // form - submit / cancel buttons
    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject();

            conn.setConnectorName(bundleTO.getConnectorName());
            conn.setBundleName(bundleTO.getBundleName());
            conn.setVersion(bundleTO.getVersion());
            conn.getConfiguration().clear();
            conn.getConfiguration().addAll(connPropView.getModelObject());

            // Set the model object's capabilities to capabilitiesPalette's converted Set
            conn.getCapabilities()
                    .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class)
                            : EnumSet.copyOf(selectedCapabilities));

            // Reset pool configuration if all fields are null
            if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null
                    && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null
                    && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null
                    && conn.getPoolConf().getMinIdle() == null) {

                conn.setPoolConf(null);
            }

            try {
                if (connInstanceTO.getId() == 0) {
                    restClient.create(conn);
                } else {
                    restClient.update(conn);
                }

                ((Resources) pageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientException e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                feedbackPanel.refresh(target);
                ((Resources) pageRef.getPage()).setModalResult(false);
                LOG.error("While creating or updating connector {}", conn, e);
            }
        }

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

            feedbackPanel.refresh(target);
        }
    };
    String roles = connInstanceTO.getId() == 0 ? xmlRolesReader.getAllAllowedRoles("Connectors", "create")
            : xmlRolesReader.getAllAllowedRoles("Connectors", "update");
    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles);
    connectorForm.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            window.close(target);
        }
    };
    cancel.setDefaultFormProcessing(false);
    connectorForm.add(cancel);
}

From source file:org.apache.syncope.console.pages.MembershipModalPage.java

License:Apache License

public MembershipModalPage(final PageReference pageRef, final ModalWindow window,
        final MembershipTO membershipTO, final boolean templateMode) {

    final Form<MembershipTO> form = new Form<MembershipTO>("MembershipForm");

    final UserTO userTO = ((UserModalPage) pageRef.getPage()).getUserTO();

    form.setModel(new CompoundPropertyModel<MembershipTO>(membershipTO));

    submit = new AjaxButton(SUBMIT, new ResourceModel(SUBMIT)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override//w  ww. j av a 2 s  .  co  m
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {
            userTO.getMemberships().remove(membershipTO);
            userTO.getMemberships().add(membershipTO);

            ((UserModalPage) pageRef.getPage()).setUserTO(userTO);

            window.close(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };

    form.add(submit);
    form.setDefaultButton(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            ((UserModalPage) pageRef.getPage()).setUserTO(userTO);
            window.close(target);
        }

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

    cancel.setDefaultFormProcessing(false);
    form.add(cancel);

    //--------------------------------
    // Attributes panel
    //--------------------------------
    form.add(new AttributesPanel("attrs", membershipTO, form, templateMode));
    form.add(new SysInfoPanel("systeminformation", membershipTO));
    //--------------------------------

    //--------------------------------
    // Derived attributes container
    //--------------------------------
    form.add(new DerivedAttributesPanel("derAttrs", membershipTO));
    //--------------------------------

    //--------------------------------
    // Virtual attributes container
    //--------------------------------
    form.add(new VirtualAttributesPanel("virAttrs", membershipTO, templateMode));
    //--------------------------------

    add(form);
}

From source file:org.apache.syncope.console.pages.PolicyModalPage.java

License:Apache License

public PolicyModalPage(final PageReference pageRef, final ModalWindow window, final T policyTO) {
    super();//from www.  ja v a 2s .c  om

    final Form<?> form = new Form<Void>(FORM);
    form.setOutputMarkupId(true);
    add(form);

    final AjaxTextFieldPanel policyid = new AjaxTextFieldPanel("id", "id",
            new PropertyModel<String>(policyTO, "id"));
    policyid.setEnabled(false);
    policyid.setStyleSheet("ui-widget-content ui-corner-all short_fixedsize");
    form.add(policyid);

    final AjaxTextFieldPanel description = new AjaxTextFieldPanel("description", "description",
            new PropertyModel<String>(policyTO, "description"));
    description.addRequiredLabel();
    description.setStyleSheet("ui-widget-content ui-corner-all medium_dynamicsize");
    form.add(description);

    final AjaxDropDownChoicePanel<PolicyType> type = new AjaxDropDownChoicePanel<PolicyType>("type", "type",
            new PropertyModel<PolicyType>(policyTO, "type"));
    switch (policyTO.getType()) {
    case GLOBAL_ACCOUNT:
    case ACCOUNT:
        type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_ACCOUNT, PolicyType.ACCOUNT }));
        break;

    case GLOBAL_PASSWORD:
    case PASSWORD:
        type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_PASSWORD, PolicyType.PASSWORD }));
        break;

    case GLOBAL_SYNC:
    case SYNC:
        type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_SYNC, PolicyType.SYNC }));

    default:
    }
    type.setChoiceRenderer(new PolicyTypeRenderer());
    type.addRequiredLabel();
    form.add(type);

    // Authentication resources - only for AccountPolicyTO
    Fragment fragment;
    if (policyTO instanceof AccountPolicyTO) {
        fragment = new Fragment("forAccountOnly", "authResourcesFragment", form);

        final List<String> resourceNames = new ArrayList<String>();
        for (ResourceTO resource : resourceRestClient.getAll()) {
            resourceNames.add(resource.getName());
        }
        fragment.add(new AjaxPalettePanel<String>("authResources",
                new PropertyModel<List<String>>(policyTO, "resources"), new ListModel<String>(resourceNames)));
    } else {
        fragment = new Fragment("forAccountOnly", "emptyFragment", form);
    }
    form.add(fragment);
    //

    final AbstractPolicySpec policy = getPolicySpecification(policyTO);

    form.add(new PolicyBeanPanel("panel", policy));

    final ModalWindow mwindow = new ModalWindow("metaEditModalWin");
    mwindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    mwindow.setInitialHeight(WIN_HEIGHT);
    mwindow.setInitialWidth(WIN_WIDTH);
    mwindow.setCookieName("meta-edit-modal");
    add(mwindow);

    List<IColumn<String, String>> resColumns = new ArrayList<IColumn<String, String>>();
    resColumns.add(new AbstractColumn<String, String>(new StringResourceModel("name", this, null, "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public void populateItem(final Item<ICellPopulator<String>> cellItem, final String componentId,
                final IModel<String> rowModel) {

            cellItem.add(new Label(componentId, rowModel.getObject()));
        }
    });
    resColumns.add(new AbstractColumn<String, String>(new StringResourceModel("actions", this, null, "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public String getCssClass() {
            return "action";
        }

        @Override
        public void populateItem(final Item<ICellPopulator<String>> cellItem, final String componentId,
                final IModel<String> model) {

            final String resource = model.getObject();

            final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference());
            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    mwindow.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new ResourceModalPage(PolicyModalPage.this.getPageReference(), mwindow,
                                    resourceRestClient.read(resource), false);
                        }
                    });

                    mwindow.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Resources");

            cellItem.add(panel);
        }
    });
    ISortableDataProvider<String, String> resDataProvider = new SortableDataProvider<String, String>() {

        private static final long serialVersionUID = 8263758912838836438L;

        @Override
        public Iterator<? extends String> iterator(final long first, final long count) {
            return policyTO.getId() == 0 ? Collections.<String>emptyList().iterator()
                    : policyRestClient.getPolicy(policyTO.getId()).getUsedByResources()
                            .subList((int) first, (int) first + (int) count).iterator();
        }

        @Override
        public long size() {
            return policyTO.getId() == 0 ? 0
                    : policyRestClient.getPolicy(policyTO.getId()).getUsedByResources().size();
        }

        @Override
        public IModel<String> model(final String object) {
            return new Model<String>(object);
        }
    };
    final AjaxFallbackDefaultDataTable<String, String> resources = new AjaxFallbackDefaultDataTable<String, String>(
            "resources", resColumns, resDataProvider, 10);
    form.add(resources);

    List<IColumn<RoleTO, String>> roleColumns = new ArrayList<IColumn<RoleTO, String>>();
    roleColumns.add(new PropertyColumn<RoleTO, String>(new ResourceModel("id", "id"), "id", "id"));
    roleColumns.add(new PropertyColumn<RoleTO, String>(new ResourceModel("name", "name"), "name", "name"));
    roleColumns.add(new AbstractColumn<RoleTO, String>(new StringResourceModel("actions", this, null, "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public String getCssClass() {
            return "action";
        }

        @Override
        public void populateItem(final Item<ICellPopulator<RoleTO>> cellItem, final String componentId,
                final IModel<RoleTO> model) {

            final RoleTO role = model.getObject();

            final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference());
            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    mwindow.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new RoleModalPage(PolicyModalPage.this.getPageReference(), mwindow, role);
                        }
                    });

                    mwindow.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Roles");

            cellItem.add(panel);
        }
    });
    ISortableDataProvider<RoleTO, String> roleDataProvider = new SortableDataProvider<RoleTO, String>() {

        private static final long serialVersionUID = 8263758912838836438L;

        @Override
        public Iterator<? extends RoleTO> iterator(final long first, final long count) {
            List<RoleTO> roles = new ArrayList<RoleTO>();

            if (policyTO.getId() > 0) {
                for (Long roleId : policyRestClient.getPolicy(policyTO.getId()).getUsedByRoles()
                        .subList((int) first, (int) first + (int) count)) {

                    roles.add(roleRestClient.read(roleId));
                }
            }

            return roles.iterator();
        }

        @Override
        public long size() {
            return policyTO.getId() == 0 ? 0
                    : policyRestClient.getPolicy(policyTO.getId()).getUsedByRoles().size();
        }

        @Override
        public IModel<RoleTO> model(final RoleTO object) {
            return new Model<RoleTO>(object);
        }
    };
    final AjaxFallbackDefaultDataTable<RoleTO, String> roles = new AjaxFallbackDefaultDataTable<RoleTO, String>(
            "roles", roleColumns, roleDataProvider, 10);
    form.add(roles);

    mwindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            target.add(resources);
            target.add(roles);
            if (isModalResult()) {
                info(getString(Constants.OPERATION_SUCCEEDED));
                feedbackPanel.refresh(target);
                setModalResult(false);
            }
        }
    });

    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(APPLY)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            setPolicySpecification(policyTO, policy);

            try {
                if (policyTO.getId() > 0) {
                    policyRestClient.updatePolicy(policyTO);
                } else {
                    policyRestClient.createPolicy(policyTO);
                }
                ((BasePage) pageRef.getPage()).setModalResult(true);

                window.close(target);
            } catch (Exception e) {
                LOG.error("While creating policy", e);

                error(getString(Constants.ERROR) + ": " + e.getMessage());
                ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target);
        }
    };
    form.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

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

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

From source file:org.sakaiproject.profile2.tool.pages.MyPreferences.java

License:Educational Community License

public MyPreferences() {

    log.debug("MyPreferences()");

    disableLink(preferencesLink);//  w w w .  ja va2s .  c  o  m

    //get current user
    final String userUuid = sakaiProxy.getCurrentUserId();

    //get the prefs record for this user from the database, or a default if none exists yet
    profilePreferences = preferencesLogic.getPreferencesRecordForUser(userUuid, false);

    //if null, throw exception
    if (profilePreferences == null) {
        throw new ProfilePreferencesNotDefinedException("Couldn't retrieve preferences record for " + userUuid);
    }

    //get email address for this user
    String emailAddress = sakaiProxy.getUserEmail(userUuid);
    //if no email, set a message into it fo display
    if (emailAddress == null || emailAddress.length() == 0) {
        emailAddress = new ResourceModel("preferences.email.none").getObject();
    }

    Label heading = new Label("heading", new ResourceModel("heading.preferences"));
    add(heading);

    //feedback for form submit action
    final Label formFeedback = new Label("formFeedback");
    formFeedback.setOutputMarkupPlaceholderTag(true);
    final String formFeedbackId = formFeedback.getMarkupId();
    add(formFeedback);

    //create model
    CompoundPropertyModel<ProfilePreferences> preferencesModel = new CompoundPropertyModel<ProfilePreferences>(
            profilePreferences);

    //setup form      
    Form<ProfilePreferences> form = new Form<ProfilePreferences>("form", preferencesModel);
    form.setOutputMarkupId(true);

    //EMAIL SECTION

    //email settings
    form.add(new Label("emailSectionHeading", new ResourceModel("heading.section.email")));
    form.add(new Label("emailSectionText",
            new StringResourceModel("preferences.email.message", null, new Object[] { emailAddress }))
                    .setEscapeModelStrings(false));

    //on/off labels
    form.add(new Label("prefOn", new ResourceModel("preference.option.on")));
    form.add(new Label("prefOff", new ResourceModel("preference.option.off")));

    //request emails
    final RadioGroup<Boolean> emailRequests = new RadioGroup<Boolean>("requestEmailEnabled",
            new PropertyModel<Boolean>(preferencesModel, "requestEmailEnabled"));
    Radio requestsOn = new Radio<Boolean>("requestsOn", new Model<Boolean>(Boolean.valueOf(true)));
    requestsOn.setMarkupId("requestsoninput");
    requestsOn.setOutputMarkupId(true);
    emailRequests.add(requestsOn);
    Radio requestsOff = new Radio<Boolean>("requestsOff", new Model<Boolean>(Boolean.valueOf(false)));
    requestsOff.setMarkupId("requestsoffinput");
    requestsOff.setOutputMarkupId(true);
    emailRequests.add(requestsOff);
    emailRequests.add(new Label("requestsLabel", new ResourceModel("preferences.email.requests")));
    form.add(emailRequests);

    //updater
    emailRequests.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });

    //visibility for request emails
    emailRequests.setVisible(sakaiProxy.isConnectionsEnabledGlobally());

    //confirm emails
    final RadioGroup<Boolean> emailConfirms = new RadioGroup<Boolean>("confirmEmailEnabled",
            new PropertyModel<Boolean>(preferencesModel, "confirmEmailEnabled"));
    Radio confirmsOn = new Radio<Boolean>("confirmsOn", new Model<Boolean>(Boolean.valueOf(true)));
    confirmsOn.setMarkupId("confirmsoninput");
    confirmsOn.setOutputMarkupId(true);
    emailConfirms.add(confirmsOn);
    Radio confirmsOff = new Radio<Boolean>("confirmsOff", new Model<Boolean>(Boolean.valueOf(false)));
    confirmsOff.setMarkupId("confirmsoffinput");
    confirmsOff.setOutputMarkupId(true);
    emailConfirms.add(confirmsOff);
    emailConfirms.add(new Label("confirmsLabel", new ResourceModel("preferences.email.confirms")));
    form.add(emailConfirms);

    //updater
    emailConfirms.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });

    //visibility for confirm emails
    emailConfirms.setVisible(sakaiProxy.isConnectionsEnabledGlobally());

    //new message emails
    final RadioGroup<Boolean> emailNewMessage = new RadioGroup<Boolean>("messageNewEmailEnabled",
            new PropertyModel<Boolean>(preferencesModel, "messageNewEmailEnabled"));
    Radio messageNewOn = new Radio<Boolean>("messageNewOn", new Model<Boolean>(Boolean.valueOf(true)));
    messageNewOn.setMarkupId("messagenewoninput");
    messageNewOn.setOutputMarkupId(true);
    emailNewMessage.add(messageNewOn);
    Radio messageNewOff = new Radio<Boolean>("messageNewOff", new Model<Boolean>(Boolean.valueOf(false)));
    messageNewOff.setMarkupId("messagenewoffinput");
    messageNewOff.setOutputMarkupId(true);
    emailNewMessage.add(messageNewOff);
    emailNewMessage.add(new Label("messageNewLabel", new ResourceModel("preferences.email.message.new")));
    form.add(emailNewMessage);

    //updater
    emailNewMessage.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });

    emailNewMessage.setVisible(sakaiProxy.isMessagingEnabledGlobally());

    //message reply emails
    final RadioGroup<Boolean> emailReplyMessage = new RadioGroup<Boolean>("messageReplyEmailEnabled",
            new PropertyModel<Boolean>(preferencesModel, "messageReplyEmailEnabled"));
    Radio messageReplyOn = new Radio<Boolean>("messageReplyOn", new Model<Boolean>(Boolean.valueOf(true)));
    messageReplyOn.setMarkupId("messagereplyoninput");
    messageNewOn.setOutputMarkupId(true);
    emailReplyMessage.add(messageReplyOn);
    Radio messageReplyOff = new Radio<Boolean>("messageReplyOff", new Model<Boolean>(Boolean.valueOf(false)));
    messageReplyOff.setMarkupId("messagereplyoffinput");
    messageNewOff.setOutputMarkupId(true);
    emailReplyMessage.add(messageReplyOff);
    emailReplyMessage.add(new Label("messageReplyLabel", new ResourceModel("preferences.email.message.reply")));
    form.add(emailReplyMessage);

    //updater
    emailReplyMessage.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });

    emailReplyMessage.setVisible(sakaiProxy.isMessagingEnabledGlobally());

    // new wall item notification emails
    final RadioGroup<Boolean> wallItemNew = new RadioGroup<Boolean>("wallItemNewEmailEnabled",
            new PropertyModel<Boolean>(preferencesModel, "wallItemNewEmailEnabled"));
    Radio wallItemNewOn = new Radio<Boolean>("wallItemNewOn", new Model<Boolean>(Boolean.valueOf(true)));
    wallItemNewOn.setMarkupId("wallitemnewoninput");
    wallItemNewOn.setOutputMarkupId(true);
    wallItemNew.add(wallItemNewOn);
    Radio wallItemNewOff = new Radio<Boolean>("wallItemNewOff", new Model<Boolean>(Boolean.valueOf(false)));
    wallItemNewOff.setMarkupId("wallitemnewoffinput");
    wallItemNewOff.setOutputMarkupId(true);
    wallItemNew.add(wallItemNewOff);
    wallItemNew.add(new Label("wallItemNewLabel", new ResourceModel("preferences.email.wall.new")));
    form.add(wallItemNew);

    //updater
    wallItemNew.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });

    //visibility for wall items
    wallItemNew.setVisible(sakaiProxy.isWallEnabledGlobally());

    // added to new worksite emails
    final RadioGroup<Boolean> worksiteNew = new RadioGroup<Boolean>("worksiteNewEmailEnabled",
            new PropertyModel<Boolean>(preferencesModel, "worksiteNewEmailEnabled"));
    Radio worksiteNewOn = new Radio<Boolean>("worksiteNewOn", new Model<Boolean>(Boolean.valueOf(true)));
    worksiteNewOn.setMarkupId("worksitenewoninput");
    worksiteNewOn.setOutputMarkupId(true);
    worksiteNew.add(worksiteNewOn);
    Radio worksiteNewOff = new Radio<Boolean>("worksiteNewOff", new Model<Boolean>(Boolean.valueOf(false)));
    worksiteNewOff.setMarkupId("worksitenewoffinput");
    worksiteNewOff.setOutputMarkupId(true);
    worksiteNew.add(worksiteNewOff);
    worksiteNew.add(new Label("worksiteNewLabel", new ResourceModel("preferences.email.worksite.new")));
    form.add(worksiteNew);

    //updater
    worksiteNew.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });

    // TWITTER SECTION

    //headings
    WebMarkupContainer twitterSectionHeadingContainer = new WebMarkupContainer(
            "twitterSectionHeadingContainer");
    twitterSectionHeadingContainer
            .add(new Label("twitterSectionHeading", new ResourceModel("heading.section.twitter")));
    twitterSectionHeadingContainer
            .add(new Label("twitterSectionText", new ResourceModel("preferences.twitter.message")));
    form.add(twitterSectionHeadingContainer);

    //panel
    if (sakaiProxy.isTwitterIntegrationEnabledGlobally()) {
        form.add(new AjaxLazyLoadPanel("twitterPanel") {
            private static final long serialVersionUID = 1L;

            @Override
            public Component getLazyLoadComponent(String markupId) {
                return new TwitterPrefsPane(markupId, userUuid);
            }
        });
    } else {
        form.add(new EmptyPanel("twitterPanel"));
        twitterSectionHeadingContainer.setVisible(false);
    }

    // IMAGE SECTION
    //only one of these can be selected at a time
    WebMarkupContainer is = new WebMarkupContainer("imageSettingsContainer");
    is.setOutputMarkupId(true);

    // headings
    is.add(new Label("imageSettingsHeading", new ResourceModel("heading.section.image")));
    is.add(new Label("imageSettingsText", new ResourceModel("preferences.image.message")));

    officialImageEnabled = sakaiProxy.isUsingOfficialImageButAlternateSelectionEnabled();
    gravatarEnabled = sakaiProxy.isGravatarImageEnabledGlobally();

    //official image
    //checkbox
    WebMarkupContainer officialImageContainer = new WebMarkupContainer("officialImageContainer");
    officialImageContainer
            .add(new Label("officialImageLabel", new ResourceModel("preferences.image.official")));
    officialImage = new CheckBox("officialImage",
            new PropertyModel<Boolean>(preferencesModel, "useOfficialImage"));
    officialImage.setMarkupId("officialimageinput");
    officialImage.setOutputMarkupId(true);
    officialImageContainer.add(officialImage);

    //updater
    officialImage.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {

            //set gravatar to false since we can't have both active
            gravatarImage.setModelObject(false);
            if (gravatarEnabled) {
                target.add(gravatarImage);
            }
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });
    is.add(officialImageContainer);

    //if using official images but alternate choice isn't allowed, hide this section
    if (!officialImageEnabled) {
        profilePreferences.setUseOfficialImage(false); //set the model false to clear data as well (doesnt really need to do this but we do it to keep things in sync)
        officialImageContainer.setVisible(false);
    }

    //gravatar
    //checkbox
    WebMarkupContainer gravatarContainer = new WebMarkupContainer("gravatarContainer");
    gravatarContainer.add(new Label("gravatarLabel", new ResourceModel("preferences.image.gravatar")));
    gravatarImage = new CheckBox("gravatarImage", new PropertyModel<Boolean>(preferencesModel, "useGravatar"));
    gravatarImage.setMarkupId("gravatarimageinput");
    gravatarImage.setOutputMarkupId(true);
    gravatarContainer.add(gravatarImage);

    //updater
    gravatarImage.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {

            //set gravatar to false since we can't have both active
            officialImage.setModelObject(false);
            if (officialImageEnabled) {
                target.add(officialImage);
            }
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });
    is.add(gravatarContainer);

    //if gravatar's are disabled, hide this section
    if (!gravatarEnabled) {
        profilePreferences.setUseGravatar(false); //set the model false to clear data as well (doesnt really need to do this but we do it to keep things in sync)
        gravatarContainer.setVisible(false);
    }

    //if official image disabled and gravatar disabled, hide the entire container
    if (!officialImageEnabled && !gravatarEnabled) {
        is.setVisible(false);
    }

    form.add(is);

    // WIDGET SECTION
    WebMarkupContainer ws = new WebMarkupContainer("widgetSettingsContainer");
    ws.setOutputMarkupId(true);
    int visibleWidgetCount = 0;

    //widget settings
    ws.add(new Label("widgetSettingsHeading", new ResourceModel("heading.section.widget")));
    ws.add(new Label("widgetSettingsText", new ResourceModel("preferences.widget.message")));

    //kudos
    WebMarkupContainer kudosContainer = new WebMarkupContainer("kudosContainer");
    kudosContainer.add(new Label("kudosLabel", new ResourceModel("preferences.widget.kudos")));
    CheckBox kudosSetting = new CheckBox("kudosSetting",
            new PropertyModel<Boolean>(preferencesModel, "showKudos"));
    kudosSetting.setMarkupId("kudosinput");
    kudosSetting.setOutputMarkupId(true);
    kudosContainer.add(kudosSetting);
    //tooltip
    kudosContainer.add(new IconWithClueTip("kudosToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("preferences.widget.kudos.tooltip")));

    //updater
    kudosSetting.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });
    ws.add(kudosContainer);
    if (sakaiProxy.isMyKudosEnabledGlobally()) {
        visibleWidgetCount++;
    } else {
        kudosContainer.setVisible(false);
    }

    //gallery feed
    WebMarkupContainer galleryFeedContainer = new WebMarkupContainer("galleryFeedContainer");
    galleryFeedContainer.add(new Label("galleryFeedLabel", new ResourceModel("preferences.widget.gallery")));
    CheckBox galleryFeedSetting = new CheckBox("galleryFeedSetting",
            new PropertyModel<Boolean>(preferencesModel, "showGalleryFeed"));
    galleryFeedSetting.setMarkupId("galleryfeedsettinginput");
    galleryFeedSetting.setOutputMarkupId(true);
    galleryFeedContainer.add(galleryFeedSetting);
    //tooltip
    galleryFeedContainer.add(new IconWithClueTip("galleryFeedToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("preferences.widget.gallery.tooltip")));

    //updater
    galleryFeedSetting.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });
    ws.add(galleryFeedContainer);
    if (sakaiProxy.isProfileGalleryEnabledGlobally()) {
        visibleWidgetCount++;
    } else {
        galleryFeedContainer.setVisible(false);
    }

    //online status
    WebMarkupContainer onlineStatusContainer = new WebMarkupContainer("onlineStatusContainer");
    onlineStatusContainer
            .add(new Label("onlineStatusLabel", new ResourceModel("preferences.widget.onlinestatus")));
    CheckBox onlineStatusSetting = new CheckBox("onlineStatusSetting",
            new PropertyModel<Boolean>(preferencesModel, "showOnlineStatus"));
    onlineStatusSetting.setMarkupId("onlinestatussettinginput");
    onlineStatusSetting.setOutputMarkupId(true);
    onlineStatusContainer.add(onlineStatusSetting);
    //tooltip
    onlineStatusContainer.add(new IconWithClueTip("onlineStatusToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("preferences.widget.onlinestatus.tooltip")));

    //updater
    onlineStatusSetting.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();");
        }
    });
    ws.add(onlineStatusContainer);

    if (sakaiProxy.isOnlineStatusEnabledGlobally()) {
        visibleWidgetCount++;
    } else {
        onlineStatusContainer.setVisible(false);
    }

    // Hide widget container if nothing to show
    if (visibleWidgetCount == 0) {
        ws.setVisible(false);
    }

    form.add(ws);

    //submit button
    IndicatingAjaxButton submitButton = new IndicatingAjaxButton("submit", form) {
        private static final long serialVersionUID = 1L;

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

            //get the backing model
            ProfilePreferences profilePreferences = (ProfilePreferences) form.getModelObject();

            formFeedback.setDefaultModel(new ResourceModel("success.preferences.save.ok"));
            formFeedback.add(new AttributeModifier("class", true, new Model<String>("success")));

            //save
            if (preferencesLogic.savePreferencesRecord(profilePreferences)) {
                formFeedback.setDefaultModel(new ResourceModel("success.preferences.save.ok"));
                formFeedback.add(new AttributeModifier("class", true, new Model<String>("success")));

                //post update event
                sakaiProxy.postEvent(ProfileConstants.EVENT_PREFERENCES_UPDATE, "/profile/" + userUuid, true);

            } else {
                formFeedback.setDefaultModel(new ResourceModel("error.preferences.save.failed"));
                formFeedback.add(new AttributeModifier("class", true, new Model<String>("alertMessage")));
            }

            //resize iframe
            target.appendJavaScript("setMainFrameHeight(window.name);");

            //PRFL-775 - set focus to feedback message so it is announced to screenreaders
            target.appendJavaScript("$('#" + formFeedbackId + "').focus();");

            target.add(formFeedback);
        }

    };
    submitButton.setModel(new ResourceModel("button.save.settings"));
    submitButton.setDefaultFormProcessing(false);
    form.add(submitButton);

    add(form);

}