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 org.apache.wicket.markup.head.IHeaderResponse;
22  import org.apache.wicket.markup.head.OnLoadHeaderItem;
23  import org.apache.wicket.markup.html.form.TextArea;
24  import org.apache.wicket.markup.html.panel.Panel;
25  import org.apache.wicket.model.IModel;
26  
27  public class JsonDiffPanel extends Panel {
28  
29      private static final long serialVersionUID = -5110368813584745668L;
30  
31      public JsonDiffPanel(final IModel<String> first, final IModel<String> second) {
32  
33          super("jsonDiffPanel");
34  
35          TextArea<String> jsonEditorInfoDefArea1 = new TextArea<>("jsonEditorInfo1", first);
36          jsonEditorInfoDefArea1.setMarkupId("jsonEditorInfo1").setOutputMarkupPlaceholderTag(true);
37          add(jsonEditorInfoDefArea1);
38  
39          TextArea<String> jsonEditorInfoDefArea2 = new TextArea<>("jsonEditorInfo2", second);
40          jsonEditorInfoDefArea2.setMarkupId("jsonEditorInfo2").setOutputMarkupPlaceholderTag(true);
41          add(jsonEditorInfoDefArea2);
42      }
43  
44      @Override
45      public void renderHead(final IHeaderResponse response) {
46          super.renderHead(response);
47          response.render(OnLoadHeaderItem.forScript(
48                  "CodeMirror.MergeView(document.getElementById('jsonDiffEditorInfoDefForm'), {"
49                          + "  value: document.getElementById('jsonEditorInfo1').innerHTML, "
50                          + "  orig: document.getElementById('jsonEditorInfo2').innerHTML, "
51                          + "  lineNumbers: true, "
52                          + "  mode: \"application/json\","
53                          + "  highlightDifferences: true,"
54                          + "  showDifferences: true,"
55                          + "  readOnly: true,"
56                          + "  revertButtons: false,"
57                          + "  autoRefresh: true"
58                          + "});"));
59      }
60  }