Package javax.swing

Examples of javax.swing.SwingWorker$DoSubmitAccumulativeRunnable


      if ((archiveId.equals(""))) {
        JOptionPane.showMessageDialog(null,
            "Enter the Archive ID of the file to be requested.",
            "Error", JOptionPane.ERROR_MESSAGE);
      } else {
        SwingWorker downloadWorker = new SwingWorker() {

          private String archiveId = jtfDownloadField.getText()
              .trim();

          @Override
          protected Object doInBackground() throws Exception {

            // Create dumb progressbar
            JFrame downloadFrame = new JFrame("Downloading");
            {
              downloadFrame
                  .setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              final JProgressBar dumJProgressBar = new JProgressBar(
                  JProgressBar.HORIZONTAL);
              dumJProgressBar.setIndeterminate(true);
              downloadFrame.add(dumJProgressBar,
                  BorderLayout.NORTH);
              downloadFrame.setSize(300, 60);
            }
            centerDefineFrame(downloadFrame, 300, 50);

            String archiveId = jtfDownloadField.getText().trim();
            try {
              String vaultName = dlVault;

              FileDialog fd = new FileDialog(new Frame(),
                  "Save Archive As...", FileDialog.SAVE);
              fd.setFile("Save Archive As...");
              fd.setDirectory(System.getProperty("user.dir"));
              fd.setLocation(50, 50);
              fd.setVisible(true);

              String filePath = "" + fd.getDirectory()
                  + System.getProperty("file.separator")
                  + fd.getFile();

              File outFile = new File(filePath);

              if (outFile != null) {
                downloadFrame.setTitle("Downloading "
                    + outFile.toString());
                downloadFrame.setVisible(true);

                Endpoints notificationEP = new Endpoints(
                    locationChoice);

                AmazonSQSClient dlSQS = new AmazonSQSClient(
                    dlCredentials);
                AmazonSNSClient dlSNS = new AmazonSNSClient(
                    dlCredentials);

                dlSQS.setEndpoint(notificationEP.sqsEndpoint());
                dlSNS.setEndpoint(notificationEP.snsEndpoint());

                // ArchiveTransferManager atm = new
                // ArchiveTransferManager(dlClient,
                // dlCredentials);
                ArchiveTransferManager atm = new ArchiveTransferManager(
                    dlClient, dlSQS, dlSNS);

                atm.download("-", vaultName, archiveId, outFile);

                JOptionPane.showMessageDialog(
                    null,
                    "Sucessfully downloaded "
                        + outFile.toString(),
                    "Success",
                    JOptionPane.INFORMATION_MESSAGE);
                downloadFrame.setVisible(false);
              }
            } catch (AmazonServiceException k) {
              JOptionPane
                  .showMessageDialog(
                      null,
                      "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.",
                      "Error", JOptionPane.ERROR_MESSAGE);
              System.out.println("" + k);
              downloadFrame.setVisible(false);
            } catch (AmazonClientException i) {
              JOptionPane
                  .showMessageDialog(
                      null,
                      "Client Error. Check that all fields are correct. Archive not downloaded.",
                      "Error", JOptionPane.ERROR_MESSAGE);
              downloadFrame.setVisible(false);
            } catch (Exception j) {
              JOptionPane.showMessageDialog(null,
                  "Archive not found. Unspecified Error.",
                  "Error", JOptionPane.ERROR_MESSAGE);
              downloadFrame.setVisible(false);
            }
            return null;
          }
        };
        downloadWorker.execute();
        try {
          Thread.sleep(500);
        } catch (InterruptedException e1) {
          e1.printStackTrace();
        }
View Full Code Here


      if ((checkAllFields()) && (checkForFile())) {

        SaveCurrentProperties(accessString, secretString, vaultString,
            locationChoice.getSelectedIndex());

        SwingWorker uploadWorker = new SwingWorker() {

          @Override
          protected Object doInBackground() throws Exception {
            String accessString = getAccessField();
            String secretString = getSecretField();
            // String vaultString = getVaultField();
            String vaultName = getVaultField();
            File[] uploadFileBatch = multiFiles;

            // work out exactly how much we are going to upload
            // so we can support a second total upload progress bar
            long totalSize = 0;
            long uploadedSize = 0;
            for (File f : uploadFileBatch) {
              totalSize += f.length();
            }

            int locInt = locationChoice.getSelectedIndex();
            multiFiles = null;
            clearFile();
            UploadWindow uw = new UploadWindow();

            if (uploadFileBatch.length > 0) {

              ArrayList<String> uploadList = new ArrayList<String>();

              for (int i = 0; i < uploadFileBatch.length; i++) {
                // Save Current Settings to properties

                try {
                  Thread.sleep(100L);
                } catch (InterruptedException e1) {
                  e1.printStackTrace();
                }

                ClientConfiguration config = new ClientConfiguration();
                config.setSocketTimeout(SOCKET_TIMEOUT);
                config.setMaxErrorRetry(MAX_RETRIES);

                BasicAWSCredentials credentials = new BasicAWSCredentials(
                    accessString, secretString);
                client = new AmazonGlacierClient(credentials,
                    config);
                Endpoints ep = new Endpoints(locInt);
                // String endpointUrl = ep.Endpoint(locInt);
                client.setEndpoint(ep.Endpoint());
                String locationUpped = ep.Location();
                String thisFile = uploadFileBatch[i]
                    .getCanonicalPath();
                String cleanFile = regexClean(thisFile);

                // char emptyChar = 0xFFFA;
                // String thisCleanFile =
                // thisFile.valueOf(emptyChar).replaceAll("\\p{C}",
                // "?");

                try {

                  ArchiveTransferManager atm = new ArchiveTransferManager(
                      client, credentials);

                  String fileLength = Long
                      .toString(uploadFileBatch[i]
                          .length());

                  uw.setTitle("(" + (i + 1) + "/"
                      + uploadFileBatch.length + ")"
                      + " Uploading: " + thisFile);

                  UploadResult result = atm.upload(vaultName,
                      cleanFile, uploadFileBatch[i]);

                  uw.addToLog("Done: " + thisFile + "\n");

                  uploadedSize += uploadFileBatch[i].length();

                  int percentage = (int) (((double) uploadedSize / totalSize) * 100);

                  uw.updateProgress(percentage);

                  Writer plainOutputLog = null;
                  Writer plainOutputTxt = null;
                  Writer plainOutputCsv = null;

                  // write to file
                  if (logCheckMenuItem.isSelected()) {
                    String treeHash = TreeHashGenerator
                        .calculateTreeHash(uploadFileBatch[i]);

                    try {
                      plainOutputLog = new BufferedWriter(
                          new FileWriter(
                              getLogFilenamePath(0),
                              true));
                      plainOutputTxt = new BufferedWriter(
                          new FileWriter(
                              getLogFilenamePath(1),
                              true));
                      plainOutputCsv = new BufferedWriter(
                          new FileWriter(
                              getLogFilenamePath(2),
                              true));

                    } catch (IOException ex) {
                      JOptionPane.showMessageDialog(null,
                          LOG_CREATION_ERROR,
                          "IO Error",
                          JOptionPane.ERROR_MESSAGE);
                      uw.dispose();
                      System.exit(1);
                    }

                    try {

                      Date d = new Date();

                      String thisResult = result
                          .getArchiveId();

                      plainOutputLog
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputLog
                          .write(" | ArchiveID: "
                              + thisResult + " ");
                      plainOutputLog
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputLog.write(" | File: "
                          + thisFile + " ");
                      plainOutputLog.write(" | Bytes: "
                          + fileLength + " ");
                      plainOutputLog.write(" | Vault: "
                          + vaultName + " ");
                      plainOutputLog
                          .write(" | Location: "
                              + locationUpped
                              + " ");
                      plainOutputLog.write(" | Date: "
                          + d.toString() + " ");
                      plainOutputLog.write(" | Hash: "
                          + treeHash + " ");
                      plainOutputLog
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputLog.close();

                      plainOutputTxt
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputTxt
                          .write(" | ArchiveID: "
                              + thisResult + " ");
                      plainOutputTxt
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputTxt.write(" | File: "
                          + thisFile + " ");
                      plainOutputTxt.write(" | Bytes: "
                          + fileLength + " ");
                      plainOutputTxt.write(" | Vault: "
                          + vaultName + " ");
                      plainOutputTxt
                          .write(" | Location: "
                              + locationUpped
                              + " ");
                      plainOutputTxt.write(" | Date: "
                          + d.toString() + " ");
                      plainOutputTxt.write(" | Hash: "
                          + treeHash + " ");
                      plainOutputTxt
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputTxt.close();

                      plainOutputCsv.write(""
                          + thisResult + ",");
                      plainOutputCsv.write("" + thisFile
                          + ",");
                      plainOutputCsv.write(""
                          + fileLength + ",");
                      plainOutputCsv.write("" + vaultName
                          + ",");
                      plainOutputCsv.write(""
                          + locationUpped + ",");
                      plainOutputCsv.write(""
                          + d.toString() + ",");
                      plainOutputCsv.write("" + treeHash
                          + ",");
                      plainOutputCsv
                          .write(System
                              .getProperty("line.separator"));
                      plainOutputCsv.close();

                      uploadList
                          .add("Successfully uploaded "
                              + thisFile
                              + " to vault "
                              + vaultName
                              + " at "
                              + locationUpped
                              + ". Bytes: "
                              + fileLength
                              + ". ArchiveID Logged.\n");
                    }

                    // v0.4 logging code
                    // output.writeUTF("ArchiveID: " +
                    // thisResult + " ");
                    // output.writeUTF(" | File: " +
                    // thisFile + " ");
                    // output.writeUTF(" | Vault: "
                    // +vaultName + " ");
                    // output.writeUTF(" | Location: " +
                    // locationUpped + " ");
                    // output.writeUTF(" | Date: "+d.toString()+"\n\n");
                    catch (IOException c) {
                      JOptionPane.showMessageDialog(null,
                          LOG_WRITE_ERROR,
                          "IO Error",
                          JOptionPane.ERROR_MESSAGE);
                      uw.dispose();
                      System.exit(1);
                    }

                  } else {
                    JOptionPane
                        .showMessageDialog(
                            null,
                            "Upload Complete!\nArchive ID: "
                                + result.getArchiveId()
                                + "\nIt may take some time for Amazon to update the inventory.",
                            "Uploaded",
                            JOptionPane.INFORMATION_MESSAGE);
                    multiFiles = null;
                    uw.dispose();
                  }

                  clearFile();

                } catch (Exception h) {
                  if (logCheckMenuItem.isSelected()) {
                    writeToErrorLog(h, thisFile);
                  }
                  JOptionPane.showMessageDialog(null, "" + h,
                      "Error", JOptionPane.ERROR_MESSAGE);
                  uw.dispose();

                }

              }
              StringBuilder sb = new StringBuilder();
              for (int j = 0; j < uploadFileBatch.length; j++) {
                sb.append(uploadList.get(j));
              }
              uw.dispose();

              JOptionPane.showMessageDialog(null,
                  "Upload Complete! \n" + sb, "Uploaded",
                  JOptionPane.INFORMATION_MESSAGE);
              // Close the JProgressBar
              multiFiles = null;
              clearFile();
            } else {
              JOptionPane.showMessageDialog(null,
                  "This wasn't supposed to happen.", "Bug!",
                  JOptionPane.ERROR_MESSAGE);
              uw.dispose();

            }

            return null;
          }

          private void writeToErrorLog(Exception h, String thisFile) {
            String thisError = h.toString();

            Writer errorOutputLog = null;
            try {
              errorOutputLog = new BufferedWriter(new FileWriter(
                  getLogFilenamePath(3), true));
            } catch (Exception badLogCreate) {
              JOptionPane.showMessageDialog(null,
                  LOG_CREATION_ERROR, "IO Error",
                  JOptionPane.ERROR_MESSAGE);
              System.exit(1);
            }
            try {
              Date d = new Date();

              errorOutputLog.write(System
                  .getProperty("line.separator"));
              errorOutputLog.write("" + d.toString() + ": \""
                  + thisFile + "\" *ERROR* " + thisError);
              errorOutputLog.write(System
                  .getProperty("line.separator"));

            } catch (Exception badLogWrite) {
              JOptionPane.showMessageDialog(null,
                  LOG_WRITE_ERROR, "IO Error",
                  JOptionPane.ERROR_MESSAGE);
              System.exit(1);
            }
          }

        };
        uploadWorker.execute();

      }

    } else {
    }
