Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHPAM-755 (Stunner) - With Process Designer, a copy of the timer is created when you copy text from a name field to a documentation field #1894

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ void setPixelSize(int wide,
private final Event<KeyUpEvent> keyUpEvent;
private final Event<CanvasMouseDownEvent> mouseDownEvent;
private final Event<CanvasMouseUpEvent> mouseUpEvent;

private View view;

private boolean listening;
protected View getView() {
return view;
}

@Inject
public LienzoPanel(final Event<KeyPressEvent> keyPressEvent,
Expand All @@ -61,7 +64,6 @@ public LienzoPanel(final Event<KeyPressEvent> keyPressEvent,
this.keyUpEvent = keyUpEvent;
this.mouseDownEvent = mouseDownEvent;
this.mouseUpEvent = mouseUpEvent;
this.listening = false;
}

@Override
Expand All @@ -84,55 +86,36 @@ public void setPixelSize(final int wide,
}

public void destroy() {
this.listening = false;
view.destroy();
view = null;
}

void onMouseDown() {
if (listening) {
mouseDownEvent.fire(new CanvasMouseDownEvent());
}
mouseDownEvent.fire(new CanvasMouseDownEvent());
}

void onMouseUp() {
if (listening) {
mouseUpEvent.fire(new CanvasMouseUpEvent());
}
}

void onMouseOver() {
this.listening = true;
}

void onMouseOut() {
this.listening = false;
mouseUpEvent.fire(new CanvasMouseUpEvent());
}

void onKeyPress(final int unicodeChar) {
if (listening) {
final KeyboardEvent.Key key = getKey(unicodeChar);
if (null != key) {
keyPressEvent.fire(new KeyPressEvent(key));
}
final KeyboardEvent.Key key = getKey(unicodeChar);
if (null != key) {
keyPressEvent.fire(new KeyPressEvent(key));
}
}

void onKeyDown(final int unicodeChar) {
if (listening) {
final KeyboardEvent.Key key = getKey(unicodeChar);
if (null != key) {
keyDownEvent.fire(new KeyDownEvent(key));
}
final KeyboardEvent.Key key = getKey(unicodeChar);
if (null != key) {
keyDownEvent.fire(new KeyDownEvent(key));
}
}

void onKeyUp(final int unicodeChar) {
if (listening) {
final KeyboardEvent.Key key = getKey(unicodeChar);
if (null != key) {
keyUpEvent.fire(new KeyUpEvent(key));
}
final KeyboardEvent.Key key = getKey(unicodeChar);
if (null != key) {
keyUpEvent.fire(new KeyUpEvent(key));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,25 @@

package org.kie.workbench.common.stunner.client.widgets.canvas.view;

import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.user.client.ui.RootPanel;
import org.kie.workbench.common.stunner.core.client.shape.view.event.HandlerRegistrationImpl;

public class LienzoPanelView extends FocusableLienzoPanelView implements LienzoPanel.View {

private final HandlerRegistrationImpl handlerRegistrationManager = new HandlerRegistrationImpl();
private final HandlerRegistrationImpl handlerRegistrationManager;
private LienzoPanel presenter;

public LienzoPanelView(final int width,
final int height) {
super(width,
height);
handlerRegistrationManager.register(
addMouseOverHandler(mouseOverEvent -> presenter.onMouseOver())
);
handlerRegistrationManager.register(
addMouseOutHandler(mouseOutEvent -> presenter.onMouseOut())
);
handlerRegistrationManager.register(
addMouseDownHandler(event -> presenter.onMouseDown())
);
handlerRegistrationManager.register(
addMouseUpHandler(event -> presenter.onMouseUp())
);
handlerRegistrationManager.register(
RootPanel.get().addDomHandler(keyPressEvent -> {
final int unicodeChar = keyPressEvent.getUnicodeCharCode();
presenter.onKeyPress(unicodeChar);
},
KeyPressEvent.getType())
);
handlerRegistrationManager.register(
RootPanel.get().addDomHandler(keyDownEvent -> {
final int unicodeChar = keyDownEvent.getNativeKeyCode();
presenter.onKeyDown(unicodeChar);
},
KeyDownEvent.getType())
);
handlerRegistrationManager.register(
RootPanel.get().addDomHandler(keyUpEvent -> {
final int unicodeChar = keyUpEvent.getNativeKeyCode();
presenter.onKeyUp(unicodeChar);
},
KeyUpEvent.getType())
);

this(width, height, new HandlerRegistrationImpl());
initHandlers();
}

protected LienzoPanelView(final int width,
final int height,
HandlerRegistrationImpl handlerRegistrationImpl) {
super(width, height);
handlerRegistrationManager = handlerRegistrationImpl;
}

@Override
Expand All @@ -77,4 +48,32 @@ public void destroy() {
presenter = null;
super.destroy();
}

protected void initHandlers() {

handlerRegistrationManager.register(
addMouseDownHandler(mouseDownEvent -> presenter.onMouseDown())
);
handlerRegistrationManager.register(
addMouseUpHandler(mouseUpEvent -> presenter.onMouseUp())
);
handlerRegistrationManager.register(
addKeyPressHandler(keyPressEvent -> {
final int unicodeChar = keyPressEvent.getUnicodeCharCode();
presenter.onKeyPress(unicodeChar);
})
);
handlerRegistrationManager.register(
addKeyDownHandler(keyDownEvent -> {
final int unicodeChar = keyDownEvent.getNativeKeyCode();
presenter.onKeyDown(unicodeChar);
})
);
handlerRegistrationManager.register(
addKeyUpHandler(keyUpEvent -> {
final int unicodeChar = keyUpEvent.getNativeKeyCode();
presenter.onKeyUp(unicodeChar);
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.client.widgets.canvas.view;

import org.junit.Before;
import org.junit.Test;
import org.kie.workbench.common.stunner.core.client.canvas.event.mouse.CanvasMouseDownEvent;
import org.kie.workbench.common.stunner.core.client.canvas.event.mouse.CanvasMouseUpEvent;
import org.kie.workbench.common.stunner.core.client.event.keyboard.KeyDownEvent;
import org.kie.workbench.common.stunner.core.client.event.keyboard.KeyPressEvent;
import org.kie.workbench.common.stunner.core.client.event.keyboard.KeyUpEvent;
import org.kie.workbench.common.stunner.core.client.event.keyboard.KeyboardEvent;
import org.mockito.Mock;
import org.uberfire.mocks.EventSourceMock;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;

public class LienzoPanelTest {

@Mock
private EventSourceMock<KeyPressEvent> keyPressEvent;

@Mock
private EventSourceMock<KeyDownEvent> keyDownEvent;

@Mock
private EventSourceMock<KeyUpEvent> keyUpEvent;

@Mock
private EventSourceMock<CanvasMouseDownEvent> mouseDownEvent;

@Mock
private EventSourceMock<CanvasMouseUpEvent> mouseUpEvent;

private LienzoPanel lienzoPanel;

@Before
public void setup() {
initMocks(this);
lienzoPanel = new LienzoPanel(keyPressEvent,
keyDownEvent,
keyUpEvent,
mouseDownEvent,
mouseUpEvent);
}

@Test
public void testOnMouseDown() {
lienzoPanel.onMouseDown();
verify(mouseDownEvent, times(1)).fire(any(CanvasMouseDownEvent.class));
}

@Test
public void testOnMouseUp() {
lienzoPanel.onMouseUp();
verify(mouseUpEvent, times(1)).fire(any(CanvasMouseUpEvent.class));
}

@Test
public void testOnKeyPress() {
lienzoPanel.onKeyPress(KeyboardEvent.Key.DELETE.getUnicharCode());
verify(keyPressEvent, times(1)).fire(any(KeyPressEvent.class));
}

@Test
public void testOnKeyDown() {
lienzoPanel.onKeyDown(KeyboardEvent.Key.DELETE.getUnicharCode());
verify(keyDownEvent, times(1)).fire(any(KeyDownEvent.class));
}

@Test
public void testOnKeyUp() {
lienzoPanel.onKeyUp(KeyboardEvent.Key.DELETE.getUnicharCode());
verify(keyUpEvent, times(1)).fire(any(KeyUpEvent.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.client.widgets.canvas.view;

import com.ait.lienzo.test.LienzoMockitoTestRunner;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.core.client.shape.view.event.HandlerRegistrationImpl;
import org.mockito.Mock;
import org.mockito.Mockito;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(LienzoMockitoTestRunner.class)
public class LienzoPanelViewTest {

@Mock
private HandlerRegistrationImpl handlerRegistrationManager;

private LienzoPanelView spyTested;

@Before
public void setup() {
spyTested = Mockito.spy(new LienzoPanelView(200, 200, handlerRegistrationManager));
}

@Test
public void testInitHandlers() {
spyTested.initHandlers();

verify(spyTested).addMouseDownHandler(any(MouseDownHandler.class));
verify(spyTested).addMouseUpHandler(any(MouseUpHandler.class));
verify(spyTested).addKeyPressHandler(any(KeyPressHandler.class));
verify(spyTested).addKeyDownHandler(any(KeyDownHandler.class));
verify(spyTested).addKeyUpHandler(any(KeyUpHandler.class));

verify(handlerRegistrationManager, times(5)).register(any(HandlerRegistration.class));
}
}