private static void openURL(String strURL) {
   if (Program.launch(strURL)) {
     return;
   }
   URL openURL = null;
   try {
     openURL = new URL(strURL);
     PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(openURL);
   } catch (PartInitException e) {
     // if no default browser (like on linux), try to open directly with firefox.
     try {
       Runtime.getRuntime().exec("firefox " + openURL.toString()); // $NON-NLS-1$
     } catch (IOException e2) {
       if (PlatformUI.getWorkbench().getBrowserSupport().isInternalWebBrowserAvailable()) {
         IWebBrowser browser;
         try {
           browser =
               PlatformUI.getWorkbench()
                   .getBrowserSupport()
                   .createBrowser("registrationId"); // $NON-NLS-1$
           browser.openURL(openURL);
         } catch (PartInitException e1) {
           ExceptionHandler.process(e);
         }
       } else {
         ExceptionHandler.process(e);
       }
     }
   } catch (MalformedURLException e) {
     ExceptionHandler.process(e);
   }
 }
Ejemplo n.º 2
0
 public void openWithDefault() {
   FileObject fileObject = (FileObject) table.getItem(currentRow).getData("fileObject");
   if (fileObject == null) return;
   File file = extractToTemp(fileObject);
   if (file == null) return;
   if (file.isFile()) {
     Program.launch(file.getPath());
   }
 }
