public void initGui()

in ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/DocumentSelectComposite.java [137:567]


  public void initGui() {
    documentList = new ArrayList<DocumentData>();

    this.setLayout(new FormLayout());
    this.setSize(600, 380);
    directoryLabel = new Label(this, SWT.NONE);
    FormData label1LData = new FormData();
    label1LData.left = new FormAttachment(0, 10);
    label1LData.top = new FormAttachment(0, 10);
    label1LData.width = 80;
    directoryLabel.setLayoutData(label1LData);
    directoryLabel.setText("Documents:");

    delButton = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData delButtonData = new FormData();
    delButtonData.width = 25;
    delButtonData.height = 25;
    delButtonData.top = new FormAttachment(directoryLabel, 0, SWT.CENTER);
    delButtonData.right = new FormAttachment(100, -10);
    delButton.setLayoutData(delButtonData);
    Image folderIcon = getImage("delete");
    delButton.setImage(folderIcon);
    delButton.setToolTipText("Remove selected documents");
    delButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        int[] indices = table.getSelectionIndices();

        for (int i = indices.length - 1; i >= 0; i--) {
          documentList.remove(indices[i]);
        }

        tableViewer.setInput(documentList);
        tableViewer.refresh();
      }
    });

    dirButton = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData dirButtonData = new FormData();
    dirButtonData.width = 25;
    dirButtonData.height = 25;
    dirButtonData.top = new FormAttachment(directoryLabel, 0, SWT.CENTER);
    // dirButtonData.left = new FormAttachment(inputDirectoryText, 10);
    dirButtonData.right = new FormAttachment(delButton, -10);
    dirButton.setLayoutData(dirButtonData);
    folderIcon = getImage("folder");
    dirButton.setImage(folderIcon);
    dirButton.setToolTipText("Select document Folder");
    dirButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        DirectoryDialog dlg = new DirectoryDialog(getShell());
        dlg.setFilterPath(inputDirectoryText.getText());
        dlg.setText("Input Directory");
        dlg.setMessage("Select a directory with input document files.");
        String dir = dlg.open();
        if (dir != null) {
          documentList = new ArrayList<DocumentData>();
          File directory = new File(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());

            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IFile file = workspace.getRoot().getFileForLocation(path);

            if (file == null) {
              // no located in the workspace?
              try {
                IProject project = workspace.getRoot().getProject("External Files");
                if (!project.exists()) {
                  project.create(null);
                }
                if (!project.isOpen()) {
                  project.open(null);
                }
                IFile extFile = project.getFile(path.lastSegment());
                if(extFile.exists()) {
                  extFile.delete(true, false, new NullProgressMonitor());
                }
                extFile.createLink(path, IResource.NONE, null);
                file = extFile;
              } catch (Exception e) {
                RutaAddonsPlugin.error(e);
              }
            }

            if (file != null) {
              IWorkbenchPage page = Workbench.getInstance().getActiveWorkbenchWindow()
                      .getActivePage();
              try {
                page.openEditor(new FileEditorInput(file), "org.apache.uima.caseditor.editor");
              } catch (PartInitException e) {
                RutaAddonsPlugin.error(e);
              }
            }
          }
        }
      }
    });

    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();
            }
          }
        }
      }
    });

    DropTarget dt2 = new DropTarget(inputDirectoryText, DND.DROP_DEFAULT | DND.DROP_MOVE);
    dt2.setTransfer(new Transfer[] { FileTransfer.getInstance() });
    dt2.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 == 1) {
          String string = fileList[0];
          inputDirectoryText.setText(string);
          setDocumentsByDir();
        }
      }
    });

    DropTarget dt3 = new DropTarget(testDirectoryText, DND.DROP_DEFAULT | DND.DROP_MOVE);
    dt3.setTransfer(new Transfer[] { FileTransfer.getInstance() });
    dt3.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 == 1) {
          String string = fileList[0];
          testDirectoryText.setText(string);
        }
      }
    });

    DropTarget dt4 = new DropTarget(tsLocationText, DND.DROP_DEFAULT | DND.DROP_MOVE);
    dt4.setTransfer(new Transfer[] { FileTransfer.getInstance() });
    dt4.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 == 1) {
          String string = fileList[0];
          File file = new File(string);
          if (file.isFile()) {
            if (file.getName().endsWith(RutaEngine.SCRIPT_FILE_EXTENSION)) {
              String typeSystemDescriptorLocation = "";
              try {
                typeSystemDescriptorLocation = RutaProjectUtils.getTypeSystemDescriptorPath(string)
                        .toPortableString();
              } catch (CoreException e) {
                RutaAddonsPlugin.error(e);
              }
              tsLocationText.setText(typeSystemDescriptorLocation);
            } else if (file.getName().endsWith(".xml")) {
              tsLocationText.setText(string);
            }
          }

        }
      }
    });

    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.refresh();
    this.layout();

  }