View Full Code Here

  {
   
   
    if(e.getSource() == jbtInventoryRequest)
        {
        SwingWorker inventoryWorker = new SwingWorker() {
         
        //private String archiveId = jtfDownloadField.getText().trim();
           
        @Override
        protected Object doInBackground() throws Exception {
         
          //Create dumb progressbar
          Date d = new Date();
            JFrame inventoryFrame = new JFrame("Waiting for inventory"); {
            inventoryFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            Calendar cal = Calendar.getInstance();
              cal.setTime(d);
              cal.add(Calendar.MINUTE, 250);             
            String doneString = cal.getTime().toString();
            JLabel doneTimeLabel = new JLabel("<html><body>Inventory of vault "+irVault+" requested.<br>Estimated completion by " + doneString + "</html></body>");
            final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
            dumJProgressBar.setIndeterminate(true);
            inventoryFrame.add(dumJProgressBar, BorderLayout.NORTH);
            inventoryFrame.add(doneTimeLabel, BorderLayout.CENTER);
            inventoryFrame.setBackground(wc);
            inventoryFrame.setSize(300, 60);}
            centerDefineFrame(inventoryFrame, 500, 100);
            inventoryFrame.setVisible(true);
         
          try
          {
          JobParameters jParameters = new JobParameters()
            .withType("inventory-retrieval");
         
            InitiateJobRequest initJobRequest = new InitiateJobRequest()
              .withVaultName(irVault)
              .withJobParameters(jParameters);
           
            InitiateJobResult initJobResult = irClient.initiateJob(initJobRequest);
            String thisJobId = initJobResult.getJobId();
           
            Thread.sleep(12600000);
           
            Boolean success = waitForJob(irClient, irVault, thisJobId);
           
            while ( success == false )
            {
              Thread.sleep(WAIT_TIME);
              success = waitForJob(irClient, irVault, thisJobId);
            }
           
            GetJobOutputRequest gjoRequest = new GetJobOutputRequest()
              .withVaultName(irVault)
              .withJobId(thisJobId);
            GetJobOutputResult gjoResult = irClient.getJobOutput(gjoRequest);
           
            Format formatter = new SimpleDateFormat("yyyyMMMdd_HHmmss");
            String fileDate = formatter.format(d);
           
            String fileName =  irVault + fileDate + ".txt";
               
            String filePath = ""+curDir+System.getProperty("file.separator")+fileName;
           
            FileWriter fileStream = new FileWriter(filePath);
             
            BufferedWriter out = new BufferedWriter(fileStream);
                       
            BufferedReader in = new BufferedReader(new InputStreamReader(gjoResult.getBody()));
           
            String inputLine;
           
            while ((inputLine = in.readLine()) != null)
            {
              out.write(inputLine);
            }
            out.close();
           
            inventoryFrame.setVisible(false);
           
            JOptionPane.showMessageDialog(null,"Successfully exported " + irVault + " inventory to " + filePath.toString(), "Saved", JOptionPane.INFORMATION_MESSAGE);                   
         
            return null;
           
       
          }
          catch (AmazonServiceException k)
          {
            JOptionPane.showMessageDialog(null,"The server returned an error. Files will not be inventoried for 24 hours after upload. Also check that correct location of vault has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE);
            System.out.println(""+k);
            inventoryFrame.setVisible(false);
          }
          catch (AmazonClientException i)
          {
                JOptionPane.showMessageDialog(null,"Client Error. Check that all fields are correct. Inventory not requested.", "Error", JOptionPane.ERROR_MESSAGE);
                inventoryFrame.setVisible(false);
              }
          catch (Exception j)
          {
                JOptionPane.showMessageDialog(null,"Inventory not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE);
                inventoryFrame.setVisible(false);
              }
          return null;
          
          
          }           
          };
          inventoryWorker.execute();
          try {
          Thread.sleep(500);
        } catch (InterruptedException e1) {
          e1.printStackTrace();
        }
View Full Code Here

TOP

Related Classes of javax.swing.SwingWorker$DoSubmitAccumulativeRunnable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.