1 32 33 package it.businesslogic.ireport.gui.library.objects; 34 import it.businesslogic.ireport.gui.library.*; 35 import it.businesslogic.ireport.*; 36 40 public class TotalObject extends AbstractLibraryObject { 41 42 private static javax.swing.ImageIcon defaultIcon; 43 44 static { 45 46 defaultIcon = new javax.swing.ImageIcon (AbstractLibraryObject.class.getResource("/it/businesslogic/ireport/icons/library/total.png")); 47 } 48 49 50 public TotalObject() { 51 } 52 53 public String getName() 54 { 55 return it.businesslogic.ireport.util.I18n.getString("gui.library.objects.total","Total"); 56 } 57 58 public void drop(java.awt.dnd.DropTargetDropEvent dtde) { 59 60 TotalObjectDialog tod = new TotalObjectDialog(getReportFrame().getMainFrame(), true ); 61 tod.setJrf( getReportFrame() ); 62 tod.setVisible(true); 63 if (tod.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) 64 { 65 Object obj = tod.getSelectedObject(); 66 if (obj == null) return; 67 String clazz = "java.lang.Integer"; 69 String expression = ""; 70 String tot_name =""; 71 if (obj instanceof JRField) 72 { 73 clazz = ((JRField)obj).getClassType(); 74 expression = "$F{" + obj + "}"; 75 tot_name += obj +"_"; 76 } 77 else if (obj instanceof JRParameter) 78 { 79 clazz = ((JRParameter)obj).getClassType(); 80 expression = "$P{" + obj + "}"; 81 tot_name += obj +"_"; 82 } 83 else if (obj instanceof JRVariable) 84 { 85 clazz = ((JRVariable)obj).getClassType(); 86 expression = "$V{" + obj + "}"; 87 tot_name += obj +"_"; 88 } 89 else 90 { 91 expression = "" + obj; 92 } 93 94 String var_name = "SUM_" + tot_name; 95 String time = "Report"; 96 String tmp_name = var_name; 97 java.util.Vector variables = getReportFrame().getReport().getVariables(); 99 for (int i=1; ; ++i) 100 { 101 var_name = tmp_name + i; 102 boolean found = false; 103 for (int k=0; k<variables.size(); ++k) 104 { 105 if ( ((JRVariable)variables.get(k)).getName().equals(var_name)) 106 { 107 found = true; 108 break; 109 } 110 } 111 if (!found) break; 112 } 113 114 Band b = getReportFrame().getBandAt(dtde.getLocation()); 116 JRVariable jrv = new JRVariable(var_name,false); 117 jrv.setClassType( clazz ); 118 jrv.setExpression( expression ); 119 120 if (b.getName().equals("pageFooter")) 121 { 122 time = "Page"; 123 } 124 else if (b.getName().equals("lastPageFooter")) 125 { 126 time = "Report"; 127 } 128 else if (b.getName().equals("columnFooter")) 129 { 130 time = "Column"; 131 } 132 else if (b.getName().endsWith("Footer")) 133 { 134 time = "Group"; 135 jrv.setResetGroup( b.getName().substring(0, b.getName().length() - "Footer".length() )); 136 } 137 138 jrv.setResetType( time ); 139 jrv.setCalculation("Sum"); 140 getReportFrame().getReport().addVariable( jrv ); 141 142 getReportFrame().dropNewTextField( dtde.getLocation(), "$V{" + var_name + "}", clazz, "Now" ); 143 } 144 } 145 146 public javax.swing.ImageIcon getIcon() 147 { 148 return defaultIcon; 149 } 150 151 } 152 | Popular Tags |