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: AnalyzersSelectionPage.java
13   * Created: 2009-03-17
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.apache.log4j.Logger;
23  import org.eclipse.core.runtime.CoreException;
24  import org.eclipse.swt.SWT;
25  import org.eclipse.swt.widgets.Composite;
26  
27  import pl.edu.agh.cast.importer.base.data.RawTabularData;
28  import pl.edu.agh.cast.importer.base.parser.ImportParser;
29  import pl.edu.agh.cast.importer.base.util.DataTypeInfo;
30  import pl.edu.agh.cast.importer.wizard.Activator;
31  import pl.edu.agh.cast.importer.wizard.dialog.analyzer.AbstractDataTypeConfigDialog;
32  import pl.edu.agh.cast.importer.wizard.util.Messages;
33  
34  /**
35   * Page of the import wizard, which serves for selection of analyzers for each column.
36   *
37   * @author AGH CAST Team
38   */
39  public class AnalyzersSelectionPage extends AbstractImportWizardPage {
40  
41  	private final Logger log = Activator.getLogger();
42  
43  	private AnalyzersSelectionPageComposite composite;
44  
45  	private RawTabularData previewDataCache;
46  
47  	/**
48  	 * The default constructor.
49  	 */
50  	public AnalyzersSelectionPage() {
51  		super(Messages.ImporterWizard_AnalyzersSelectionPageTitle,
52  		        Messages.ImporterWizard_AnalyzersSelectionPageDescription);
53  	}
54  
55  	/**
56  	 * {@inheritDoc}
57  	 *
58  	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
59  	 */
60  	public void createControl(Composite parent) {
61  		composite = new AnalyzersSelectionPageComposite(parent, SWT.NULL, this);
62  		setControl(composite);
63  
64  		refreshSelectedData();
65  	}
66  
67  	/*
68  	 * -----------------------------------------------------------------------------------------------------------
69  	 * --------------------------OVERRIDED METHODS-------------------------------------------------------
70  	 * -----------------------------------------------------------------------------------------------------------
71  	 */
72  
73  	/**
74  	 * {@inheritDoc}
75  	 *
76  	 * @see pl.edu.agh.cast.importer.wizard.page.AbstractImportWizardPage#initPage()
77  	 */
78  	@Override
79  	public void initPage() {
80  		refreshSelectedData();
81  	}
82  
83  	/**
84  	 * {@inheritDoc}
85  	 *
86  	 * @see pl.edu.agh.cast.importer.wizard.page.AbstractImportWizardPage#refreshImportData()
87  	 */
88  	@Override
89  	public void refreshImportData() {
90  		getImportProcess().setParser(new ImportParser(composite.getSelectedAnalyzers()));
91  	}
92  
93  	/*----------------------------------------------------------------------------------------------------------*/
94  
95  	/*
96  	 * -----------------------------------------------------------------------------------------------------------
97  	 * --------------------------HELPER METHODS------------------------------------------------------------
98  	 * -----------------------------------------------------------------------------------------------------------
99  	 */
100 
101 	/**
102 	 * Method is called whenever any widget had been selected or modified, and checks if the page had arrived to its
103 	 * completed state.
104 	 */
105 	public void widgetModified() {
106 		getImportProcess().setParser(new ImportParser(composite.getSelectedAnalyzers()));
107 		super.widgetModified();
108 	}
109 
110 	protected boolean isComplete() {
111 		return getImportProcess().isParserConfigured();
112 	}
113 
114 	private void refreshSelectedData() {
115 		if (composite != null && previewDataCache != getImportProcess().getTokenizePreview()) {
116 			previewDataCache = getImportProcess().getTokenizePreview();
117 			composite.createTable(previewDataCache);
118 		}
119 	}
120 
121 	/*----------------------------------------------------------------------------------------------------------*/
122 
123 	/*
124 	 * -----------------------------------------------------------------------------------------------------------
125 	 * --------------------------GETTERS AND SETTERS------------------------------------------------------
126 	 * -----------------------------------------------------------------------------------------------------------
127 	 */
128 
129 	/**
130 	 * Retrieves the available data types information.
131 	 *
132 	 * @return the data types information
133 	 */
134 	public DataTypeInfo[] getDataTypesInfos() {
135 		List<DataTypeInfo> dataTypeInfos = null;
136 		try {
137 			dataTypeInfos = getImportWizard().getImporterUtil().getDataTypeInfos();
138 		} catch (CoreException e) {
139 			final String errorMsg = "CoreException while retrieving data type information."; //$NON-NLS-1$
140 			log.error(errorMsg, e);
141 			throw new RuntimeException(errorMsg, e);
142 		}
143 
144 		if (dataTypeInfos == null) {
145 			return null;
146 		}
147 
148 		return dataTypeInfos.toArray(new DataTypeInfo[0]);
149 	}
150 
151 	/**
152 	 * Retrieves the data type configuration dialog instance for the specified data type identifier.
153 	 *
154 	 * @param dataTypeId
155 	 *            the data type identifier
156 	 * @return data type configuration dialog
157 	 */
158 	public AbstractDataTypeConfigDialog getDataTypeConfigDialogInstance(String dataTypeId) {
159 		try {
160 			return getImportWizard().getWizardUtil().getDataTypeConfigDialogInstance(dataTypeId);
161 		} catch (CoreException e) {
162 			final String errorMsg = "CoreException while retrieving instance of data type " //$NON-NLS-1$
163 			        + "configuration dialog with id: " + dataTypeId; //$NON-NLS-1$
164 			log.error(errorMsg, e);
165 			throw new RuntimeException(errorMsg, e);
166 		}
167 	}
168 
169 	/*----------------------------------------------------------------------------------------------------------*/
170 }