private void testAddField(String dsName, Type type) throws Exception { DataSource d = dsf.getDataSource(dsName, DataSourceFactory.EDITABLE); d.open(); Metadata m = d.getMetadata(); int fc = m.getFieldCount(); String name = "toto"; int i = 0; while (m.getFieldIndex(name + "_" + i) != -1) { i++; } // System.out.println(fc + " fields"); // System.out.println("adding " + name + "_" + i); d.addField(name + "_" + i, type); d.commit(); d.close(); d.open(); assertEquals(fc + 1, d.getMetadata().getFieldCount()); // System.out.println(d.getMetadata().getFieldCount() + " fields"); // for (int j = 0; j < d.getFieldCount(); j++) { // System.out.println(j + " field " + d.getFieldName(j)); // } // System.out.println(d.getFieldName(fc)); assertEquals(d.getFieldName(fc), name + "_" + i); assertEquals(d.getFieldType(fc).getTypeCode(), Type.STRING); assertNull(d.getFieldType(fc).getConstraintValue(Constraint.PK)); assertNull(d.getFieldType(fc).getConstraintValue(Constraint.READONLY)); d.close(); }
/** * Adds the symbol panel attached to the given {@link Symbolizer} and returns the panel. * * @param symb Symbolizer * @return The newly generated symbol panel */ private ILegendPanel addSymbolPanel(Symbolizer symb) { // Get the legend corresponding to this symbolizer. Legend legend = LegendFactory.getLegend(symb); if (legend instanceof AbstractRecodedLegend) { DataSource dataSource = layer.getDataSource(); AbstractRecodedLegend leg = (AbstractRecodedLegend) legend; try { Metadata metadata = dataSource.getMetadata(); String f = leg.getLookupFieldName(); int in = metadata.getFieldIndex(f); leg.setComparator(AbstractRecodedLegend.getComparator(metadata.getFieldType(in))); } catch (DriverException e) { LOGGER.warn("Can't retrieve an accurate Comparator for this classification"); } } // Initialize a panel for this legend. ILegendPanel panel = ILegendPanelFactory.getILegendPanel(this, legend); // Give it a new id. panel.setId(createNewID()); // Add the symbol panel to the container after putting it in a // new JScrollPane. dialogContainer.add(panel.getId(), getJScrollPane(panel)); return panel; }