private void addButtonCreate(Button button) { String buttonId = WidgetUtil.getId(button); writer.appendCreate(buttonId, "org.eclipse.swt.widgets.Button"); writer.appendSet(buttonId, "parent", shellId); writer.appendSet(buttonId, "styles", new JsonArray().add("PUSH").add("BORDER")); writer.appendSet(buttonId, "text", "foo"); }
@Test public void testPreserveValues() { Fixture.preserveWidgets(); WidgetAdapter adapter = WidgetUtil.getAdapter(progressBar); Object preserved = adapter.getPreserved(ProgressBarLCA.PROP_STATE); assertNull(preserved); }
@Test public void testMessageWithMixedOperations() { Button button = new Button(shell, SWT.PUSH); addShellCreate(shell); addShellListeners(shell); addButtonCreate(button); addButtonCall(button); String buttonId = WidgetUtil.getId(button); Message message = getMessage(); assertEquals(4, message.getOperationCount()); CreateOperation shellCreateOperation = (CreateOperation) message.getOperation(0); assertEquals(shellId, shellCreateOperation.getTarget()); assertEquals(2, shellCreateOperation.getPropertyNames().size()); ListenOperation shellListenOperation = (ListenOperation) message.getOperation(1); assertEquals(shellId, shellListenOperation.getTarget()); assertEquals(2, shellListenOperation.getPropertyNames().size()); CreateOperation buttonCreateOperation = (CreateOperation) message.getOperation(2); assertEquals(buttonId, buttonCreateOperation.getTarget()); assertEquals(3, buttonCreateOperation.getPropertyNames().size()); CallOperation buttonCallOperation = (CallOperation) message.getOperation(3); assertEquals(buttonId, buttonCallOperation.getTarget()); assertEquals(1, buttonCallOperation.getPropertyNames().size()); }
@Test public void testRenderParent() throws IOException { lca.renderInitialization(progressBar); Message message = Fixture.getProtocolMessage(); CreateOperation operation = message.findCreateOperation(progressBar); assertEquals(WidgetUtil.getId(progressBar.getParent()), operation.getParent()); }
@Before public void setUp() { Fixture.setUp(); Display display = new Display(); shell = new Shell(display); writer = new ProtocolMessageWriter(); shellId = WidgetUtil.getId(shell); }
@Override public void createControl(Composite parent) { if (control == null) { Composite container = new Composite(parent, SWT.NONE); container.setLayout(new FillLayout()); page.createContent(container, ui); control = container; remoteObject.set(PROPERTY_CONTROL, WidgetUtil.getId(control)); } }
@Test public void testMessageWithDestroy() { Button button = new Button(shell, SWT.PUSH); String buttonId = WidgetUtil.getId(button); writer.appendDestroy(buttonId); DestroyOperation operation = (DestroyOperation) getMessage().getOperation(0); assertEquals(buttonId, operation.getTarget()); }
private void createClientScriptingSignInButton(Composite parent) { Button signInButton = new Button(parent, SWT.PUSH); WidgetUtil.registerDataKeys("clientId"); signInButton.setData("clientId", Authorization.clientSecrets.getWeb().getClientId()); signInButton.setText("Sign in with Google"); String scriptCode = ResourceLoaderUtil.readTextContent("signInButton.js"); signInButton.addListener(SWT.Selection, new ClientListener(scriptCode)); addDescription( parent, "<- This button uses RAP client scripting to trigger Google's JavaScript based OAuth flow."); }
@Test public void testMessageWithDestroyTwice() { Button button = new Button(shell, SWT.PUSH); String buttonId = WidgetUtil.getId(button); writer.appendDestroy(buttonId); writer.appendDestroy(shellId); Message message = getMessage(); assertTrue(message.getOperation(0) instanceof DestroyOperation); assertTrue(message.getOperation(1) instanceof DestroyOperation); }
@Test public void testMessageWithMultipleOperations() { Button button = new Button(shell, SWT.PUSH); String buttonId = WidgetUtil.getId(button); writer.appendCreate(shellId, "org.Text"); writer.appendCreate(buttonId, "org.Shell"); Message message = getMessage(); assertTrue(message.getOperation(0) instanceof CreateOperation); assertTrue(message.getOperation(1) instanceof CreateOperation); }
@Test public void testEditablePreserveValues() { Fixture.markInitialized(display); Fixture.preserveWidgets(); WidgetAdapter adapter = WidgetUtil.getAdapter(combo); assertEquals(Boolean.TRUE, adapter.getPreserved(ComboLCA.PROP_EDITABLE)); Fixture.clearPreserved(); // textLimit combo.setTextLimit(10); Fixture.preserveWidgets(); Integer textLimit = (Integer) adapter.getPreserved(ComboLCA.PROP_TEXT_LIMIT); assertEquals(new Integer(10), textLimit); }
@Test public void testDoesNotAppendToOtherWidgetsOperation() { Button button = new Button(shell, SWT.PUSH); String buttonId = WidgetUtil.getId(button); writer.appendSet(shellId, "key1", "value1"); writer.appendSet(buttonId, "key2", "value2"); Message message = getMessage(); SetOperation firstOperation = (SetOperation) message.getOperation(0); assertEquals("value1", firstOperation.getProperty("key1").asString()); assertFalse(firstOperation.getPropertyNames().contains("key2")); }
@Test public void testMessageWithListen() { Button button = new Button(shell, SWT.PUSH); String buttonId = WidgetUtil.getId(button); writer.appendListen(buttonId, "selection", false); writer.appendListen(buttonId, "focus", true); writer.appendListen(buttonId, "fake", true); ListenOperation operation = (ListenOperation) getMessage().getOperation(0); assertEquals(buttonId, operation.getTarget()); assertFalse(operation.listensTo("selection")); assertTrue(operation.listensTo("focus")); assertTrue(operation.listensTo("fake")); }
@Test public void testStartsNewOperation() { Button button = new Button(shell, SWT.PUSH); String buttonId = WidgetUtil.getId(button); writer.appendCreate(shellId, "foo.Class"); writer.appendCreate(buttonId, "org.eclipse.swt.widgets.Button"); writer.appendSet(buttonId, "parent", shellId); writer.appendSet(buttonId, "key1", "value1"); writer.appendSet(buttonId, "key2", "value2"); Message message = getMessage(); CreateOperation createOperation = (CreateOperation) message.getOperation(1); assertEquals(shellId, createOperation.getParent()); assertEquals("value1", createOperation.getProperty("key1").asString()); assertEquals("value2", createOperation.getProperty("key2").asString()); }
@Test public void testMarkDisposed() { Fixture.fakeNewRequest(); Fixture.fakeResponseWriter(); // dispose un-initialized widget: must not occur in list of disposed widgets Widget widget = new Shell(display); widget.dispose(); assertTrue(widget.isDisposed()); assertEquals(0, DisposedWidgets.getAll().length); // dispose initialized widget: must be present in list of disposed widgets widget = new Shell(display); WidgetAdapterImpl adapter = (WidgetAdapterImpl) WidgetUtil.getAdapter(widget); adapter.setInitialized(true); widget.dispose(); assertTrue(widget.isDisposed()); assertEquals(1, DisposedWidgets.getAll().length); }
private void addButtonCall(Button button) { JsonObject parameters = new JsonObject().add("key1", "a1"); writer.appendCall(WidgetUtil.getId(button), "select", parameters); }
@Test public void testPreserveValues() { Combo combo = new Combo(shell, SWT.READ_ONLY); Fixture.markInitialized(display); // Test preserving a combo with no items and (naturally) no selection Fixture.preserveWidgets(); WidgetAdapter adapter = WidgetUtil.getAdapter(combo); String[] items = ((String[]) adapter.getPreserved(PROP_ITEMS)); assertEquals(0, items.length); assertEquals(new Integer(-1), adapter.getPreserved(PROP_SELECTION_INDEX)); assertNull(adapter.getPreserved(ComboLCA.PROP_TEXT_LIMIT)); Object visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT); assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount); assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE)); assertEquals(new Point(0, 0), adapter.getPreserved(ComboLCA.PROP_SELECTION)); // Test preserving combo with items were one is selected Fixture.clearPreserved(); combo.add("item 1"); combo.add("item 2"); combo.select(1); combo.setListVisible(true); SelectionListener selectionListener = new SelectionAdapter() {}; combo.addSelectionListener(selectionListener); combo.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent event) {} }); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(combo); items = ((String[]) adapter.getPreserved(PROP_ITEMS)); assertEquals(2, items.length); assertEquals("item 1", items[0]); assertEquals("item 2", items[1]); assertEquals(new Integer(1), adapter.getPreserved(PROP_SELECTION_INDEX)); visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT); assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount); assertEquals("item 2", adapter.getPreserved(Props.TEXT)); assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE)); Fixture.clearPreserved(); // foreground background font Color background = new Color(display, 122, 33, 203); combo.setBackground(background); Color foreground = new Color(display, 211, 178, 211); combo.setForeground(foreground); Font font = new Font(display, "font", 12, SWT.BOLD); combo.setFont(font); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(combo); assertEquals(background, adapter.getPreserved(Props.BACKGROUND)); assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND)); assertEquals(font, adapter.getPreserved(Props.FONT)); Fixture.clearPreserved(); // tooltiptext Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(combo); assertEquals(null, combo.getToolTipText()); Fixture.clearPreserved(); combo.setToolTipText("some text"); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(combo); assertEquals("some text", combo.getToolTipText()); Fixture.clearPreserved(); }