Package org.sf.mustru.ui

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

package org.sf.mustru.ui;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/**
* Create the second page of the wizard
*/
public class SecondPage extends WizardPage
{
Table table;
ArrayList<String> dirs = new ArrayList<String>();

/**
  * Constructor for the SecondPage
  */
public SecondPage()
{ super("Second Page");
setTitle("Crawl Configuration Part 2/4");
setDescription("Add a list of directories to INCLUDE in the index.");
setPageComplete(true);
}

/**
  * Create the second page with the list of directories to include
  *
  */
public void createControl(Composite parent)
{
  final Composite composite = new Composite(parent, SWT.NULL);
  GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;
  composite.setLayout(gridLayout);

  //*-- build the table consisting of the list of directories to scan
  table = new Table ( composite, SWT.BORDER | SWT.SINGLE );  
  table.setLinesVisible(true); table.setHeaderVisible(true);
  GridData tableGd = new GridData(); tableGd.horizontalSpan= 2; tableGd.grabExcessHorizontalSpace = true;
  tableGd.horizontalAlignment = GridData.FILL;
  table.setLayoutData(tableGd);
  TableColumn tcol1 = new TableColumn( table, SWT.LEFT, 0);
  tcol1.setText("Directories:"); tcol1.setWidth(500);

  //*-- populate the table with the entries from the crawl configuration
  String incDirList = ( (CrawlConfigWizard) getWizard()).crawlConfig.getIncDirs().trim();
  String[] incDirs = incDirList.split(";");
  for (int i = 0; i < incDirs.length; i++)
   if (!incDirs[i].equals("")) dirs.add(incDirs[i]);
  fillUpTable();
  table.setItemCount(5);

  //*-- add the two buttons to add and delete directory names
  final Button addButton = new Button(composite, SWT.PUSH); addButton.setText("Add");
  GridData addButtonGd = new GridData(); addButtonGd.horizontalAlignment = GridData.BEGINNING;
  addButtonGd.grabExcessHorizontalSpace = false;
  addButton.setLayoutData(addButtonGd);
  addButton.addListener( SWT.Selection, new Listener()
  {
   public void handleEvent(Event e)
   {
    DirectoryDialog dd = new DirectoryDialog(composite.getShell());
    dd.setMessage("Please select a directory to include in the scan");
    String dir = dd.open();
    if (dir != null)  { dirs.add(dir); fillUpTable(); }
   }
  });

  final Button deleteButton = new Button(composite, SWT.PUSH); deleteButton.setText("Delete");
  GridData delButtonGd = new GridData(); delButtonGd.horizontalAlignment = GridData.BEGINNING;
  delButtonGd.grabExcessHorizontalSpace = false;
  deleteButton.setLayoutData(delButtonGd);
  deleteButton.addListener( SWT.Selection, new Listener()
  {
   public void handleEvent(Event e)
   {
    int i = table.getSelectionIndex();
    if (i != -1) { dirs.remove(i); fillUpTable(); }
   }
  });

  setControl(composite);

}

//*-- populate the table with entries from the dirs list
private void fillUpTable()
{
  //*-- create a hash with the directories to remove dups from the dirs list
  HashSet<String> h = new HashSet<String>();
  for (int i = 0; i < dirs.size(); i++) h.add((String) dirs.get(i));
  dirs = new ArrayList<String>();
  Iterator it =  h.iterator();
  while (it != null && it.hasNext()) dirs.add( (String) it.next() );  

  //*-- re-create the table and set the incDirs string
  StringBuffer incDirs = new StringBuffer();
  table.removeAll();
  for (int i = 0; i < dirs.size(); i++)
  { TableItem ti = new TableItem(table, SWT.LEFT, i);
  String dir = (String) dirs.get(i);
  ti.setText(dir); incDirs.append(dir); incDirs.append( ";");
  }
  ( (CrawlConfigWizard) getWizard()).crawlConfig.setIncDirs(incDirs.toString());
}

}
TOP

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

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.