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.fit.console;
20  
21  import java.io.Serializable;
22  import org.apache.wicket.MarkupContainer;
23  import org.apache.wicket.markup.IMarkupResourceStreamProvider;
24  import org.apache.wicket.markup.html.WebPage;
25  import org.apache.wicket.markup.html.form.Form;
26  import org.apache.wicket.markup.html.panel.Panel;
27  import org.apache.wicket.util.resource.IResourceStream;
28  import org.apache.wicket.util.resource.StringResourceStream;
29  
30  public final class TestPage<T extends Serializable, S extends Panel>
31          extends WebPage implements IMarkupResourceStreamProvider {
32  
33      private static final long serialVersionUID = 483736530078975170L;
34  
35      public static final String FIELD = "field";
36  
37      private final Form<T> form;
38  
39      private final S fieldPanel;
40  
41      private TestPage(final S field, final Builder<T, S> builder) {
42          this.form = builder.form;
43          this.fieldPanel = field;
44  
45          field.setOutputMarkupId(builder.outputMarkupId);
46          add(form);
47          form.add(field);
48      }
49  
50      public Form<T> getForm() {
51          return form;
52      }
53  
54      public S getFieldPanel() {
55          return fieldPanel;
56      }
57  
58      public static class Builder<T extends Serializable, S extends Panel> implements Serializable {
59  
60          private static final long serialVersionUID = 4882978420728876617L;
61  
62          private final Form<T> form;
63  
64          private boolean outputMarkupId;
65  
66          public Builder() {
67              this.form = new Form<>("form");
68  
69          }
70  
71          public Builder<T, S> setOutputMarkupId(final boolean outputMarkupId) {
72              this.outputMarkupId = outputMarkupId;
73              return this;
74          }
75  
76          public TestPage<T, S> build(final S field) {
77              return new TestPage<>(field, this);
78          }
79      }
80  
81      @Override
82      public IResourceStream getMarkupResourceStream(final MarkupContainer container,
83              final Class<?> containerClass) {
84          return new StringResourceStream("<html><body>"
85                  + "<form wicket:id=\"form\"><span wicket:id=\"field\"></span></form></body></html>");
86      }
87  }