List of usage examples for org.apache.wicket.markup.html.form CheckBoxMultipleChoice CheckBoxMultipleChoice
public CheckBoxMultipleChoice(String id, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer)
From source file:edu.tsinghua.software.pages.columnFamily.DeleteColumnFamilyPage.java
License:Apache License
/** * DeleteKeyspacePage Construct/*from w w w .j av a 2s.c om*/ * @param parameters * */ public DeleteColumnFamilyPage(final PageParameters parameters) throws TException { init(parameters); //navigation add(new BookmarkablePageLink<Void>("clusterNavigation", ClusterView.class) .add(new Label("clusterName", clusterName))); add(new BookmarkablePageLink<Void>("keyspaceNevigation", KeyspacePage.class, parameters) .add(new Label("keyspaceName", keyspaceName))); final FeedbackPanel feedBack = new FeedbackPanel("feedback"); feedBack.setOutputMarkupId(true); final CheckBoxMultipleChoice<String> listColumnFamilies = new CheckBoxMultipleChoice<String>( "listColumnFamilies", new Model(columnFamilySelect), columnFamilyNameList); listColumnFamilies.setOutputMarkupId(true); AjaxLink checkAll = new AjaxLink<Void>("checkAll") { @Override public void onClick(AjaxRequestTarget target) { columnFamilySelect.addAll(listColumnFamilies.getChoices()); target.add(listColumnFamilies); } }; AjaxLink uncheckAll = new AjaxLink<Void>("uncheckAll") { @Override public void onClick(AjaxRequestTarget target) { columnFamilySelect.clear(); target.add(listColumnFamilies); } }; Form<?> form = new Form<Void>("userForm") { @Override public void onSubmit() { for (String columnFamilyName : columnFamilySelect) { try { client.dropColumnFamily(keyspaceName, columnFamilyName); columnFamilyNameList.remove(columnFamilyName); } catch (Exception e) { e.printStackTrace(); } } info("drop" + columnFamilySelect); listColumnFamilies.setChoices(columnFamilyNameList); try { pageParameters.set("clusterParam", clusterName); pageParameters.set("keyspaceParam", keyspaceName); setResponsePage(new DeleteColumnFamilyPage(pageParameters)); } catch (TException e) { // TODO Auto-generated catch block System.out.println("*************"); e.printStackTrace(); } } }; add(feedBack); add(form); form.add(listColumnFamilies); form.add(checkAll); form.add(uncheckAll); }
From source file:edu.tsinghua.software.pages.keyspace.DeleteKeyspacePage.java
License:Apache License
/** * DeleteKeyspacePage Construct/* w ww.j av a 2 s . c om*/ * @param parameters * */ public DeleteKeyspacePage(final PageParameters parameters) throws TException { init(parameters); //navigation add(new BookmarkablePageLink<Void>("clusterNavigation", ClusterView.class) .add(new Label("clusterName", clusterName))); final FeedbackPanel feedBack = new FeedbackPanel("feedback"); feedBack.setOutputMarkupId(true); final CheckBoxMultipleChoice<String> listKeyspaces = new CheckBoxMultipleChoice<String>("keyspaces", new Model(keyspacesSelect), keyspaceNameList); listKeyspaces.setOutputMarkupId(true); AjaxLink checkAll = new AjaxLink<Void>("checkAll") { @Override public void onClick(AjaxRequestTarget target) { keyspacesSelect.addAll(listKeyspaces.getChoices()); target.add(listKeyspaces); } }; AjaxLink uncheckAll = new AjaxLink<Void>("uncheckAll") { @Override public void onClick(AjaxRequestTarget target) { keyspacesSelect.clear(); target.add(listKeyspaces); } }; Form<?> form = new Form<Void>("userForm") { @Override public void onSubmit() { for (String keyspaceName : keyspacesSelect) { try { client.dropKeyspace(keyspaceName); keyspaceNameList.remove(keyspaceName); } catch (Exception e) { e.printStackTrace(); } } if (getSession().getLocale() == Locale.CHINA) { info("" + keyspacesSelect); try { setResponsePage(new DeleteKeyspacePage(pageParameters)); } catch (TException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (getSession().getLocale() == Locale.US) { info("drop keyspace" + keyspacesSelect); try { setResponsePage(new DeleteKeyspacePage(pageParameters)); } catch (TException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; add(feedBack); add(form); form.add(listKeyspaces); form.add(checkAll); form.add(uncheckAll); }
From source file:eu.uqasar.web.pages.qmtree.quality.indicator.panels.QualityIndicatorEditPanel.java
License:Apache License
public QualityIndicatorEditPanel(String id, final IModel<QMQualityIndicator> model, final boolean isNew) { super(id, model); QMQualityIndicator indicator = model.getObject(); metaDataClasses = (List<Class>) (List<?>) (MetaData.getAllClasses()); form = new Form<QMQualityIndicator>("form", model) { /**// www.j a v a 2s. c o m * */ private static final long serialVersionUID = -5887857218309554465L; @Override protected void onSubmit() { QMQualityIndicator qi = model.getObject(); qi = checkCompleted(qi); qmodelService.update(qi); //If "create copy" check is selected if (chkCreateCopy.getModelObject()) { if (qi.getQModel() != null) { QMQualityIndicator ind = new QMQualityIndicator(qi); (qi.getParent()).addChild(ind); QMTreeNode parent = qmodelService.update(qi.getParent()); Iterator children = parent.getChildren().iterator(); boolean found = false; QMTreeNode qmn = null; while (children.hasNext() && !found) { qmn = (QMTreeNode) children.next(); if (qmn.equals(ind)) { found = true; } } PageParameters params = new PageParameters(); params.add("qmodel-key", qi.getQModel().getNodeKey()); params.add("id", qmn.getId()); params.add("isNew", true); setResponsePage(QMQualityIndicatorEditPage.class, params); } } else { PageParameters parameters = BasePage.appendSuccessMessage( QMQualityIndicatorViewPage.forQualityIndicator(getModelObject()), new StringResourceModel("treenode.saved.message", this, getModel())); setResponsePage(QMQualityIndicatorViewPage.class, parameters); } } }; //Name form.add(name = new TextField("name", new PropertyModel<>(model, "name"))); form.add(feedbackName = new ComponentFeedbackPanel("feedbackName", name)); feedbackName.setOutputMarkupId(true); // Purpose final FormComponent<Purpose> purpose = new DropDownChoice<>("purpose", new PropertyModel<Purpose>(indicator, "indicatorPurpose"), Purpose.getAllPurposes()); purposeAtt.add(purpose); // Purpose attributes: process -> paradigm final DropDownChoice<Paradigm> paradigm = new DropDownChoice<>("attContent", new PropertyModel<Paradigm>(indicator, "paradigm"), Paradigm.getAllParadigms()); final Label paradigmLabel = new Label("attLabel", new StringResourceModel("label.indicator.paradigm", this, null)); // Purpose attributes: product -> version final FormComponent<Version> version = new DropDownChoice<>("attContent", new PropertyModel<Version>(indicator, "version"), Version.getAllVersions()); final Label versionLabel = new Label("attLabel", new StringResourceModel("label.indicator.version", this, null)); final Label stageLabel = new Label("attLabel2", new StringResourceModel("label.indicator.lcStage", this, null)); final DropDownChoice<LifeCycleStage> lcStage = new DropDownChoice<>("attContent2", new PropertyModel<LifeCycleStage>(indicator, "lifeCycleStage"), LifeCycleStage.getAllLifeCycleStages()); final DropDownChoice<RupStage> rupStage = new DropDownChoice<>("attContent2", new PropertyModel<RupStage>(indicator, "rupStage"), RupStage.getAllRupStages()); final Label emptyLabel2 = new Label("attLabel2"); final FormComponent<Purpose> emptyContent2 = new DropDownChoice("attContent2"); emptyContent2.setVisible(false); if (indicator.getIndicatorPurpose().equals(Purpose.Process)) { purposeAtt.add(paradigm); purposeAtt.add(paradigmLabel); purposeAtt.add(stageLabel); if (indicator.getParadigm().equals(Paradigm.Waterfall)) { //Waterfall process lcStage.setOutputMarkupId(true); purposeAtt.add(lcStage); } else { //RUP Process rupStage.setOutputMarkupId(true); purposeAtt.add(rupStage); } } else { purposeAtt.add(version); purposeAtt.add(versionLabel); purposeAtt.add(emptyLabel2); purposeAtt.add(emptyContent2); } version.setOutputMarkupId(true); paradigm.setOutputMarkupId(true); purpose.setOutputMarkupId(true); purpose.setOutputMarkupPlaceholderTag(true); purposeAtt.setOutputMarkupId(true); purposeAtt.setOutputMarkupPlaceholderTag(true); form.add(purposeAtt); purpose.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (getFormComponent().getConvertedInput().equals(Purpose.Process)) { purposeAtt.remove(versionLabel); purposeAtt.remove(version); purposeAtt.remove(emptyLabel2); purposeAtt.remove(emptyContent2); purposeAtt.add(paradigmLabel); paradigm.setDefaultModelObject(Paradigm.Waterfall); purposeAtt.add(paradigm); purposeAtt.add(stageLabel); purposeAtt.add(lcStage); } else { purposeAtt.remove(paradigmLabel); purposeAtt.remove(paradigm); purposeAtt.remove(stageLabel); purposeAtt.remove(rupStage); purposeAtt.remove(lcStage); purposeAtt.add(versionLabel); purposeAtt.add(version); purposeAtt.add(emptyLabel2); purposeAtt.add(emptyContent2); } if (target != null) { target.add(purposeAtt); } } }); paradigm.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (getFormComponent().getConvertedInput().equals(Paradigm.Waterfall)) { purposeAtt.remove(rupStage); purposeAtt.add(lcStage); } else { purposeAtt.remove(lcStage); purposeAtt.add(rupStage); } if (target != null) { target.add(purposeAtt); } } }); // Description form.add(description = new TextArea<>("description", new PropertyModel<String>(model, "description"))); description.add(tinyMceBehavior = new TinyMceBehavior(DefaultTinyMCESettings.get())); form.add(new AjaxCheckBox("toggle.richtext", richEnabledModel) { /** * */ private static final long serialVersionUID = -3568270438060786890L; @Override protected void onUpdate(AjaxRequestTarget target) { if (getModelObject()) { description.add(tinyMceBehavior); } else { description.remove(tinyMceBehavior); tinyMceBehavior = new TinyMceBehavior(DefaultTinyMCESettings.get()); } target.add(QualityIndicatorEditPanel.this); } }); //roles final CheckBoxMultipleChoice<Role> targetAudience = new CheckBoxMultipleChoice<>("targetAudience", new PropertyModel<List<Role>>(indicator, "targetAudience"), Role.getAllRoles()); form.add(targetAudience); //lower and upper limits form.add(new Label("limitsLabel", new StringResourceModel("label.indicator.limits", this, null))); form.add(new Label("lowerLabel", new StringResourceModel("label.indicator.lower.limit", this, null))); form.add(new Label("upperLabel", new StringResourceModel("label.indicator.upper.limit", this, null))); form.add(lowerLimit = new TextField("lowerLimit", new PropertyModel<>(model, "lowerLimit"))); lowerLimit.setRequired(false); form.add(feedbackLow = new ComponentFeedbackPanel("feedbackLow", lowerLimit)); feedbackLow.setOutputMarkupId(true); if (Double.MAX_VALUE == indicator.getUpperLimit()) { //TODO empty field indicator.setUpperLimit(Double.MIN_VALUE); } form.add(upperLimit = new TextField("upperLimit", new PropertyModel<>(model, "upperLimit")) .setRequired(false)); form.add(feedbackLimits = new ComponentFeedbackPanel("feedbackLimits", upperLimit)); feedbackLimits.setOutputMarkupId(true); //Sprint 2. Added QProject attributes //targetValue form.add(targetValue = new TextField("targetValue", new PropertyModel<>(model, "targetValue")) .setRequired(false)); //Weight form.add(weight = new TextField("weight", new PropertyModel<>(model, "weight")).setRequired(false)); // add modal for adding tags tagsModal = newTagsSelectionModal(); tagsModal.setOutputMarkupId(true); form.add(tagsModal); select = newSelect2("qModelTagData", QModelTagData.class, new PropertyModel<Collection<QModelTagData>>(model.getObject(), "qModelTagData"), form); form.add(select); if (isNew) { Button cancel = new Button("cancel") { private static final long serialVersionUID = -6733104400111745683L; @Override public void onSubmit() { QMQualityObjective parent = qmodelService .getQualityObjective(model.getObject().getParent().getId()); qmodelService.removeTreeNode(model.getObject().getId()); setResponsePage(QMQualityObjectiveViewPage.class, QMQualityObjectiveViewPage.forQualityObjective(parent)); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); } else { form.add(new BootstrapBookmarkablePageLink<QMQualityIndicator>("cancel", QMQualityIndicatorViewPage.class, QMQualityIndicatorViewPage.forQualityIndicator(model.getObject()), de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons.Type.Default) .setLabel(new StringResourceModel("button.cancel", this, null))); } form.add(save = new AjaxButton("save", new StringResourceModel("button.save", this, null)) { /** * */ private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { form.add(feedbackName); form.add(feedbackLimits); form.add(feedbackLow); target.add(form); } }); save.add(new TinyMceAjaxSubmitModifier()); //Create additional qi with predefined values chkCreateCopy = new CheckBox("checkboxCopy", Model.of(Boolean.FALSE)); form.add(chkCreateCopy); form.add(new Label("checkboxCopyLabel", new StringResourceModel("label.indicator.checkboxCopy", this, null))); form.setOutputMarkupId(true); setOutputMarkupId(true); form.add(new QMQualityIndicatorFormValidator(name, lowerLimit, upperLimit)); add(form); }
From source file:eu.uqasar.web.pages.qmtree.quality.objective.panels.QualityObjectiveEditPanel.java
License:Apache License
public QualityObjectiveEditPanel(String id, final IModel<QMQualityObjective> model, final boolean isNew) { super(id, model); QMQualityObjective indicator = model.getObject(); metaDataClasses = (List<Class>) (List<?>) (MetaData.getAllClasses()); form = new Form<QMQualityObjective>("form", model) { /**/*w ww .j a va 2 s .c o m*/ * */ private static final long serialVersionUID = 7134281091722157566L; @Override protected void onSubmit() { QMQualityObjective qo = model.getObject(); qo = checkCompleted(qo); qmodelService.update(qo); //If "create copy" check is selected if (chkCreateCopy.getModelObject()) { if (qo.getQModel() != null) { QMQualityObjective obj = new QMQualityObjective(qo); (qo.getQModel()).addChild(obj); QMTreeNode parent = qmodelService.update(qo.getQModel()); Iterator children = parent.getChildren().iterator(); boolean found = false; QMTreeNode qmn = null; while (children.hasNext() && !found) { qmn = (QMTreeNode) children.next(); if (qmn.equals(obj)) { found = true; } } PageParameters params = new PageParameters(); params.add("qmodel-key", qo.getQModel().getNodeKey()); params.add("id", qmn.getId()); params.add("isNew", true); setResponsePage(QMQualityObjectiveEditPage.class, params); } } else { PageParameters parameters = BasePage.appendSuccessMessage( QMQualityObjectiveViewPage.forQualityObjective(getModelObject()), new StringResourceModel("treenode.saved.message", this, getModel())); setResponsePage(QMQualityObjectiveViewPage.class, parameters); } } }; //Name form.add(name = new TextField("name", new PropertyModel<>(model, "name"))); form.add(feedbackName = new ComponentFeedbackPanel("feedbackName", name)); feedbackName.setOutputMarkupId(true); //Domains domain = new CheckBoxMultipleChoice<>("domain", new PropertyModel<List<Domain>>(indicator, "domain"), Domain.getAllDomains()); form.add(domain); // Purpose purpose = new DropDownChoice<>("purpose", new PropertyModel<Purpose>(indicator, "indicatorPurpose"), Purpose.getAllPurposes()); // Purpose attributes paradigm = new DropDownChoice<>("attContent", new PropertyModel<Paradigm>(indicator, "paradigm"), Paradigm.getAllParadigms()); final Label paradigmLabel = new Label("attLabel", new StringResourceModel("label.objective.paradigm", this, null)); version = new DropDownChoice<>("attContent", new PropertyModel<Version>(indicator, "version"), Version.getAllVersions()); final Label versionLabel = new Label("attLabel", new StringResourceModel("label.objective.version", this, null)); if (indicator.getIndicatorPurpose().equals(Purpose.Process)) { purposeAtt.add(paradigm); purposeAtt.add(paradigmLabel); } else { purposeAtt.add(version); purposeAtt.add(versionLabel); } purpose.setOutputMarkupId(true); purpose.setOutputMarkupPlaceholderTag(true); purposeAtt.setOutputMarkupId(true); purposeAtt.setOutputMarkupPlaceholderTag(true); form.add(purposeAtt); form.add(purpose); purpose.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (getFormComponent().getConvertedInput().equals(Purpose.Process)) { purposeAtt.remove(versionLabel); purposeAtt.remove(version); purposeAtt.add(paradigmLabel); purposeAtt.add(paradigm); } else { purposeAtt.remove(paradigmLabel); purposeAtt.remove(paradigm); purposeAtt.add(versionLabel); purposeAtt.add(version); } if (target != null) { target.add(purposeAtt); } } }); // Description description = new TextArea<>("description", new PropertyModel<String>(model, "description")); form.add(description); description.add(tinyMceBehavior = new TinyMceBehavior(DefaultTinyMCESettings.get())); form.add(new AjaxCheckBox("toggle.richtext", richEnabledModel) { /** * */ private static final long serialVersionUID = 390304436557732288L; @Override protected void onUpdate(AjaxRequestTarget target) { if (getModelObject()) { description.add(tinyMceBehavior); } else { description.remove(tinyMceBehavior); tinyMceBehavior = new TinyMceBehavior(DefaultTinyMCESettings.get()); } target.add(QualityObjectiveEditPanel.this); } }); //roles final CheckBoxMultipleChoice<Role> targetAudience = new CheckBoxMultipleChoice<>("targetAudience", new PropertyModel<List<Role>>(indicator, "targetAudience"), Role.getAllRoles()); form.add(targetAudience); //lower and upper limits form.add(new Label("limitsLabel", new StringResourceModel("label.objective.limits", this, null))); form.add(new Label("lowerLabel", new StringResourceModel("label.objective.lower.limit", this, null))); form.add(new Label("upperLabel", new StringResourceModel("label.objective.upper.limit", this, null))); lowerLimit = new TextField("lowerLimit", new PropertyModel<Double>(model, "lowerLimit")).setRequired(false); form.add(lowerLimit); feedbackLow = (ComponentFeedbackPanel) new ComponentFeedbackPanel("feedbackLow", lowerLimit) .setOutputMarkupId(true); form.add(feedbackLow); if (Double.MAX_VALUE == indicator.getUpperLimit()) { //TODO empty field indicator.setUpperLimit(Double.MIN_VALUE); } upperLimit = new TextField("upperLimit", new PropertyModel<>(model, "upperLimit")).setRequired(false); form.add(upperLimit); feedbackLimits = (ComponentFeedbackPanel) new ComponentFeedbackPanel("feedbackLimits", upperLimit) .setOutputMarkupId(true); form.add(feedbackLimits); //Sprint 2. Added QProject attributes weight = new TextField("weight", new PropertyModel<>(model, "weight")).setRequired(false); form.add(weight); targetValue = new TextField("targetValue", new PropertyModel<>(model, "targetValue")).setRequired(false); form.add(targetValue); // add modal for adding tags tagsModal = newTagsSelectionModal(); tagsModal.setOutputMarkupId(true); form.add(tagsModal); select = newSelect2("qModelTagData", QModelTagData.class, new PropertyModel<Collection<QModelTagData>>(model.getObject(), "qModelTagData"), form); form.add(select); if (isNew) { Button cancel = new Button("cancel") { private static final long serialVersionUID = -6733104400111745683L; public void onSubmit() { QModel parent = qmodelService.getQModel(model.getObject().getParent().getId()); qmodelService.removeTreeNode(model.getObject().getId()); setResponsePage(QModelViewPage.class, QModelViewPage.forQModel(parent)); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); } else { form.add(new BootstrapBookmarkablePageLink<QMQualityObjective>("cancel", QMQualityObjectiveViewPage.class, QMQualityObjectiveViewPage.forQualityObjective(model.getObject()), de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons.Type.Default) .setLabel(new StringResourceModel("button.cancel", this, null))); } form.add(save = new AjaxButton("save", new StringResourceModel("button.save", this, null)) { /** * */ private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { form.add(feedbackName); form.add(feedbackLimits); form.add(feedbackLow); target.add(form); } }); save.add(new TinyMceAjaxSubmitModifier()); //Create additional qo with predefined values chkCreateCopy = new CheckBox("checkboxCopy", Model.of(Boolean.FALSE)); form.add(chkCreateCopy); form.add(new Label("checkboxCopyLabel", new StringResourceModel("label.objective.checkboxCopy", this, null))); form.setOutputMarkupId(true); setOutputMarkupId(true); form.add(new QMQualityObjectiveFormValidator(name, lowerLimit, upperLimit)); add(form); }
From source file:org.apache.jetspeed.portlets.prm.portlet.SupportsPanel.java
License:Apache License
@Override public void buildNew(Fragment fragment) { fragment.add(new TextField<String>("newMimeType", new PropertyModel<String>(this, "newMimeType"))); fragment.add(new CheckBoxMultipleChoice("newPortletModes", new PropertyModel(this, "newPortletModes"), availablePortletModes));//from w w w. j a va 2 s . c o m }
From source file:org.apache.jetspeed.portlets.prm.portlet.SupportsPanel.java
License:Apache License
@Override public void buildItems(Fragment fragment, final Supports field) { JetspeedServiceLocator locator = ((AbstractAdminWebApplication) getApplication()).getServiceLocator(); fragment.add(new TextField<String>("mimeType", new PropertyModel(new SupportsModel(locator, paNodeBean, field), "mimeType"))); fragment.add(new CheckBoxMultipleChoice("portletModes", new PropertyModel(new SupportsModel(locator, paNodeBean, field), "portletModes"), availablePortletModes));/*from w w w .java 2 s . co m*/ }
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 av a2s.co 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.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>>()); }//from w w w .j a v a2 s . c om 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.wicket.markup.html.form.CheckBoxMultipleChoiceFieldPanel.java
License:Apache License
public CheckBoxMultipleChoiceFieldPanel(final String id, final IModel<List<E>> model, final IModel<List<E>> choices) { super(id, model); field = new CheckBoxMultipleChoice<E>("checkBoxMultipleChoice", model, choices); add(field);// ww w . j ava 2 s . c o m }
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();/*from w ww . j av a 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); }