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.panels;
20  
21  import org.apache.wicket.ajax.AjaxRequestTarget;
22  import org.apache.wicket.ajax.markup.html.AjaxLink;
23  import org.apache.wicket.markup.html.IHeaderContributor;
24  import org.apache.wicket.markup.html.WebMarkupContainer;
25  import org.apache.wicket.markup.html.basic.Label;
26  import org.apache.wicket.markup.html.panel.Panel;
27  import org.apache.wicket.model.ResourceModel;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  public class MultilevelPanel extends Panel implements IHeaderContributor {
32  
33      private static final long serialVersionUID = -4064294905566247729L;
34  
35      protected static final Logger LOG = LoggerFactory.getLogger(MultilevelPanel.class);
36  
37      public static final String FIRST_LEVEL_ID = "first";
38  
39      public static final String SECOND_LEVEL_ID = "second";
40  
41      private boolean isFirstLevel = true;
42  
43      private final WebMarkupContainer firstLevelContainer;
44  
45      private final WebMarkupContainer secondLevelContainer;
46  
47      public MultilevelPanel(final String id) {
48          super(id);
49  
50          firstLevelContainer = new WebMarkupContainer("firstLevelContainer");
51          firstLevelContainer.setOutputMarkupPlaceholderTag(true);
52          firstLevelContainer.setVisible(true);
53          add(firstLevelContainer);
54  
55          secondLevelContainer = new WebMarkupContainer("secondLevelContainer");
56          secondLevelContainer.setOutputMarkupPlaceholderTag(true);
57          secondLevelContainer.setVisible(false);
58          add(secondLevelContainer);
59  
60          secondLevelContainer.add(new AjaxLink<String>("back") {
61  
62              private static final long serialVersionUID = -7978723352517770644L;
63  
64              @Override
65              public void onClick(final AjaxRequestTarget target) {
66                  onClickBackInternal(target);
67                  prev(target);
68              }
69          });
70      }
71  
72      public final void next(final String title, final SecondLevel secondLevel, final AjaxRequestTarget target) {
73          if (isFirstLevel) {
74              secondLevelContainer.addOrReplace(new Label("title", new ResourceModel(title, title)));
75              secondLevelContainer.addOrReplace(secondLevel);
76              secondLevelContainer.setVisible(true);
77              target.add(secondLevelContainer);
78  
79              firstLevelContainer.setVisible(false);
80              target.add(firstLevelContainer);
81  
82              isFirstLevel = false;
83          } else {
84              LOG.warn("No further level available");
85          }
86      }
87  
88      public void prev(final AjaxRequestTarget target) {
89          if (isFirstLevel) {
90              LOG.warn("No further level available");
91          } else {
92              firstLevelContainer.setVisible(true);
93              target.add(firstLevelContainer);
94  
95              secondLevelContainer.setVisible(false);
96              target.add(secondLevelContainer);
97  
98              isFirstLevel = true;
99          }
100     }
101 
102     protected void onClickBackInternal(final AjaxRequestTarget taget) {
103     }
104 
105     /**
106      * Add panel with id {@code first}
107      *
108      * @param panel panel to be used into the first level.
109      * @return the current MultilevelPanel instance.
110      */
111     public MultilevelPanel setFirstLevel(final Panel panel) {
112         firstLevelContainer.addOrReplace(panel);
113         return this;
114     }
115 
116     public static class SecondLevel extends Panel {
117 
118         private static final long serialVersionUID = 5685291231060035528L;
119 
120         public SecondLevel() {
121             this(SECOND_LEVEL_ID);
122         }
123 
124         public SecondLevel(final String id) {
125             super(id);
126         }
127     }
128 }