private void initGUI()

in ruta-ep-addons/src/main/java/org/apache/uima/ruta/query/ui/QueryComposite.java [146:462]


  private void initGUI() {
    try {
      this.setLayout(new FormLayout());
      this.setSize(600, 380);

      // first row

      dataLocationLabel = new Label(this, SWT.NONE);
      FormData label1LData = new FormData();
      label1LData.left = new FormAttachment(0, 1000, 12);
      label1LData.top = new FormAttachment(0, 1000, 10);
      label1LData.width = 70;
      dataLocationLabel.setLayoutData(label1LData);
      dataLocationLabel.setText("Data location");

      dataLocationField = new Text(this, SWT.SINGLE | SWT.BORDER);
      FormData inputDirectoryTexLData = new FormData();
      inputDirectoryTexLData.width = 150;
      inputDirectoryTexLData.left = new FormAttachment(dataLocationLabel, 10);
      inputDirectoryTexLData.top = new FormAttachment(0, 1000, 10);
      inputDirectoryTexLData.right = new FormAttachment(1000, 1000, -65);
      dataLocationField.setLayoutData(inputDirectoryTexLData);
      dataLocationField.setText("");
      dataLocationField.addModifyListener(new ModifyListener() {
        @Override
        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();
        }
      });

      dirButton = new Button(this, SWT.PUSH | SWT.CENTER);
      FormData dirButtoLData = new FormData();
      dirButtoLData.width = 25;
      dirButtoLData.height = 25;
      dirButtoLData.top = new FormAttachment(0, 1000, 8);
      dirButtoLData.right = new FormAttachment(1000, 1000, -35);
      dirButton.setLayoutData(dirButtoLData);
      Image folderIcon = getImage("folder");
      dirButton.setImage(folderIcon);
      dirButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
          DirectoryDialog dlg = new DirectoryDialog(getShell());
          dlg.setFilterPath(dataLocationField.getText());
          dlg.setText("Data location");
          dlg.setMessage("Select a directory with input XMI files.");
          String dir = dlg.open();
          if (dir != null) {
            dataLocationField.setText(dir);
          }
        }
      });

      recursiveButton = new Button(this, SWT.CHECK | SWT.LEFT);
      FormData recuriveButtonLData = new FormData();
      recuriveButtonLData.width = 20;
      recuriveButtonLData.height = 18;
      recuriveButtonLData.top = new FormAttachment(0, 1000, 10);
      recuriveButtonLData.right = new FormAttachment(1000, 1000, -10);
      recursiveButton.setLayoutData(recuriveButtonLData);
      recursiveButton.setSelection(true);

      // next row

      FormAttachment top2 = new FormAttachment(dataLocationLabel, 10);
      fileFilterLabel = new Label(this, SWT.NONE);
      FormData label2LData = new FormData();
      label2LData.left = new FormAttachment(0, 1000, 12);
      label2LData.top = top2; // new FormAttachment(0, 1000, 34);
      label2LData.width = 70;
      fileFilterLabel.setLayoutData(label2LData);
      fileFilterLabel.setText("File filter");

      inputPatternText = new Text(this, SWT.SINGLE | SWT.BORDER);
      FormData inputPatternTextData = new FormData();
      inputPatternTextData.width = 150;
      inputPatternTextData.left = new FormAttachment(fileFilterLabel, 10);
      inputPatternTextData.top = top2;
      inputPatternTextData.right = new FormAttachment(1000, 1000, -65);
      inputPatternText.setLayoutData(inputPatternTextData);
      inputPatternText.setText(".+\\.xmi");

      decoFileFilterPattern = new ControlDecoration(this.inputPatternText, SWT.TOP | SWT.LEFT);
      Image imageError = FieldDecorationRegistry.getDefault()
              .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
      decoFileFilterPattern
              .setDescriptionText("PatternSyntaxException for this regular expression.");
      decoFileFilterPattern.setImage(imageError);
      decoFileFilterPattern.hide();
      inputPatternText.addModifyListener(e -> decoFileFilterPattern.hide());

      // next row

      FormAttachment top3 = new FormAttachment(fileFilterLabel, 10);
      typeSystemLabel = new Label(this, SWT.NONE);
      FormData label3LData = new FormData();
      label3LData.width = 70;
      label3LData.left = new FormAttachment(0, 1000, 12);
      label3LData.top = top3;
      typeSystemLabel.setLayoutData(label3LData);
      typeSystemLabel.setText("Type system");

      typeSystemFileText = new Text(this, SWT.SINGLE | SWT.BORDER);
      FormData preFileTexLData = new FormData();
      preFileTexLData.width = 150;
      preFileTexLData.left = new FormAttachment(typeSystemLabel, 10);
      preFileTexLData.top = top3;
      preFileTexLData.right = new FormAttachment(1000, 1000, -65);
      typeSystemFileText.setLayoutData(preFileTexLData);
      typeSystemFileText.setText("");
      typeSystemFileText.addModifyListener(new ModifyListener() {
        @Override
        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();
        }
      });

      fileChooseButton = new Button(this, SWT.PUSH | SWT.CENTER);
      FormData fileChooseButtoLData = new FormData();
      fileChooseButtoLData.width = 25;
      fileChooseButtoLData.height = 25;
      fileChooseButtoLData.top = top3;
      fileChooseButtoLData.right = new FormAttachment(1000, 1000, -35);
      fileChooseButton.setLayoutData(fileChooseButtoLData);
      Image icon = getImage("prepFolder");
      fileChooseButton.setImage(icon);
      fileChooseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
          FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
          fd.setText("Choose Type System Descriptor or Ruta Script");
          String[] filterExt = { "*.ruta", "*.*" };
          fd.setFilterExtensions(filterExt);
          String file = fd.open();
          if (file != null) {
            typeSystemFileText.setText(file);
          }
        }
      });

      // next row: query rules

      FormAttachment top4 = new FormAttachment(typeSystemLabel, 10);
      Composite compositeQueryRules = new Composite(this, SWT.NULL);
      FormData compData = new FormData();
      compData.height = 100;
      compData.left = new FormAttachment(0, 1000, 10);
      compData.top = top4;
      compData.right = new FormAttachment(1000, 1000, -10);
      compositeQueryRules.setLayoutData(compData);
      compositeQueryRules.setLayout(new FillLayout());
      IDLTKUILanguageToolkit toolkit = DLTKUILanguageManager
              .getLanguageToolkit(RutaLanguageToolkit.getDefault().getNatureId());
      final ScriptTextTools textTools = toolkit.getTextTools();
      IPreferenceStore store = toolkit.getCombinedPreferenceStore();
      viewer = new ScriptSourceViewer(compositeQueryRules, null, null, false,
              SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, store);

      ScriptSourceViewerConfiguration configuration = textTools
              .createSourceViewerConfiguraton(store, (ITextEditor) null);
      viewer.configure(configuration);
      setInformation("");
      compositeQueryRules.layout();

      viewer.addTextListener(new ITextListener() {

        @Override
        public void textChanged(TextEvent arg0) {
          setRutaQuerySyntaxError(false);
        }
      });

      decoQueryRules = new ControlDecoration(compositeQueryRules, SWT.TOP | SWT.LEFT);
      decoQueryRules.setDescriptionText("Could not run query, maybe illegal Ruta rule syntax.");
      decoQueryRules.setImage(imageError);
      decoQueryRules.hide();
      // TODO
      // inputPatternText.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;
      // decoPattern.hide();
      // }
      // });

      // next row: query results

      FormAttachment top5 = new FormAttachment(compositeQueryRules, 10);

      resultLabel = new Label(this, SWT.NONE);
      FormData resultLabelData = new FormData();
      resultLabelData.left = new FormAttachment(0, 1000, 12);
      resultLabelData.top = top5;
      resultLabelData.width = 300;
      resultLabel.setLayoutData(resultLabelData);
      resultLabel.setText("Result:");

      Composite composite2 = new Composite(this, SWT.NONE);
      FormData comp2Data = new FormData();
      // comp2Data.width = 300;
      // comp2Data.height = 200;
      comp2Data.left = new FormAttachment(0, 1000, 10);
      comp2Data.top = new FormAttachment(resultLabel, 10);
      comp2Data.right = new FormAttachment(1000, 1000, -10);
      comp2Data.bottom = new FormAttachment(1000, 1000, -10);
      // compData.left = new FormAttachment(0, 1000, 12);
      // compData.top = new FormAttachment(0, 1000, 70);
      // compData.bottom = new FormAttachment(0, 1000, -10);
      // compData.right = new FormAttachment(1000, 1000, -10);
      // compData.width = 109;
      // composite2.setSize(500, 500);
      // composite.setBackground(new Color(getDisplay(), 128, 0, 0));
      composite2.setLayoutData(comp2Data);
      composite2.setLayout(new FillLayout());

      resultViewer = new TableViewer(composite2,
              SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI);
      final QueryResultLabelProvider queryResultLabelProvider = new QueryResultLabelProvider();
      resultViewer.setLabelProvider(queryResultLabelProvider);
      resultViewer.setContentProvider(new QueryResultContentProvider());
      resultViewer.addSelectionChangedListener(this);
      resultViewer.getTable().addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
          if (((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'c')) {
            String output = "";
            TableItem[] items = resultViewer.getTable().getSelection();
            for (TableItem item : items) {
              QueryResult data = (QueryResult) item.getData();
              if (output.length() != 0) {
                output += System.getProperty("line.separator");
              }
              output += queryResultLabelProvider.getText(data);
            }
            clipboard.setContents(new Object[] { output },
                    new Transfer[] { TextTransfer.getInstance() });
          }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }
      });
      resultViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
          Object obj = event.getSelection();
          if (obj instanceof IStructuredSelection) {
            StructuredSelection selection = (StructuredSelection) obj;
            Iterator<?> iterator = selection.iterator();
            while (iterator.hasNext()) {
              Object element = iterator.next();
              if (element instanceof QueryResult) {
                QueryResult data = (QueryResult) element;
                if (data.getFile() != null) {
                  openInCasEditor(data.getFile(), data.getBegin(), data.getEnd());
                }
              }
            }
          }

        }
      });
      composite2.layout();

      this.layout();
    } catch (Exception e) {
      RutaAddonsPlugin.error(e);
    }

    DropTarget dt = new DropTarget(dataLocationField, 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) {
          dataLocationField.setText(fileList[0]);
        }
      }
    });

    DropTarget dt2 = new DropTarget(typeSystemFileText, 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 > 0) {
          typeSystemFileText.setText(fileList[0]);
        }
      }
    });

  }