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 org.apache.wicket.Page;
23  import org.apache.wicket.ajax.AjaxRequestTarget;
24  import org.apache.wicket.request.mapper.parameter.PageParameters;
25  
26  public abstract class ActionLink<T extends Serializable> implements Serializable {
27  
28      private static final long serialVersionUID = 7031329706998320639L;
29  
30      private boolean reloadFeedbackPanel = true;
31  
32      private T modelObject;
33  
34      private boolean enabled = true;
35  
36      private String confirmMessage;
37  
38      public ActionLink() {
39      }
40  
41      public ActionLink(final T modelObject) {
42          this.modelObject = modelObject;
43      }
44  
45      public enum ActionType {
46  
47          UP("up"),
48          DOWN("down"),
49          MAPPING("update"),
50          MUSTCHANGEPASSWORD("update"),
51          SET_LATEST_SYNC_TOKEN("update"),
52          REMOVE_SYNC_TOKEN("update"),
53          CLONE("create"),
54          CREATE("create"),
55          CREATE_CONNECTOR("create"),
56          CREATE_RESOURCE("create"),
57          TEMPLATE("read"),
58          EDIT("read"),
59          TYPE_EXTENSIONS("read"),
60          HTML("read"),
61          TEXT("read"),
62          COMPOSE("update"),
63          LAYOUT_EDIT("read"),
64          RESET("update"),
65          ENABLE("update"),
66          NOT_FOUND("read"),
67          VIEW("view"),
68          MEMBERS("members"),
69          SEARCH("search"),
70          DELETE("delete"),
71          EXECUTE("execute"),
72          PASSWORD_MANAGEMENT("update"),
73          REQUEST_PASSWORD_RESET("update"),
74          DRYRUN("execute"),
75          CLAIM("claim"),
76          UNCLAIM("unclaim"),
77          SELECT("read"),
78          CLOSE("read"),
79          EXPORT("read"),
80          SUSPEND("update"),
81          REACTIVATE("update"),
82          RELOAD("import"),
83          CHANGE_VIEW("changeView"),
84          UNLINK("update"),
85          LINK("update"),
86          UNASSIGN("update"),
87          ASSIGN("update"),
88          DEPROVISION("update"),
89          PROVISION("update"),
90          DEPROVISION_MEMBERS("update"),
91          PROVISION_MEMBERS("update"),
92          RECONCILIATION_PUSH("update"),
93          RECONCILIATION_PULL("update"),
94          RECONCILIATION_RESOURCE("update"),
95          MANAGE_RESOURCES("update"),
96          MANAGE_ACCOUNTS("update"),
97          MERGE_ACCOUNTS("update"),
98          MANAGE_USERS("update"),
99          MANAGE_GROUPS("update"),
100         PROPAGATION_TASKS("read"),
101         NOTIFICATION_TASKS("read"),
102         PULL_TASKS("read"),
103         PUSH_TASKS("read"),
104         ZOOM_IN("zoomin"),
105         ZOOM_OUT("zoomout"),
106         VIEW_EXECUTIONS("read"),
107         VIEW_DETAILS("read"),
108         MANAGE_APPROVAL("edit"),
109         EDIT_APPROVAL("edit"),
110         VIEW_AUDIT_HISTORY("read"),
111         EXTERNAL_EDITOR("externalEditor"),
112         EXPLORE_RESOURCE("search");
113 
114         private final String actionId;
115 
116         ActionType(final String actionId) {
117             this.actionId = actionId;
118         }
119 
120         public String getActionId() {
121             return actionId;
122         }
123     }
124 
125     public T getModelObject() {
126         return modelObject;
127     }
128 
129     public abstract void onClick(AjaxRequestTarget target, T modelObject);
130 
131     public void postClick() {
132     }
133 
134     public boolean feedbackPanelAutomaticReload() {
135         return reloadFeedbackPanel;
136     }
137 
138     public ActionLink<T> feedbackPanelAutomaticReload(final boolean reloadFeedbackPanel) {
139         this.reloadFeedbackPanel = reloadFeedbackPanel;
140         return this;
141     }
142 
143     protected boolean statusCondition(final T modelObject) {
144         return true;
145     }
146 
147     public Class<? extends Page> getPageClass() {
148         return null;
149     }
150 
151     public PageParameters getPageParameters() {
152         return null;
153     }
154 
155     public final ActionLink<T> disable() {
156         this.enabled = false;
157         return this;
158     }
159 
160     public final boolean isEnabled(final T modelObject) {
161         return this.enabled && statusCondition(modelObject);
162     }
163 
164     public boolean isIndicatorEnabled() {
165         return true;
166     }
167 
168     public String getConfirmMessage() {
169         return confirmMessage;
170     }
171 
172     public ActionLink<T> confirmMessage(final String confirmMessage) {
173         this.confirmMessage = confirmMessage;
174         return this;
175     }
176 }