Ejemplo n.º 1
0
  @Test
  public void testSetItems_ResetsSelectionIndex() {
    handler.handleSet(new JsonObject().add("selectionIndex", 7));
    dropDown.setItems(new String[] {"a"});

    assertEquals(-1, dropDown.getSelectionIndex());
  }
Ejemplo n.º 2
0
  @Test
  public void testHide_SetsVisible() {
    dropDown.setVisible(true);
    dropDown.setVisible(false);

    assertFalse(dropDown.getVisible());
  }
Ejemplo n.º 3
0
  @Test
  public void testGetItems_returnsItems() {
    String[] items = new String[] {"a", "b", "c"};
    dropDown.setItems(items);

    assertTrue(Arrays.equals(items, dropDown.getItems()));
  }
Ejemplo n.º 4
0
  @Test
  public void testRemoveListener_DefaultSelectionRenderListenFalse() {
    Listener listener = mock(Listener.class);
    dropDown.addListener(SWT.DefaultSelection, listener);
    dropDown.removeListener(SWT.DefaultSelection, listener);

    verify(remoteObject).listen(eq("DefaultSelection"), eq(false));
  }
Ejemplo n.º 5
0
  @Test
  public void testProcessSetVisible_ValueIsFalse() {
    dropDown.setVisible(true);

    handler.handleSet(new JsonObject().add("visible", false));

    assertFalse(dropDown.getVisible());
  }
Ejemplo n.º 6
0
  @Test
  public void testSetSelectionIndex_RendersSelection() {
    dropDown.setItems(FOUR_ITEMS);

    dropDown.setSelectionIndex(2);

    verify(remoteObject).set("selectionIndex", 2);
  }
Ejemplo n.º 7
0
  @Test
  public void testSetSelectionIndex_SetsSelection() {
    dropDown.setItems(FOUR_ITEMS);

    dropDown.setSelectionIndex(2);

    assertEquals(2, dropDown.getSelectionIndex());
  }
Ejemplo n.º 8
0
  @Test
  public void testHide_RendersVisibleFalse() {
    dropDown.setVisible(true);

    dropDown.setVisible(false);

    verify(remoteObject).set("visible", false);
  }
Ejemplo n.º 9
0
  @Test
  public void testSetItems_storesSaveCopy() {
    String[] items = new String[] {"a", "b", "c"};
    dropDown.setItems(items);

    items[1] = "x";

    assertEquals("b", dropDown.getItems()[1]);
  }
Ejemplo n.º 10
0
  @Test
  public void testSetSelectionIndex_IgnoredForTooBigValue() {
    dropDown.setItems(FOUR_ITEMS);
    dropDown.setSelectionIndex(2);

    dropDown.setSelectionIndex(4);

    assertEquals(2, dropDown.getSelectionIndex());
  }
Ejemplo n.º 11
0
  @Test
  public void testRemoveListener_SelectionRenderListenFalse() {
    Listener listener = mock(Listener.class);
    dropDown.addListener(SWT.Selection, listener);
    // Mockito.reset( remoteObject );
    dropDown.removeListener(SWT.Selection, listener);

    verify(remoteObject).listen(eq("Selection"), eq(false));
  }
Ejemplo n.º 12
0
  @Test
  public void testDispose_FiresDispose() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);
    Listener listener = mock(Listener.class);
    dropDown.addListener(SWT.Dispose, listener);

    dropDown.dispose();

    verify(listener).handleEvent(any(Event.class));
  }
Ejemplo n.º 13
0
 protected void disableInputFields(boolean disable) {
   txtName.setDisabled(disable);
   txtDesc.setDisabled(disable);
   txtNotes.setDisabled(disable);
   cbbMembers.setDisabled(disable);
   cbbCategory.setDisabled(disable);
   cbbSubCategory.setDisabled(disable);
   btnAddSubCat.setDisabled(disable);
   btnRemoveSubCat.setDisabled(disable || subCatUnremovable());
 }
Ejemplo n.º 14
0
  @Test
  public void testSetVisibleItemCount_DoesNotRenderVisibleItemCountIfUnchanged() {
    dropDown.setVisibleItemCount(7);
    dropDown.setVisibleItemCount(7);

    verify(remoteObject, times(1)).set("visibleItemCount", 7);
  }
Ejemplo n.º 15
0
  @Test
  public void testSetItems_RenderItems() {
    dropDown.setItems(new String[] {"a", "b", "c"});

    JsonArray expected = JsonUtil.createJsonArray(new String[] {"a", "b", "c"});
    verify(remoteObject).set(eq("items"), eq(expected));
  }
Ejemplo n.º 16
0
  @Test
  public void testVisible_SetToTrueTwiceRenderVisibleOnce() {
    dropDown.setVisible(true);
    dropDown.setVisible(true);

    verify(remoteObject, times(1)).set("visible", true);
  }
Ejemplo n.º 17
0
  @Test
  public void testStyles_addsHSroll() {
    dropDown = new DropDown(text, SWT.H_SCROLL);

    assertEquals(SWT.V_SCROLL, dropDown.getStyle() & SWT.V_SCROLL);
    assertEquals(SWT.H_SCROLL, dropDown.getStyle() & SWT.H_SCROLL);
  }
Ejemplo n.º 18
0
  @Test
  public void testAddListener_Selection_doesNotSendListenTwice() {
    dropDown.addListener(SWT.Selection, mock(Listener.class));
    dropDown.addListener(SWT.Selection, mock(Listener.class));

    verify(remoteObject, times(1)).listen(eq("Selection"), eq(true));
  }
