List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow close
public void close(final IPartialPageRequestHandler target)
From source file:org.apache.syncope.client.console.pages.VirSchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, VirSchemaTO schema, final boolean createFlag) { if (schema == null) { schema = new VirSchemaTO(); }//from w ww . j a va 2 s.com final Form<VirSchemaTO> schemaForm = new Form<>(FORM); schemaForm.setModel(new CompoundPropertyModel<>(schema)); final AjaxTextFieldPanel name = new AjaxTextFieldPanel("key", getString("key"), new PropertyModel<String>(schema, "key")); name.addRequiredLabel(); name.setEnabled(createFlag); final AjaxCheckBoxPanel readonly = new AjaxCheckBoxPanel("readonly", getString("readonly"), new PropertyModel<Boolean>(schema, "readonly")); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { VirSchemaTO schemaTO = (VirSchemaTO) form.getDefaultModelObject(); try { if (createFlag) { schemaRestClient.createVirSchema(kind, schemaTO); } else { schemaRestClient.updateVirSchema(kind, schemaTO); } if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton 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); String allowedRoles = createFlag ? xmlRolesReader.getEntitlement("Schema", "create") : xmlRolesReader.getEntitlement("Schema", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); schemaForm.add(name); schemaForm.add(readonly); schemaForm.add(submit); schemaForm.add(cancel); add(schemaForm); }
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>>()); }/* ww w . j a v a 2s . c o m*/ final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs .get(connBundleTO.getLocation()); // by name if (!byLocation.containsKey(connBundleTO.getBundleName())) { byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>()); } final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName()); // by version if (!byName.containsKey(connBundleTO.getVersion())) { byName.put(connBundleTO.getVersion(), connBundleTO); } } bundleTO = getSelectedBundleTO(connInstanceTO); properties = fillProperties(bundleTO, connInstanceTO); // form - first tab final Form<ConnInstanceTO> connectorForm = new Form<>(FORM); connectorForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorForm.setOutputMarkupId(true); add(connectorForm); propertiesContainer = new WebMarkupContainer("container"); propertiesContainer.setOutputMarkupId(true); connectorForm.add(propertiesContainer); final Form<ConnInstanceTO> connectorPropForm = new Form<>("connectorPropForm"); connectorPropForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorPropForm.setOutputMarkupId(true); propertiesContainer.add(connectorPropForm); final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name", new PropertyModel<String>(connInstanceTO, "displayName")); displayName.setOutputMarkupId(true); displayName.addRequiredLabel(); connectorForm.add(displayName); final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<>("location", "location", new Model<>(bundleTO == null ? null : bundleTO.getLocation())); ((DropDownChoice<String>) location.getField()).setNullValid(true); location.setStyleSheet("long_dynamicsize"); location.setChoices(new ArrayList<>(mapConnBundleTOs.keySet())); location.setRequired(true); location.addRequiredLabel(); location.setOutputMarkupId(true); location.setEnabled(connInstanceTO.getKey() == 0); location.getField().setOutputMarkupId(true); connectorForm.add(location); final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<>("connectorName", "connectorName", new Model<>(bundleTO == null ? null : bundleTO.getBundleName())); ((DropDownChoice<String>) connectorName.getField()).setNullValid(true); connectorName.setStyleSheet("long_dynamicsize"); connectorName.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet())); connectorName.setRequired(true); connectorName.addRequiredLabel(); connectorName.setEnabled(connInstanceTO.getLocation() != null); connectorName.setOutputMarkupId(true); connectorName.setEnabled(connInstanceTO.getKey() == 0); connectorName.getField().setOutputMarkupId(true); connectorForm.add(connectorName); final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version", new Model<>(bundleTO == null ? null : bundleTO.getVersion())); version.setStyleSheet("long_dynamicsize"); version.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()) .get(connInstanceTO.getBundleName()).keySet())); version.setRequired(true); version.addRequiredLabel(); version.setEnabled(connInstanceTO.getBundleName() != null); version.setOutputMarkupId(true); version.addRequiredLabel(); version.getField().setOutputMarkupId(true); connectorForm.add(version); final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<>("connRequestTimeout", "connRequestTimeout", Integer.class, new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null); connRequestTimeout.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(connRequestTimeout); if (connInstanceTO.getPoolConf() == null) { connInstanceTO.setPoolConf(new ConnPoolConfTO()); } final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<>("poolMaxObjects", "poolMaxObjects", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null); poolMaxObjects.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxObjects); final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<>("poolMinIdle", "poolMinIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null); poolMinIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMinIdle); final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<>("poolMaxIdle", "poolMaxIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null); poolMaxIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxIdle); final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<>("poolMaxWait", "poolMaxWait", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null); poolMaxWait.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMaxWait); final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<>("poolMinEvictableIdleTime", "poolMinEvictableIdleTime", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null); poolMinEvictableIdleTime.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMinEvictableIdleTime); // form - first tab - onchange() location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) location.getField()).setNullValid(false); connInstanceTO.setLocation(location.getModelObject()); target.add(location); connectorName.setChoices(new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()).keySet())); connectorName.setEnabled(true); connectorName.getField().setModelValue(null); target.add(connectorName); version.setChoices(new ArrayList<String>()); version.getField().setModelValue(null); version.setEnabled(false); target.add(version); properties.clear(); target.add(propertiesContainer); } }); connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) connectorName.getField()).setNullValid(false); connInstanceTO.setBundleName(connectorName.getModelObject()); target.add(connectorName); List<String> versions = new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()) .get(connectorName.getModelObject()).keySet()); version.setChoices(versions); version.setEnabled(true); if (versions.size() == 1) { selectVersion(target, connInstanceTO, version, versions.get(0)); version.getField().setModelObject(versions.get(0)); } else { version.getField().setModelValue(null); properties.clear(); target.add(propertiesContainer); } target.add(version); } }); version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { selectVersion(target, connInstanceTO, version, version.getModelObject()); } }); // form - second tab (properties) final ListView<ConnConfProperty> connPropView = new ConnConfPropertyListView("connectorProperties", new PropertyModel<List<ConnConfProperty>>(this, "properties"), true, connInstanceTO.getConfiguration()); connPropView.setOutputMarkupId(true); connectorPropForm.add(connPropView); final AjaxButton check = new IndicatingAjaxButton("check", new ResourceModel("check")) { private static final long serialVersionUID = -7978723352517770644L; @Override public void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); // ensure that connector bundle information is in sync conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.setConnectorName(bundleTO.getConnectorName()); if (connectorRestClient.check(conn)) { info(getString("success_connection")); } else { error(getString("error_connection")); } feedbackPanel.refresh(target); } }; connectorPropForm.add(check); // form - third tab (capabilities) final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<ConnectorCapability> load() { return Arrays.asList(ConnectorCapability.values()); } }; CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<>( "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"), capabilities); capabilitiesPalette.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { } }); connectorForm.add(capabilitiesPalette); // form - submit / cancel buttons final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<>(getString(SUBMIT))) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); conn.setConnectorName(bundleTO.getConnectorName()); conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.getConfiguration().clear(); conn.getConfiguration().addAll(connPropView.getModelObject()); // Set the model object's capabilities to capabilitiesPalette's converted Set conn.getCapabilities().clear(); conn.getCapabilities() .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class) : EnumSet.copyOf(selectedCapabilities)); // Reset pool configuration if all fields are null if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null && conn.getPoolConf().getMinIdle() == null) { conn.setPoolConf(null); } try { if (connInstanceTO.getKey() == 0) { connectorRestClient.create(conn); } else { connectorRestClient.update(conn); } ((BasePage) pageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); ((BasePage) pageRef.getPage()).setModalResult(false); LOG.error("While creating or updating connector {}", conn, e); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; String entitlements = connInstanceTO.getKey() == 0 ? Entitlement.CONNECTOR_CREATE : Entitlement.CONNECTOR_UPDATE; MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, entitlements); connectorForm.add(submit); final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); connectorForm.add(cancel); }
From source file:org.apache.syncope.client.console.panels.ResourceModal.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public ResourceModal(final ModalWindow window, final PageReference pageRef, final ResourceTO resourceTO, final boolean createFlag) { super(window, pageRef); final Form<ResourceTO> form = new Form<>(FORM); form.setModel(new CompoundPropertyModel<>(resourceTO)); //-------------------------------- // Resource details panel //-------------------------------- form.add(new ResourceDetailsPanel("details", resourceTO, resourceRestClient.getPropagationActionsClasses(), createFlag));// w w w .j a va2s . com form.add(new AnnotatedBeanPanel("systeminformation", resourceTO)); //-------------------------------- //-------------------------------- // Resource mapping panels //-------------------------------- form.add(new ResourceMappingPanel("umapping", resourceTO, AnyTypeKind.USER)); form.add(new ResourceMappingPanel("gmapping", resourceTO, AnyTypeKind.GROUP)); //-------------------------------- //-------------------------------- // Resource connector configuration panel //-------------------------------- ResourceConnConfPanel resourceConnConfPanel = new ResourceConnConfPanel("connconf", resourceTO, createFlag); MetaDataRoleAuthorizationStrategy.authorize(resourceConnConfPanel, ENABLE, Entitlement.CONNECTOR_READ); form.add(resourceConnConfPanel); //-------------------------------- //-------------------------------- // Resource security panel //-------------------------------- form.add(new ResourceSecurityPanel("security", resourceTO)); //-------------------------------- AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT, SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ResourceTO resourceTO = (ResourceTO) form.getDefaultModelObject(); boolean connObjectKeyError = false; final Collection<ProvisionTO> provisions = new ArrayList<>(resourceTO.getProvisions()); for (ProvisionTO provision : provisions) { if (provision != null) { if (provision.getMapping() == null || provision.getMapping().getItems().isEmpty()) { resourceTO.getProvisions().remove(provision); } else { int uConnObjectKeyCount = CollectionUtils.countMatches( provision.getMapping().getItems(), new Predicate<MappingItemTO>() { @Override public boolean evaluate(final MappingItemTO item) { return item.isConnObjectKey(); } }); connObjectKeyError = uConnObjectKeyCount != 1; } } } if (connObjectKeyError) { error(getString("connObjectKeyValidation")); feedbackPanel.refresh(target); } else { try { if (createFlag) { resourceRestClient.create(resourceTO); send(pageRef.getPage(), Broadcast.BREADTH, new ResourceCreateEvent(target, resourceTO)); } else { resourceRestClient.update(resourceTO); } if (pageRef.getPage() instanceof AbstractBasePage) { ((AbstractBasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (Exception e) { LOG.error("Failure managing resource {}", resourceTO, e); error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; form.add(submit); form.setDefaultButton(submit); final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { } }; cancel.setDefaultFormProcessing(false); form.add(cancel); add(form); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, createFlag ? Entitlement.RESOURCE_CREATE : Entitlement.RESOURCE_UPDATE); }
From source file:org.apache.syncope.console.pages.AbstractSchedTaskModalPage.java
License:Apache License
public AbstractSchedTaskModalPage(final ModalWindow window, final SchedTaskTO taskTO, final PageReference pageRef) { super(taskTO); crontab = new CrontabContainer("crontab", new PropertyModel<String>(taskTO, "cronExpression"), taskTO.getCronExpression()); form.add(crontab);//from w ww . j a v a 2 s. c om final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", "name", new PropertyModel<String>(taskTO, "name")); name.setEnabled(true); profile.add(name); final AjaxTextFieldPanel description = new AjaxTextFieldPanel("description", "description", new PropertyModel<String>(taskTO, "description")); description.setEnabled(true); profile.add(description); final AjaxTextFieldPanel lastExec = new AjaxTextFieldPanel("lastExec", getString("lastExec"), new DateFormatROModel(new PropertyModel<String>(taskTO, "lastExec"))); lastExec.setEnabled(false); profile.add(lastExec); final AjaxTextFieldPanel nextExec = new AjaxTextFieldPanel("nextExec", getString("nextExec"), new DateFormatROModel(new PropertyModel<String>(taskTO, "nextExec"))); nextExec.setEnabled(false); profile.add(nextExec); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(APPLY)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { SchedTaskTO taskTO = (SchedTaskTO) form.getModelObject(); taskTO.setCronExpression( StringUtils.hasText(taskTO.getCronExpression()) ? crontab.getCronExpression() : null); try { submitAction(taskTO); ((BasePage) pageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientException e) { LOG.error("While creating or updating task", e); error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton 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); if (taskTO.getId() > 0) { MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER, xmlRolesReader.getAllAllowedRoles(TASKS, "update")); } else { MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER, xmlRolesReader.getAllAllowedRoles(TASKS, "create")); } form.add(submit); form.add(cancel); }
From source file:org.apache.syncope.console.pages.ApprovalModalPage.java
License:Apache License
public ApprovalModalPage(final PageReference pageRef, final ModalWindow window, final WorkflowFormTO formTO) { super();//from www . j a v a2 s . com IModel<List<WorkflowFormPropertyTO>> formProps = new LoadableDetachableModel<List<WorkflowFormPropertyTO>>() { private static final long serialVersionUID = 3169142472626817508L; @Override protected List<WorkflowFormPropertyTO> load() { return formTO.getProperties(); } }; final ListView<WorkflowFormPropertyTO> propView = new AltListView<WorkflowFormPropertyTO>("propView", formProps) { private static final long serialVersionUID = 9101744072914090143L; @Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected void populateItem(final ListItem<WorkflowFormPropertyTO> item) { final WorkflowFormPropertyTO prop = item.getModelObject(); Label label = new Label("key", prop.getName() == null ? prop.getId() : prop.getName()); item.add(label); FieldPanel field; switch (prop.getType()) { case Boolean: field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(), new Model<Boolean>(Boolean.valueOf(prop.getValue()))) .setChoices(Arrays.asList(new String[] { "Yes", "No" })); break; case Date: SimpleDateFormat df = StringUtils.isNotBlank(prop.getDatePattern()) ? new SimpleDateFormat(prop.getDatePattern()) : new SimpleDateFormat(); Date parsedDate = null; if (StringUtils.isNotBlank(prop.getValue())) { try { parsedDate = df.parse(prop.getValue()); } catch (ParseException e) { LOG.error("Unparsable date: {}", prop.getValue(), e); } } field = new DateTimeFieldPanel("value", label.getDefaultModelObjectAsString(), new Model<Date>(parsedDate), df.toLocalizedPattern()); break; case Enum: MapChoiceRenderer<String, String> enumCR = new MapChoiceRenderer<String, String>( prop.getEnumValues()); field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(), new Model(prop.getValue())).setChoiceRenderer(enumCR).setChoices(new Model() { private static final long serialVersionUID = -858521070366432018L; @Override public Serializable getObject() { return new ArrayList<String>(prop.getEnumValues().keySet()); } }); break; case Long: field = new SpinnerFieldPanel<Long>("value", label.getDefaultModelObjectAsString(), Long.class, new Model<Long>(NumberUtils.toLong(prop.getValue())), null, null); break; case String: default: field = new AjaxTextFieldPanel("value", PARENT_PATH, new Model<String>(prop.getValue())); break; } field.setReadOnly(!prop.isWritable()); if (prop.isRequired()) { field.addRequiredLabel(); } item.add(field); } }; final AjaxButton userDetails = new IndicatingAjaxButton("userDetails", new Model<String>(getString("userDetails"))) { private static final long serialVersionUID = -4804368561204623354L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { editUserWin.setPageCreator(new ModalWindow.PageCreator() { private static final long serialVersionUID = -7834632442532690940L; @Override public Page createPage() { return new ViewUserModalPage(ApprovalModalPage.this.getPageReference(), editUserWin, userRestClient.read(formTO.getUserId())) { private static final long serialVersionUID = -2819994749866481607L; @Override protected void closeAction(final AjaxRequestTarget target, final Form form) { setResponsePage(ApprovalModalPage.this); } }; } }); editUserWin.show(target); } }; MetaDataRoleAuthorizationStrategy.authorize(userDetails, ENABLE, xmlRolesReader.getAllAllowedRoles("Users", "read")); 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) { Map<String, WorkflowFormPropertyTO> props = formTO.getPropertyMap(); for (int i = 0; i < propView.size(); i++) { @SuppressWarnings("unchecked") ListItem<WorkflowFormPropertyTO> item = (ListItem<WorkflowFormPropertyTO>) propView.get(i); String input = ((FieldPanel) item.get("value")).getField().getInput(); if (!props.containsKey(item.getModelObject().getId())) { props.put(item.getModelObject().getId(), new WorkflowFormPropertyTO()); } if (item.getModelObject().isWritable()) { switch (item.getModelObject().getType()) { case Boolean: props.get(item.getModelObject().getId()).setValue(String.valueOf("0".equals(input))); break; case Date: case Enum: case String: case Long: default: props.get(item.getModelObject().getId()).setValue(input); break; } } } formTO.setProperties(props.values()); try { restClient.submitForm(formTO); ((Todo) pageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); LOG.error("While submitting form {}", formTO, e); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form form) { window.close(target); } @Override protected void onError(final AjaxRequestTarget target, final Form form) { // nothing } }; cancel.setDefaultFormProcessing(false); Form form = new Form(FORM); form.add(propView); form.add(userDetails); form.add(submit); form.add(cancel); MetaDataRoleAuthorizationStrategy.authorize(form, ENABLE, xmlRolesReader.getAllAllowedRoles("Approval", SUBMIT)); editUserWin = new ModalWindow("editUserWin"); editUserWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY); editUserWin.setInitialHeight(USER_WIN_HEIGHT); editUserWin.setInitialWidth(USER_WIN_WIDTH); editUserWin.setCookieName("edit-user-modal"); add(editUserWin); add(form); }
From source file:org.apache.syncope.console.pages.BulkActionModalPage.java
License:Apache License
public BulkActionModalPage(final ModalWindow window, final Collection<T> items, final List<IColumn<T, S>> columns, final Collection<ActionLink.ActionType> actions, final BaseRestClient bulkActionExecutor, final String idFieldName, final String pageId) { super();//from w w w . j a v a 2 s . com final SortableDataProvider<T, S> dataProvider = new SortableDataProvider<T, S>() { private static final long serialVersionUID = 5291903859908641954L; @Override public Iterator<? extends T> iterator(final long first, final long count) { return items.iterator(); } @Override public long size() { return items.size(); } @Override public IModel<T> model(final T object) { return new CompoundPropertyModel<T>(object); } }; add(new AjaxFallbackDefaultDataTable<T, S>("selectedObjects", new ArrayList<IColumn<T, S>>(columns.subList(1, columns.size() - 1)), dataProvider, Integer.MAX_VALUE).setVisible(items != null && !items.isEmpty())); final ActionLinksPanel actionPanel = new ActionLinksPanel("actions", new Model(), getPageReference()); add(actionPanel); for (ActionLink.ActionType action : actions) { final BulkAction bulkAction = new BulkAction(); for (T item : items) { try { bulkAction.getTargets().add(getTargetId(item, idFieldName).toString()); } catch (Exception e) { LOG.error("Error retrieving item id {}", idFieldName, e); } } switch (action) { case DELETE: bulkAction.setOperation(BulkAction.Type.DELETE); break; case SUSPEND: bulkAction.setOperation(BulkAction.Type.SUSPEND); break; case REACTIVATE: bulkAction.setOperation(BulkAction.Type.REACTIVATE); break; case EXECUTE: bulkAction.setOperation(BulkAction.Type.EXECUTE); break; case DRYRUN: bulkAction.setOperation(BulkAction.Type.DRYRUN); break; default: LOG.error("Bulk action type not supported"); } actionPanel.add(new ActionLink() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target) { try { final BulkActionResult res = (BulkActionResult) bulkActionExecutor.getClass() .getMethod("bulkAction", BulkAction.class).invoke(bulkActionExecutor, bulkAction); setResponsePage( new BulkActionResultModalPage<T, S>(window, items, columns, res, idFieldName)); } catch (Exception e) { LOG.error("Operation {} not supported", bulkAction.getOperation(), e); } } }, action, pageId, !items.isEmpty()); } final Form<Void> form = new Form<Void>(FORM); add(form); final AjaxButton cancel = new ClearIndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL), getPageReference()) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); }
From source file:org.apache.syncope.console.pages.BulkActionResultModalPage.java
License:Apache License
public BulkActionResultModalPage(final ModalWindow window, final Collection<T> items, final List<IColumn<T, S>> columns, final BulkActionResult results, final String idFieldName) { super();/* ww w .j av a 2 s . c o m*/ final List<IColumn<T, S>> newColumnList = new ArrayList<IColumn<T, S>>( columns.subList(1, columns.size() - 1)); newColumnList.add(newColumnList.size(), new ActionResultColumn<T, S>(results, idFieldName)); final SortableDataProvider<T, S> dataProvider = new SortableDataProvider<T, S>() { private static final long serialVersionUID = 5291903859908641954L; @Override public Iterator<? extends T> iterator(final long first, final long count) { return items.iterator(); } @Override public long size() { return items.size(); } @Override public IModel<T> model(final T object) { return new CompoundPropertyModel<T>(object); } }; add(new AjaxFallbackDefaultDataTable<T, S>("selectedObjects", newColumnList, dataProvider, Integer.MAX_VALUE).setVisible(items != null && !items.isEmpty())); final AjaxLink<Void> close = new IndicatingAjaxLink<Void>("close") { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target) { window.close(target); } }; add(close); }
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 w w . j a v a 2 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.apache.syncope.console.pages.DerSchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, DerSchemaTO schema, final boolean createFlag) { if (schema == null) { schema = new DerSchemaTO(); }/*from w ww . java 2 s.com*/ final Form<DerSchemaTO> schemaForm = new Form<DerSchemaTO>(FORM); schemaForm.setModel(new CompoundPropertyModel<DerSchemaTO>(schema)); final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(schema, "name")); name.addRequiredLabel(); final AjaxTextFieldPanel expression = new AjaxTextFieldPanel("expression", getString("expression"), new PropertyModel<String>(schema, "expression")); expression.addRequiredLabel(); final WebMarkupContainer jexlHelp = JexlHelpUtil.getJexlHelpWebContainer("jexlHelp"); final AjaxLink<Void> questionMarkJexlHelp = JexlHelpUtil.getAjaxLink(jexlHelp, "questionMarkJexlHelp"); schemaForm.add(questionMarkJexlHelp); questionMarkJexlHelp.add(jexlHelp); name.setEnabled(createFlag); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form form) { DerSchemaTO schemaTO = (DerSchemaTO) form.getDefaultModelObject(); try { if (createFlag) { schemaRestClient.createDerSchema(kind, schemaTO); } else { schemaRestClient.updateDerSchema(kind, schemaTO); } if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton 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); String allowedRoles = createFlag ? xmlRolesReader.getAllAllowedRoles("Schema", "create") : xmlRolesReader.getAllAllowedRoles("Schema", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); schemaForm.add(name); schemaForm.add(expression); schemaForm.add(submit); schemaForm.add(cancel); add(schemaForm); }
From source file:org.apache.syncope.console.pages.DisplayAttributesModalPage.java
License:Apache License
public DisplayAttributesModalPage(final PageReference pageRef, final ModalWindow window, final List<String> schemaNames, final List<String> dSchemaNames, final List<String> vSchemaNames) { super();//from w ww .j av a 2 s .c o m final IModel<List<String>> fnames = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { return SearchableFields.get(UserTO.class); } }; final IModel<List<String>> names = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { return schemaNames; } }; final IModel<List<String>> dsnames = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { return dSchemaNames; } }; final IModel<List<String>> vsnames = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { return vSchemaNames; } }; final Form form = new Form(FORM); form.setModel(new CompoundPropertyModel(this)); selectedDetails = prefMan.getList(getRequest(), Constants.PREF_USERS_DETAILS_VIEW); selectedSchemas = prefMan.getList(getRequest(), Constants.PREF_USERS_ATTRIBUTES_VIEW); selectedDerSchemas = prefMan.getList(getRequest(), Constants.PREF_USERS_DERIVED_ATTRIBUTES_VIEW); selectedVirSchemas = prefMan.getList(getRequest(), Constants.PREF_USERS_VIRTUAL_ATTRIBUTES_VIEW); final CheckGroup dgroup = new CheckGroup("dCheckGroup", new PropertyModel(this, "selectedDetails")); form.add(dgroup); final ListView<String> details = new ListView<String>("details", fnames) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(final ListItem<String> item) { item.add(new Check("dcheck", item.getModel())); item.add(new Label("dname", new ResourceModel(item.getModelObject(), item.getModelObject()))); } }; dgroup.add(details); if (names.getObject() == null || names.getObject().isEmpty()) { final Fragment fragment = new Fragment("schemas", "emptyFragment", form); form.add(fragment); selectedSchemas.clear(); } else { final Fragment fragment = new Fragment("schemas", "sfragment", form); form.add(fragment); final CheckGroup sgroup = new CheckGroup("sCheckGroup", new PropertyModel(this, "selectedSchemas")); fragment.add(sgroup); final ListView<String> schemas = new ListView<String>("schemas", names) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(ListItem<String> item) { item.add(new Check("scheck", item.getModel())); item.add(new Label("sname", new ResourceModel(item.getModelObject(), item.getModelObject()))); } }; sgroup.add(schemas); } if (dsnames.getObject() == null || dsnames.getObject().isEmpty()) { final Fragment fragment = new Fragment("dschemas", "emptyFragment", form); form.add(fragment); selectedDerSchemas.clear(); } else { final Fragment fragment = new Fragment("dschemas", "dsfragment", form); form.add(fragment); final CheckGroup dsgroup = new CheckGroup("dsCheckGroup", new PropertyModel(this, "selectedDerSchemas")); fragment.add(dsgroup); final ListView<String> derSchemas = new ListView<String>("derSchemas", dsnames) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(ListItem<String> item) { item.add(new Check("dscheck", item.getModel())); item.add(new Label("dsname", new ResourceModel(item.getModelObject(), item.getModelObject()))); } }; dsgroup.add(derSchemas); } if (vsnames.getObject() == null || vsnames.getObject().isEmpty()) { final Fragment fragment = new Fragment("vschemas", "emptyFragment", form); form.add(fragment); selectedVirSchemas.clear(); } else { final Fragment fragment = new Fragment("vschemas", "vsfragment", form); form.add(fragment); final CheckGroup vsgroup = new CheckGroup("vsCheckGroup", new PropertyModel(this, "selectedVirSchemas")); fragment.add(vsgroup); final ListView<String> virSchemas = new ListView<String>("virSchemas", vsnames) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(ListItem<String> item) { item.add(new Check("vscheck", item.getModel())); item.add(new Label("vsname", new ResourceModel(item.getModelObject(), item.getModelObject()))); } }; vsgroup.add(virSchemas); } final AjaxButton submit = new IndicatingAjaxButton(SUBMIT, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -4804368561204623354L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { if (selectedDetails.size() + selectedSchemas.size() + selectedVirSchemas.size() + selectedDerSchemas.size() > MAX_SELECTIONS) { error(getString("tooManySelections")); onError(target, form); } else { final Map<String, List<String>> prefs = new HashMap<String, List<String>>(); prefs.put(Constants.PREF_USERS_DETAILS_VIEW, selectedDetails); prefs.put(Constants.PREF_USERS_ATTRIBUTES_VIEW, selectedSchemas); prefs.put(Constants.PREF_USERS_DERIVED_ATTRIBUTES_VIEW, selectedDerSchemas); prefs.put(Constants.PREF_USERS_VIRTUAL_ATTRIBUTES_VIEW, selectedVirSchemas); prefMan.setList(getRequest(), getResponse(), prefs); ((BasePage) pageRef.getPage()).setModalResult(true); window.close(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; form.add(submit); final AjaxButton 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); form.add(cancel); add(form); }