View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.wizards.mapping;
20  
21  import java.io.Serializable;
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.syncope.client.console.panels.TogglePanel;
24  import org.apache.syncope.client.ui.commons.Constants;
25  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
26  import org.apache.syncope.common.lib.to.Item;
27  import org.apache.wicket.PageReference;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
30  import org.apache.wicket.markup.html.WebMarkupContainer;
31  import org.apache.wicket.markup.html.form.Form;
32  import org.apache.wicket.model.Model;
33  import org.apache.wicket.model.PropertyModel;
34  
35  public class JEXLTransformersTogglePanel extends TogglePanel<Serializable> {
36  
37      private static final long serialVersionUID = -1284019117452782479L;
38  
39      private final AjaxTextFieldPanel propagationJEXLTransformer;
40  
41      private final AjaxTextFieldPanel pullJEXLTransformer;
42  
43      public JEXLTransformersTogglePanel(final WebMarkupContainer container, final PageReference pageRef) {
44          super(Constants.OUTER, "jexlTransformersTogglePanel", pageRef);
45  
46          Form<?> form = new Form<>("form");
47          addInnerObject(form);
48  
49          propagationJEXLTransformer = new AjaxTextFieldPanel(
50                  "propagationJEXLTransformer",
51                  "Propagation",
52                  Model.of(""));
53          form.add(propagationJEXLTransformer.enableJexlHelp("value.toLowecase()", "'PREFIX' + value"));
54  
55          pullJEXLTransformer = new AjaxTextFieldPanel(
56                  "pullJEXLTransformer",
57                  "Pull",
58                  Model.of(""));
59          form.add(pullJEXLTransformer.enableJexlHelp("value.toLowecase()", "'PREFIX' + value"));
60  
61          form.add(new AjaxSubmitLink("submit", form) {
62  
63              private static final long serialVersionUID = 4617041491286858973L;
64  
65              @Override
66              public void onSubmit(final AjaxRequestTarget target) {
67                  toggle(target, false);
68                  target.add(container);
69              }
70          });
71      }
72  
73      public JEXLTransformersTogglePanel setItem(final AjaxRequestTarget target, final Item item) {
74          this.propagationJEXLTransformer.setNewModel(new PropertyModel<>(item, "propagationJEXLTransformer"));
75          this.pullJEXLTransformer.setNewModel(new PropertyModel<>(item, "pullJEXLTransformer"));
76          setHeader(target, StringUtils.EMPTY);
77          return this;
78      }
79  }