public void openUrl(String url) {
    String os = System.getProperty("os.name");
    Runtime runtime = Runtime.getRuntime();
    try {
      // Block for Windows Platform
      if (os.startsWith("Windows")) {
        String cmd = "rundll32 url.dll,FileProtocolHandler " + url;
        Process p = runtime.exec(cmd);

        // Block for Mac OS
      } else if (os.startsWith("Mac OS")) {
        Class fileMgr = Class.forName("com.apple.eio.FileManager");
        Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
        openURL.invoke(null, new Object[] {url});

        // Block for UNIX Platform
      } else {
        String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
        String browser = null;
        for (int count = 0; count < browsers.length && browser == null; count++)
          if (runtime.exec(new String[] {"which", browsers[count]}).waitFor() == 0)
            browser = browsers[count];

        if (browser == null) throw new Exception("Could not find web browser");
        else runtime.exec(new String[] {browser, url});
      }
    } catch (Exception x) {
      System.err.println("Exception occurd while invoking Browser!");
      x.printStackTrace();
    }
  }
Exemple #2
0
  /** Export the selected values from the table to a csv file */
  private void export() {

    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    String[] filterNames = new String[] {"CSV Files", "All Files (*)"};
    String[] filterExtensions = new String[] {"*.csv;", "*"};
    String filterPath = "/";
    String platform = SWT.getPlatform();
    if (platform.equals("win32") || platform.equals("wpf")) {
      filterNames = new String[] {"CSV Files", "All Files (*.*)"};
      filterExtensions = new String[] {"*.csv", "*.*"};
      filterPath = "c:\\";
    }
    dialog.setFilterNames(filterNames);
    dialog.setFilterExtensions(filterExtensions);
    dialog.setFilterPath(filterPath);
    try {
      dialog.setFileName(this.getCurrentKey() + ".csv");
    } catch (Exception e) {
      dialog.setFileName("export.csv");
    }
    String fileName = dialog.open();

    FileOutputStream fos;
    OutputStreamWriter out;
    try {
      fos = new FileOutputStream(fileName);
      out = new OutputStreamWriter(fos, "UTF-8");
    } catch (Exception e) {
      MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      messageBox.setMessage("Error creating export file " + fileName + " : " + e.getMessage());
      messageBox.open();
      return;
    }

    Vector<TableItem> sel = new Vector<TableItem>(this.dataTable.getSelection().length);

    sel.addAll(Arrays.asList(this.dataTable.getSelection()));
    Collections.reverse(sel);

    for (TableItem item : sel) {
      String date = item.getText(0);
      String value = item.getText(1);
      try {
        out.write(date + ";" + value + "\n");
      } catch (IOException e) {
        continue;
      }
    }

    try {
      out.close();
      fos.close();
    } catch (IOException e) {
      MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      messageBox.setMessage("Error writing export file " + fileName + " : " + e.getMessage());
      messageBox.open();
      e.printStackTrace();
    }
  }
