예제 #1
0
파일: ViewData.java 프로젝트: schugabe/FWS
  /** 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();
    }
  }
예제 #2
0
파일: FindTool.java 프로젝트: URMC/i2b2
  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();
    }
  }