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 java.io.Serializable;
22  import org.apache.syncope.client.console.wicket.markup.head.MetaHeaderItem;
23  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
24  import org.apache.syncope.client.ui.commons.pages.BaseWebPage;
25  import org.apache.syncope.client.ui.commons.panels.SubmitableModalPanel;
26  import org.apache.syncope.client.ui.commons.panels.WizardModalPanel;
27  import org.apache.wicket.PageReference;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.markup.head.HeaderItem;
30  import org.apache.wicket.markup.head.IHeaderResponse;
31  import org.apache.wicket.markup.head.PriorityHeaderItem;
32  import org.apache.wicket.markup.html.panel.Panel;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  public class AbstractModalPanel<T extends Serializable> extends Panel
37          implements SubmitableModalPanel, WizardModalPanel<T> {
38  
39      private static final long serialVersionUID = 8611724965544132636L;
40  
41      protected static final Logger LOG = LoggerFactory.getLogger(AbstractModalPanel.class);
42  
43      private static final HeaderItem META = new MetaHeaderItem("X-UA-Compatible", "IE=edge");
44  
45      protected final BaseModal<T> modal;
46  
47      protected final PageReference pageRef;
48  
49      public AbstractModalPanel(final BaseModal<T> modal, final PageReference pageRef) {
50          this(BaseModal.CONTENT_ID, modal, pageRef);
51      }
52  
53      public AbstractModalPanel(final String id, final BaseModal<T> modal, final PageReference pageRef) {
54          super(id);
55          this.pageRef = pageRef;
56          this.modal = modal;
57      }
58  
59      @Override
60      public void renderHead(final IHeaderResponse response) {
61          super.renderHead(response);
62          response.render(new PriorityHeaderItem(META));
63      }
64  
65      @Override
66      public void onSubmit(final AjaxRequestTarget target) {
67          ((BaseWebPage) pageRef.getPage()).getNotificationPanel().refresh(target);
68      }
69  
70      @Override
71      public void onError(final AjaxRequestTarget target) {
72          ((BaseWebPage) pageRef.getPage()).getNotificationPanel().refresh(target);
73      }
74  
75      @Override
76      public T getItem() {
77          return modal.getFormModel();
78      }
79  }