示例#1
0
 // Utility method to make sure a task is executed on the Swing display
 // thread.
 private void invokeAndWait(Runnable aRunnable) {
   if (!SwingUtilities.isEventDispatchThread()) {
     try {
       SwingUtilities.invokeAndWait(aRunnable);
     } catch (Exception e) {
       e.printStackTrace();
     }
   } else {
     aRunnable.run();
   }
 }
  private void onOK() {

    if (nameTextField.getText().length() < 3
        || nameTextField.getText().length() > 24
        || !nameTextField.getText().matches("[a-z0-9]+")) {
      JOptionPane.showMessageDialog(
          this,
          "Invalid storage account name. The name should be between 3 and 24 characters long and \n"
              + "can contain only lowercase letters and numbers.",
          "Error creating the storage account",
          JOptionPane.ERROR_MESSAGE);
      return;
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    createProgressBar.setVisible(true);

    try {
      String name = nameTextField.getText();
      String region =
          (regionOrAffinityGroupComboBox.getSelectedItem() instanceof Location)
              ? regionOrAffinityGroupComboBox.getSelectedItem().toString()
              : "";
      String affinityGroup =
          (regionOrAffinityGroupComboBox.getSelectedItem() instanceof AffinityGroup)
              ? regionOrAffinityGroupComboBox.getSelectedItem().toString()
              : "";
      String replication = replicationComboBox.getSelectedItem().toString();

      storageAccount =
          new StorageAccount(
              name, replication, region, affinityGroup, "", subscription.getId().toString());
      AzureSDKManagerImpl.getManager().createStorageAccount(storageAccount);
      AzureSDKManagerImpl.getManager().refreshStorageAccountInformation(storageAccount);

      onCreate.run();
    } catch (AzureCmdException e) {
      storageAccount = null;
      UIHelper.showException(
          "An error occurred while trying to create the specified storage account.",
          e,
          "Error Creating Storage Account",
          false,
          true);
    }

    setCursor(Cursor.getDefaultCursor());

    this.setVisible(false);
    dispose();
  }
示例#3
0
 private void showSaveConfirmationIfNecessaryAndRun(
     String message, String title, Runnable runnable) {
   if (!mHasEdits) {
     runnable.run();
   } else {
     int result =
         JOptionPane.showConfirmDialog(
             SpreadsheetFrame.this,
             message,
             title,
             JOptionPane.YES_NO_CANCEL_OPTION,
             JOptionPane.WARNING_MESSAGE);
     switch (result) {
       case JOptionPane.YES_OPTION:
         if (saveToDisk(false)) {
           runnable.run();
         }
         break;
       case JOptionPane.NO_OPTION:
         runnable.run();
         break;
     }
   }
 }
示例#4
0
  @Override
  @SuppressWarnings("SSBasedInspection")
  protected void dispose() {
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    for (Runnable runnable : myDisposeActions) {
      runnable.run();
    }
    myDisposeActions.clear();
    final JRootPane root = myDialog.getRootPane();

    Runnable disposer =
        new Runnable() {
          @Override
          public void run() {
            myDialog.dispose();
            myProject = null;

            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (myDialog != null && root != null) {
                      myDialog.remove(root);
                    }
                  }
                });
          }
        };

    if (EventQueue.isDispatchThread()) {
      disposer.run();
    } else {
      SwingUtilities.invokeLater(disposer);
    }
  }
示例#5
0
  /** simply dump status info to the textarea */
  private void sout(final String s) {
    Runnable soutRunner =
        new Runnable() {
          public void run() {
            if (ttaStatus.getText().equals("")) {
              ttaStatus.setText(s);
            } else {
              ttaStatus.setText(ttaStatus.getText() + "\n" + s);
            }
          }
        };

    if (ThreadUtils.isInEDT()) {
      soutRunner.run();
    } else {
      SwingUtilities.invokeLater(soutRunner);
    }
  }
  public void showAddSharesDialog() {
    // Define this as a runnable as we might need to login first
    Runnable flarp =
        new CatchingRunnable() {
          @Override
          public void doRun() throws Exception {
            JFileChooser fc = new JFileChooser();
            fc.setFileFilter(
                new javax.swing.filechooser.FileFilter() {
                  public boolean accept(File f) {
                    if (f.isDirectory()) return true;
                    return "mp3".equalsIgnoreCase(FileUtil.getFileExtension(f));
                  }

                  public String getDescription() {
                    return "MP3 files";
                  }
                });
            fc.setMultiSelectionEnabled(true);
            fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int retVal = fc.showOpenDialog(RobonoboFrame.this);
            if (retVal == JFileChooser.APPROVE_OPTION) {
              final File[] selFiles = fc.getSelectedFiles();
              control
                  .getExecutor()
                  .execute(
                      new CatchingRunnable() {
                        public void doRun() throws Exception {
                          importFilesOrDirectories(Arrays.asList(selFiles));
                        }
                      });
            }
          }
        };
    if (control.getMyUser() != null) flarp.run();
    else showLogin(flarp);
  }