@Test
 public void getFromPrimitiveCollectionInteger() {
   Container container =
       ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new Integer[] {1, 2, 3}));
   assertNotNull(container);
   assertEquals(3, container.size());
   for (Object object : container.getItemIds()) {
     assertTrue(object instanceof Integer);
   }
 }
 @Test
 public void getFromPrimitiveCollectionDouble() {
   Container container =
       ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new Double[] {1d, 2d, 3d}));
   assertNotNull(container);
   assertEquals(3, container.size());
   for (Object object : container.getItemIds()) {
     assertTrue(object instanceof Double);
   }
 }
Beispiel #3
0
 private void addContainerproperties() {
   /* Create HierarchicalContainer container */
   container.addContainerProperty(SPUILabelDefinitions.NAME, Link.class, null);
   container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null);
   container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, Date.class, null);
   container.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, Date.class, null);
   container.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null);
   container.addContainerProperty(
       SPUILabelDefinitions.AUTO_ASSIGN_DISTRIBUTION_SET, String.class, null);
 }
 @Test
 public void getFromPrimitiveCollectionString() {
   Container container =
       ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new String[] {"a", "b", "c"}));
   assertNotNull(container);
   assertEquals(3, container.size());
   for (Object object : container.getItemIds()) {
     assertTrue(object instanceof String);
   }
 }
 @Test
 public void addContainerPropertyMetadata() {
   Container container = new IndexedContainer();
   PropertyMetadata metadata =
       new PropertyMetadata("propertyName", String.class, null, "propertyName");
   ContainerUtils.addContainerProperty(container, metadata);
   assertTrue(
       "container should contains a property 'propertyName'",
       container.getContainerPropertyIds().contains(metadata.getPropertyName()));
   assertEquals(String.class, container.getType("propertyName"));
 }
  @Override
  protected void doSetValue(Object source, Object value) {
    Container container = (Container) source;
    @SuppressWarnings("unchecked")
    Collection<Object> itemIds = (Collection<Object>) value;

    for (Object id : container.getItemIds().toArray()) {
      container.removeItem(id);
    }

    for (Object id : itemIds) {
      container.addItem(id);
    }
  }
 @Test
 public void initContainerIndexed() throws InstantiationException {
   try {
     Container container = ContainerUtils.initContainer(IndexedContainer.class);
     assertNotNull("container should not be null", container);
     assertTrue("container should be a Filterable", container instanceof Filterable);
     assertEquals(
         "container should be an IndexedContainer", IndexedContainer.class, container.getClass());
   } catch (IllegalAccessException e) {
     fail("Should not throw an IllegalAccessException");
   } catch (InstantiationException e) {
     fail("Should not throw an InstantiationException");
   }
 }
 private void containerReturnsPropertyWithFieldNullable(boolean nullable) {
   ColumnProperty property =
       new ColumnProperty("test", true, false, nullable, false, "1", String.class);
   when(containerMock.getItem(1)).thenReturn(itemMock);
   when(itemMock.getItemProperty("test")).thenReturn(property);
   when(containerFieldMock.isRequired()).thenReturn(!nullable);
 }
