View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.component.monacoeditor;
23  
24  import java.util.Collection;
25  import java.util.Map;
26  
27  import javax.faces.application.ResourceDependency;
28  import javax.faces.event.BehaviorEvent;
29  
30  /**
31   * Component for the Monaco code editor JavaScript library .This is the framed Monaco editor that creates a new instance in a separate iframe to allow for
32   * better scoping, i.e. loading types etc. without affecting other editors. There is also an inline widget when this scoping is not required as iframes create
33   * additional overhead.
34   *
35   * @see MonacoEditorInline
36   * @since 10.0.0
37   */
38  @SuppressWarnings("java:S110")
39  @ResourceDependency(library = "primefaces", name = "jquery/jquery.js")
40  @ResourceDependency(library = "primefaces", name = "core.js")
41  @ResourceDependency(library = "primefaces-extensions", name = "primefaces-extensions.js")
42  @ResourceDependency(library = "primefaces-extensions", name = "monacoeditor/widget-framed.js")
43  @ResourceDependency(library = "primefaces-extensions", name = "monacoeditor/monacoeditor.css")
44  public class MonacoEditorFramed extends MonacoEditorBase {
45  
46      public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.MonacoEditorFramed";
47  
48      public static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.MonacoEditorFramedRenderer";
49  
50      public static final String STYLE_CLASS = "ui-monaco-editor ui-monaco-editor-code ui-monaco-editor-framed ";
51  
52      public static final String WIDGET_NAME = "ExtMonacoCodeEditorFramed";
53  
54      /**
55       * Default no-arg constructor for this widget invoked by the framework.
56       */
57      public MonacoEditorFramed() {
58          super(DEFAULT_RENDERER);
59      }
60  
61      @Override
62      public Map<String, Class<? extends BehaviorEvent>> getBehaviorEventMapping() {
63          // no additional events for now
64          return BASE_BEHAVIOR_EVENT_MAPPING;
65      }
66  
67      @Override
68      public Collection<String> getEventNames() {
69          // no additional events for now
70          return BASE_EVENT_NAMES;
71      }
72  
73      public String getExtender() {
74          return (String) getStateHelper().eval(CodeEditorFramedPropertyKeys.extender, null);
75      }
76  
77      public void setExtender(final String extender) {
78          getStateHelper().put(CodeEditorFramedPropertyKeys.extender, extender);
79      }
80  
81      public Object getIframeUrlParams() {
82          return getStateHelper().eval(CodeEditorFramedPropertyKeys.iframeUrlParams, null);
83      }
84  
85      public void setIframeUrlParams(final Object iframeUrlParams) {
86          getStateHelper().put(CodeEditorFramedPropertyKeys.iframeUrlParams, iframeUrlParams);
87      }
88  }