From 62dbe1e0125a6c71b35352de4e9b0aecb1693d2f Mon Sep 17 00:00:00 2001 From: Dmitrii Tikhomirov Date: Tue, 9 Feb 2021 17:58:46 +0100 Subject: [PATCH] KOGITO-4344 CCE while running Monaco in dev mode --- .../factory/dom/MonacoEditorDOMElement.java | 28 ++--------- .../factory/dom/MonacoEditorWidget.java | 47 +++++++++++-------- .../dom/MonacoEditorDOMElementTest.java | 9 +--- .../factory/dom/MonacoEditorWidgetTest.java | 22 +-------- .../showcase/DMNKogitoRuntimeWebapp.gwt.xml | 4 -- .../showcase/DMNKogitoTestingWebapp.gwt.xml | 4 -- .../common/dmn/showcase/DMNShowcase.gwt.xml | 4 -- 7 files changed, 32 insertions(+), 86 deletions(-) diff --git a/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElement.java b/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElement.java index 5016e6be3b37..524dc561e267 100644 --- a/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElement.java +++ b/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElement.java @@ -27,9 +27,6 @@ import com.google.gwt.user.client.TakesValue; import com.google.gwt.user.client.ui.Focusable; import com.google.gwt.user.client.ui.SimplePanel; -import elemental2.dom.Element; -import jsinterop.base.Js; -import org.kie.workbench.common.dmn.client.widgets.codecompletion.MonacoPropertiesFactory; import org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple; import org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple; import org.kie.workbench.common.stunner.core.client.api.SessionManager; @@ -37,7 +34,6 @@ import org.kie.workbench.common.stunner.core.client.command.SessionCommandManager; import org.kie.workbench.common.stunner.core.command.Command; import org.kie.workbench.common.stunner.core.util.StringUtils; -import org.uberfire.client.views.pfly.monaco.jsinterop.MonacoEditor; import org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor; import org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue; import org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext; @@ -99,21 +95,11 @@ void setupInternalComponent() { style.setHeight(100, PCT); - final MonacoPropertiesFactory properties = makeMonacoPropertiesFactory(); - final MonacoStandaloneCodeEditor codeEditor = getMonacoEditor().create(uncheckedCast(widget.getElement()), - properties.getConstructionOptions()); - - codeEditor.onKeyDown(getOnKeyDown(codeEditor)); - codeEditor.onDidBlurEditorWidget(getWidgetTrigger(getBlurEvent())); - - widget.setCodeEditor(codeEditor); + widget.getCodeEditor().onKeyDown(getOnKeyDown(widget.getCodeEditor())); + widget.getCodeEditor().onDidBlurEditorWidget(getWidgetTrigger(getBlurEvent())); widget.setFocus(true); } - MonacoEditor getMonacoEditor() { - return MonacoEditor.get(); - } - MonacoStandaloneCodeEditor.CallbackFunction getOnKeyDown(final MonacoStandaloneCodeEditor codeEditor) { return event -> { boolean isSuggestWidgetVisible = codeEditor.isSuggestWidgetVisible(); @@ -169,8 +155,7 @@ public void setTabIndex(final int index) { @Override @SuppressWarnings("unchecked") public void flush(final String value) { - - widget.getCodeEditor().ifPresent(c -> c.dispose()); + widget.dispose(); if (Objects.equals(value, originalValue)) { @@ -209,11 +194,4 @@ NativeEvent getBlurEvent() { return Document.get().createBlurEvent(); } - Element uncheckedCast(final com.google.gwt.user.client.Element element) { - return Js.uncheckedCast(element); - } - - MonacoPropertiesFactory makeMonacoPropertiesFactory() { - return new MonacoPropertiesFactory(); - } } diff --git a/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorWidget.java b/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorWidget.java index 989a23a01e7b..1f65d6a1c816 100644 --- a/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorWidget.java +++ b/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorWidget.java @@ -16,48 +16,51 @@ package org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.dom; -import java.util.Optional; - import com.google.gwt.dom.client.Document; +import jsinterop.base.Js; import org.gwtbootstrap3.client.ui.base.TextBoxBase; +import org.kie.workbench.common.dmn.client.widgets.codecompletion.MonacoPropertiesFactory; +import org.uberfire.client.views.pfly.monaco.jsinterop.MonacoEditor; import org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor; public class MonacoEditorWidget extends TextBoxBase { - private MonacoStandaloneCodeEditor codeEditor; + private final MonacoPropertiesFactory monacoPropertiesFactory = new MonacoPropertiesFactory(); + private final MonacoEditor monacoEditor = MonacoEditor.get(); + private final MonacoStandaloneCodeEditor codeEditor; public MonacoEditorWidget() { super(Document.get().createDivElement()); + codeEditor = monacoEditor.create(Js.uncheckedCast(getElement()), + monacoPropertiesFactory.getConstructionOptions()); } - public void setCodeEditor(final MonacoStandaloneCodeEditor codeEditor) { + /** + * for testing + */ + MonacoEditorWidget(MonacoStandaloneCodeEditor codeEditor) { + super(Document.get().createDivElement()); this.codeEditor = codeEditor; } - public void setValue(final String value) { - getCodeEditor().ifPresent(c -> c.setValue(value)); + public MonacoStandaloneCodeEditor getCodeEditor() { + return codeEditor; } @Override public String getValue() { - return getCodeEditor() - .map(editor -> editor.getValue()) - .orElse(""); + return codeEditor.getValue() != null ? codeEditor.getValue() : ""; } - @Override - public void setFocus(final boolean focused) { - getCodeEditor().ifPresent(c -> { - if (focused) { - c.focus(); - } - // IStandaloneCodeEditor(codeEditor) supports focus, but does not support blur. - // https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandalonecodeeditor.html - }); + public void setValue(final String value) { + codeEditor.setValue(value); } - public Optional getCodeEditor() { - return Optional.ofNullable(codeEditor); + @Override + public void setFocus(final boolean focused) { + if (focused) { + codeEditor.focus(); + } } @Override @@ -65,4 +68,8 @@ public void setTabIndex(final int index) { // IStandaloneCodeEditor(codeEditor) does not support tab index. // https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandalonecodeeditor.html } + + public void dispose() { + codeEditor.dispose(); + } } diff --git a/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElementTest.java b/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElementTest.java index 67da5b329d21..78d64d96e2be 100644 --- a/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElementTest.java +++ b/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/widgets/grid/columns/factory/dom/MonacoEditorDOMElementTest.java @@ -16,7 +16,6 @@ package org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.dom; -import java.util.Optional; import java.util.function.Function; import com.ait.lienzo.test.LienzoMockitoTestRunner; @@ -45,7 +44,6 @@ import static com.google.gwt.dom.client.Style.Unit.PCT; import static com.google.gwt.dom.client.Style.Unit.PX; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -62,7 +60,6 @@ public class MonacoEditorDOMElementTest extends BaseDOMElementTest - - - - diff --git a/kie-wb-common-dmn/kie-wb-common-dmn-webapp-kogito-testing/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNKogitoTestingWebapp.gwt.xml b/kie-wb-common-dmn/kie-wb-common-dmn-webapp-kogito-testing/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNKogitoTestingWebapp.gwt.xml index 0407321d3fed..8c9e195c438c 100644 --- a/kie-wb-common-dmn/kie-wb-common-dmn-webapp-kogito-testing/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNKogitoTestingWebapp.gwt.xml +++ b/kie-wb-common-dmn/kie-wb-common-dmn-webapp-kogito-testing/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNKogitoTestingWebapp.gwt.xml @@ -39,8 +39,4 @@ - - - - diff --git a/kie-wb-common-dmn/kie-wb-common-dmn-webapp-standalone/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNShowcase.gwt.xml b/kie-wb-common-dmn/kie-wb-common-dmn-webapp-standalone/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNShowcase.gwt.xml index 40418c9da628..6188ffb0d86f 100644 --- a/kie-wb-common-dmn/kie-wb-common-dmn-webapp-standalone/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNShowcase.gwt.xml +++ b/kie-wb-common-dmn/kie-wb-common-dmn-webapp-standalone/src/main/resources/org/kie/workbench/common/dmn/showcase/DMNShowcase.gwt.xml @@ -71,8 +71,4 @@ - - - -