Exemple #3
0
  public List getCategories() {
    List concepts = null;
    try {
      //		GetReturnType request = new GetReturnType();
      //		request.setType("limited");

      GetCategoriesType request = new GetCategoriesType();
      request.setType("core");
      request.setHiddens(false);
      request.setSynonyms(false);

      OntologyResponseMessage msg = new OntologyResponseMessage();
      StatusType procStatus = null;
      while (procStatus == null || !procStatus.getType().equals("DONE")) {
        String response = OntServiceDriver.getCategories(request, "FIND");
        procStatus = msg.processResult(response);
        //				if  other error codes
        //				TABLE_ACCESS_DENIED and USER_INVALID, DATABASE ERROR
        if (procStatus.getType().equals("ERROR")) {
          System.setProperty("errorMessage", procStatus.getValue());
          return concepts;
        }
        procStatus.setType("DONE");
      }
      ConceptsType allConcepts = msg.doReadConcepts();
      if (allConcepts != null) concepts = allConcepts.getConcept();

    } catch (AxisFault e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", "Ontology cell unavailable");
    } catch (I2B2Exception e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", e.getMessage());
    } catch (Exception e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", "Remote server unavailable");
    }

    return concepts;
  }
  private void openFile(String fileName, Table table) {
    String outStr;
    try {

      CSVReader reader = new CSVReader(new FileReader(fileName), ',', '"');
      String[] strLineArr;

      // Open the file that is the first
      // command line parameter
      FileInputStream fstream = new FileInputStream(fileName);
      // Get the object of DataInputStream
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;

      table.clearAll();
      table.removeAll();
      table.redraw();

      int length = 0;
      boolean first = true;
      // Read File Line By Line
      while ((strLineArr = reader.readNext()) != null) {
        // while ((strLine = br.readLine()) != null)   {
        // Print the content on the console
        // outStr = strLine;
        TableItem item = null;

        if (first) {
          length = strLineArr.length;
        } else {
          item = new TableItem(table, SWT.NONE);
        }

        int thisLen = strLineArr.length;
        if (thisLen <= length) {
          // String[] line = new String[length];
          for (int i = 0; i < thisLen; i++) {
            // line[i] = st.nextToken();
            // item.setText (i, st.nextToken());
            if (first) {
              TableColumn column = new TableColumn(table, SWT.NONE);
              column.setText(strLineArr[i]);
            } else {

              // System.out.println("-- "+i+" -- " + strLineArr[i]);
              item.setText(i, strLineArr[i]);
            }
          }
        }
        first = false;
      }

      // System.out.println("Finisehd file");

      for (int i = 0; i < length; i++) {
        table.getColumn(i).pack();
      }
      // System.out.println("finished packing");
      // Close the input stream
      in.close();
    } catch (Exception e) { // Catch exception if any
      System.err.println("Error: " + e.getMessage());
      e.printStackTrace();
    }
  }
  public void openResultsXML(String fileName) {

    String outStr;
    try {

      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = (Document) dBuilder.parse(fileName);
      doc.getDocumentElement().normalize();

      if (doc.getElementsByTagName("wuid") != null) {
        wuid = doc.getElementsByTagName("wuid").item(0).getTextContent();
      }
      if (doc.getElementsByTagName("jobname") != null) {
        jobname = doc.getElementsByTagName("jobname").item(0).getTextContent();
      }
      if (doc.getElementsByTagName("serverAddress") != null) {
        serverAddress = doc.getElementsByTagName("serverAddress").item(0).getTextContent();
      }
      // WUID
      // System.out.println(wuid);
      // lets create a tab for the wuid
      CTabItem wuidTab = new CTabItem(folder, SWT.NONE);
      wuidTab.setText(jobname + " " + wuid);

      folder.setSelection(folder.indexOf(wuidTab));
      System.out.println("BUILDTAB--------" + folder.indexOf(wuidTab));
      Composite tabHolder = new Composite(folder, SWT.NONE);
      tabHolder.setLayout(new GridLayout());
      tabHolder.setLayoutData(new GridData(GridData.FILL_BOTH));
      final String thisWuid = wuid;
      final String thisServerAddress = serverAddress;
      // add link here
      // Label link = new Label();
      Link link = new Link(tabHolder, SWT.NONE);
      link.setText("<a>View Workunit in the Default Web Browser</a>");
      link.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event event) {
              openUrl(thisServerAddress + "/WsWorkunits/WUInfo?Wuid=" + thisWuid);
            }
          });

      CTabFolder subfolder = new CTabFolder(tabHolder, SWT.CLOSE);
      subfolder.setSimple(false);
      subfolder.setBorderVisible(true);
      subfolder.setLayoutData(new GridData(GridData.FILL_BOTH));

      NodeList results = doc.getElementsByTagName("result");

      for (int temp = 0; temp < results.getLength(); temp++) {
        Node result = results.item(temp);
        NamedNodeMap att = result.getAttributes();
        // type
        String resType = att.getNamedItem("resulttype").getTextContent();
        // System.out.println("resType: |" + resType + "|");
        // filename
        String filePath = result.getTextContent();
        // System.out.println(filePath);

        // CTabItem resultTab = new CTabItem(subfolder, SWT.NONE);
        // resultTab.setText(resType);
        // so here we use type and decide what tab to open and pass filename
        // buildTab(filePath,resType,subfolder);
        if (resType != null && filePath != null) {
          if (resType.equalsIgnoreCase("ClusterCounts")) {
            buildClusterCountsTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("SrcProfiles")) {
            buildSrcProfilesTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("Hygiene_ValidityErrors")) {
            buildHygieneValidityErrorsTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("ClusterSrc")) {
            buildClusterSrcTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("SrcOutliers")) {
            buildSrcOutliersTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("Dataprofiling_AllProfiles")) {
            buildProfileTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("Dataprofiling_SummaryReport")) {
            buildSummaryTab(filePath, resType, subfolder);
          } else if (resType.equalsIgnoreCase("Dataprofiling_OptimizedLayout")) {
            buildOptimizedLayoutTab(filePath, resType, subfolder);
          } else { // CleanedData
            buildTab(filePath, resType, subfolder);
          }
        }
      }
      wuidTab.setControl(tabHolder);
    } catch (Exception e) { // Catch exception if any
      System.err.println("Error: " + e.getMessage());
      e.printStackTrace();
    }
  }
  /** Initializes the GUI. */
  private void initGUI() {
    try {
      getShell()
          .addDisposeListener(
              new DisposeListener() {
                public void widgetDisposed(DisposeEvent evt) {
                  shellWidgetDisposed(evt);
                }
              });

      getShell()
          .addControlListener(
              new ControlAdapter() {
                public void controlResized(ControlEvent evt) {
                  shellControlResized(evt);
                }
              });

      getShell()
          .addControlListener(
              new ControlAdapter() {
                public void controlMoved(ControlEvent evt) {
                  shellControlMoved(evt);
                }
              });

      GridLayout thisLayout = new GridLayout();
      this.setLayout(thisLayout);
      {
        GridData toolBarLData = new GridData();
        toolBarLData.grabExcessHorizontalSpace = true;
        toolBarLData.horizontalAlignment = GridData.FILL;
        toolBar = new ToolBar(this, SWT.FLAT);
        toolBar.setLayoutData(toolBarLData);
        toolBar.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
        {
          newToolItem = new ToolItem(toolBar, SWT.NONE);
          newToolItem.setImage(SWTResourceManager.getImage("images/new.gif"));
          newToolItem.setToolTipText("New");
        }
        {
          openToolItem = new ToolItem(toolBar, SWT.NONE);
          openToolItem.setToolTipText("Open");
          openToolItem.setImage(SWTResourceManager.getImage("images/open.gif"));
          openToolItem.addSelectionListener(
              new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                  openToolItemWidgetSelected(evt);
                }
              });
        }
        {
          saveToolItem = new ToolItem(toolBar, SWT.NONE);
          saveToolItem.setToolTipText("Save");
          saveToolItem.setImage(SWTResourceManager.getImage("images/save.gif"));
        }
      }
      {
        clientArea = new Composite(this, SWT.NONE);
        GridData clientAreaLData = new GridData();
        clientAreaLData.grabExcessHorizontalSpace = true;
        clientAreaLData.grabExcessVerticalSpace = true;
        clientAreaLData.horizontalAlignment = GridData.FILL;
        clientAreaLData.verticalAlignment = GridData.FILL;
        clientArea.setLayoutData(clientAreaLData);
        clientArea.setLayout(null);
      }
      {
        statusArea = new Composite(this, SWT.NONE);
        GridLayout statusAreaLayout = new GridLayout();
        statusAreaLayout.makeColumnsEqualWidth = true;
        statusAreaLayout.horizontalSpacing = 0;
        statusAreaLayout.marginHeight = 0;
        statusAreaLayout.marginWidth = 0;
        statusAreaLayout.verticalSpacing = 0;
        statusAreaLayout.marginLeft = 3;
        statusAreaLayout.marginRight = 3;
        statusAreaLayout.marginTop = 3;
        statusAreaLayout.marginBottom = 3;
        statusArea.setLayout(statusAreaLayout);
        GridData statusAreaLData = new GridData();
        statusAreaLData.horizontalAlignment = GridData.FILL;
        statusAreaLData.grabExcessHorizontalSpace = true;
        statusArea.setLayoutData(statusAreaLData);
        statusArea.setBackground(SWTResourceManager.getColor(239, 237, 224));
        {
          statusText = new Label(statusArea, SWT.BORDER);
          statusText.setText(" Ready");
          GridData txtStatusLData = new GridData();
          txtStatusLData.horizontalAlignment = GridData.FILL;
          txtStatusLData.grabExcessHorizontalSpace = true;
          txtStatusLData.verticalIndent = 3;
          statusText.setLayoutData(txtStatusLData);
        }
      }
      thisLayout.verticalSpacing = 0;
      thisLayout.marginWidth = 0;
      thisLayout.marginHeight = 0;
      thisLayout.horizontalSpacing = 0;
      thisLayout.marginTop = 3;
      this.setSize(474, 312);
      {
        menu1 = new Menu(getShell(), SWT.BAR);
        getShell().setMenuBar(menu1);
        {
          fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
          fileMenuItem.setText("&File");
          {
            fileMenu = new Menu(fileMenuItem);
            {
              newFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              newFileMenuItem.setText("&New");
              newFileMenuItem.setImage(SWTResourceManager.getImage("images/new.gif"));
            }
            {
              openFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              openFileMenuItem.setText("&Open");
              openFileMenuItem.setImage(SWTResourceManager.getImage("images/open.gif"));
              openFileMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      openFileMenuItemWidgetSelected(evt);
                    }
                  });
            }
            {
              closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
              closeFileMenuItem.setText("Close");
            }
            {
              fileMenuSep1 = new MenuItem(fileMenu, SWT.SEPARATOR);
            }
            {
              saveFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              saveFileMenuItem.setText("&Save");
              saveFileMenuItem.setImage(SWTResourceManager.getImage("images/save.gif"));
              saveFileMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      saveFileMenuItemWidgetSelected(evt);
                    }
                  });
            }
            {
              fileMenuSep2 = new MenuItem(fileMenu, SWT.SEPARATOR);
            }
            {
              exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
              exitMenuItem.setText("E&xit");
              exitMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      exitMenuItemWidgetSelected(evt);
                    }
                  });
            }
            fileMenuItem.setMenu(fileMenu);
          }
        }
        {
          helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
          helpMenuItem.setText("&Help");
          {
            helpMenu = new Menu(helpMenuItem);
            {
              aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
              aboutMenuItem.setText("&About");
              aboutMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      aboutMenuItemWidgetSelected(evt);
                    }
                  });
            }
            helpMenuItem.setMenu(helpMenu);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }