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 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 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"));
  }
 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"));
 }
 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);
 }
 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);
 }
 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));
 }
示例#9
0
 private static void preserveMenuBounds(final Shell shell) {
   Object adapter = shell.getAdapter(IShellAdapter.class);
   IShellAdapter shellAdapter = (IShellAdapter) adapter;
   Rectangle menuBounds = shellAdapter.getMenuBounds();
   IWidgetAdapter widgetAdapter = WidgetUtil.getAdapter(shell);
   widgetAdapter.preserve(PROP_SHELL_MENU_BOUNDS, menuBounds);
 }
 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));
 }
示例#11
0
 // TODO [rh] is this safe for multiple shells?
 private static void processActivate(final Shell shell) {
   HttpServletRequest request = ContextProvider.getRequest();
   String widgetId = request.getParameter(JSConst.EVENT_WIDGET_ACTIVATED);
   if (widgetId != null) {
     Widget widget = WidgetUtil.find(shell, widgetId);
     if (widget != null) {
       setActiveControl(shell, widget);
     }
   } else {
     String activeControlId = WidgetLCAUtil.readPropertyValue(shell, "activeControl");
     Widget widget = WidgetUtil.find(shell, activeControlId);
     if (widget != null) {
       setActiveControl(shell, widget);
     }
   }
 }
 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);
 }
 private void testPreserveControlProperties(Scale scale) {
   // bound
   Rectangle rectangle = new Rectangle(10, 10, 10, 10);
   scale.setBounds(rectangle);
   Fixture.preserveWidgets();
   IWidgetAdapter adapter = WidgetUtil.getAdapter(scale);
   assertEquals(rectangle, adapter.getPreserved(Props.BOUNDS));
   Fixture.clearPreserved();
   // enabled
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.TRUE, adapter.getPreserved(Props.ENABLED));
   Fixture.clearPreserved();
   scale.setEnabled(false);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.FALSE, adapter.getPreserved(Props.ENABLED));
   Fixture.clearPreserved();
   scale.setEnabled(true);
   // visible
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.TRUE, adapter.getPreserved(Props.VISIBLE));
   Fixture.clearPreserved();
   scale.setVisible(false);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.FALSE, adapter.getPreserved(Props.VISIBLE));
   Fixture.clearPreserved();
   // menu
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(null, adapter.getPreserved(Props.MENU));
   Fixture.clearPreserved();
   Menu menu = new Menu(scale);
   MenuItem item = new MenuItem(menu, SWT.NONE);
   item.setText("1 Item");
   scale.setMenu(menu);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(menu, adapter.getPreserved(Props.MENU));
   Fixture.clearPreserved();
   // foreground background font
   Color background = Graphics.getColor(122, 33, 203);
   scale.setBackground(background);
   Color foreground = Graphics.getColor(211, 178, 211);
   scale.setForeground(foreground);
   Font font = Graphics.getFont("font", 12, SWT.BOLD);
   scale.setFont(font);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(background, adapter.getPreserved(Props.BACKGROUND));
   assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND));
   assertEquals(font, adapter.getPreserved(Props.FONT));
   Fixture.clearPreserved();
 }
 public void preserveValues(final Widget widget) {
   JITVisualizationWidget vWidget = (JITVisualizationWidget) widget;
   ControlLCAUtil.preserveValues(vWidget);
   IWidgetAdapter adapter = WidgetUtil.getAdapter(vWidget);
   adapter.preserve(PROP_VISIBLE, String.valueOf(vWidget.isVisible()));
   adapter.preserve(WIDGET_DATA, new JSVar(vWidget.getJSONData()));
   // only needed for custom variants (theming)
   WidgetLCAUtil.preserveCustomVariant(vWidget);
 }
  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);
 }
