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.wicket.markup.html.form;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.List;
24  import org.apache.commons.lang3.StringUtils;
25  import org.apache.wicket.model.Model;
26  
27  /**
28   * Action link basic details.
29   *
30   * @param <T> model object type.
31   */
32  public final class Action<T extends Serializable> implements Serializable {
33  
34      private static final long serialVersionUID = -7989237020377623993L;
35  
36      private final List<String> realms = new ArrayList<>();
37  
38      private final ActionLink<T> link;
39  
40      private final ActionLink.ActionType type;
41  
42      private String entitlements;
43  
44      private boolean onConfirm;
45  
46      private boolean visibleLabel;
47  
48      private Model<String> label;
49  
50      private Model<String> title;
51  
52      private Model<String> alt;
53  
54      private Model<String> icon;
55  
56      private boolean indicator;
57  
58      public Action(final ActionLink<T> link, final ActionLink.ActionType type) {
59          this.link = link;
60          this.type = type;
61          this.entitlements = StringUtils.EMPTY;
62          this.onConfirm = false;
63          this.visibleLabel = true;
64          this.label = null;
65          this.title = null;
66          this.alt = null;
67          this.icon = null;
68          this.indicator = true;
69      }
70  
71      public String[] getRealms() {
72          return realms.toArray(String[]::new);
73      }
74  
75      public void setRealm(final String realm) {
76          this.realms.clear();
77  
78          if (realm != null) {
79              this.realms.add(realm);
80          }
81      }
82  
83      public void setRealms(final String realm, final List<String> dynRealms) {
84          setRealm(realm);
85  
86          if (dynRealms != null) {
87              this.realms.addAll(dynRealms);
88          }
89      }
90  
91      public ActionLink<T> getLink() {
92          return link;
93      }
94  
95      public ActionLink.ActionType getType() {
96          return type;
97      }
98  
99      public String getEntitlements() {
100         return entitlements;
101     }
102 
103     public boolean isOnConfirm() {
104         return onConfirm;
105     }
106 
107     public Action<T> setEntitlements(final String entitlements) {
108         this.entitlements = entitlements;
109         return this;
110     }
111 
112     public Action<T> setOnConfirm(final boolean onConfirm) {
113         this.onConfirm = onConfirm;
114         return this;
115     }
116 
117     public Action<T> hideLabel() {
118         this.visibleLabel = false;
119         return this;
120     }
121 
122     public Action<T> showLabel() {
123         this.visibleLabel = true;
124         return this;
125     }
126 
127     public boolean isVisibleLabel() {
128         return visibleLabel;
129     }
130 
131     /**
132      * Override default action label.
133      *
134      * @param label new action label;
135      * @return updated action.
136      */
137     public Action<T> setLabel(final Model<String> label) {
138         this.label = label;
139         return this;
140     }
141 
142     public Model<String> getLabel() {
143         return label;
144     }
145 
146     /**
147      * Override default action title.
148      *
149      * @param title new action title;
150      * @return updated action.
151      */
152     public Action<T> setTitleI(final Model<String> title) {
153         this.title = title;
154         return this;
155     }
156 
157     public Model<String> getTitle() {
158         return title;
159     }
160 
161     /**
162      * Override default action icon text name.
163      *
164      * @param alt action icon text name;
165      * @return updated action.
166      */
167     public Action<T> setAlt(final Model<String> alt) {
168         this.alt = alt;
169         return this;
170     }
171 
172     public Model<String> getAlt() {
173         return alt;
174     }
175 
176     /**
177      * Override default action css class.
178      *
179      * @param icon new action class;
180      * @return updated action.
181      */
182     public Action<T> setIcon(final Model<String> icon) {
183         this.icon = icon;
184         return this;
185     }
186 
187     public Model<String> getIcon() {
188         return icon;
189     }
190 
191     /**
192      * Override disable AJAX indicator.
193      *
194      * @return updated action.
195      */
196     public Action<T> disableIndicator() {
197         this.indicator = false;
198         return this;
199     }
200 
201     public boolean hasIndicator() {
202         return indicator;
203     }
204 }