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 org.apache.syncope.common.lib.types.MappingPurpose;
22  import org.apache.wicket.AttributeModifier;
23  import org.apache.wicket.ajax.AjaxRequestTarget;
24  import org.apache.wicket.ajax.markup.html.AjaxLink;
25  import org.apache.wicket.markup.html.WebMarkupContainer;
26  import org.apache.wicket.markup.html.panel.Panel;
27  import org.apache.wicket.model.IModel;
28  import org.apache.wicket.model.Model;
29  
30  public class MappingPurposePanel extends Panel {
31  
32      private static final long serialVersionUID = 322966537010107771L;
33  
34      private final AjaxLink<Void> propagation;
35  
36      private final AjaxLink<Void> pull;
37  
38      private final AjaxLink<Void> both;
39  
40      private final AjaxLink<Void> none;
41  
42      public MappingPurposePanel(final String componentId, final IModel<MappingPurpose> model,
43              final WebMarkupContainer container) {
44  
45          super(componentId, model);
46  
47          propagation = new AjaxLink<>("propagationPurposeLink") {
48  
49              private static final long serialVersionUID = -6957616042924610305L;
50  
51              @Override
52              public void onClick(final AjaxRequestTarget target) {
53                  model.setObject(MappingPurpose.PROPAGATION);
54                  setOpacity(MappingPurpose.PROPAGATION);
55                  target.add(container);
56              }
57          };
58  
59          pull = new AjaxLink<>("pullPurposeLink") {
60  
61              private static final long serialVersionUID = -6957616042924610305L;
62  
63              @Override
64              public void onClick(final AjaxRequestTarget target) {
65                  model.setObject(MappingPurpose.PULL);
66                  setOpacity(MappingPurpose.PULL);
67                  target.add(container);
68              }
69          };
70  
71          both = new AjaxLink<>("bothPurposeLink") {
72  
73              private static final long serialVersionUID = -6957616042924610305L;
74  
75              @Override
76              public void onClick(final AjaxRequestTarget target) {
77                  model.setObject(MappingPurpose.BOTH);
78                  setOpacity(MappingPurpose.BOTH);
79                  target.add(container);
80              }
81          };
82  
83          none = new AjaxLink<>("nonePurposeLink") {
84  
85              private static final long serialVersionUID = -6957616042924610305L;
86  
87              @Override
88              public void onClick(final AjaxRequestTarget target) {
89                  model.setObject(MappingPurpose.NONE);
90                  setOpacity(MappingPurpose.NONE);
91                  target.add(container);
92              }
93          };
94  
95          add(propagation);
96          add(pull);
97          add(both);
98          add(none);
99  
100         setOpacity(model.getObject());
101     }
102 
103     private void setOpacity(final MappingPurpose mappingPurpose) {
104         switch (mappingPurpose) {
105             case PROPAGATION:
106                 propagation.add(new AttributeModifier("style", new Model<>("opacity: 1;")));
107                 pull.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
108                 both.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
109                 none.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
110                 break;
111 
112             case PULL:
113                 pull.add(new AttributeModifier("style", new Model<>("opacity: 1;")));
114                 propagation.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
115                 both.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
116                 none.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
117                 break;
118 
119             case BOTH:
120                 both.add(new AttributeModifier("style", new Model<>("opacity: 1;")));
121                 propagation.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
122                 pull.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
123                 none.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
124                 break;
125 
126             case NONE:
127                 none.add(new AttributeModifier("style", new Model<>("opacity: 1;")));
128                 pull.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
129                 propagation.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
130                 both.add(new AttributeModifier("style", new Model<>("opacity: 0.3;")));
131                 break;
132 
133             default:
134             // do nothing
135         }
136     }
137 }