Package org.apache.uima.ruta.cde.utils

Examples of org.apache.uima.ruta.cde.utils.DocumentData


          System.out.println("dir :" + dir);

          String[] files = directory.list();

          for (String filePath : files) {
            DocumentData documentData = new DocumentData(new File(directory
                    + System.getProperty("file.separator") + filePath));
            documentList.add(documentData);
          }
          inputDirectoryText.setText(dir);
          tableViewer.setInput(documentList);
          tableViewer.refresh();
        }
      }
    });

    inputDirectoryText = new Text(this, SWT.SINGLE | SWT.BORDER);
    FormData inputDirectoryTextData = new FormData();
    // inputDirectoryTextData.width = 150;
    inputDirectoryTextData.left = new FormAttachment(directoryLabel, 10);
    inputDirectoryTextData.top = new FormAttachment(directoryLabel, 0, SWT.CENTER);
    inputDirectoryTextData.right = new FormAttachment(dirButton, -12);
    inputDirectoryText.setLayoutData(inputDirectoryTextData);
    inputDirectoryText.setText("");

    inputDirectoryText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        // without that listener, the text fields forget the
        // last change when leaving with tab! don't know why!
        // we also MUST call getText() otherwise the changes in
        // the field are lost (what is this???!!)
        Text t = (Text) e.widget;
        t.getText();
        // updateViewer(t.getText());
      }
    });

    // GUI Definitions for Test Data Selection Components

    testDataLabel = new Label(this, SWT.NONE);
    FormData testDataLabelData = new FormData();
    testDataLabelData.left = new FormAttachment(0, 10);
    // testDataLabelData.right = new FormAttachment(100, -12);
    testDataLabelData.top = new FormAttachment(directoryLabel, 15);
    testDataLabel.setLayoutData(testDataLabelData);
    testDataLabel.setText("Test Data:");

    testDataButton = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData testDataButtonData = new FormData();
    testDataButtonData.width = 25;
    testDataButtonData.height = 25;
    testDataButtonData.top = new FormAttachment(testDataLabel, 0, SWT.CENTER);
    testDataButtonData.right = new FormAttachment(100, -10);
    testDataButton.setLayoutData(testDataButtonData);
    folderIcon = getImage("folder");
    testDataButton.setImage(folderIcon);
    testDataButton.setToolTipText("Select the folder containing the test files");

    testDataButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        DirectoryDialog dlg2 = new DirectoryDialog(getShell());
        dlg2.setFilterPath(testDirectoryText.getText());
        dlg2.setText("Location of the test files");
        String dir = dlg2.open();
        if (dir != null) {
          testDirectoryText.setText(dir);
        }
      }
    });

    testDirectoryText = new Text(this, SWT.SINGLE | SWT.BORDER);
    FormData testDirectoryTextData = new FormData();
    testDirectoryTextData.top = new FormAttachment(testDataLabel, 0, SWT.CENTER);
    testDirectoryTextData.left = new FormAttachment(directoryLabel, 10);
    testDirectoryTextData.right = new FormAttachment(testDataButton, -10);
    testDirectoryText.setLayoutData(testDirectoryTextData);
    testDirectoryText.setText("");

    testDirectoryText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        // without that listener, the text fields forget the
        // last change when leaving with tab! don't know why!
        // we also MUST call getText() otherwise the changes in
        // the field are lost (what is this???!!)
        Text t = (Text) e.widget;
        t.getText();
        // updateViewer(t.getText());
      }
    });

    // GUI Code for TypeSystem Selection

    this.typeSystemLabel = new Label(this, SWT.NONE);
    FormData tSLabelData = new FormData();
    tSLabelData.left = new FormAttachment(0, 10);
    tSLabelData.top = new FormAttachment(testDataLabel, 15);
    tSLabelData.width = 80;
    typeSystemLabel.setLayoutData(tSLabelData);
    typeSystemLabel.setText("Type System:");

    tsButton = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData tsButtonData = new FormData();
    tsButtonData.width = 25;
    tsButtonData.height = 25;
    tsButtonData.top = new FormAttachment(typeSystemLabel, 0, SWT.CENTER);
    tsButtonData.right = new FormAttachment(100, -10);
    tsButton.setLayoutData(tsButtonData);
    folderIcon = getImage("folder");
    tsButton.setImage(folderIcon);
    tsButton.setToolTipText("Select the Type System");
    tsButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        FileDialog dlg = new FileDialog(getShell());
        dlg.setFilterPath(tsLocationText.getText());
        dlg.setText("Type System Location");
        String dir = dlg.open();
        if (dir != null) {
          tsLocationText.setText(dir);
        }
      }
    });

    tsLocationText = new Text(this, SWT.SINGLE | SWT.BORDER);
    FormData tsLocationTextData = new FormData();
    tsLocationTextData.left = new FormAttachment(typeSystemLabel, 10);
    tsLocationTextData.top = new FormAttachment(typeSystemLabel, 0, SWT.CENTER);
    tsLocationTextData.right = new FormAttachment(tsButton, -10);
    tsLocationText.setLayoutData(tsLocationTextData);
    tsLocationText.setText("");

    tsLocationText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        // without that listener, the text fields forget the
        // last change when leaving with tab! don't know why!
        // we also MUST call getText() otherwise the changes in
        // the field are lost (what is this???!!)
        Text t = (Text) e.widget;
        t.getText();
      }
    });

    measuresText = new Text(this, SWT.READ_ONLY);
    FormData cNrTextData = new FormData();
    cNrTextData.left = new FormAttachment(0, 10);
    cNrTextData.top = new FormAttachment(typeSystemLabel, 15);
    cNrTextData.right = new FormAttachment(100, -10);
    // cNrLabelData.width = 30;
    measuresText.setLayoutData(cNrTextData);
    measuresText.setText("... no measures available yet");

    tableViewer = new TableViewer(this, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
            | SWT.FULL_SELECTION);

    labelProvider = new DocumentTableLabelProvider();
    tableViewer.setLabelProvider(labelProvider);
    contentProvider = new DocumentTableContentProvider();
    tableViewer.setContentProvider(contentProvider);

    tableViewer.addDoubleClickListener(new IDoubleClickListener() {
      public void doubleClick(DoubleClickEvent event) {
        if (event.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
          Object object = selection.getFirstElement();
          if (object instanceof DocumentData) {
            DocumentData data = (DocumentData) object;
            Path path = new Path(data.getDocument().getAbsolutePath());

            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
            // IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

            IWorkbenchPage page = Workbench.getInstance().getActiveWorkbenchWindow()
                    .getActivePage();
            try {
              page.openEditor(new FileEditorInput(file), "org.apache.uima.caseditor.editor");
            } catch (PartInitException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        }
      }
    });

    this.table = tableViewer.getTable();
    FormData tableFormData = new FormData();
    tableFormData.top = new FormAttachment(measuresText, 15);
    tableFormData.bottom = new FormAttachment(100, 0);
    tableFormData.left = new FormAttachment(0, 0);
    tableFormData.right = new FormAttachment(100, 0);
    table.setLayoutData(tableFormData);
    table.addKeyListener(new KeyListener() {

      public void keyPressed(KeyEvent e) {
        if (((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'c')) {
          String output = "";
          TableItem[] items = table.getSelection();
          for (TableItem item : items) {
            DocumentData data = (DocumentData) item.getData();
            output = output + data.getDocument().getName() + ", " + data.getAugmentedResult()
                    + ", " + data.getFMeasure() + ", \n";
          }
          clipboard.setContents(new Object[] { output },
                  new Transfer[] { TextTransfer.getInstance() });
        }
      }

      public void keyReleased(KeyEvent arg0) {
      }
    });

    tc0 = new TableColumn(table, SWT.LEFT);
    tc0.setText("  ");
    tc0.setWidth(25);

    tc1 = new TableColumn(table, SWT.LEFT);
    tc1.setText("Document");
    tc1.setWidth(160);
    tc1.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        Comparator comparator = compareFactory.getComparator(tc1);
        Collections.sort(documentList, comparator);
        tableViewer.setInput(documentList);
        tableViewer.refresh();
      }
    });

    tc2 = new TableColumn(table, SWT.RIGHT);
    tc2.setText("CDE");
    tc2.setWidth(45);
    tc2.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        Comparator comparator = compareFactory.getComparator(tc2);
        Collections.sort(documentList, comparator);
        tableViewer.setInput(documentList);
        tableViewer.refresh();
      }
    });

    tc3 = new TableColumn(table, SWT.RIGHT);
    tc3.setText("F1");
    tc3.setWidth(45);
    tc3.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        Comparator comparator = compareFactory.getComparator(tc3);
        Collections.sort(documentList, comparator);
        tableViewer.setInput(documentList);
        tableViewer.refresh();
      }
    });

    DropTarget dt = new DropTarget(table, DND.DROP_DEFAULT | DND.DROP_MOVE);
    dt.setTransfer(new Transfer[] { FileTransfer.getInstance() });
    dt.addDropListener(new DropTargetAdapter() {
      @Override
      public void drop(DropTargetEvent event) {
        String fileList[] = null;
        FileTransfer ft = FileTransfer.getInstance();
        if (ft.isSupportedType(event.currentDataType)) {
          fileList = (String[]) event.data;
        }
        if (fileList != null && fileList.length > 0) {
          for (int i = 0; i < fileList.length; i++) {
            File file = new File(fileList[i]);
            if (file.isDirectory()) {

            } else {
              DocumentData newDocument = new DocumentData(file);
              documentList.add(newDocument);
              tableViewer.setInput(documentList);
              tableViewer.refresh();
            }
          }
View Full Code Here


      tsLocationText.setText(tsLocation.getID());
    }
    IMemento documents = memento.getChild("documents");
    if (documents != null) {
      for (IMemento document : documents.getChildren("document")) {
        DocumentData docData = new DocumentData(new File(document.getID()));
        documentList.add(docData);
      }
      tableViewer.setInput(documentList);
      tableViewer.refresh();
    }
View Full Code Here

  public void setDocumentsByDir(File dir) {
    documentList = new ArrayList<DocumentData>();
    Iterator<File> iterateFiles = FileUtils.iterateFiles(dir, new String[] { "xmi" }, true);
    while (iterateFiles.hasNext()) {
      File file = (File) iterateFiles.next();
      DocumentData documentData = new DocumentData(file);
      documentList.add(documentData);
    }
    tableViewer.setInput(documentList);
    tableViewer.refresh();
  }
View Full Code Here

  public void removeListener(ILabelProviderListener arg0) {
  }

  public Image getColumnImage(Object element, int columnIndex) {
    if (element instanceof DocumentData && columnIndex == 0) {
      DocumentData data = (DocumentData) element;
      Image image = red;

      if (data.getAugmentedResult() * 100 > RutaAddonsPlugin.getDefault().getPreferenceStore()
              .getInt(CDEPreferenceConstants.AVERAGE_RESULT_THRESHOLD)) {
        image = yellow;
      }
      if (data.getAugmentedResult() * 100 > RutaAddonsPlugin.getDefault().getPreferenceStore()
              .getInt(CDEPreferenceConstants.GOOD_RESULT_THRESHOLD)) {
        image = green;
      }
      return image;
    }
View Full Code Here

    return null;
  }

  public String getColumnText(Object element, int columnIndex) {
    if (element instanceof DocumentData) {
      DocumentData data = (DocumentData) element;
      switch (columnIndex) {
        case 0:
          return null;
        case 1:
          return data.getDocument().getName();
        case 2:
          return String.valueOf(EvaluationMeasures.round(data.getAugmentedResult()));
        case 3:
          return String.valueOf(EvaluationMeasures.round(data.getFMeasure()));
      }
    }
    return "failure";
  }
View Full Code Here

      IStructuredSelection strucSel = (IStructuredSelection) selection;
      Iterator<?> iter = strucSel.iterator();
      if (iter.hasNext()) {
        Object o = iter.next();
        if (o instanceof DocumentData) {
          DocumentData data = (DocumentData) o;
          ArrayList<String[]> results = data.getResults();
          tableViewer.setInput(results);
          tableViewer.refresh();
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.uima.ruta.cde.utils.DocumentData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.