示例#17
0
 /* (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 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);
 }
 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 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 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);
 }
 public void preserveValues(final Widget widget) {
   ScrolledComposite composite = (ScrolledComposite) widget;
   ControlLCAUtil.preserveValues(composite);
   IWidgetAdapter adapter = WidgetUtil.getAdapter(composite);
   adapter.preserve(PROP_BOUNDS, composite.getBounds());
   adapter.preserve(PROP_OVERFLOW, getOverflow(composite));
   adapter.preserve(PROP_H_BAR_SELECTION, getBarSelection(composite.getHorizontalBar()));
   adapter.preserve(PROP_V_BAR_SELECTION, getBarSelection(composite.getVerticalBar()));
   adapter.preserve(Props.SELECTION_LISTENERS, Boolean.valueOf(hasSelectionListener(composite)));
   adapter.preserve(PROP_SHOW_FOCUSED_CONTROL, Boolean.valueOf(composite.getShowFocusedControl()));
   WidgetLCAUtil.preserveCustomVariant(composite);
 }
示例#23
0
 private static void processWidgetDefaultSelectedEvent(final Tree tree) {
   HttpServletRequest request = ContextProvider.getRequest();
   String eventName = JSConst.EVENT_WIDGET_DEFAULT_SELECTED;
   if (WidgetLCAUtil.wasEventSent(tree, eventName)) {
     String itemId = request.getParameter(eventName + ".item");
     Item treeItem = (Item) WidgetUtil.find(tree, itemId);
     int eventType = SelectionEvent.WIDGET_DEFAULT_SELECTED;
     SelectionEvent event = new SelectionEvent(tree, treeItem, eventType);
     event.stateMask = EventLCAUtil.readStateMask(JSConst.EVENT_WIDGET_SELECTED_MODIFIER);
     event.processEvent();
   }
 }
示例#24
0
 private static void processWidgetSelectedEvent(final Tree tree) {
   HttpServletRequest request = ContextProvider.getRequest();
   String eventName = JSConst.EVENT_WIDGET_SELECTED;
   if (WidgetLCAUtil.wasEventSent(tree, eventName)) {
     Rectangle bounds = new Rectangle(0, 0, 0, 0);
     String itemId = request.getParameter(eventName + ".item");
     Item treeItem = (Item) WidgetUtil.find(tree, itemId);
     String detailStr = request.getParameter(eventName + ".detail");
     int detail = "check".equals(detailStr) ? SWT.CHECK : SWT.NONE;
     int eventType = SelectionEvent.WIDGET_SELECTED;
     int stateMask = EventLCAUtil.readStateMask(JSConst.EVENT_WIDGET_SELECTED_MODIFIER);
     SelectionEvent event =
         new SelectionEvent(tree, treeItem, eventType, bounds, stateMask, null, true, detail);
     event.processEvent();
   }
 }
 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);
 }
示例#26
0
 public void preserveValues(final Widget widget) {
   ControlLCAUtil.preserveValues((Control) widget);
   Shell shell = (Shell) widget;
   IWidgetAdapter adapter = WidgetUtil.getAdapter(shell);
   adapter.preserve(PROP_ACTIVE_CONTROL, getActiveControl(shell));
   adapter.preserve(PROP_ACTIVE_SHELL, shell.getDisplay().getActiveShell());
   adapter.preserve(PROP_TEXT, shell.getText());
   adapter.preserve(PROP_IMAGE, shell.getImage());
   adapter.preserve(PROP_ALPHA, new Integer(shell.getAlpha()));
   adapter.preserve(PROP_MODE, getMode(shell));
   adapter.preserve(PROP_FULLSCREEN, Boolean.valueOf(shell.getFullScreen()));
   adapter.preserve(PROP_SHELL_LISTENER, Boolean.valueOf(ShellEvent.hasListener(shell)));
   adapter.preserve(PROP_SHELL_MENU, shell.getMenuBar());
   adapter.preserve(PROP_MINIMUM_SIZE, shell.getMinimumSize());
   WidgetLCAUtil.preserveCustomVariant(shell);
 }
示例#27
0
 public void preserveValues(final Widget widget) {
   Tree tree = (Tree) widget;
   ControlLCAUtil.preserveValues((Control) widget);
   IWidgetAdapter adapter = WidgetUtil.getAdapter(tree);
   adapter.preserve(PROP_SELECTION_LISTENERS, Boolean.valueOf(SelectionEvent.hasListener(tree)));
   adapter.preserve(PROP_HEADER_HEIGHT, new Integer(tree.getHeaderHeight()));
   adapter.preserve(PROP_HEADER_VISIBLE, Boolean.valueOf(tree.getHeaderVisible()));
   int[] values = tree.getColumnOrder();
   Integer[] columnOrder = new Integer[values.length];
   for (int i = 0; i < values.length; i++) {
     columnOrder[i] = new Integer(values[i]);
   }
   adapter.preserve(PROP_COLUMN_ORDER, columnOrder);
   adapter.preserve(PROP_SCROLL_LEFT, getScrollLeft(tree));
   adapter.preserve(PROP_HAS_H_SCROLL_BAR, hasHScrollBar(tree));
   adapter.preserve(PROP_HAS_V_SCROLL_BAR, hasVScrollBar(tree));
   WidgetLCAUtil.preserveCustomVariant(tree);
 }
示例#28
0
 private static void readSelection(final Tree tree) {
   String value = WidgetLCAUtil.readPropertyValue(tree, "selection");
   if (value != null) {
     String[] values = value.split(",");
     TreeItem[] selectedItems = new TreeItem[values.length];
     boolean validItemFound = false;
     for (int i = 0; i < values.length; i++) {
       selectedItems[i] = (TreeItem) WidgetUtil.find(tree, values[i]);
       if (selectedItems[i] != null) {
         validItemFound = true;
       }
     }
     if (!validItemFound) {
       selectedItems = new TreeItem[0];
     }
     tree.setSelection(selectedItems);
   }
 }
  public void renderChanges(final Widget widget) throws IOException {
    JITVisualizationWidget vWidget = (JITVisualizationWidget) widget;
    JSWriter writer = JSWriter.getWriterFor(vWidget);
    writer.set(PROP_VISIBLE, PROP_VISIBLE, String.valueOf(vWidget.isVisible()));
    // We compare the JSON text directly because JSVar does not override Object.equals();
    IWidgetAdapter adapter = WidgetUtil.getAdapter(vWidget);
    JSVar oldValue = (JSVar) adapter.getPreserved(WIDGET_DATA);
    String jsonData = vWidget.getJSONData();
    if (jsonData != null && (oldValue == null || !jsonData.equals(oldValue.toString()))) {
      writer.set(WIDGET_DATA, WIDGET_DATA, new JSVar(jsonData));
    }
    ControlLCAUtil.writeChanges(vWidget);

    WidgetCommandQueue cmdQueue = (WidgetCommandQueue) vWidget.getAdapter(WidgetCommandQueue.class);
    if (cmdQueue != null) {
      while (cmdQueue.peek() != null) {
        Object[] functionCall = (Object[]) cmdQueue.poll();
        writer.call((String) functionCall[0], (Object[]) functionCall[1]);
      }
    }
  }
  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);
  }