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.syncope.client.console.panels.AbstractModalPanel;
22  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
23  import org.apache.wicket.PageReference;
24  import org.apache.wicket.markup.head.IHeaderResponse;
25  import org.apache.wicket.markup.head.OnLoadHeaderItem;
26  import org.apache.wicket.markup.html.form.TextArea;
27  import org.apache.wicket.model.IModel;
28  
29  public class JsonEditorPanel extends AbstractModalPanel<String> {
30  
31      private static final long serialVersionUID = -5110368813584745668L;
32  
33      private final IModel<String> content;
34  
35      private final boolean readOnly;
36  
37      public JsonEditorPanel(final IModel<String> content) {
38          this(null, content, false, null);
39      }
40  
41      public JsonEditorPanel(
42              final BaseModal<String> modal,
43              final IModel<String> content,
44              final boolean readOnly,
45              final PageReference pageRef) {
46  
47          super(modal, pageRef);
48          this.content = content;
49          this.readOnly = readOnly;
50          TextArea<String> jsonEditorInfoDefArea = new TextArea<>("jsonEditorInfo", this.content);
51          jsonEditorInfoDefArea.setMarkupId("jsonEditorInfo").setOutputMarkupPlaceholderTag(true);
52          add(jsonEditorInfoDefArea);
53      }
54  
55      @Override
56      public void renderHead(final IHeaderResponse response) {
57          super.renderHead(response);
58          response.render(OnLoadHeaderItem.forScript(
59                  "CodeMirror.fromTextArea(document.getElementById('jsonEditorInfo'), {"
60                  + "  readOnly: " + readOnly + ", "
61                  + "  lineNumbers: true, "
62                  + "  lineWrapping: true, "
63                  + "  matchBrackets: true,"
64                  + "  autoCloseBrackets: true,"
65                  + "  autoRefresh: true"
66                  + "}).on('change', updateTextArea);"));
67      }
68  }