private void init()

in ruta-ep-textruler/src/main/java/org/apache/uima/ruta/textruler/ui/AddRemoveList.java [141:349]


  private void init() {

    this.setLayout(new FormLayout());
    this.setSize(200, 300);

    types = new ArrayList<String>();
    listViewer = CheckboxTableViewer.newCheckList(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
            | SWT.MULTI);
    FormData listViewerLData = new FormData();
    listViewerLData.width = 160;
    listViewerLData.height = 150;
    listViewerLData.left = new FormAttachment(0, 1000, 0);
    listViewerLData.right = new FormAttachment(1000, 1000, -40);
    listViewerLData.top = new FormAttachment(0, 1000, 0);
    listViewerLData.bottom = new FormAttachment(1000, 1000, -10);
    listViewer.getControl().setLayoutData(listViewerLData);
    listViewer.setContentProvider(parent.new ListContentProvider());
    listViewer.setLabelProvider(parent.new DefaultLabelProvider(name));
    // listViewer.setLabelProvider(parent.new ViewLabelProvider());
    // listViewer.setSorter(parent.new NameSorter());
    listViewer.getTable().setVisible(true);

    if (name.equals("FilterTypes")) {
      String input = TextRulerToolkit.getStandardFilterSetString();
      addAll(input);
    } else {
      listViewer.setAllChecked(true);
    }

    listViewer.getControl().addKeyListener(new KeyAdapter() {
      @Override
      public void keyPressed(KeyEvent e) {
        int keyCode = e.keyCode;
        // backspace or delete
        if (keyCode == SWT.BS || keyCode == SWT.DEL) {
          String selected = listViewer.getSelection().toString();
          selected = selected.substring(1, selected.length() - 1);
          String[] types = selected.split(", ");
          for (String string : types) {
            listViewer.remove(string);
          }
        }
      }

    });

    ts = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData tsLData = new FormData();
    tsLData.width = 25;
    tsLData.height = 25;
    tsLData.top = new FormAttachment(0, 1000, 0);
    tsLData.right = new FormAttachment(1000, 1000, -10);
    ts.setLayoutData(tsLData);
    Image tsIcon = images.get("prepFolder");
    ts.setImage(tsIcon);
    ts.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
        fd.setText("Choose Type System Descriptor");
        String[] filterExt = { "*.xml", "*.*" };
        fd.setFilterExtensions(filterExt);
        fd.setFileName(parent.getPreprocessorTMFile());
        String file = fd.open();
        if (file != null) {
          XMLizable descriptor = null;
          try {
            descriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(file));
          } catch (InvalidXMLException e) {
          } catch (IOException e) {
          }
          if (descriptor instanceof TypeSystemDescription) {
            TypeSystemDescription tsd = (TypeSystemDescription) descriptor;
            try {
              tsd.resolveImports();
            } catch (InvalidXMLException e) {
            }
            List<String> tsTypes = new ArrayList<String>();
            TypeDescription[] typeDescs = tsd.getTypes();
            for (TypeDescription typeDescription : typeDescs) {
              String n = typeDescription.getName();
              tsTypes.add(n);
            }
            addAll(tsTypes);
          }
        }
      }
    });

    add = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData addLData = new FormData();
    addLData.width = 25;
    addLData.height = 25;
    addLData.top = new FormAttachment(0, 1000, 27);
    addLData.right = new FormAttachment(1000, 1000, -10);
    add.setLayoutData(addLData);
    Image addIcon = images.get("add");
    add.setImage(addIcon);
    add.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        setTypes();
        if (error)
          return;
        Display display = Display.getDefault();
        Shell shell = new Shell(display, SWT.RESIZE | SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
        if (name.equals("FilterTypes"))
          shell.setText("Filter Types");
        else
          shell.setText("Slot Types");
        new SelectTypesDialog(shell, types, AddRemoveList.this);
      }
    });

    remove = new Button(this, SWT.PUSH | SWT.CENTER);
    FormData removeLData = new FormData();
    removeLData.width = 25;
    removeLData.height = 25;
    removeLData.top = new FormAttachment(0, 1000, 54);
    removeLData.right = new FormAttachment(1000, 1000, -10);
    remove.setLayoutData(removeLData);
    Image deleteIcon = images.get("delete");
    remove.setImage(deleteIcon);
    remove.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        String selected = listViewer.getSelection().toString();
        selected = selected.substring(1, selected.length() - 1);
        String[] types = selected.split(", ");
        for (String string : types) {
          listViewer.remove(string);
        }
      }
    });

    if (ordered) {
      up = new Button(this, SWT.PUSH | SWT.CENTER);
      FormData upLData = new FormData();
      upLData.width = 25;
      upLData.height = 25;
      upLData.top = new FormAttachment(0, 1000, 81);
      upLData.right = new FormAttachment(1000, 1000, -10);
      up.setLayoutData(upLData);
      Image upIcon = images.get("up");
      up.setImage(upIcon);
      up.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
          ISelection selection = listViewer.getSelection();
          List<String> dataList = new ArrayList<String>();
          if (selection instanceof StructuredSelection) {
            StructuredSelection ss = (StructuredSelection) selection;
            Iterator<?> iterator = ss.iterator();
            while (iterator.hasNext()) {
              Object object = (Object) iterator.next();
              if (object instanceof String) {
                String obj = (String) object;
                dataList = new ArrayList<String>();
                TableItem[] items = listViewer.getTable().getItems();
                for (TableItem tableItem : items) {
                  dataList.add((String) tableItem.getData());
                }
                int indexOf = dataList.indexOf(obj);
                Collections.swap(dataList, indexOf, indexOf - 1);
              }
            }
          }
          listViewer.remove(dataList.toArray());
          addAll(dataList);
        }
      });

      down = new Button(this, SWT.PUSH | SWT.CENTER);
      FormData downLData = new FormData();
      downLData.width = 25;
      downLData.height = 25;
      downLData.top = new FormAttachment(0, 1000, 108);
      downLData.right = new FormAttachment(1000, 1000, -10);
      down.setLayoutData(downLData);
      Image downIcon = images.get("down");
      down.setImage(downIcon);
      down.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
          ISelection selection = listViewer.getSelection();
          List<String> dataList = new ArrayList<String>();
          if (selection instanceof StructuredSelection) {
            StructuredSelection ss = (StructuredSelection) selection;
            Iterator<?> iterator = ss.iterator();
            while (iterator.hasNext()) {
              Object object = (Object) iterator.next();
              if (object instanceof String) {
                String obj = (String) object;
                dataList = new ArrayList<String>();
                TableItem[] items = listViewer.getTable().getItems();
                for (TableItem tableItem : items) {
                  dataList.add((String) tableItem.getData());
                }
                int indexOf = dataList.indexOf(obj);
                Collections.swap(dataList, indexOf, indexOf + 1);
              }
            }
          }
          listViewer.remove(dataList.toArray());
          addAll(dataList);
        }
      });
    }
  }