/** * Creates a generic element by copying an existing element. * * @param element the element to copy * @param factory the object factory to be used for creating sub objects */ public JRBaseGenericElement(JRGenericElement element, JRBaseObjectFactory factory) { super(element, factory); this.genericType = element.getGenericType(); this.evaluationTimeValue = element.getEvaluationTimeValue(); this.evaluationGroupName = element.getEvaluationGroupName(); JRGenericElementParameter[] elementParameters = element.getParameters(); this.parameters = new ArrayList<JRGenericElementParameter>(elementParameters.length); for (int i = 0; i < elementParameters.length; i++) { JRGenericElementParameter elementParameter = elementParameters[i]; JRGenericElementParameter parameter = factory.getGenericElementParameter( elementParameter); this.parameters.add(parameter); } }
/** * Removes a parameter by name from the element. * * @param parameterName the name of the parameter to remove * @return the removed parameter, or <code>null</code> if not found */ public JRGenericElementParameter removeParameter(String parameterName) { JRGenericElementParameter removed = null; for (ListIterator<JRGenericElementParameter> it = parameters.listIterator(); it.hasNext();) { JRGenericElementParameter parameter = it.next(); if (parameter.getName() != null && parameter.getName().equals(parameterName)) { removed = parameter; it.remove(); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_PARAMETERS, parameter, it.nextIndex()); break; } } return removed; }
protected void evaluateElement(byte evaluation) throws JRException { evaluateProperties(evaluation); evaluateStyle(evaluation); parameterValues.clear(); for (int i = 0; i < parameters.length; i++) { JRGenericElementParameter parameter = parameters[i]; Object value = null; JRExpression valueExpression = parameter.getValueExpression(); if (valueExpression != null) { value = evaluateExpression(valueExpression, evaluation); } if (value != null || !parameter.isSkipWhenEmpty()) { parameterValues.put(parameter.getName(), value); } } }
/** Creates new form SubreportParametersPanel */ public GenericElementParametersPanel() { initComponents(); jTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null && value instanceof JRGenericElementParameter) { label.setText( ((JRGenericElementParameter)value).getName() ); } return label; } }); javax.swing.DefaultListSelectionModel dlsm = (javax.swing.DefaultListSelectionModel)this.jTable.getSelectionModel(); dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent e) { jTableSelectionValueChanged(e); } }); }
/** * Creates a generic element parameter by copying an existing instance. * * @param parameter the parameter to copy * @param factory the object factory to be used for creating sub objects */ public JRBaseGenericElementParameter(JRGenericElementParameter parameter, JRBaseObjectFactory factory) { this.name = parameter.getName(); this.valueExpression = factory.getExpression(parameter.getValueExpression()); this.skipWhenEmpty = parameter.isSkipWhenEmpty(); factory.put(parameter, this); }
protected static void addGenericElementRules(Digester digester) { String genericElementPattern = "*/" + JRXmlConstants.ELEMENT_genericElement; digester.addFactoryCreate(genericElementPattern, JRGenericElementFactory.class); digester.addSetNext(genericElementPattern, "addElement", JRDesignElement.class.getName()); String genericElementTypePattern = genericElementPattern + "/" + JRXmlConstants.ELEMENT_genericElementType; digester.addFactoryCreate(genericElementTypePattern, JRGenericElementTypeFactory.class); digester.addSetNext(genericElementTypePattern, "setGenericType", JRGenericElementType.class.getName()); String genericElementParameterPattern = genericElementPattern + "/" + JRXmlConstants.ELEMENT_genericElementParameter; digester.addFactoryCreate(genericElementParameterPattern, JRGenericElementParameterFactory.class); digester.addSetNext(genericElementParameterPattern, "addParameter", JRGenericElementParameter.class.getName()); String genericElementParameterExpressionPattern = genericElementParameterPattern + "/" + JRXmlConstants.ELEMENT_genericElementParameter_valueExpression; @SuppressWarnings("deprecation") Class<?> depArbitraryExprFactory = JRExpressionFactory.ArbitraryExpressionFactory.class; digester.addFactoryCreate(genericElementParameterExpressionPattern, depArbitraryExprFactory); digester.addSetNext(genericElementParameterExpressionPattern, "setValueExpression", JRExpression.class.getName()); digester.addCallMethod(genericElementParameterExpressionPattern, "setText", 0); }
/** * * protected XmlNamespace getNamespace() { return JASPERREPORTS_NAMESPACE; } /** * */ public void writeGenericElement( JRGenericElement element, String elementName) { write( "JRDesignGenericElement " + elementName + " = new JRDesignGenericElement(jasperDesign);\n"); write( elementName + ".setEvaluationTime({0});\n", element.getEvaluationTimeValue(), EvaluationTimeEnum.NOW); write( elementName + ".setEvaluationGroup(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(element.getEvaluationGroupName())); writeReportElement( element, elementName); JRGenericElementType printKey = element.getGenericType(); // JRGenericElementType t = new JRGenericElementType(printKey.getNamespace(), printKey.getName()); write( "JRGenericElementType " + elementName + "Type = new JRGenericElementType(\"" + JRStringUtil.escapeJavaStringLiteral(printKey.getNamespace()) + "\", \"" + JRStringUtil.escapeJavaStringLiteral(printKey.getName()) + "\");\n"); write( elementName + ".setGenericType(" + elementName + "Type);\n"); flush();//genericElementType JRGenericElementParameter[] params = element.getParameters(); for (int i = 0; i < params.length; i++) { JRGenericElementParameter param = params[i]; String paramName = elementName + "Parameter" + i; write( "JRDesignGenericElementParameter " + paramName + " = new JRDesignGenericElementParameter();\n"); write( paramName + ".setName(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(param.getName())); write( paramName + ".setSkipWhenEmpty({0});\n", param.isSkipWhenEmpty(), false); writeExpression(param.getValueExpression(), paramName, "ValueExpression"); write( elementName + ".addParameter({0});\n", paramName); flush();//genericElementParameter } flush();//genericElement }
/** * Adds a parameter to the element. * * @param parameter the parameter to add. * @see #getParameters() */ public void addParameter(JRGenericElementParameter parameter) { this.parameters.add(parameter); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_PARAMETERS, parameter, parameters.size() - 1); }
/** * Removes a parameter from the element. * * @param parameter the parameter to remove * @return whether the parameter has been found and removed */ public boolean removeParameter(JRGenericElementParameter parameter) { int idx = parameters.indexOf(parameter); if (idx >= 0) { parameters.remove(idx); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_PARAMETERS, parameter, idx); return true; } return false; }
@Override protected void collectDelayedEvaluations() { super.collectDelayedEvaluations(); for (int i = 0; i < parameters.length; i++) { JRGenericElementParameter parameter = parameters[i]; collectDelayedEvaluations(parameter.getValueExpression()); } }
public String getColumnText(Object element, int columnIndex) { switch (columnIndex) { case 0: return ((JRGenericElementParameter) element).getName(); case 1: JRGenericElementParameter value2 = (JRGenericElementParameter) element; if (value2 != null && value2.getValueExpression() != null) return value2.getValueExpression().getText(); break; case 2: return Boolean.toString(((JRGenericElementParameter) element).isSkipWhenEmpty()); } return ""; //$NON-NLS-1$ }
@Override public void dispose() { // clear all properties List<JRGenericElementParameter> props = (List<JRGenericElementParameter>) tableViewer.getInput(); value = new ParameterDTO(); value.setValue(props.toArray(new JRGenericElementParameter[props.size()])); super.dispose(); }
@Override public void setPropertyValue(Object id, Object value) { JRDesignGenericElement jrElement = (JRDesignGenericElement) getValue(); JRGenericElementType genericType = jrElement.getGenericType(); if (id.equals(JRDesignGenericElement.PROPERTY_EVALUATION_TIME)) jrElement.setEvaluationTime((EvaluationTimeEnum) evaluationTimeD.getEnumValue(value)); else if (id.equals(JRDesignGenericElement.PROPERTY_EVALUATION_GROUP_NAME)) jrElement.setEvaluationGroupName((String) value); else if (id.equals(JRDesignGenericElement.PROPERTY_PARAMETERS)) { if (value instanceof ParameterDTO) { ParameterDTO v = (ParameterDTO) value; if (jrElement.getParameters() != null) for (JRGenericElementParameter prm : jrElement.getParameters()) jrElement.removeParameter(prm); for (JRGenericElementParameter param : v.getValue()) jrElement.addParameter(param); propertyDTO = v; } // FIXME: in JR rewrite hashCode to work with null values for namespace and name } else if (id.equals(PROPERTY_NAME)) { String namespace = genericType != null ? genericType.getNamespace() : ""; jrElement.setGenericType(new JRGenericElementType(namespace, (String) value)); } else if (id.equals(PROPERTY_NAMESPACE)) { String name = genericType != null ? genericType.getName() : ""; jrElement.setGenericType(new JRGenericElementType((String) value, name)); } super.setPropertyValue(id, value); }
private boolean findParameter(List parameters, String name) { for (int i=0; i<parameters.size(); ++i) { JRGenericElementParameter param = (JRGenericElementParameter)parameters.get(i); if (param.getName().equals(name)) return true; } return false; }
@Override public JRGenericElementParameter[] getParameters() { return parameters.toArray(new JRGenericElementParameter[parameters.size()]); }
public void writeGenericElement(JRGenericElement element) throws IOException { if(isNewerVersionOrEqual(JRConstants.VERSION_3_1_0)) { writer.startElement(JRXmlConstants.ELEMENT_genericElement, getNamespace()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_evaluationTime, element.getEvaluationTimeValue(), EvaluationTimeEnum.NOW); if (element.getEvaluationGroupName() != null) { writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_evaluationGroup, element.getEvaluationGroupName()); } writeReportElement(element); writer.startElement(JRXmlConstants.ELEMENT_genericElementType); JRGenericElementType printKey = element.getGenericType(); if (printKey != null) { writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_namespace, printKey.getNamespace()); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, printKey.getName()); } writer.closeElement();//genericElementType JRGenericElementParameter[] params = element.getParameters(); for (int i = 0; i < params.length; i++) { JRGenericElementParameter param = params[i]; writer.startElement(JRXmlConstants.ELEMENT_genericElementParameter); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, param.getName()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_skipWhenNull, param.isSkipWhenEmpty(), false); JRExpression valueExpression = param.getValueExpression(); if (valueExpression != null) { writeExpression(JRXmlConstants.ELEMENT_genericElementParameter_valueExpression, valueExpression, true, Object.class.getName()); } writer.closeElement();//genericElementParameter } writer.closeElement();//genericElement } }
protected void verifyGenericElement(JRGenericElement element) { verifyReportElement(element); if (element.getEvaluationTimeValue() == EvaluationTimeEnum.GROUP) { String groupName = element.getEvaluationGroupName(); if (groupName == null) { addBrokenRule("Evaluation group not set for generic element", element); } else { if (!jasperDesign.getGroupsMap().containsKey(groupName)) { addBrokenRule("Generic element evaluation group " + groupName + " not found in report", element); } } } JRGenericElementType type = element.getGenericType(); if (type == null) { addBrokenRule("No type set for generic element", element); } else { if (type.getNamespace() == null) { addBrokenRule("No namespace set for generic element type", type); } if (type.getName() == null) { addBrokenRule("No name set for generic element type", type); } } JRGenericElementParameter[] parameters = element.getParameters(); for (int i = 0; i < parameters.length; i++) { JRGenericElementParameter parameter = parameters[i]; if (parameter.getName() == null) { addBrokenRule("No name set for generic element parameter", parameter); } } }
/** * @deprecated Replaced by {@link #getParametersList()}. */ public List<JRGenericElementParameter> getParamtersList() { return getParametersList(); }
@Override public JRGenericElementParameter[] getParameters() { return parameters; }
public JRGenericElementParameter[] getValue() { return value; }
public void setValue(JRGenericElementParameter[] value) { this.value = value; }
private void fillTable(Table table) { List<JRGenericElementParameter> lst = new ArrayList<JRGenericElementParameter>(); if (value.getValue() != null) lst.addAll(Arrays.asList(value.getValue())); tableViewer.setInput(lst); }
protected JRGenericElementParameter getGenericElementParameterExpression(DRIDesignParameterExpression parameterExpression) { JRDesignGenericElementParameter jrParameterExpression = new JRDesignGenericElementParameter(); jrParameterExpression.setName(parameterExpression.getName()); jrParameterExpression.setValueExpression(getExpression(parameterExpression.getValueExpression())); return jrParameterExpression; }
/** * Exposes the internal list of element parameters. * * @return the list of element parameters * @see #getParameters() */ public List<JRGenericElementParameter> getParametersList() { return parameters; }