Пример #1
0
  /**
   * Initialize the toolbar with icons and selection listeners in the appropriate part of the window
   */
  public void initToolbar() {

    Device dev = shell.getDisplay();
    try {
      exitImg = new Image(dev, "img/exit.png");
      //            openImg = new Image(dev, "img/open.png");
      playImg = new Image(dev, "img/play.png");
      //            pauseImg = new Image(dev, "img/pause.png");

    } catch (Exception e) {
      System.out.println("Cannot load images");
      System.out.println(e.getMessage());
      System.exit(1);
    }

    ToolBar toolBar = new ToolBar(shell, SWT.BORDER);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    toolBar.setLayoutData(gridData);

    ToolItem exit = new ToolItem(toolBar, SWT.PUSH);
    exit.setImage(exitImg);

    // ToolItem open = new ToolItem(toolBar, SWT.PUSH);
    // exit.setImage(openImg);

    ToolItem play = new ToolItem(toolBar, SWT.PUSH);
    play.setImage(playImg);

    //        ToolItem pause = new ToolItem(toolBar, SWT.PUSH);
    //        pause.setImage(pauseImg);

    toolBar.pack();

    exit.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.exit(0);
          }
        });

    // open.addSelectionListener(new SelectionAdapter() {
    //     @Override
    //     public void widgetSelected(SelectionEvent e) {
    //         FileDialog dialog = new FileDialog(shell, SWT.NULL);
    //         String path = dialog.open();
    //     }
    // });

    play.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            controller.RunAnimation();
          }
        });
  }
Пример #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();
    }
  }
Пример #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;
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    display = parent.getDisplay();
    sashForm = new SashForm(parent, SWT.VERTICAL);
    FillLayout layout = new FillLayout();
    sashForm.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    sashForm.setLayoutData(data);
    initializeDialogUnits(sashForm);

    Composite composite = new Composite(sashForm, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    composite.setLayout(gridLayout);

    treeViewer = createTreeViewer(composite);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_HEIGHT);
    data.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH);
    Tree tree = treeViewer.getTree();
    tree.setLayoutData(data);
    tree.setHeaderVisible(true);
    activateCopy(tree);
    TreeViewerColumn nameColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    nameColumn.getColumn().setText(ProvUIMessages.ProvUI_NameColumnTitle);
    nameColumn.getColumn().setWidth(400);
    nameColumn.getColumn().setMoveable(true);
    nameColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            String label = iu.getProperty(IInstallableUnit.PROP_NAME, null);
            if (label == null) label = iu.getId();
            return label;
          }

          public Image getImage(Object element) {
            if (element instanceof ProvElement) return ((ProvElement) element).getImage(element);
            if (ProvUI.getAdapter(element, IInstallableUnit.class) != null)
              return ProvUIImages.getImage(ProvUIImages.IMG_IU);
            return null;
          }

          public String getToolTipText(Object element) {
            if (element instanceof AvailableIUElement
                && ((AvailableIUElement) element).getImageOverlayId(null) == ProvUIImages.IMG_INFO)
              return ProvUIMessages.RemedyElementNotHighestVersion;
            return super.getToolTipText(element);
          }
        });
    TreeViewerColumn versionColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    versionColumn.getColumn().setText(ProvUIMessages.ProvUI_VersionColumnTitle);
    versionColumn.getColumn().setWidth(200);
    versionColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            if (element instanceof IIUElement) {
              if (((IIUElement) element).shouldShowVersion()) return iu.getVersion().toString();
              return ""; //$NON-NLS-1$
            }
            return iu.getVersion().toString();
          }
        });
    TreeViewerColumn idColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    idColumn.getColumn().setText(ProvUIMessages.ProvUI_IdColumnTitle);
    idColumn.getColumn().setWidth(200);

    idColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            return iu.getId();
          }
        });

    // Filters and sorters before establishing content, so we don't refresh unnecessarily.
    IUComparator comparator = new IUComparator(IUComparator.IU_NAME);
    comparator.useColumnConfig(getColumnConfig());
    treeViewer.setComparator(comparator);
    treeViewer.setComparer(new ProvElementComparer());
    ColumnViewerToolTipSupport.enableFor(treeViewer);
    contentProvider = new ProvElementContentProvider();
    treeViewer.setContentProvider(contentProvider);
    //		labelProvider = new IUDetailsLabelProvider(null, getColumnConfig(), getShell());
    //		treeViewer.setLabelProvider(labelProvider);

    // Optional area to show the size
    createSizingInfo(composite);

    // The text area shows a description of the selected IU, or error detail if applicable.
    iuDetailsGroup =
        new IUDetailsGroup(
            sashForm,
            treeViewer,
            convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH),
            true);

    setControl(sashForm);
    sashForm.setWeights(getSashWeights());
    Dialog.applyDialogFont(sashForm);

    // Controls for filtering/presentation/site selection
    Composite controlsComposite = new Composite(composite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = true;
    gridLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    controlsComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    controlsComposite.setLayoutData(gd);

    final Runnable runnable =
        new Runnable() {
          public void run() {
            treeViewer.addSelectionChangedListener(
                new ISelectionChangedListener() {
                  public void selectionChanged(SelectionChangedEvent event) {
                    setDetailText(resolvedOperation);
                  }
                });
            setDrilldownElements(input, resolvedOperation);
            treeViewer.setInput(input);
          }
        };

    if (resolvedOperation != null && !resolvedOperation.hasResolved()) {
      try {
        getContainer()
            .run(
                true,
                false,
                new IRunnableWithProgress() {
                  public void run(IProgressMonitor monitor) {
                    resolvedOperation.resolveModal(monitor);
                    display.asyncExec(runnable);
                  }
                });
      } catch (Exception e) {
        StatusManager.getManager()
            .handle(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, e.getMessage(), e));
      }
    } else {
      runnable.run();
    }
  }
  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();
    }
  }