public void paste() { JsonObject properties = new JsonObject(); properties.add("rowStart", this.cursorPosition.row); properties.add("columnStart", this.cursorPosition.column); properties.add("text", this.clipboard); getRemoteObject().call("insertText", properties); }
@Test public void testEmptyMessage() { JsonObject message = writer.createMessage(); JsonObject head = message.get("head").asObject(); assertEquals(0, head.size()); JsonArray operations = message.get("operations").asArray(); assertEquals(0, operations.size()); }
@Test public void testCreatesWidget() throws IOException { lifeCycleAdapter.renderInitialization(video); assertTrue(MessageUtil.hasCreateOperation("tabris.widgets.Video")); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), CREATE, null); assertEquals(video.getURL().toString(), properties.get(Constants.PROPERTY_URL).asString()); }
void handleFocusGained(Event event) { JsonObject data = (JsonObject) event.data; if (data != null && data instanceof JsonObject) { JsonObject position = (JsonObject) data.get("value"); int row = position.get("row").asInt(); int column = position.get("column").asInt(); this.cursorPosition = new Position(row, column); } }
protected void handleTextSelected(Event event) { String selection = event.text; JsonObject coordinates = (JsonObject) event.data; int rowStart = coordinates.get("rowStart").asInt(); int rowEnd = coordinates.get("rowEnd").asInt(); int columnStart = coordinates.get("columnStart").asInt(); int columnEnd = coordinates.get("columnEnd").asInt(); this.selection = new TextSelection(selection, rowStart, rowEnd, columnStart, columnEnd); }
public void cut(TextSelection selection) { checkWidget(); if ((style & SWT.READ_ONLY) != 0) return; this.clipboard = selection.getText(); JsonObject properties = new JsonObject(); properties.add("rowStart", this.cursorPosition.row); properties.add("columnStart", this.cursorPosition.column); properties.add("text", this.clipboard); getRemoteObject().call("removeText", properties); }
/** * Sets the receiver's background color to the color specified by the argument, or to the default * system color for the control if the argument is null. * * @param color the new color (or null) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setBackground(Color color) { // super.setBackground(color); // This has no effect as the background // will // be hidden by the client script JsonObject properties = new JsonObject(); properties.add("R", color.getRed()); properties.add("G", color.getGreen()); properties.add("B", color.getBlue()); getRemoteObject().set("background", properties); }
@Test public void testRendersHeadPointer() throws IOException { lifeCycleAdapter.preserveValues(video); video.stepToTime(23); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null); assertEquals(23, properties.get(keyForEnum(PlaybackOptions.HEAD_POSITION)).asInt()); }
@Test public void testRendersControlsVisible() throws IOException { lifeCycleAdapter.preserveValues(video); video.setPlayerControlsVisible(false); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null); assertFalse(properties.get(keyForEnum(PlaybackOptions.CONTROLS_VISIBLE)).asBoolean()); }
@Test public void testRendersRepeat() throws IOException { lifeCycleAdapter.preserveValues(video); video.setRepeat(true); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null); assertTrue(properties.get(keyForEnum(PlaybackOptions.REPEAT)).asBoolean()); }
@Test public void testRendersSpeedBackward() throws IOException { lifeCycleAdapter.preserveValues(video); video.fastBackward(-2); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null); assertEquals(-2, properties.get(keyForEnum(PlaybackOptions.SPEED)).asDouble(), 0); }
@Test public void testFiresPlaybackChange() { environment.getRemoteObject().setHandler(new VideoOperationHandler(video)); video.addPlaybackListener(playbackListener); JsonObject parameters = new JsonObject(); parameters.add(PROPERTY_PLAYBACK, Playback.ERROR.name()); environment.dispatchNotify(Constants.EVENT_PLAYBACK, parameters); verify(playbackListener).playbackChanged(Playback.ERROR); }
@Test public void testRendersPresentationListener() throws IOException { lifeCycleAdapter.preserveValues(video); video.addPresentationListener(presentationListener); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), LISTEN, null); assertNotNull(properties.get(Constants.EVENT_PRESENTATION)); }
@Test public void testRendersPlaybackMode() throws IOException { lifeCycleAdapter.preserveValues(video); video.play(); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null); assertEquals( keyForEnum(Playback.PLAY), properties.get(keyForEnum(PlaybackOptions.PLAYBACK)).asString()); }
@Test public void testFiresPresentationChangeToFullScreen() { environment.getRemoteObject().setHandler(new VideoOperationHandler(video)); video.addPresentationListener(presentationListener); JsonObject parameters = new JsonObject(); parameters.add(PROPERTY_PRESENTATION, Presentation.FULL_SCREEN.name()); environment.dispatchNotify(Constants.EVENT_PRESENTATION, parameters); verify(presentationListener).presentationChanged(Presentation.FULL_SCREEN); }
@Test public void testRendersPresentationMode() throws IOException { lifeCycleAdapter.preserveValues(video); video.setFullscreen(true); lifeCycleAdapter.renderChanges(video); JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null); assertEquals( keyForEnum(Presentation.FULL_SCREEN), properties.get(keyForEnum(PlaybackOptions.PRESENTATION)).asString()); }
@Test public void testRendersPlaybackPlayOnce() { environment.getRemoteObject().setHandler(new VideoOperationHandler(video)); video.addPlaybackListener(playbackListener); environment.newRequest(); JsonObject parameters = new JsonObject(); parameters.add(PROPERTY_PLAYBACK, Playback.PLAY.name()); environment.dispatchNotify(Constants.EVENT_PLAYBACK, parameters); verify(playbackListener).playbackChanged(Playback.PLAY); assertFalse(hasOperation(WidgetUtil.getId(video), SET, null)); }
@Test public void testActivatesItemOnlyIfDifferentFromClientItem() { SwipeItemProvider itemProvider = mockProvider(2); mockSwipeItem(itemProvider, 0, true); mockSwipeItem(itemProvider, 1, true); Swipe swipe = new Swipe(shell, itemProvider); swipe.show(0); JsonObject properties = new JsonObject(); properties.add("item", 1); environment.dispatchNotify("Swipe", properties); verify(remoteObject, times(1)).set("active", 0); verify(remoteObject, never()).set("active", 1); }
public void notifyListeners(String eventName, JsonObject properties) { JsonValue value = properties.get("value"); Event event = new Event(); event.type = stringToTypeEvent(eventName); event.text = (value != null && value.isString() ? value.asString() : ""); event.data = properties; listener.handleEvent(event); }
@Test public void testGetAllOperationsFor_withEmtpyMessage() { String json = "{ \"head\" : {}, \"operations\" : [] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); List<Operation> operations = message.getAllOperationsFor("w5"); assertTrue(operations.isEmpty()); }
@Test public void testConstructor_JsonObject_createsIndex() { String json = "{ \"head\" : {}, \"operations\" : [" + "[ \"set\", \"w3\", { \"foo\" : 23 } ]" + "] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); List<Operation> operations = message.getAllOperationsFor("w3"); assertFalse(operations.isEmpty()); }
@Test public void testGetAllOperationsFor_withoutMatchingOperations() { String json = "{ \"head\" : {}, \"operations\" : [" + "[ \"set\", \"w3\", { \"p1\" : \"foo\" } ]," + "[ \"set\", \"w4\", { \"p2\" : \"bar\" } ]," + "[ \"notify\", \"w3\", \"widgetSelected\", {} ]" + "] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); List<Operation> operations = message.getAllOperationsFor("w5"); assertTrue(operations.isEmpty()); }
@Test public void testGetLastNotifyOperation_withNullTarget() { String json = "{ \"head\" : {}, \"operations\" : [" + "[ \"notify\", \"w3\", \"foo\", {} ]," + "[ \"notify\", \"w4\", \"foo\", {} ]," // <--- + "[ \"notify\", \"w5\", \"bar\", {} ]" + "] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); NotifyOperation operation = message.getLastNotifyOperationFor(null, "foo"); assertEquals("w4", operation.getTarget()); }
@Test public void testGetAllOperationsFor_selectsMatchingOperations() { String json = "{ \"head\" : {}, \"operations\" : [" + "[ \"set\", \"w3\", { \"foo\" : 23 } ]," + "[ \"set\", \"w4\", { \"foo\" : 42 } ]," + "[ \"notify\", \"w3\", \"event\", {} ]" + "] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); List<Operation> operations = message.getAllOperationsFor("w3"); assertEquals(2, operations.size()); assertTrue(operations.get(0) instanceof SetOperation); assertTrue(operations.get(1) instanceof NotifyOperation); }
@Test public void testGetAllCallOperations_withoutTargetAndMethodName() { String json = "{ \"head\" : {}, \"operations\" : [" + "[ \"set\", \"w3\", { \"count\" : 1 } ]," + "[ \"call\", \"w3\", \"foo\", { \"count\" : 2 } ]," // <--- + "[ \"call\", \"w4\", \"bar\", { \"count\" : 3 } ]" // <--- + "] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); List<CallOperation> operations = message.getAllCallOperationsFor(null, null); assertEquals(2, operations.size()); assertEquals(2, operations.get(0).getParameters().get("count").asInt()); assertEquals(3, operations.get(1).getParameters().get("count").asInt()); }
private void assertLoadProperties( List<JsonObject> list, TestItem firstItem, TestItem secondItem) { JsonObject properties1 = list.get(0); assertEquals(0, properties1.get("index").asInt()); assertEquals( WidgetUtil.getId(firstItem.getLoadedComposite()), properties1.get("control").asString()); JsonObject properties2 = list.get(1); assertEquals(1, properties2.get("index").asInt()); assertEquals( WidgetUtil.getId(secondItem.getLoadedComposite()), properties2.get("control").asString()); }
@Test public void testGetLastNotifyOperation() { String json = "{ \"head\" : {}, \"operations\" : [" + "[ \"notify\", \"w3\", \"foo\", { \"count\" : 1 } ]," + "[ \"notify\", \"w3\", \"bar\", { \"count\" : 2 } ]," + "[ \"notify\", \"w3\", \"foo\", { \"count\" : 3 } ]," // <--- + "[ \"notify\", \"w3\", \"bar\", { \"count\" : 4 } ]," + "[ \"notify\", \"w4\", \"foo\", { \"count\" : 5 } ]," + "[ \"notify\", \"w4\", \"bar\", { \"count\" : 6 } ]" + "] }"; ClientMessage message = new ClientMessage(JsonObject.readFrom(json)); NotifyOperation operation = message.getLastNotifyOperationFor("w3", "foo"); assertEquals(3, operation.getProperties().get("count").asInt()); }
private void setCustomItemHeight(JsonObject parameters) { String widgetID = parameters.get(PROPERTY_TARGET).asString(); int itemHeight = parameters.get(PROPERTY_ITEM_HEIGHT).asInt(); Widget widget = findWidget(widgetID); setRowHeight(itemHeight, widget); }