List of usage examples for org.apache.wicket.extensions.ajax.markup.html IndicatingAjaxLink IndicatingAjaxLink
public IndicatingAjaxLink(final String id, final IModel<T> model)
From source file:com.francetelecom.clara.cloud.presentation.environments.EnvironmentActionPanel.java
License:Apache License
/** START BUTTON ENABLE **/ private void createStartEnableBtn() { startBtn = new IndicatingAjaxLink<E>("env-start-link", getModel()) { private static final long serialVersionUID = -3624723770141461652L; @Override/*from www . j a v a2 s.c o m*/ public void onClick(AjaxRequestTarget target) { try { String envUID = getModelObject().getUid(); if (parentPage instanceof SelectedEnvironmentPage) { ((SelectedEnvironmentPage) parentPage).getManageEnvironment().startEnvironment(envUID); } else if (parentPage instanceof EnvironmentsPage) { ((EnvironmentsPage) parentPage).getManageEnvironment().startEnvironment(envUID); } else { ((SelectedReleasePage) parentPage).getManageEnvironment().startEnvironment(envUID); } propagateAjaxUpdate(target); } catch (ObjectNotFoundException e) { String errMsg = getString("portal.environment.action.start.error.objectnotfound", new Model<Object[]>(new Object[] { getModelObject().getLabel() })); logger.error(errMsg); error(errMsg); } } @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { attributes.getAjaxCallListeners().add(new BlockUIDecorator(getString("portal.info.env.start"))); } @Override public boolean isVisible() { EnvironmentStatusEnum envStatus = getModelObject().getStatus(); return getModelObject().isEditable() && (envStatus == EnvironmentStatusEnum.STOPPED || envStatus == EnvironmentStatusEnum.FAILED); } }; add(startBtn); }
From source file:com.francetelecom.clara.cloud.presentation.environments.EnvironmentActionPanel.java
License:Apache License
/** STOP BUTTON ENABLE **/ private void createStopEnableBtn() { stopBtn = new IndicatingAjaxLink<E>("env-stop-link", getModel()) { private static final long serialVersionUID = -7938349139632727052L; @Override/*w w w . j ava 2s . c o m*/ public void onClick(AjaxRequestTarget target) { try { String envUID = getModelObject().getUid(); if (parentPage instanceof SelectedEnvironmentPage) { ((SelectedEnvironmentPage) parentPage).getManageEnvironment().stopEnvironment(envUID); } else if (parentPage instanceof EnvironmentsPage) { ((EnvironmentsPage) parentPage).getManageEnvironment().stopEnvironment(envUID); } else { ((SelectedReleasePage) parentPage).getManageEnvironment().stopEnvironment(envUID); } propagateAjaxUpdate(target); } catch (ObjectNotFoundException e) { String errMsg = getString("portal.environment.action.stop.error.objectnotfound", new Model<Object[]>(new Object[] { getModelObject().getLabel() })); logger.error(errMsg); error(errMsg); } } @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { attributes.getAjaxCallListeners().add(new BlockUIDecorator(getString("portal.info.env.stop"))); } @Override public boolean isVisible() { EnvironmentStatusEnum envStatus = getModelObject().getStatus(); return getModelObject().isEditable() && (envStatus == EnvironmentStatusEnum.RUNNING || envStatus == EnvironmentStatusEnum.FAILED); } }; add(stopBtn); }
From source file:com.francetelecom.clara.cloud.presentation.environments.EnvironmentActionPanel.java
License:Apache License
/** DELETE BUTTON ENABLE **/ private void createDeleteEnableBtn() { deleteBtn = new IndicatingAjaxLink<E>("env-delete-link", getModel()) { private static final long serialVersionUID = -8608226682718820756L; @Override//from www. j a v a 2 s .c o m public void onClick(AjaxRequestTarget target) { try { String envUID = getModelObject().getUid(); if (parentPage instanceof SelectedEnvironmentPage) { ((SelectedEnvironmentPage) parentPage).getManageEnvironment().deleteEnvironment(envUID); } else if (parentPage instanceof EnvironmentsPage) { ((EnvironmentsPage) parentPage).getManageEnvironment().deleteEnvironment(envUID); } else { ((SelectedReleasePage) parentPage).getManageEnvironment().deleteEnvironment(envUID); } propagateAjaxUpdate(target); } catch (ObjectNotFoundException e) { String errMsg = getString("portal.environment.action.delete.error.objectnotfound", new Model<Object[]>(new Object[] { getModelObject().getLabel() })); logger.error(errMsg); error(errMsg); } } @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { attributes.getAjaxCallListeners() .add(new DeleteConfirmationBlockUIDecorator( getString("portal.environment.action.delete.confirm", new Model<String[]>(new String[] { getModelObject().getLabel() })), getString("portal.info.env.delete"))); } @Override public boolean isVisible() { EnvironmentStatusEnum envStatus = getModelObject().getStatus(); return getModelObject().isEditable() && (envStatus == EnvironmentStatusEnum.RUNNING || envStatus == EnvironmentStatusEnum.STOPPED || envStatus == EnvironmentStatusEnum.FAILED); } }; add(deleteBtn); }
From source file:nl.knaw.dans.dccd.web.project.ProjectViewStatusPanel.java
License:Apache License
private void init() { IModel<Project> projectModel = (IModel<Project>) this.getDefaultModel(); add(new Label("project_status_value", new StringResourceModel( "datasetState.${administrativeMetadata.administrativeState}", this, projectModel))); add(new DateTimeLabel("project_status_date", getString("dateTimeFormat"), new PropertyModel(projectModel, "administrativeMetadata.lastStateChange"))); // buttons//from w ww. ja v a2 s .c o m // link to editing this project // may take some time due to the validation IndicatingAjaxLink editLink = new IndicatingAjaxLink("project_edit", projectModel) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { Project project = (Project) getModelObject(); setResponsePage(new ProjectEditPage(project)); } }; add(editLink); // link to archive this project // may take some time due to the validation IndicatingAjaxLink archiveLink = new IndicatingAjaxLink("project_archive", projectModel) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { // Set this Page to return to ((DccdSession) Session.get()).setRedirectPage(ProjectArchivingPage.class, getPage()); Project project = (Project) getModelObject(); setResponsePage(new ProjectArchivingPage(project)); } }; add(archiveLink); Link deleteLink = new Link("project_delete", projectModel) { private static final long serialVersionUID = 1L; @Override public void onClick() { Project project = (Project) getDefaultModelObject(); logger.debug("delete project"); try { DccdDataService.getService().deleteProject(project, (DccdUser) ((DccdSession) getSession()).getUser()); } catch (DataServiceException e) { logger.error("Failed to delete project", e); getSession().error("Failed to delete project"); // use resource? throw new RestartResponseException(ErrorPage.class); } // this is where we get from //setResponsePage(new MyProjectsPage()); setResponsePage(new MyProjectsSearchResultPage()); /* // return to the project view, // ehhh that's where we are! // refresh then? Page page = getPage(); if (page instanceof BasePage) ((BasePage)page).refresh(); // page should reflect new project status // But if it is deleted, we can see it when we have management permission?? // maybe just go back (and to Home if there is no back) //Page backPage = ((DccdSession)Session.get()).getRedirectPage(getPage().getClass()); */ } }; add(deleteLink); // show dialog... confirmation alert deleteLink.add(new LinkConfirmationBehavior(getString("deleteConfirmationMessage"))); // NOTE: unarchiving is available until versioning is implemented! // // link to (UN)archive this project // may take some time due to the validation IndicatingAjaxLink unarchiveLink = new IndicatingAjaxLink("project_unarchive", projectModel) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { // logger.debug("Unarchiving project"); Project project = (Project) getModelObject(); try { DccdDataService.getService().unarchiveProject(project, (DccdUser) ((DccdSession) getSession()).getUser()); } catch (DataServiceException e) { logger.error("Failed to update project", e); getSession().error("Failed to update project"); // use resource? throw new RestartResponseException(ErrorPage.class); } // reload the page with new status? // setResponsePage(new ProjectViewPage(project)); } }; add(unarchiveLink); Label unarchiveMsgLabel = new Label("unarchive_message", new ResourceModel("unarchive_message")); add(unarchiveMsgLabel); // Hide buttons when not in Draft ! if (projectModel.getObject().getAdministrativeMetadata().getAdministrativeState() != DatasetState.DRAFT) { // Not Draft == Archived editLink.setVisible(false); archiveLink.setVisible(false); deleteLink.setVisible(false); } // DISABLE UNARCHIVING else { // Draft unarchiveLink.setVisible(false); unarchiveMsgLabel.setVisible(false); } }
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();// ww w. j a v a2 s . c o 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.syncope.console.pages.ConnectorModalPage.java
License:Apache License
public ConnectorModalPage(final PageReference callerPageRef, final ModalWindow window, final ConnInstanceTO connectorTO) { super();//from w ww . jav a 2 s . c o m selectedCapabilities = new ArrayList(connectorTO.getId() == 0 ? EnumSet.noneOf(ConnectorCapability.class) : connectorTO.getCapabilities()); 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()); } }; final IModel<List<ConnBundleTO>> bundles = new LoadableDetachableModel<List<ConnBundleTO>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<ConnBundleTO> load() { return restClient.getAllBundles(); } }; bundleTO = getSelectedBundleTO(bundles.getObject(), connectorTO); properties = getProperties(bundleTO, connectorTO); final AjaxTextFieldPanel connectorName = new AjaxTextFieldPanel("connectorName", "connector name", new PropertyModel<String>(connectorTO, "connectorName"), false); connectorName.setOutputMarkupId(true); connectorName.setEnabled(false); final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name", new PropertyModel<String>(connectorTO, "displayName"), false); displayName.setOutputMarkupId(true); displayName.addRequiredLabel(); final AjaxTextFieldPanel version = new AjaxTextFieldPanel("version", "version", new PropertyModel<String>(connectorTO, "version"), false); displayName.setOutputMarkupId(true); version.setEnabled(false); final AjaxDropDownChoicePanel<ConnBundleTO> bundle = new AjaxDropDownChoicePanel<ConnBundleTO>("bundle", "bundle", new Model<ConnBundleTO>(bundleTO), false); bundle.setStyleShet("long_dynamicsize"); bundle.setChoices(bundles.getObject()); bundle.setChoiceRenderer(new ChoiceRenderer<ConnBundleTO>() { private static final long serialVersionUID = -1945543182376191187L; @Override public Object getDisplayValue(final ConnBundleTO object) { return object.getBundleName() + " " + object.getVersion(); } @Override public String getIdValue(final ConnBundleTO object, final int index) { // idValue must include version as well in order to cope // with multiple version of the same bundle. return object.getBundleName() + "#" + object.getVersion(); } }); ((DropDownChoice) bundle.getField()).setNullValid(true); bundle.setRequired(true); bundle.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { //reset all informations stored in connectorTO connectorTO.setConfiguration(new HashSet<ConnConfProperty>()); ((DropDownChoice) bundle.getField()).setNullValid(false); target.add(bundle.getField()); target.add(connectorName); target.add(version); target.add(propertiesContainer); } }); bundle.getField().setModel(new IModel<ConnBundleTO>() { private static final long serialVersionUID = -3736598995576061229L; @Override public ConnBundleTO getObject() { return bundleTO; } @Override public void setObject(final ConnBundleTO object) { if (object != null && connectorTO != null) { connectorTO.setBundleName(object.getBundleName()); connectorTO.setVersion(object.getVersion()); connectorTO.setConnectorName(object.getConnectorName()); properties = getProperties(object, connectorTO); bundleTO = object; } } @Override public void detach() { } }); bundle.addRequiredLabel(); bundle.setEnabled(connectorTO.getId() == 0); final ListView<ConnConfProperty> view = new ListView<ConnConfProperty>("connectorProperties", new PropertyModel(this, "properties")) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(final ListItem<ConnConfProperty> item) { final ConnConfProperty property = item.getModelObject(); final Label label = new Label("connPropAttrSchema", property.getSchema().getDisplayName() == null || property.getSchema().getDisplayName().isEmpty() ? property.getSchema().getName() : property.getSchema().getDisplayName()); item.add(label); final FieldPanel field; boolean required = false; boolean isArray = false; if (GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType()) || GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) { field = new AjaxPasswordFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(), true); ((PasswordTextField) field.getField()).setResetPassword(false); required = property.getSchema().isRequired(); } else { Class propertySchemaClass; try { propertySchemaClass = ClassUtils.forName(property.getSchema().getType(), ClassUtils.getDefaultClassLoader()); } catch (Exception e) { LOG.error("Error parsing attribute type", e); propertySchemaClass = String.class; } if (NUMBER.contains(propertySchemaClass)) { field = new AjaxNumberFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(), ClassUtils.resolvePrimitiveIfNecessary(propertySchemaClass), true); required = property.getSchema().isRequired(); } else if (Boolean.class.equals(propertySchemaClass) || boolean.class.equals(propertySchemaClass)) { field = new AjaxCheckBoxPanel("panel", label.getDefaultModelObjectAsString(), new Model(), true); } else { field = new AjaxTextFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(), true); required = property.getSchema().isRequired(); } if (String[].class.equals(propertySchemaClass)) { isArray = true; } } field.setTitle(property.getSchema().getHelpMessage()); if (isArray) { field.removeRequiredLabel(); if (property.getValues().isEmpty()) { property.getValues().add(null); } item.add(new MultiValueSelectorPanel<String>("panel", new PropertyModel<List<String>>(property, "values"), String.class, field)); } else { if (required) { field.addRequiredLabel(); } field.setNewModel(property.getValues()); item.add(field); } final AjaxCheckBoxPanel overridable = new AjaxCheckBoxPanel("connPropAttrOverridable", "connPropAttrOverridable", new PropertyModel(property, "overridable"), true); item.add(overridable); connectorTO.getConfiguration().add(property); } }; final Form connectorForm = new Form("form"); connectorForm.setModel(new CompoundPropertyModel(connectorTO)); final Form connectorPropForm = new Form("connectorPropForm"); connectorPropForm.setModel(new CompoundPropertyModel(connectorTO)); connectorPropForm.setOutputMarkupId(true); propertiesContainer = new WebMarkupContainer("container"); propertiesContainer.setOutputMarkupId(true); propertiesContainer.add(connectorPropForm); connectorForm.add(propertiesContainer); connectorPropForm.add(view); final AjaxLink check = new IndicatingAjaxLink("check", new ResourceModel("check")) { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target) { connectorTO.setBundleName(bundleTO.getBundleName()); connectorTO.setVersion(bundleTO.getVersion()); if (restClient.check(connectorTO).booleanValue()) { info(getString("success_connection")); } else { error(getString("error_connection")); } target.add(feedbackPanel); } }; connectorPropForm.add(check); 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.getDefaultModelObject(); conn.setBundleName(bundleTO.getBundleName()); // Set the model object's capabilites to // capabilitiesPalette's converted Set if (!selectedCapabilities.isEmpty()) { // exception if selectedCapabilities is empy conn.setCapabilities(EnumSet.copyOf(selectedCapabilities)); } else { conn.setCapabilities(EnumSet.noneOf(ConnectorCapability.class)); } try { if (connectorTO.getId() == 0) { restClient.create(conn); } else { restClient.update(conn); } ((Resources) callerPageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientCompositeErrorException e) { error(getString("error") + ":" + e.getMessage()); target.add(feedbackPanel); ((Resources) callerPageRef.getPage()).setModalResult(false); LOG.error("While creating or updating connector {}", conn); } } @Override protected void onError(final AjaxRequestTarget target, final Form form) { target.add(feedbackPanel); } }; String roles = connectorTO.getId() == 0 ? xmlRolesReader.getAllAllowedRoles("Connectors", "create") : xmlRolesReader.getAllAllowedRoles("Connectors", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles); connectorForm.add(connectorName); connectorForm.add(displayName); connectorForm.add(bundle); connectorForm.add(version); capabilitiesPalette = new CheckBoxMultipleChoice("capabilitiesPalette", new PropertyModel(this, "selectedCapabilities"), capabilities); connectorForm.add(capabilitiesPalette); connectorForm.add(submit); add(connectorForm); }
From source file:org.syncope.console.pages.panels.ResourceConnConfPanel.java
License:Apache License
public ResourceConnConfPanel(final String id, final ResourceTO resourceTO, final boolean createFlag) { super(id);// w w w . j ava2s .c om setOutputMarkupId(true); this.createFlag = createFlag; this.resourceTO = resourceTO; connConfProperties = getConnConfProperties(); connConfPropContainer = new WebMarkupContainer("connectorPropertiesContainer"); connConfPropContainer.setOutputMarkupId(true); add(connConfPropContainer); check = new IndicatingAjaxLink("check", new ResourceModel("check")) { private static final long serialVersionUID = -4199438518229098169L; @Override public void onClick(final AjaxRequestTarget target) { ConnInstanceTO connectorTO = connRestClient.read(resourceTO.getConnectorId()); connectorTO.setConfiguration( ConnConfPropUtils.joinConnInstanceProperties(connectorTO.getConfigurationMap(), ConnConfPropUtils.getConnConfPropertyMap(resourceTO.getConnConfProperties()))); if (connRestClient.check(connectorTO).booleanValue()) { info(getString("success_connection")); } else { error(getString("error_connection")); } target.add(((BaseModalPage) getPage()).getFeedbackPanel()); } }; check.setEnabled(!connConfProperties.isEmpty()); connConfPropContainer.add(check); /* * the list of overridable connector properties */ connConfPropContainer.add(new ListView<ConnConfProperty>("connectorProperties", new PropertyModel(this, "connConfProperties")) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(final ListItem<ConnConfProperty> item) { final ConnConfProperty property = item.getModelObject(); final Label label = new Label("connPropAttrSchema", property.getSchema().getDisplayName() == null || property.getSchema().getDisplayName().isEmpty() ? property.getSchema().getName() : property.getSchema().getDisplayName()); item.add(label); final FieldPanel field; boolean required = false; boolean isArray = false; if (GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType()) || GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) { field = new AjaxPasswordFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(), true); ((PasswordTextField) field.getField()).setResetPassword(false); required = property.getSchema().isRequired(); } else { Class propertySchemaClass; try { propertySchemaClass = ClassUtils.forName(property.getSchema().getType(), ClassUtils.getDefaultClassLoader()); } catch (Exception e) { LOG.error("Error parsing attribute type", e); propertySchemaClass = String.class; } if (NUMBER.contains(propertySchemaClass)) { field = new AjaxNumberFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(), ClassUtils.resolvePrimitiveIfNecessary(propertySchemaClass), true); required = property.getSchema().isRequired(); } else if (Boolean.class.equals(propertySchemaClass) || boolean.class.equals(propertySchemaClass)) { field = new AjaxCheckBoxPanel("panel", label.getDefaultModelObjectAsString(), new Model(), true); } else { field = new AjaxTextFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(), true); required = property.getSchema().isRequired(); } if (String[].class.equals(propertySchemaClass)) { isArray = true; } } field.setTitle(property.getSchema().getHelpMessage()); if (isArray) { field.removeRequiredLabel(); if (property.getValues().isEmpty()) { property.getValues().add(null); } final MultiValueSelectorPanel multiFields = new MultiValueSelectorPanel<String>("panel", new PropertyModel<List<String>>(property, "values"), String.class, field, true); item.add(multiFields); } else { if (required) { field.addRequiredLabel(); } field.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { send(getPage(), Broadcast.BREADTH, new ConnConfModEvent(target, connConfProperties)); } }); field.setNewModel(property.getValues()); item.add(field); } resourceTO.getConnConfProperties().add(property); } }); }