Ejemplo n.º 3
0
 public void open(TreeItem items[], String defaultFilename) {
   try {
     String html = getHtml(items);
     final FileDialog dialog =
         new FileDialog(Display.getCurrent().getActiveShell().getShell(), SWT.SAVE);
     dialog.setFilterExtensions(new String[] {"*.html"}); // $NON-NLS-1$
     if (defaultFilename != null && !defaultFilename.equals("")) { // $NON-NLS-1$
       dialog.setFileName(defaultFilename);
     }
     String filename = dialog.open();
     if (filename == null || filename.equals("")) { // $NON-NLS-1$
       return;
     }
     try {
       XViewerLib.writeStringToFile(html, new File(filename));
     } catch (IOException ex) {
       XViewerLog.log(Activator.class, Level.SEVERE, ex);
       return;
     }
     Program.launch(filename);
   } catch (Exception ex) {
     XViewerLog.logAndPopup(Activator.class, Level.SEVERE, ex);
   }
 }
  @Override
  public void run(TableLoadOption... tableLoadOptions) {
    try {
      Set<Artifact> groupOptions = getEmailGroupsAndUserGroups(UserManager.getUser());
      UserGroupsCheckTreeDialog dialog = new UserGroupsCheckTreeDialog(groupOptions);
      dialog.setTitle("Select Groups to Email");
      if (dialog.open() == 0) {

        Set<String> emails = new HashSet<String>();
        for (Artifact artifact : dialog.getSelection()) {
          if (artifact.isOfType(CoreArtifactTypes.UniversalGroup)) {
            for (Artifact userArt :
                artifact.getRelatedArtifacts(CoreRelationTypes.Universal_Grouping__Members)) {
              if (userArt instanceof User) {
                if (!EmailUtil.isEmailValid((User) userArt)) {
                  OseeLog.logf(
                      Activator.class,
                      Level.SEVERE,
                      "Invalid email [%s] for user [%s]; skipping",
                      ((User) userArt).getEmail(),
                      userArt);
                } else if (((User) userArt).isActive()) {
                  emails.add(((User) userArt).getEmail());
                }
              }
            }
          } else if (artifact.isOfType(CoreArtifactTypes.UserGroup)) {
            for (User user :
                artifact.getRelatedArtifacts(CoreRelationTypes.Users_User, User.class)) {
              if (!EmailUtil.isEmailValid(user)) {
                OseeLog.logf(
                    Activator.class,
                    Level.SEVERE,
                    "Invalid email [%s] for user [%s]; skipping",
                    user.getEmail(),
                    user);
              } else if (user.isActive()) {
                emails.add(user.getEmail());
              }
            }
          }
        }
        if (emails.isEmpty()) {
          AWorkbench.popup("Error", "No emails configured.");
          return;
        }
        String emailStr =
            org.eclipse.osee.framework.jdk.core.util.Collections.toString(";", emails);
        if (emailStr.length() > 2048) {
          AWorkbench.popup(
              "Email list too big for auto-open. Emails opened in editor for copy/paste.");
          ResultsEditor.open("Email Addresses", "Email Addresses", emailStr);
        } else {
          Program.launch("mailto:" + emailStr);
        }
        AWorkbench.popup("Complete", "Configured emails openened in local email client.");
      }
    } catch (OseeCoreException ex) {
      OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
    }
  }
 @Override
 public void run(IAction action) {
   File file;
   try {
     view =
         Activator.getDefault()
             .getWorkbench()
             .getActiveWorkbenchWindow()
             .getActivePage()
             .findView(AddressTreeView.ID);
     file =
         File.createTempFile(
             "output_" + new Date().getTime(), ".xls"); // $NON-NLS-1$ //$NON-NLS-2$
     WritableWorkbook workbook = Workbook.createWorkbook(file);
     WritableSheet sheet = workbook.createSheet("Export", 0); // $NON-NLS-1$
     sheet.addCell(new Label(0, 0, Messages.CompanyEditor_Label_Denomination));
     sheet.addCell(new Label(1, 0, Messages.ScrolledCRMFormEditor_Label_Title));
     sheet.addCell(new Label(2, 0, Messages.ScrolledCRMFormEditor_Label_Firstname));
     sheet.addCell(new Label(3, 0, Messages.ScrolledCRMFormEditor_Label_Lastname));
     sheet.addCell(new Label(4, 0, Messages.CompanyEditor_Label_Street));
     sheet.addCell(new Label(5, 0, Messages.CompanyEditor_Label_Zip));
     sheet.addCell(new Label(6, 0, Messages.CompanyEditor_Label_City));
     sheet.addCell(new Label(7, 0, Messages.CompanyEditor_Label_State));
     sheet.addCell(new Label(8, 0, Messages.CompanyEditor_Label_Country));
     sheet.addCell(new Label(9, 0, Messages.CompanyEditor_Label_Phone));
     sheet.addCell(new Label(10, 0, Messages.CompanyEditor_Label_Mobile));
     sheet.addCell(new Label(11, 0, Messages.CompanyEditor_Label_Fax));
     sheet.addCell(new Label(12, 0, Messages.CompanyEditor_Label_Email));
     sheet.addCell(new Label(13, 0, Messages.CompanyEditor_Label_Website));
     sheet.addCell(new Label(14, 0, Messages.CompanyEditor_Label_Note));
     int i = 1;
     Addressbook book =
         (Addressbook) ConnectionFactory.getConnection("AddressbookBean"); // $NON-NLS-1$
     for (Company company : ((AddressTreeView) view).getCompanies()) {
       company = (Company) book.getAddress(company);
       sheet.addCell(new Label(0, i, company.getDenomination()));
       sheet.addCell(new Label(1, i, company.getContact_title()));
       sheet.addCell(new Label(2, i, company.getContact_firstname()));
       sheet.addCell(new Label(3, i, company.getContact_lastname()));
       sheet.addCell(new Label(4, i, company.getStreet()));
       sheet.addCell(new Label(5, i, company.getZip()));
       sheet.addCell(new Label(6, i, company.getCity()));
       sheet.addCell(new Label(7, i, company.getState()));
       sheet.addCell(new Label(8, i, company.getCountry()));
       sheet.addCell(new Label(9, i, company.getPhone()));
       sheet.addCell(new Label(10, i, company.getMobilephone()));
       sheet.addCell(new Label(11, i, company.getFax()));
       sheet.addCell(new Label(12, i, company.getEmail()));
       sheet.addCell(new Label(13, i, company.getWebsite()));
       sheet.addCell(new Label(14, i, company.getNote()));
       i++;
     }
     workbook.write();
     workbook.close();
     Program.launch(file.toString());
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (RowsExceededException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (WriteException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (ConnectionException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (Throwable t) {
     // TODO Auto-generated catch block
     t.printStackTrace();
   }
 }
Ejemplo n.º 6
0
  public Result export(String speratorChar, String fileExtension) {
    if (!popupConfirm
        || popupConfirm
            && MessageDialog.openConfirm(
                Displays.getActiveShell(), "Export Table", "Export Table to CSV?")) {
      StringBuilder sb = new StringBuilder();
      sb.append(title + "\n");
      String htmlStr = AHTML.htmlToText(html);
      Matcher m =
          Pattern.compile(
                  "<table.*?</table>",
                  Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE)
              .matcher(htmlStr);
      if (m.find()) {
        String csv = m.group();
        Matcher rowM =
            Pattern.compile(
                    "<tr.*?>(.*?)</tr>",
                    Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE)
                .matcher(csv);
        while (rowM.find()) {
          String row = rowM.group(1);
          row = row.replaceAll("[\n\r]*", "");
          // Handle all the headers
          for (String tag : elementTags) {
            Matcher thM =
                Pattern.compile(
                        "<" + tag + ".*?>(.*?)</" + tag + ">",
                        Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE)
                    .matcher(row);
            String csvRow = "";
            while (thM.find()) {
              String cellStr = removeLeadTrailSpaces(thM.group(1));
              String excelTextPrefix = (excelTextFields && !cellStr.contains(",")) ? "=" : "";
              csvRow += excelTextPrefix + "\"" + cellStr + "\"" + speratorChar;
            }
            if (!csvRow.equals("")) {
              csvRow = csvRow.replaceFirst(speratorChar + "$", "\n");
              sb.append(csvRow);
            }
          }
        }
        String path = "";
        if (popupConfirm) {
          FileDialog dialog = new FileDialog(Displays.getActiveShell(), SWT.SAVE | SWT.SINGLE);
          dialog.setFilterExtensions(new String[] {"*." + fileExtension});
          dialog.setFilterPath(System.getProperty("user.home"));
          dialog.setFileName("table.csv");
          path = dialog.open();
        } else {
          path = System.getProperty("user.home") + File.separator + "table." + fileExtension;
        }

        if (path != null) {
          try {
            File file = new File(path);
            Lib.writeStringToFile(sb.toString(), file);
            if (openInSystem) {
              Program.launch(file.getAbsolutePath());
            }
            return Result.TrueResult;
          } catch (IOException ex) {
            OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
          }
        }
      } else {
        AWorkbench.popup("ERROR", "Can't find table in results.\n\nNothing to export");
      }
    }
    return Result.FalseResult;
  }
Ejemplo n.º 7
0
 private void openFile(String fullName) {
   if (!MessageDialog.openConfirm(
       this, "Information", fullName + " File saved success, do you want to open file?")) return;
   Program.launch(fullName);
 }