View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: DelimiterSelectionPage.java
13   * Created: 2009-03-11
14   * Author: bmilos
15   * $Id$
16   */
17  
18  package pl.edu.agh.cast.importer.wizard.page;
19  
20  import java.util.List;
21  
22  import org.eclipse.swt.SWT;
23  import org.eclipse.swt.widgets.Composite;
24  
25  import pl.edu.agh.cast.importer.base.data.RawTabularData;
26  import pl.edu.agh.cast.importer.base.tokenizer.ITokenizerOption;
27  import pl.edu.agh.cast.importer.wizard.util.Messages;
28  
29  /**
30   * Page of the import wizard, which serves for selection of data column delimiters.
31   *
32   * @author AGH CAST Team
33   */
34  public class DelimiterSelectionPage extends AbstractImportWizardPage {
35  
36  	private DelimiterSelectionPageComposite composite;
37  
38  	/**
39  	 * The default constructor.
40  	 */
41  	public DelimiterSelectionPage() {
42  		super(Messages.ImporterWizard_DelimiterSelectionPageTitle,
43  		        Messages.ImporterWizard_DelimiterSelectionPageDescription);
44  	}
45  
46  	/**
47  	 * {@inheritDoc}
48  	 *
49  	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
50  	 */
51  	public void createControl(Composite parent) {
52  		composite = new DelimiterSelectionPageComposite(parent, SWT.NULL, this);
53  		setControl(composite);
54  
55  		refreshSelectedData();
56  	}
57  
58  	/*
59  	 * -----------------------------------------------------------------------------------------------------------
60  	 * --------------------------OVERRIDED METHODS-------------------------------------------------------
61  	 * -----------------------------------------------------------------------------------------------------------
62  	 */
63  
64  	/**
65  	 * {@inheritDoc}
66  	 *
67  	 * @see pl.edu.agh.cast.importer.wizard.page.AbstractImportWizardPage#initPage()
68  	 */
69  	@Override
70  	public void initPage() {
71  		refreshSelectedData();
72  	}
73  
74  	/**
75  	 * {@inheritDoc}
76  	 *
77  	 * @see pl.edu.agh.cast.importer.wizard.page.AbstractImportWizardPage#refreshImportData()
78  	 */
79  	@Override
80  	public void refreshImportData() {
81  		getImportProcess().setTokenizerOptions(composite.getSelectedTokenizerOptions());
82  	}
83  
84  	/*----------------------------------------------------------------------------------------------------------*/
85  
86  	/*
87  	 * -----------------------------------------------------------------------------------------------------------
88  	 * --------------------------HELPER METHODS------------------------------------------------------------
89  	 * -----------------------------------------------------------------------------------------------------------
90  	 */
91  
92  	protected boolean isComplete() {
93  		return true;
94  	}
95  
96  	/**
97  	 * Loads a data preview by importing a given amount of rows of a specified data file, with use of a tokenizer of a
98  	 * specified identifier and its options.
99  	 *
100 	 * <p>
101 	 * TODO: now the method loads a preview of only a single tabular data; future versions must include tabs for every
102 	 * tokenized tabular data
103 	 *
104 	 * @param options
105 	 *            the tokenizer options
106 	 * @param previewRowsLimit
107 	 *            the limit of rows previewed
108 	 * @return the raw tabular data ready for preview
109 	 */
110 	RawTabularData loadPreview(List<ITokenizerOption> options, int previewRowsLimit) {
111 		getImportProcess().setTokenizerOptions(options);
112 		return getImportProcess().getTokenizePreview();
113 	}
114 
115 	private void refreshSelectedData() {
116 		if (composite == null) {
117 			return;
118 		}
119 		composite.refreshFilePreviewGroupLabel(getImportProcess().getFilePath());
120 		composite.refreshFilePreview();
121 	}
122 
123 	/*----------------------------------------------------------------------------------------------------------*/
124 }