Package org.sf.mustru.ui

Source Code of org.sf.mustru.ui.FirstPage

package org.sf.mustru.ui;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

/**
* Create the first page of the wizard
*/
public class FirstPage extends WizardPage
{
/**
  * Constructor for the FirstPage
  */
public FirstPage()
{ super("First Page");
setTitle("Crawl Configuration Part 1/4");
setDescription("Set the values for the following fields");
}

/**
  * Create the first page for the following parameters
  *
  * freshCrawl:  Re-create a new Lucene index and database
  * keepDups:    Index duplicate documents
  * skipHidden:  Skip directories that start with
  * numThreads:  Number of threads to use during the index process
  * followLinks:  Follow symbolic links
  */
public void createControl(Composite parent)
{
  Composite composite = new Composite(parent, SWT.NULL);
  GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 5;
  composite.setLayout(gridLayout);
  Color backYellow = new Color(composite.getDisplay(), 231, 231, 191);
  Color[] labelColors =new Color[] {backYellow, composite.getDisplay().getSystemColor(SWT.COLOR_WHITE) };

  //*-- build first row and description for scanning hidden directories 
  GridData skipGd = new GridData(); skipGd.grabExcessHorizontalSpace = true; skipGd.horizontalAlignment = GridData.FILL;
  Label skipLabel = new Label(composite, SWT.LEFT); skipLabel.setText("Skip Hidden Directories: ");
  skipLabel.setLayoutData(skipGd);

  final Button skipYesButton = new Button(composite, SWT.RADIO); skipYesButton.setText("Yes");
  final Button skipNoButton = new Button(composite, SWT.RADIO);  skipNoButton.setText("No");
  if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isSkipHidden() ) skipYesButton.setSelection(true);
  else skipNoButton.setSelection(true);

  CLabel skipDescr = new CLabel (composite, SWT.BORDER);
  GridData skiplGd = new GridData();
  skiplGd.horizontalSpan = 5; skiplGd.grabExcessHorizontalSpace = true;
  skiplGd.horizontalAlignment = GridData.FILL;
  skipDescr.setText("A hidden directory starts with a period and may contain files that you do not want to index");
  skipDescr.setBackground( labelColors, new int[] {100} );
  skipDescr.setLayoutData(skiplGd);

  //*-- build second row and description for extracting entities
  GridData extGd = new GridData(); extGd.grabExcessHorizontalSpace = true; extGd.horizontalAlignment = GridData.FILL;
  Label extLabel = new Label(composite, SWT.LEFT); extLabel.setText("Follow Symbolic Links: ");
  extLabel.setLayoutData(extGd);

