/** * Save the properties of all renderers to the specified filename. * * @param propertyFilename String */ private static void saveReportProperties(String propertyFilename) { Properties props = new Properties(); for (Renderer renderer : ReportManager.instance.allRenderers()) { Map<PropertyDescriptor<?>, Object> valuesByProp = renderer.getPropertiesByPropertyDescriptor(); for (Map.Entry<PropertyDescriptor<?>, Object> entry : valuesByProp.entrySet()) { PropertyDescriptor desc = entry.getKey(); props.put(keyOf(renderer, desc), desc.asDelimitedString(entry.getValue())); } } FileOutputStream fos = null; try { fos = new FileOutputStream(propertyFilename); props.storeToXML(fos, "asdf"); } catch (Exception e) { e.printStackTrace(); } finally { IOUtil.closeQuietly(fos); } }
/** * Load the properties for all renderers from the specified filename. Return whether we succeeded * or not. * * @param propertyFilename String * @return boolean */ private static boolean loadReportProperties(String propertyFilename) { Properties props = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(propertyFilename); props.loadFromXML(fis); } catch (Exception e) { return false; } finally { IOUtil.closeQuietly(fis); } for (Renderer renderer : ReportManager.instance.allRenderers()) { for (PropertyDescriptor pDesc : renderer.getPropertyDescriptors()) { String key = keyOf(renderer, pDesc); if (props.containsKey(key)) { Object value = pDesc.valueFrom((String) props.get(key)); renderer.setProperty(pDesc, value); } } } return true; }
/** Only add a new widget row if there are any remaining choices to make */ @Override protected boolean canAddNewRowFor(PropertyDescriptor<?> desc, PropertySource source) { Object[] choices = desc.choices(); Object[] values = (Object[]) source.getProperty(desc); return choices.length > values.length; }
public boolean usesDefaultValues() { List<PropertyDescriptor<?>> descriptors = getOverriddenPropertyDescriptors(); if (!descriptors.isEmpty()) { return false; } for (PropertyDescriptor<?> desc : descriptors) { if (!isSame(desc.defaultValue(), getProperty(desc))) { return false; } } if (!getRule().usesDefaultValues()) { return false; } return true; }
/** * Derive a map key for the renderer, descriptor pair. * * @param renderer Renderer * @param desc PropertyDescriptor<?> * @return String */ private static String keyOf(Renderer renderer, PropertyDescriptor<?> desc) { return renderer.getName() + "__" + desc.name(); }