1 6 7 package com.jaspersoft.jasperserver.irplugin.gui.jrxmlvalidator; 8 9 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor; 10 import it.businesslogic.ireport.gui.MainFrame; 11 import it.businesslogic.ireport.util.Misc; 12 import java.awt.Image ; 13 import javax.swing.JOptionPane ; 14 import javax.swing.SwingUtilities ; 15 16 20 public class UploadResourcesDialog extends javax.swing.JDialog implements Runnable { 21 22 private JrxmlValidationDialog validationDialog = null; 23 private java.util.List resourceItems = null; 24 25 26 public UploadResourcesDialog(java.awt.Frame parent, boolean modal) { 27 super(parent, modal); 28 initComponents(); 29 30 jProgressBar1.setMinimum(0); 31 jProgressBar1.setMaximum(100); 32 jProgressBar1.setValue(0); 33 34 Misc.centerFrame(this); 35 } 36 37 public void setLabel(String label) 38 { 39 jLabel.setText( label ); 40 } 41 42 public void setCompletation(int d) 43 { 44 jProgressBar1.setValue(d); 45 } 46 47 48 public void startProcessing() 49 { 50 Thread t = new Thread (this); 51 t.start(); 52 } 53 54 public void run() 55 { 56 jProgressBar1.setValue(0); 57 58 jLabel.setText("Adapting JRXML source..."); 59 JrxmlValidationDialog vd = getValidationDialog(); 60 61 jProgressBar1.setValue(5); 62 63 try { 64 65 for (int i=0; i< resourceItems.size(); ++i) 66 { 67 jProgressBar1.setValue(15); 68 ImageElementValidationItem iev = (ImageElementValidationItem)resourceItems.get(i); 69 Image img = iev.getReportElement().getImg(); 70 iev.getReportElement().setImageExpression("\"" + iev.getProposedExpression() + "\""); 71 iev.getReportElement().setImg( img ); 72 73 jProgressBar1.setValue(20); 74 ResourceDescriptor newDescriptor = new ResourceDescriptor(); 75 newDescriptor.setWsType( ResourceDescriptor.TYPE_IMAGE ); 76 newDescriptor.setParentFolder( (vd.getReportUnit() != null) ? vd.getReportUnit().getDescriptor().getUriString() : "/"); 77 newDescriptor.setName( iev.getResourceName() ); 78 newDescriptor.setLabel( iev.getResourceName() ); 79 newDescriptor.setIsNew(true); 80 newDescriptor.setHasData(true); 81 82 jLabel.setText("Uploading " + iev.getOriginalFileName().getName() ); 83 vd.getServer().getWSClient().modifyReportUnitResource( 84 (vd.getReportUnit() != null) ? vd.getReportUnit().getDescriptor().getUriString() : null, 85 newDescriptor, iev.getOriginalFileName()); 86 87 jProgressBar1.setValue( (int)(100.0/(double)i)); 88 } 89 90 vd.getReport().saveXMLFile(); 91 92 } catch (Exception ex) 93 { 94 final Exception ex2 = ex; 95 ex.printStackTrace(); 96 try { 97 SwingUtilities.invokeAndWait( new Runnable (){ 98 99 public void run() 100 { 101 setVisible(false); 102 dispose(); 103 104 JOptionPane.showMessageDialog(MainFrame.getMainInstance(), "An error occurred during resource upload: " + ex2.getMessage(),"Error", 105 JOptionPane.ERROR_MESSAGE); 106 } 107 }); 108 109 } catch (Exception ex3){ 110 } 111 112 ex.printStackTrace(); 113 } 114 finally { 115 116 try { 117 SwingUtilities.invokeAndWait( new Runnable (){ 118 public void run() 119 { 120 setVisible(false); 121 dispose(); 122 } 123 }); 124 } catch (Exception ex3){ 125 } 126 } 127 getValidationDialog().elaborationFinished(true); 128 } 129 130 public void setVisible(boolean b) 131 { 132 if (b) startProcessing(); 133 super.setVisible(b); 134 } 135 136 137 142 private void initComponents() { 144 java.awt.GridBagConstraints gridBagConstraints; 145 146 jLabel = new javax.swing.JLabel (); 147 jProgressBar1 = new javax.swing.JProgressBar (); 148 149 getContentPane().setLayout(new java.awt.GridBagLayout ()); 150 151 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 152 setResizable(false); 153 jLabel.setText("Uploading resources..."); 154 gridBagConstraints = new java.awt.GridBagConstraints (); 155 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 156 gridBagConstraints.weightx = 1.0; 157 gridBagConstraints.insets = new java.awt.Insets (8, 8, 4, 8); 158 getContentPane().add(jLabel, gridBagConstraints); 159 160 jProgressBar1.setPreferredSize(new java.awt.Dimension (250, 18)); 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridx = 0; 163 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 164 gridBagConstraints.weightx = 1.0; 165 gridBagConstraints.insets = new java.awt.Insets (0, 8, 8, 8); 166 getContentPane().add(jProgressBar1, gridBagConstraints); 167 168 pack(); 169 } 171 174 public static void main(String args[]) { 175 java.awt.EventQueue.invokeLater(new Runnable () { 176 public void run() { 177 new UploadResourcesDialog(new javax.swing.JFrame (), true).setVisible(true); 178 } 179 }); 180 } 181 182 public JrxmlValidationDialog getValidationDialog() { 183 return validationDialog; 184 } 185 186 public void setValidationDialog(JrxmlValidationDialog validationDialog) { 187 this.validationDialog = validationDialog; 188 } 189 190 public java.util.List getResourceItems() { 191 return resourceItems; 192 } 193 194 public void setResourceItems(java.util.List resourceItems) { 195 this.resourceItems = resourceItems; 196 } 197 198 private javax.swing.JLabel jLabel; 200 private javax.swing.JProgressBar jProgressBar1; 201 203 } 204 | Popular Tags |