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

    assertEquals(-1, dropDown.getSelectionIndex());
  }
예제 #2
0
  @Test
  public void testHide_SetsVisible() {
    dropDown.setVisible(true);
    dropDown.setVisible(false);

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

    assertTrue(Arrays.equals(items, dropDown.getItems()));
  }
예제 #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));
  }
예제 #5
0
  @Test
  public void testProcessSetVisible_ValueIsFalse() {
    dropDown.setVisible(true);

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

    assertFalse(dropDown.getVisible());
  }
예제 #6
0
  @Test
  public void testSetSelectionIndex_RendersSelection() {
    dropDown.setItems(FOUR_ITEMS);

    dropDown.setSelectionIndex(2);

    verify(remoteObject).set("selectionIndex", 2);
  }
예제 #7
0
  @Test
  public void testSetSelectionIndex_SetsSelection() {
    dropDown.setItems(FOUR_ITEMS);

    dropDown.setSelectionIndex(2);

    assertEquals(2, dropDown.getSelectionIndex());
  }
예제 #8
0
  @Test
  public void testHide_RendersVisibleFalse() {
    dropDown.setVisible(true);

    dropDown.setVisible(false);

    verify(remoteObject).set("visible", false);
  }
예제 #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]);
  }
예제 #10
0
  @Test
  public void testSetSelectionIndex_IgnoredForTooBigValue() {
    dropDown.setItems(FOUR_ITEMS);
    dropDown.setSelectionIndex(2);

    dropDown.setSelectionIndex(4);

    assertEquals(2, dropDown.getSelectionIndex());
  }
예제 #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));
  }
예제 #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));
  }
예제 #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());
 }
예제 #14
0
  @Test
  public void testSetVisibleItemCount_DoesNotRenderVisibleItemCountIfUnchanged() {
    dropDown.setVisibleItemCount(7);
    dropDown.setVisibleItemCount(7);

    verify(remoteObject, times(1)).set("visibleItemCount", 7);
  }
예제 #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));
  }
예제 #16
0
  @Test
  public void testVisible_SetToTrueTwiceRenderVisibleOnce() {
    dropDown.setVisible(true);
    dropDown.setVisible(true);

    verify(remoteObject, times(1)).set("visible", true);
  }
예제 #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);
  }
예제 #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));
  }
예제 #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)));
  }
예제 #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));
  }
예제 #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));
  }
예제 #22
0
  @Test
  public void testAddListener_SelectionRenderListenTrue() {
    Listener listener = mock(Listener.class);

    dropDown.addListener(SWT.Selection, listener);

    verify(remoteObject).listen(eq("Selection"), eq(true));
  }
예제 #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")));
  }
예제 #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));
  }
예제 #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));
  }
예제 #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);
  }
예제 #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;
  }
예제 #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
  }
예제 #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);
  }
예제 #30
0
 protected void clearCombos() {
   cbbCategory.setSelected(null);
   cbbSubCategory.setSelected(null);
   cbbCategory.setItems(null);
   cbbSubCategory.setItems(null);
 }