public void testMessageWithFireEvent() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); writer.addFireEventPayload(WidgetUtil.getId(button), "selection"); String widgetId = WidgetUtil.getId(button); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_FIRE_EVENT, type); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String actualEvent = payload.getString(IProtocolConstants.KEY_EVENT); assertEquals("selection", actualEvent); writer.addFireEventPayload(WidgetUtil.getId(button), "focus"); writer.finish(); actual = stringWriter.getBuffer().toString(); message = new JSONObject(actual); widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); widgetObject = widgetArray.getJSONObject(1); type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_FIRE_EVENT, type); actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); actualEvent = payload.getString(IProtocolConstants.KEY_EVENT); assertEquals("focus", actualEvent); }
public void testBlockWithStream() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); writer.addConstructPayload( WidgetUtil.getId(button), WidgetUtil.getId(button.getParent()), button.getClass().getName(), new String[] {"PUSH"}, null); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_CONSTRUCT, "key", "value"); writer.finish(); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String parentId = payload.getString(IProtocolConstants.KEY_PARENT_ID); assertEquals(WidgetUtil.getId(shell), parentId); }
public void testMessageWithDestroy() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); writer.addDestroyPayload(WidgetUtil.getId(button)); String widgetId = WidgetUtil.getId(button); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_DESTROY, type); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); Object payload = widgetObject.get(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals(JSONObject.NULL, payload); writer.addDestroyPayload(WidgetUtil.getId(shell)); writer.finish(); String shellId = WidgetUtil.getId(shell); actual = stringWriter.getBuffer().toString(); message = new JSONObject(actual); widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); widgetObject = widgetArray.getJSONObject(1); type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_DESTROY, type); actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(shellId, actualId); payload = widgetObject.get(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals(JSONObject.NULL, payload); }
public void testMessageWithListen() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); Map listeners = new HashMap(); listeners.put("selection", new Boolean(false)); listeners.put("focus", new Boolean(true)); listeners.put("fake", new Boolean(true)); writer.addListenPayload(WidgetUtil.getId(button), listeners); String widgetId = WidgetUtil.getId(button); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_LISTEN, type); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); assertFalse(payload.getBoolean("selection")); assertTrue(payload.getBoolean("focus")); assertTrue(payload.getBoolean("fake")); }
public void testStreamArray() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_CONSTRUCT, "key", new Integer[] {new Integer(1), new Integer(2)}); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_CONSTRUCT, "key2", new Boolean(true)); writer.finish(); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); JSONArray array = payload.getJSONArray("key"); assertEquals(1, array.getInt(0)); assertEquals(2, array.getInt(1)); assertTrue(payload.getBoolean("key2")); }
private void addButtonConstruct(final Button button, final ProtocolMessageWriter writer) { String[] styles = new String[] {"PUSH", "BORDER"}; Object[] arguments = new Object[] {new Integer(4), new Boolean(true)}; writer.addConstructPayload( WidgetUtil.getId(button), WidgetUtil.getId(button.getParent()), button.getClass().getName(), styles, arguments); }
public void renderInitialization(Widget widget) throws IOException { ToolTip toolTip = (ToolTip) widget; IClientObject clientObject = ClientObjectFactory.getClientObject(toolTip); clientObject.create(TYPE); clientObject.set("parent", WidgetUtil.getId(toolTip.getParent())); clientObject.set("style", WidgetLCAUtil.getStyles(toolTip, ALLOWED_STYLES)); }
public void renderInitialization(Widget widget) throws IOException { ControlDecorator decorator = (ControlDecorator) widget; IClientObject clientObject = ClientObjectFactory.getClientObject(decorator); clientObject.create(TYPE); clientObject.set("parent", WidgetUtil.getId(decorator.getParent())); clientObject.set("style", WidgetLCAUtil.getStyles(decorator, ALLOWED_STYLES)); }
private void addShellSynchronize(final Shell shell, final ProtocolMessageWriter writer) { Map properties = new HashMap(); for (int i = 0; i < 5; i++) { properties.put("key" + i, "value" + i); } writer.addSychronizePayload(WidgetUtil.getId(shell), properties); }
private void addShellListeners(final Shell shell, final ProtocolMessageWriter writer) { Map listeners = new HashMap(); for (int i = 0; i < 5; i++) { boolean listen = i % 2 == 0 ? true : false; listeners.put("listener" + i, new Boolean(listen)); } writer.addListenPayload(WidgetUtil.getId(shell), listeners); }
public void testRenderParent() throws IOException { Scale scale = new Scale(shell, SWT.NONE); lca.renderInitialization(scale); Message message = Fixture.getProtocolMessage(); CreateOperation operation = message.findCreateOperation(scale); assertEquals(WidgetUtil.getId(scale.getParent()), operation.getParent()); }
private void addShellConstruct(final Shell shell, final ProtocolMessageWriter writer) { String[] styles = new String[] {"SHELL_TRIM"}; writer.addConstructPayload( WidgetUtil.getId(shell), DisplayUtil.getId(shell.getDisplay()), shell.getClass().getName(), styles, null); }
public void testMessageWithExecuteScript() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); String script = "var c = 4; c++;"; String scriptType = "text/javascript"; writer.addExecuteScript(WidgetUtil.getId(button), scriptType, script); String widgetId = WidgetUtil.getId(button); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_EXECUTE_SCRIPT, type); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String actualType = payload.getString(IProtocolConstants.KEY_SCRIPT_TYPE); assertEquals(scriptType, actualType); String actualScript = payload.getString(IProtocolConstants.KEY_SCRIPT); assertEquals(script, actualScript); scriptType = "text/vb"; script = "really bad VB;"; writer.addExecuteScript(WidgetUtil.getId(shell), scriptType, script); writer.finish(); widgetId = WidgetUtil.getId(shell); actual = stringWriter.getBuffer().toString(); message = new JSONObject(actual); widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); widgetObject = widgetArray.getJSONObject(1); type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_EXECUTE_SCRIPT, type); actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); actualType = payload.getString(IProtocolConstants.KEY_SCRIPT_TYPE); assertEquals(scriptType, actualType); actualScript = payload.getString(IProtocolConstants.KEY_SCRIPT); assertEquals(script, actualScript); }
/* (intentionally non-JavaDoc'ed) * This method is declared public only to be accessible from DisplayLCA */ public static void writeActiveControl(final Shell shell) throws IOException { final Control activeControl = getActiveControl(shell); String prop = PROP_ACTIVE_CONTROL; if (WidgetLCAUtil.hasChanged(shell, prop, activeControl, null)) { // JSWriter writer = JSWriter.getWriterFor( shell ); // writer.set( "activeControl", new Object[] { activeControl } ); IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell); synchronizer.setWidgetProperty("activeControl", WidgetUtil.getId(activeControl)); } }
public void testMessageWithSynchronize() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); Map properties = new HashMap(); properties.put("text", "newText"); properties.put("image", "aUrl"); properties.put("fake", new Integer(1)); writer.addSychronizePayload(WidgetUtil.getId(button), properties); String widgetId = WidgetUtil.getId(button); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_SYNCHRONIZE, type); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals("newText", payload.getString("text")); assertEquals("aUrl", payload.getString("image")); assertEquals(1, payload.getInt("fake")); properties.remove("image"); properties.put("state", new Boolean(true)); writer.addSychronizePayload(WidgetUtil.getId(button), properties); writer.finish(); actual = stringWriter.getBuffer().toString(); message = new JSONObject(actual); widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); widgetObject = widgetArray.getJSONObject(1); type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_SYNCHRONIZE, type); actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals("newText", payload.getString("text")); assertEquals(1, payload.getInt("fake")); assertTrue(payload.getBoolean("state")); }
public void testMessageWithExecute() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); String methodName = "methodName"; Display display = new Display(); Shell shell = new Shell(display); writer.addExecutePayload(WidgetUtil.getId(shell), methodName, new Object[] {"a", "b"}); String widgetId = WidgetUtil.getId(shell); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgets = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgets.getJSONObject(0); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_EXECUTE, type); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String actualMethod = payload.getString(IProtocolConstants.KEY_METHODNAME); assertEquals(methodName, actualMethod); JSONArray actualParams = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST); assertEquals("a", actualParams.getString(0)); assertEquals("b", actualParams.getString(1)); Object[] array = new Object[] {new Integer(5), "b", new Boolean(false)}; writer.addExecutePayload(WidgetUtil.getId(shell), methodName, array); writer.finish(); actual = stringWriter.getBuffer().toString(); message = new JSONObject(actual); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); widgetObject = widgetArray.getJSONObject(1); type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_EXECUTE, type); actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); actualMethod = payload.getString(IProtocolConstants.KEY_METHODNAME); assertEquals(methodName, actualMethod); JSONArray params = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST); assertEquals(5, params.getInt(0)); assertEquals("b", params.getString(1)); assertFalse(params.getBoolean(2)); }
public void testMessageWithMixedPayloads() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); createShellPayload(shell, writer); createButtonPayload(button, writer); writer.finish(); String shellId = WidgetUtil.getId(shell); String buttonId = WidgetUtil.getId(button); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual); checkShellConstruct(shell, message); checkShellSynchronize(shellId, message); checkShellListen(shellId, message); checkButtonConstruct(button, shellId, buttonId, message); checkButtonExecute(buttonId, message); }
private void checkShellConstruct(final Shell shell, final JSONObject message) throws JSONException { JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String actualShellId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(WidgetUtil.getId(shell), actualShellId); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String actualDisplayId = payload.getString(IProtocolConstants.KEY_PARENT_ID); assertEquals(DisplayUtil.getId(shell.getDisplay()), actualDisplayId); JSONArray styles = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE); assertEquals("SHELL_TRIM", styles.getString(0)); Object params = payload.get(IProtocolConstants.KEY_PARAMETER_LIST); assertSame(JSONObject.NULL, params); }
public void testMessageWithWrongArguments() throws IOException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); boolean isExceptionThrown = false; try { writer.addConstructPayload( DisplayUtil.getId(display), WidgetUtil.getId(shell), "org.Text", new String[] {"TRIM"}, new Object[] {"a", button}); } catch (final IllegalArgumentException e) { isExceptionThrown = true; } assertTrue(isExceptionThrown); }
private void testSelectionEvent(final Scale scale) { final StringBuilder log = new StringBuilder(); SelectionListener selectionListener = new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { assertEquals(scale, event.getSource()); assertEquals(null, event.item); assertEquals(SWT.NONE, event.detail); assertEquals(0, event.x); assertEquals(0, event.y); assertEquals(0, event.width); assertEquals(0, event.height); assertEquals(true, event.doit); log.append("widgetSelected"); } }; scale.addSelectionListener(selectionListener); String scaleId = WidgetUtil.getId(scale); Fixture.fakeRequestParam(JSConst.EVENT_WIDGET_SELECTED, scaleId); Fixture.readDataAndProcessAction(scale); assertEquals("widgetSelected", log.toString()); }
public void testStream() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_CONSTRUCT, "key", "value"); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_CONSTRUCT, "key2", "value2"); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_SYNCHRONIZE, "key", "value"); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_SYNCHRONIZE, "key2", "value2"); writer.appendPayload( WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_SYNCHRONIZE, "key3", "value3"); writer.appendPayload( WidgetUtil.getId(button), IProtocolConstants.PAYLOAD_SYNCHRONIZE, "key", "value"); writer.finish(); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals("value", payload.getString("key")); assertEquals("value2", payload.getString("key2")); widgetObject = widgetArray.getJSONObject(1); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals("value", payload.getString("key")); assertEquals("value2", payload.getString("key2")); assertEquals("value3", payload.getString("key3")); widgetObject = widgetArray.getJSONObject(2); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(WidgetUtil.getId(button), actualId); assertEquals("value", payload.getString("key")); }
public void testMessageWithMultiSynchronize() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); int widgetCount = 5; String[] widgetIds = new String[widgetCount]; for (int i = 0; i < widgetCount; i++) { Label label = new Label(shell, SWT.NONE); widgetIds[i] = WidgetUtil.getId(label); } Map properties = new HashMap(); properties.put("text", "newText"); properties.put("image", "aUrl"); properties.put("fake", new Integer(1)); writer.addMultipleSychronizePayload(widgetIds, properties); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_MULTI_SYNCHRONIZE, type); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals("null", actualId); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); assertEquals("newText", payload.getString("text")); assertEquals("aUrl", payload.getString("image")); assertEquals(1, payload.getInt("fake")); JSONArray multiWidgets = payload.getJSONArray(IProtocolConstants.KEY_WIDGETS); for (int i = 0; i < widgetCount; i++) { String actualWidgetId = multiWidgets.getString(i); String expectedWidgetId = widgetIds[i]; assertEquals(expectedWidgetId, actualWidgetId); } }
public void renderInitialization(final Widget widget) throws IOException { IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(widget); List styleList = new ArrayList(); int style = widget.getStyle(); if ((style & SWT.BORDER) != 0) { styleList.add("BORDER"); } if ((style & MODAL) != 0) { styleList.add("MODAL"); } if ((style & SWT.ON_TOP) != 0) { styleList.add("ON_TOP"); } if ((style & SWT.TITLE) != 0) { styleList.add("TITLE"); } if ((style & SWT.TOOL) != 0) { styleList.add("TOOL"); } if ((style & SWT.SHEET) != 0) { styleList.add("SHEET"); } if ((style & SWT.MIN) != 0) { styleList.add("MIN"); } if ((style & SWT.MAX) != 0) { styleList.add("MAX"); } if ((style & SWT.CLOSE) != 0) { styleList.add("CLOSE"); } if ((style & SWT.RESIZE) != 0) { styleList.add("RESIZE"); } String[] styles = new String[styleList.size()]; styleList.toArray(styles); Composite parent = ((Shell) widget).getParent(); if (parent instanceof Shell) { String parentId = WidgetUtil.getId(parent); synchronizer.newWidget(styles, new Object[] {parentId}); } synchronizer.newWidget(styles); // old // JSWriter writer = JSWriter.getWriterFor( widget ); // Shell shell = ( Shell )widget; // writer.newWidget( QX_TYPE ); // ControlLCAUtil.writeStyleFlags( shell ); // if( ( style & MODAL ) != 0 ) { // writer.call( "addState", new Object[] { "rwt_APPLICATION_MODAL" } ); // } // if( ( style & SWT.ON_TOP ) != 0 ) { // writer.call( "addState", new Object[] { "rwt_ON_TOP" } ); // } // if( ( style & SWT.TITLE ) != 0 ) { // writer.call( "addState", new Object[]{ "rwt_TITLE" } ); // } // if( ( style & SWT.TOOL ) != 0 ) { // writer.call( "addState", new Object[]{ "rwt_TOOL" } ); // } // if( ( style & SWT.SHEET ) != 0 ) { // writer.call( "addState", new Object[]{ "rwt_SHEET" } ); // } // writer.set( "showMinimize", ( style & SWT.MIN ) != 0 ); // writer.set( "allowMinimize", ( style & SWT.MIN ) != 0 ); // writer.set( "showMaximize", ( style & SWT.MAX ) != 0 ); // writer.set( "allowMaximize", ( style & SWT.MAX ) != 0 ); // writer.set( "showClose", ( style & SWT.CLOSE ) != 0 ); // writer.set( "allowClose", ( style & SWT.CLOSE ) != 0 ); // Boolean resizable = Boolean.valueOf( ( style & SWT.RESIZE ) != 0 ); // writer.set( "resizable", // new Object[] { resizable, resizable, resizable, resizable } ); // if( parent instanceof Shell ) { // writer.set( "parentShell", parent ); // } // writer.call( "initialize", null ); }
public void testMessageWithConstruct() throws IOException, JSONException { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ProtocolMessageWriter writer = new JsonMessageWriter(printWriter); Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); writer.addConstructPayload( WidgetUtil.getId(shell), DisplayUtil.getId(display), "org.Text", new String[] {"TRIM"}, new Object[] {"a", "b"}); String parentId = ""; if (shell.getParent() != null) { parentId = WidgetUtil.getId(shell.getParent()); } else { parentId = DisplayUtil.getId(display); } String widgetId = WidgetUtil.getId(shell); String actual = stringWriter.getBuffer().toString(); JSONObject message = new JSONObject(actual + "]}"); JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); JSONObject widgetObject = widgetArray.getJSONObject(0); String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type); String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(widgetId, actualId); JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); String actualParentId = payload.getString(IProtocolConstants.KEY_PARENT_ID); assertEquals(parentId, actualParentId); String actualType = payload.getString(IProtocolConstants.KEY_WIDGET_TYPE); assertEquals("org.Text", actualType); JSONArray actualStyle = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE); assertEquals("TRIM", actualStyle.getString(0)); JSONArray actualParams = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST); assertEquals("a", actualParams.getString(0)); assertEquals("b", actualParams.getString(1)); writer.addConstructPayload( WidgetUtil.getId(button), WidgetUtil.getId(shell), "org.Shell", new String[] {"PUSH", "BORDER"}, new Object[] {"a", new Boolean(true)}); writer.finish(); actual = stringWriter.getBuffer().toString(); message = new JSONObject(actual); widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS); widgetObject = widgetArray.getJSONObject(1); type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE); assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type); actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID); assertEquals(WidgetUtil.getId(button), actualId); payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD); JSONArray styles = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE); assertEquals("PUSH", styles.getString(0)); assertEquals("BORDER", styles.getString(1)); String actualParent = payload.getString(IProtocolConstants.KEY_PARENT_ID); assertEquals(WidgetUtil.getId(shell), actualParent); JSONArray params = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST); assertTrue(params.getBoolean(1)); }
protected Collection getInitializationParameters(JITVisualizationWidget vWidget) { ArrayList params = new ArrayList(); String id = WidgetUtil.getId(vWidget); params.add(id); return params; }
private void addButtonExecute(final Button button, final ProtocolMessageWriter writer) { Object[] arguments = new Object[] {"a1"}; writer.addExecutePayload(WidgetUtil.getId(button), "select", arguments); }