Skip to content

Commit

Permalink
KOGITO-4344 CCE while running Monaco in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Feb 9, 2021
1 parent d7f0d76 commit 62dbe1e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@
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;
import org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler;
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,60 @@

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<MonacoStandaloneCodeEditor> getCodeEditor() {
return Optional.ofNullable(codeEditor);
@Override
public void setFocus(final boolean focused) {
if (focused) {
codeEditor.focus();
}
}

@Override
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -62,7 +60,6 @@ public class MonacoEditorDOMElementTest extends BaseDOMElementTest<MonacoEditorW

@Override
protected MonacoEditorWidget getWidget() {
when(monacoEditorWidget.getCodeEditor()).thenReturn(Optional.empty());
return monacoEditorWidget;
}

Expand Down Expand Up @@ -139,22 +136,18 @@ public void testSetupInternalComponent() {

when(widget.getElement()).thenReturn(element);
when(element.getStyle()).thenReturn(style);
when(domElement.uncheckedCast(any())).thenReturn(mockedElement);
when(properties.getConstructionOptions()).thenReturn(constructionOptions);
doReturn(onKeyDown).when(domElement).getOnKeyDown(standaloneCodeEditor);
doReturn(widgetTrigger).when(domElement).getWidgetTrigger(blurEvent);
doReturn(blurEvent).when(domElement).getBlurEvent();
doReturn(properties).when(domElement).makeMonacoPropertiesFactory();
doReturn(editor).when(domElement).getMonacoEditor();
doReturn(standaloneCodeEditor).when(editor).create(mockedElement, constructionOptions);
doReturn(standaloneCodeEditor).when(widget).getCodeEditor();

domElement.setupInternalComponent();

verify(style).setWidth(100, PCT);
verify(style).setHeight(100, PCT);
verify(standaloneCodeEditor).onKeyDown(onKeyDown);
verify(standaloneCodeEditor).onDidBlurEditorWidget(widgetTrigger);
verify(widget).setCodeEditor(standaloneCodeEditor);
verify(widget).setFocus(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

@RunWith(LienzoMockitoTestRunner.class)
Expand All @@ -40,8 +39,7 @@ public class MonacoEditorWidgetTest {

@Before
public void setup() {
widget = spy(new MonacoEditorWidget());
widget.setCodeEditor(codeEditor);
widget = spy(new MonacoEditorWidget(codeEditor));
}

@Test
Expand All @@ -54,17 +52,6 @@ public void testSetValueWhenCodeEditorIsPresent() {
verify(codeEditor).setValue(value);
}

@Test
public void testSetValueWhenCodeEditorIsNotPresent() {

final String value = "value";

widget.setCodeEditor(null);
widget.setValue(value);

verifyNoMoreInteractions(codeEditor);
}

@Test
public void testGetValueWhenCodeEditorIsPresent() {

Expand All @@ -82,7 +69,6 @@ public void testGetValueWhenCodeEditorIsNotPresent() {

final String expectedValue = "";

widget.setCodeEditor(null);
when(widget.getValue()).thenReturn(expectedValue);

final String actualValue = widget.getValue();
Expand All @@ -102,10 +88,4 @@ public void testSetFocusWhenFocusIsNotEnabled() {
verify(codeEditor, never()).focus();
}

@Test
public void testSetFocusWhenCodeEditorIsNotPresent() {
widget.setCodeEditor(null);
widget.setFocus(true);
verify(codeEditor, never()).focus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,4 @@
<when-type-is class="org.uberfire.client.workbench.WorkbenchCloseHandler"/>
</replace-with>

<!-- Temporary workaround for ClassCastExceptions happening on DMN Marshaller models -->
<set-property name="jre.checks.type" value="DISABLED" />
<set-property name="jre.checkedMode" value="DISABLED" />

</module>
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@
<when-type-is class="org.uberfire.client.workbench.WorkbenchCloseHandler"/>
</replace-with>

<!-- Temporary workaround for ClassCastExceptions happening on DMN Marshaller models -->
<set-property name="jre.checks.type" value="DISABLED" />
<set-property name="jre.checkedMode" value="DISABLED" />

</module>
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,4 @@
<source path="api"/>
<source path="client"/>

<!-- Temporary workaround for ClassCastExceptions happening on DMN Marshaller models -->
<set-property name="jre.checks.type" value="DISABLED" />
<set-property name="jre.checkedMode" value="DISABLED" />

</module>

0 comments on commit 62dbe1e

Please sign in to comment.