Beispiel #9
0
  /**
   * Sets the Container that serves as the data source of the viewer.
   *
   * @see com.vaadin.data.Container.Viewer#setContainerDataSource(Container)
   */
  @Override
  public void setContainerDataSource(Container newDataSource) {
    if (newDataSource == null) {
      newDataSource = new HierarchicalContainer();
    }

    // Assure that the data source is ordered by making unordered
    // containers ordered by wrapping them
    if (Container.Hierarchical.class.isAssignableFrom(newDataSource.getClass())) {
      super.setContainerDataSource(newDataSource);
    } else {
      super.setContainerDataSource(new ContainerHierarchicalWrapper(newDataSource));
    }

    /*
     * Ensure previous expanded items are cleaned up if they don't exist in
     * the new container
     */
    if (expanded != null) {
      /*
       * We need to check that the expanded-field is not null since
       * setContainerDataSource() is called from the parent constructor
       * (AbstractSelect()) and at that time the expanded field is not yet
       * initialized.
       */
      cleanupExpandedItems();
    }
  }
 @Test
 public void initContainerHierarchicalContainer() throws InstantiationException {
   try {
     Container container = ContainerUtils.initContainer(HierarchicalContainer.class);
     assertNotNull("container should not be null", container);
     assertTrue("container should be a Hierarchical", container instanceof Hierarchical);
     assertEquals(
         "container should be an HierarchicalContainer",
         HierarchicalContainer.class,
         container.getClass());
   } catch (IllegalAccessException e) {
     fail("Should not throw an IllegalAccessException");
   } catch (InstantiationException e) {
     fail("Should not throw an InstantiationException");
   }
 }
  protected void replaceToCombo(String key, String query) {
    Container container = new HierarchicalContainer();
    container.addContainerProperty("id", String.class, "");
    String defaultValue = null;
    try {
      Connection connection = DriverManager.getConnection("jdbc:sqlite:ivan.db3");
      try {
        ResultSet rs = connection.createStatement().executeQuery(query);
        while (rs.next()) {
          defaultValue = rs.getString(1);
          container.addItem(defaultValue).getItemProperty("id").setValue(defaultValue);
        }
      } finally {
        connection.close();
      }
    } catch (Exception ex) {

    }

    replaceToCombo(key, container, defaultValue);
  }
  public void displayReport(Filter filter, Map<String, Object> parameters) {
    // TODO make the report generation asynchronous and display the first page when it is ready
    // and not after last
    // page is ready
    currentParameters = parameters;

    // Load template
    ReportDefinition rd = (ReportDefinition) getReportSelection().getValue();
    String path = getFullPath(rd);
    jasperReport = reportGenerator.loadTemplate(path);

    // Set parameters
    Map<String, Object> params = JRUtils.createParametersFromFilter(jasperReport, filter);
    params.putAll(currentParameters);
    currentParameters.putAll(params);

    // Set datasource
    jrDataSource = null;
    if (!rd.requiresDatabaseConnection()) {
      if (container instanceof Indexed) {
        jrDataSource = new JRIndexedContainerDataSource((Indexed) container);
      } else {
        jrDataSource = new JRContainerDataSource(container);
      }
    }

    // Generate report
    reportGenerator.setShowMargins(showMargins.getValue());
    String html =
        reportGenerator.executeReportAsHtml(
            jasperReport,
            params,
            jrDataSource,
            ((WrappedHttpSession) VaadinSession.getCurrent().getSession()).getHttpSession(),
            VaadinSession.getCurrent().getLocale());
    if (html == null || "".equals(html) || (container != null && container.size() <= 0)) {
      reportArea.setValue(getMessageService().getMessage(NO_DATA_FOUND_KEY));
      exportPDF.setEnabled(false);
    } else {
      if (rd.requiresExternalScript()) {
        VaadinUtils.loadScript(REPORT_AREA_ID, html, rd.requiresExternalScript(), alreadyLoaded);

        // only load external script for the map
        alreadyLoaded = true;
      } else {
        reportArea.setValue(html);
      }
      exportPDF.setEnabled(true);
    }
  }
  protected void replaceToCombo(String key, Container container, String defaultValue) {
    final TextField field = (TextField) map.get(key);
    HorizontalLayout layout = (HorizontalLayout) field.getParent();
    field.setVisible(false);
    final ComboBox comboBox = new ComboBox("", container);
    comboBox.setImmediate(true);
    comboBox.setNullSelectionAllowed(false);

    comboBox.addValueChangeListener(
        new Property.ValueChangeListener() {
          @Override
          public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            field.setValue((String) comboBox.getValue());
          }
        });

    if (container.containsId(field.getValue())) {
      comboBox.select(field.getValue());
    } else {
      field.setValue(defaultValue);
      comboBox.select(defaultValue);
    }
    layout.addComponent(comboBox, 1);
  }
 @Override
 protected Object doGetValue(Object source) {
   Container container = (Container) source;
   return new ArrayList<Object>(container.getItemIds());
 }
 private Resource getResource(final Object itemId) {
   final Container container = this.getContainerDataSource();
   final BeanItem<Resource> item = (BeanItem<Resource>) container.getItem(itemId);
   return (item != null) ? item.getBean() : null;
 }
 @Test
 public void getFromPrimitiveCollectionEmpty() {
   Container container = ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new String[] {}));
   assertNotNull(container);
   assertEquals(0, container.size());
 }