Ejemplo n.º 19
0
  @Test
  public void testSetData_RendersColumns() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);

    dropDown.setData("columns", new int[] {10, 20});

    verify(remoteObject).set(eq("columns"), eq(new JsonArray().add(10).add(20)));
  }
Ejemplo n.º 20
0
  @Test
  public void testSetData_RendersMarkupEnabled() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);

    dropDown.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);

    verify(remoteObject).set(eq("markupEnabled"), eq(true));
  }
Ejemplo n.º 21
0
  @Test
  public void testSetData_RendersIncorrectTypeAsNull() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);

    dropDown.setData("columns", Boolean.TRUE);

    verify(remoteObject).set(eq("columns"), eq(JsonValue.NULL));
  }
Ejemplo n.º 22
0
  @Test
  public void testAddListener_SelectionRenderListenTrue() {
    Listener listener = mock(Listener.class);

    dropDown.addListener(SWT.Selection, listener);

    verify(remoteObject).listen(eq("Selection"), eq(true));
  }
Ejemplo n.º 23
0
  @Test
  public void testSetData_RendersDataInWhiteList() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);

    WidgetUtil.registerDataKeys("foo", "bar");
    dropDown.setData("foo", "bar");

    verify(remoteObject).set(eq("data"), eq(new JsonObject().add("foo", "bar")));
  }
Ejemplo n.º 24
0
  @Test
  public void testSetData_DoesNotRenderDataNotInWhiteList() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);

    WidgetUtil.registerDataKeys("foo", "bar");
    dropDown.setData("fool", "bar");

    verify(remoteObject, never()).set(eq("data"), any(JsonObject.class));
  }
Ejemplo n.º 25
0
  @Test
  public void testRemoveListener_rendersClientListeners() {
    ClientListener listener = new ClientListener("");
    String listenerId = ClientListenerUtil.getRemoteId(listener);

    dropDown.removeListener(SWT.Show, listener);

    JsonObject expectedParameters =
        new JsonObject().add("eventType", "Show").add("listenerId", listenerId);
    verify(remoteObject).call(eq("removeListener"), eq(expectedParameters));
  }
Ejemplo n.º 26
0
  /* sets or hides fields depending on which tab is shown */
  public void setVisibleComponents(nonHumanMgt.SelType sType) {
    boolean catTab = (sType == nonHumanMgt.SelType.category);

    // these only appear on the resources tab
    cbbCategory.setVisible(!catTab);
    lblSubCategory.setVisible(!catTab);
    cbbSubCategory.setVisible(!catTab);

    // these only appear on the categories tab
    lblMembers.setVisible(catTab);
    cbbMembers.setVisible(catTab);
    lbxSubCatItems.setVisible(catTab);
    btnAddSubCat.setVisible(catTab);
    btnRemoveSubCat.setVisible(catTab);

    // nullify lists
    if (catTab) {
      cbbCategory.setItems(null);
      cbbSubCategory.setItems(null);
    } else lbxSubCatItems.setItems(null);
  }
Ejemplo n.º 27
0
  /* saves a newly added resource to the org database */
  public boolean addResource(String name) {
    if (!_orgDataSet.isKnownNonHumanResourceName(name)) {
      String catID = (String) cbbCategory.getSelected();
      NonHumanCategory category = _orgDataSet.getNonHumanCategory(catID);
      String subCat = (String) cbbSubCategory.getSelected();

      NonHumanResource resource = _sb.getSelectedNonHumanResource();
      if (resource == null) resource = new NonHumanResource();
      resource.setName(name);
      resource.setCategory(category);
      resource.setSubCategory(subCat);
      resource.setDescription((String) txtDesc.getText());
      resource.setNotes((String) txtNotes.getText());
      String newID = _orgDataSet.addNonHumanResource(resource);
      if (_rm.successful(newID)) {
        updateSelectedResource(resource, false);
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Resource");

    return false;
  }
Ejemplo n.º 28
0
  /* fills ui with the selected resource's values */
  private void populateGUI(NonHumanResource resource, String id) {

    // selected resource is null after a selection change
    if (resource == null) {
      resource = _orgDataSet.getNonHumanResource(id);
      updateSelectedResource(resource);
    }
    if (resource != null) {
      populateSimpleFields(resource);
      NonHumanCategory category = resource.getCategory();
      String subCatName = resource.getSubCategoryName();
      if (category == null) {
        category = getFirstListedCategory(); // default
      }
      if (subCatName == null) subCatName = "None";
      if (category != null) {
        cbbCategory.setSelected(category.getID());
        _sb.setNhResourcesSubcategoryItems(getSubCategoryList(category));
        cbbSubCategory.setSelected(subCatName);
      } else _sb.setNhResourcesSubcategoryItems(null); // no categories defined
    }
    _sb.setNhResourcesSubcategoryList(null); // empty the category tab list box
  }
Ejemplo n.º 29
0
  @Test
  public void testFireDefaultSelectionEvent() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);
    final List<Event> log = new ArrayList<Event>();
    dropDown.addListener(
        SWT.DefaultSelection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            log.add(event);
          }
        });

    handler.handleNotify("DefaultSelection", new JsonObject().add("index", 2).add("text", "foo"));

    assertEquals(1, log.size());
    assertEquals(2, log.get(0).index);
    assertEquals("foo", log.get(0).text);
  }
Ejemplo n.º 30
0
 protected void clearCombos() {
   cbbCategory.setSelected(null);
   cbbSubCategory.setSelected(null);
   cbbCategory.setItems(null);
   cbbSubCategory.setItems(null);
 }