  final Button folYesButton = new Button(composite, SWT.RADIO); folYesButton.setText("Yes");
  final Button folNoButton = new Button(composite, SWT.RADIO); folNoButton.setText("No");
  if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isFollowLinks() ) folYesButton.setSelection(true);
  else folNoButton.setSelection(true);

  CLabel folDescr = new CLabel (composite, SWT.BORDER);
  GridData folGd = new GridData();
  folGd.horizontalSpan = 5; folGd.grabExcessHorizontalSpace = true;
  folGd.horizontalAlignment = GridData.FILL;
  folDescr.setText("Following symbolic links may lead to an infinite loop");
  folDescr.setBackground( labelColors, new int[] {100} );
  folDescr.setLayoutData(folGd);

  //*-- build third row and description to skip duplicate files
  GridData keepGd = new GridData(); keepGd.grabExcessHorizontalSpace = true; keepGd.horizontalAlignment = GridData.FILL;
  Label keepLabel = new Label(composite, SWT.LEFT);
  keepLabel.setText("Keep Duplicate Files: ");
  keepLabel.setLayoutData(keepGd);

  final Button keepYesButton = new Button(composite, SWT.RADIO); keepYesButton.setText("Yes");
  final Button keepNoButton = new Button(composite, SWT.RADIO);  keepNoButton.setText("No");
  if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isKeepDups() ) keepYesButton.setSelection(true);
  else keepNoButton.setSelection(true);

  CLabel keepDescr = new CLabel (composite, SWT.BORDER);
  GridData keeplGd = new GridData();
  keeplGd.horizontalSpan = 5; keeplGd.grabExcessHorizontalSpace = true;
  keeplGd.horizontalAlignment = GridData.FILL;
  keepDescr.setText("Duplicate files have the same text content and will appear twice in hit lists");
  keepDescr.setBackground( labelColors, new int[] {100} );
  keepDescr.setLayoutData(keeplGd);

  //*-- build fourth row and description to handle a fresh crawl
  GridData freshGd = new GridData(); freshGd.grabExcessHorizontalSpace = true; freshGd.horizontalAlignment = GridData.FILL;
  Label freshLabel = new Label(composite, SWT.LEFT);
  freshLabel.setText("Fresh Crawl: ");
  freshLabel.setLayoutData(freshGd);

  final Button freshYesButton = new Button(composite, SWT.RADIO); freshYesButton.setText("Yes");
  final Button freshNoButton = new Button(composite, SWT.RADIO); freshNoButton.setText("No");
  if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isFreshCrawl() ) freshYesButton.setSelection(true);
  else freshNoButton.setSelection(true);

  CLabel freshDescr = new CLabel (composite, SWT.BORDER);
  GridData freshlGd = new GridData();
  freshlGd.horizontalSpan = 5; freshlGd.grabExcessHorizontalSpace = true;
  freshlGd.horizontalAlignment = GridData.FILL;
  freshDescr.setText("A fresh crawl starts indexing after wiping all earlier entries");
  freshDescr.setBackground( labelColors, new int[] {100} );
  freshDescr.setLayoutData(freshlGd);

  //*-- add the fifth row for the number of threads
  GridData numGd = new GridData(); numGd.grabExcessHorizontalSpace = true; numGd.horizontalAlignment = GridData.FILL;
  Label numLabel = new Label(composite, SWT.LEFT);
  numLabel.setText("Number of Threads: ");
  numLabel.setLayoutData(numGd);

  final Combo threadCombo = new Combo(composite, SWT.SINGLE |  SWT.BORDER );
  final String[] threads =  new String[] { "1", "2", "4", "8"};
  for (int i = 0; i < threads.length; i++) threadCombo.add(threads[i]);
  int numThreads = ( (CrawlConfigWizard) getWizard()).crawlConfig.getNumThreads();
  switch (numThreads)
  { case 1: threadCombo.select(0); break;
  case 2: threadCombo.select(1); break;
  case 4: threadCombo.select(2); break;
  case 8: threadCombo.select(3); break;
  }

  CLabel threadDescr = new CLabel (composite, SWT.BORDER);
  GridData threadlGd = new GridData();
  threadlGd.horizontalSpan = 5; threadlGd.grabExcessHorizontalSpace = true;
  threadlGd.horizontalAlignment = GridData.FILL;
  threadDescr.setText("More than one thread will be beneficial in a multi-processor machine");
  threadDescr.setBackground( labelColors, new int[] {100} );
  threadDescr.setLayoutData(freshlGd);

  //*-- build sizth row and description to handle the spell checker
  GridData spellGd = new GridData(); spellGd.grabExcessHorizontalSpace = true; spellGd.horizontalAlignment = GridData.FILL;
  Label spellLabel = new Label(composite, SWT.LEFT);
  spellLabel.setText("Use Spell Checker: ");
  spellLabel.setLayoutData(freshGd);

  final Button spellYesButton = new Button(composite, SWT.RADIO); spellYesButton.setText("Yes");
  final Button spellNoButton = new Button(composite, SWT.RADIO); spellNoButton.setText("No");
  if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isSpellCheck() ) spellYesButton.setSelection(true);
  else spellNoButton.setSelection(true);

  CLabel spellDescr = new CLabel (composite, SWT.BORDER);
  GridData spelllGd = new GridData();
  spelllGd.horizontalSpan = 5; spelllGd.grabExcessHorizontalSpace = true;
  spelllGd.horizontalAlignment = GridData.FILL;
  spellDescr.setText("A spell checker can provide alternative queries");
  spellDescr.setBackground( labelColors, new int[] {100} );
  spellDescr.setLayoutData(freshlGd);
  //*-- build the listener
  Listener selectionListener = new Listener()
  { public void handleEvent(Event event)
  {
   //*-- set the crawl configuration based on the selected buttons
   if (skipYesButton.getSelection())   ( (CrawlConfigWizard) getWizard() ).crawlConfig.setSkipHidden(true);
   if (skipNoButton.getSelection())   ( (CrawlConfigWizard) getWizard() ).crawlConfig.setSkipHidden(false);
   if (folYesButton.getSelection()) ( (CrawlConfigWizard) getWizard() ).crawlConfig.setFollowLinks(true);
   if (folNoButton.getSelection())  ( (CrawlConfigWizard) getWizard() ).crawlConfig.setFollowLinks(false);
   if (keepYesButton.getSelection())  ( (CrawlConfigWizard) getWizard() ).crawlConfig.setKeepDups(true);
   if (keepNoButton.getSelection())   ( (CrawlConfigWizard) getWizard() ).crawlConfig.setKeepDups(false);
   if (freshYesButton.getSelection())   ( (CrawlConfigWizard) getWizard() ).crawlConfig.setFreshCrawl(true);
   if (freshNoButton.getSelection())  ( (CrawlConfigWizard) getWizard() ).crawlConfig.setFreshCrawl(false);
   if (spellYesButton.getSelection())   ( (CrawlConfigWizard) getWizard() ).crawlConfig.setSpellCheck(true);
   if (spellNoButton.getSelection())  ( (CrawlConfigWizard) getWizard() ).crawlConfig.setSpellCheck(false);
   int numThreads = Integer.parseInt( threads[threadCombo.getSelectionIndex() ] );
   ( (CrawlConfigWizard) getWizard() ).crawlConfig.setNumThreads(numThreads);

   //*-- set the selected buttons in the window
   if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isSkipHidden() ) skipYesButton.setSelection(true);
   else skipNoButton.setSelection(true);  
   if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isFollowLinks() ) folYesButton.setSelection(true);
   else folNoButton.setSelection(true);
   if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isKeepDups() ) keepYesButton.setSelection(true);
   else keepNoButton.setSelection(true);
   if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isFreshCrawl() ) freshYesButton.setSelection(true);
   else freshNoButton.setSelection(true);
   if ( ( (CrawlConfigWizard) getWizard()).crawlConfig.isSpellCheck() ) spellYesButton.setSelection(true);
   else spellNoButton.setSelection(true);
   switch (numThreads)
   { case 1: threadCombo.select(0); break;
   case 2: threadCombo.select(1); break;
   case 4: threadCombo.select(2); break;
   case 8: threadCombo.select(3); break;
   }
  }
  };

  skipYesButton.addListener( SWT.Selection, selectionListener);   skipNoButton.addListener( SWT.Selection, selectionListener);
  folYesButton.addListener( SWT.Selection, selectionListener);    folNoButton.addListener( SWT.Selection, selectionListener);
  keepYesButton.addListener( SWT.Selection, selectionListener);   keepNoButton.addListener( SWT.Selection, selectionListener);
  freshYesButton.addListener( SWT.Selection, selectionListener);   freshNoButton.addListener( SWT.Selection, selectionListener);
  spellYesButton.addListener( SWT.Selection, selectionListener);   spellNoButton.addListener( SWT.Selection, selectionListener);
  threadCombo.addListener( SWT.Selection, selectionListener);

  setControl(composite);

}

}
TOP

Related Classes of org.sf.mustru.ui.FirstPage

TOP
Copyright © 2018 www.massapi.com. 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.