public void createPartControl()

in caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusExplorerView.java [136:300]


  public void createPartControl(Composite parent) {

    explorerComposite = new Composite(parent, SWT.NONE);
    GridLayout explorerLayout = new GridLayout();
    explorerLayout.numColumns = 2;
    explorerComposite.setLayout(explorerLayout);

    // URL field to connect to corpus server and corpus
    Label serverLabel = new Label(explorerComposite, SWT.NONE);
    serverLabel.setText("Server:");

    serverUrl = new Text(explorerComposite, SWT.BORDER);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
        .applyTo(serverUrl);

    final IPreferenceStore store = CorpusServerPlugin.getDefault().getPreferenceStore();
    
    String lastUsedServer = store.getString(CorpusServerPreferenceConstants.LAST_USED_SERVER_ADDRESS);
    
    if (lastUsedServer.isEmpty()) {
      lastUsedServer = "http://localhost:8080/corpus-server/rest/corpora/wikinews";
    }
    
    serverUrl.setText(lastUsedServer);
    
    serverUrl.addModifyListener(event -> store.setValue(CorpusServerPreferenceConstants.LAST_USED_SERVER_ADDRESS, serverUrl.getText()));
    
    // Search field to view content of corpus
    Label queryLabel = new Label(explorerComposite, SWT.NONE);
    queryLabel.setText("Query");
    
    queryText = new Combo(explorerComposite, SWT.BORDER);
    
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
        .applyTo(queryText);

    
    String lastUsedSearchQueriesString = 
        store.getString(CorpusServerPreferenceConstants.LAST_USED_SEARCH_QUERIES);
    
    // TODO: Set default via preference initializer
    if (lastUsedSearchQueriesString.isEmpty()) {
      lastUsedSearchQueriesString = "*:*";
    }
    
    String[] lastUsedQueries = lastUsedSearchQueriesString.split(LUCENE_QUERY_DELIMITER);
    
    if (lastUsedQueries.length > 0)
      queryText.setText(lastUsedQueries[0]);

    for (String lastUsedQuery : lastUsedQueries) {
      queryText.add(lastUsedQuery);
    }

    queryText.addSelectionListener(new SelectionListener() {
      
      @Override
      public void widgetSelected(SelectionEvent event) {
        doSearch();
      }
      
      @Override
      public void widgetDefaultSelected(SelectionEvent event) {
      }
    });
    
    queryText.addKeyListener(new KeyListener() {
      
      @Override
      public void keyReleased(KeyEvent event) {
        if (event.character ==SWT.CR)
          doSearch();
      }
      
      @Override
      public void keyPressed(KeyEvent event) {
      }
    });
    
    Button queryServer = new Button(explorerComposite, SWT.BORDER);
    queryServer.setText("Query");
    GridDataFactory.swtDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER)
        .grab(true, false).applyTo(queryServer);
    
    queryServer.addSelectionListener(new SelectionListener() {

      @Override
      public void widgetSelected(SelectionEvent event) {
        doSearch();
      }

      @Override
      public void widgetDefaultSelected(SelectionEvent event) {
      }
    });
    
    book = new PageBook(explorerComposite, SWT.NONE);
    
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
            .span(2, 1).applyTo(book);
    
    messageText = new Text(book, SWT.WRAP | SWT.READ_ONLY);
    messageText.setText("Enter the server address and a query to search a corpus on the Corpus Server.");

    // List with casIds in the corpus ... (might be later replaced with a title)
    // The table should later be virtual, and be able to scroll through very huge
    // lits of CASes ... might be connected to a repository with millions of documents
    searchResultViewer = new TableViewer(book);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
        .span(2, 1).applyTo(searchResultViewer.getControl());

    searchResultViewer.setLabelProvider(new ITableLabelProvider() {

      @Override
      public void addListener(ILabelProviderListener arg0) {
      }

      @Override
      public void dispose() {
      }

      @Override
      public boolean isLabelProperty(Object arg0, String arg1) {
        return false;
      }

      @Override
      public void removeListener(ILabelProviderListener arg0) {
      }

      @Override
      public Image getColumnImage(Object arg0, int arg1) {
        return null;
      }

      @Override
      public String getColumnText(Object arg0, int arg1) {
        return arg0.toString();
      }});
    
    searchResultViewer.addOpenListener(event -> {

      IWorkbenchPage page = CorpusExplorerView.this.getSite().getPage();

      StructuredSelection selection = (StructuredSelection) searchResultViewer.getSelection();

      if (selection.isEmpty())
        return;

      String selectedCAS = (String) selection.getFirstElement();

      // Hard code it for now, lets work on retrieval code first ...
      IEditorInput input = new CorpusServerCasEditorInput(serverUrl.getText(), selectedCAS);

      try {
        page.openEditor(input, "org.apache.uima.caseditor.editor");
      } catch (PartInitException e) {
        e.printStackTrace();
      }
    });

    book.showPage(messageText);
    
    // TODO: Context menu should have open action
  }