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 de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
22  import de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel;
23  import java.io.Serializable;
24  import java.util.ArrayList;
25  import java.util.List;
26  import org.apache.syncope.client.console.commons.ITabComponent;
27  import org.apache.syncope.client.console.rest.SCIMConfRestClient;
28  import org.apache.syncope.client.console.wizards.WizardMgtPanel;
29  import org.apache.syncope.common.lib.scim.SCIMConf;
30  import org.apache.wicket.PageReference;
31  import org.apache.wicket.ajax.AjaxRequestTarget;
32  import org.apache.wicket.ajax.markup.html.AjaxLink;
33  import org.apache.wicket.extensions.markup.html.tabs.ITab;
34  import org.apache.wicket.markup.html.WebMarkupContainer;
35  import org.apache.wicket.markup.html.panel.Panel;
36  import org.apache.wicket.model.Model;
37  import org.apache.wicket.spring.injection.annot.SpringBean;
38  import org.slf4j.Logger;
39  import org.slf4j.LoggerFactory;
40  
41  public abstract class SCIMConfPanel extends WizardMgtPanel<SCIMConf> {
42  
43      private static final long serialVersionUID = -1100228004207271270L;
44  
45      protected static final Logger LOG = LoggerFactory.getLogger(SCIMConfPanel.class);
46  
47      @SpringBean
48      protected SCIMConfRestClient scimConfRestClient;
49  
50      protected final SCIMConf scimConfTO;
51  
52      public SCIMConfPanel(
53              final String id,
54              final SCIMConf scimConfTO,
55              final PageReference pageRef) {
56  
57          super(id, true);
58  
59          this.scimConfTO = scimConfTO;
60          this.pageRef = pageRef;
61  
62          setPageRef(pageRef);
63  
64          AjaxBootstrapTabbedPanel<ITab> tabbedPanel =
65                  new AjaxBootstrapTabbedPanel<>("tabbedPanel", buildTabList());
66          tabbedPanel.setSelectedTab(0);
67          addInnerObject(tabbedPanel);
68  
69          AjaxLink<String> saveButton = new AjaxLink<>("saveButton") {
70  
71              private static final long serialVersionUID = -7978723352517770644L;
72  
73              @Override
74              public void onClick(final AjaxRequestTarget target) {
75                  scimConfRestClient.set(SCIMConfPanel.this.scimConfTO);
76              }
77          };
78          addInnerObject(saveButton);
79  
80          setShowResultPanel(true);
81  
82          modal.size(Modal.Size.Large);
83          setWindowClosedReloadCallback(modal);
84      }
85  
86      protected List<ITab> buildTabList() {
87          List<ITab> tabs = new ArrayList<>();
88  
89          tabs.add(new ITabComponent(new Model<>(getString("tab1"))) {
90  
91              private static final long serialVersionUID = -5861786415855103549L;
92  
93              @Override
94              public Panel getPanel(final String panelId) {
95                  return new SCIMConfGeneralPanel(panelId, scimConfTO);
96              }
97  
98              @Override
99              public boolean isVisible() {
100                 return true;
101             }
102         });
103 
104         tabs.add(new ITabComponent(
105                 new Model<>(getString("tab2")), getString("tab2")) {
106 
107             private static final long serialVersionUID = 1998052474181916792L;
108 
109             @Override
110             public WebMarkupContainer getPanel(final String panelId) {
111                 return new SCIMConfUserPanel(panelId, scimConfTO);
112             }
113 
114             @Override
115             public boolean isVisible() {
116                 return true;
117             }
118         });
119 
120         tabs.add(new ITabComponent(
121                 new Model<>(getString("tab3")), getString("tab3")) {
122 
123             private static final long serialVersionUID = 1998052474181916792L;
124 
125             @Override
126             public WebMarkupContainer getPanel(final String panelId) {
127                 return new SCIMConfEnterpriseUserPanel(panelId, scimConfTO);
128             }
129 
130             @Override
131             public boolean isVisible() {
132                 return true;
133             }
134         });
135 
136         tabs.add(new ITabComponent(
137                 new Model<>(getString("tab4")), getString("tab4")) {
138 
139             private static final long serialVersionUID = 1998052474181916792L;
140 
141             @Override
142             public WebMarkupContainer getPanel(final String panelId) {
143                 return new SCIMConfGroupPanel(panelId, scimConfTO);
144             }
145 
146             @Override
147             public boolean isVisible() {
148                 return true;
149             }
150         });
151 
152         return tabs;
153     }
154 
155     @Override
156     protected Panel customResultBody(final String panelId, final SCIMConf item, final Serializable result) {
157         return null;
158     }
159 }