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: AnalyzersSelectionPageComposite.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.LinkedList;
21  import java.util.List;
22  
23  import org.eclipse.swt.SWT;
24  import org.eclipse.swt.layout.FillLayout;
25  import org.eclipse.swt.layout.GridData;
26  import org.eclipse.swt.layout.GridLayout;
27  import org.eclipse.swt.widgets.Composite;
28  
29  import pl.edu.agh.cast.importer.base.data.RawTabularData;
30  import pl.edu.agh.cast.importer.base.parser.analyzer.IAnalyzer;
31  import pl.edu.agh.cast.importer.base.util.DataTypeInfo;
32  import pl.edu.agh.cast.importer.wizard.utils.ComboBoxTableCreator;
33  
34  /**
35   * The main composite of the {@link AnalyzersSelectionPage}.
36   *
37   * @author AGH CAST Team
38   */
39  public class AnalyzersSelectionPageComposite extends Composite {
40  
41  	private Composite rootContainer;
42  
43  	private ComboBoxTableCreator tableCreator;
44  
45  	private AnalyzersSelectionPage mediator;
46  
47  	/**
48  	 * The default constructor.
49  	 *
50  	 * @param parent
51  	 *            the parent composite
52  	 * @param style
53  	 *            the style of widget to construct
54  	 * @param mediator
55  	 *            the mediating wizard page
56  	 */
57  	public AnalyzersSelectionPageComposite(Composite parent, int style, AnalyzersSelectionPage mediator) {
58  		super(parent, style);
59  		this.mediator = mediator;
60  		initGUI();
61  	}
62  
63  	private void initGUI() {
64  		GridLayout thisLayout = new GridLayout();
65  		this.setLayout(thisLayout);
66  		this.setSize(800, 600);
67  
68  		rootContainer = new Composite(this, SWT.NULL);
69  		rootContainer.setLayout(new FillLayout());
70  		GridData rootContainerLData = new GridData(SWT.FILL, SWT.FILL, true, true);
71  		rootContainer.setLayoutData(rootContainerLData);
72  
73  		tableCreator = new ComboBoxTableCreator(mediator);
74  	}
75  
76  	/*
77  	 * -----------------------------------------------------------------------------------------------------------
78  	 * --------------------------HELPER METHODS------------------------------------------------------------
79  	 * -----------------------------------------------------------------------------------------------------------
80  	 */
81  
82  	/**
83  	 * Calls <code>ComboBoxTableCreator.createTable()</code> method, which creates table basing on items and data to
84  	 * insert into the combo boxes and tokenized raw tabular data.
85  	 *
86  	 * @param data
87  	 *            the data to be inserted into the table
88  	 */
89  	public void createTable(RawTabularData data) {
90  		DataTypeInfo[] dataTypes = mediator.getDataTypesInfos();
91  		String[] dataTypeNames = new String[dataTypes.length];
92  
93  		for (int i = 0; i < dataTypes.length; i++) {
94  			dataTypeNames[i] = dataTypes[i].getName();
95  		}
96  
97  		tableCreator.createTable(rootContainer, dataTypeNames, dataTypes, data);
98  
99  		rootContainer.layout();
100 	}
101 
102 	/*----------------------------------------------------------------------------------------------------------*/
103 
104 	/*
105 	 * -----------------------------------------------------------------------------------------------------------
106 	 * --------------------------GETTERS AND SETTERS------------------------------------------------------
107 	 * -----------------------------------------------------------------------------------------------------------
108 	 */
109 
110 	/**
111 	 * Retrieves the selected analyzers from the combo data of the table creator.
112 	 *
113 	 * @return list of selected analyzers
114 	 */
115 	public List<IAnalyzer> getSelectedAnalyzers() {
116 		List<Object> objects = tableCreator.getSelectedComboData();
117 		List<IAnalyzer> analyzers = new LinkedList<IAnalyzer>();
118 
119 		if (objects == null) {
120 			return null;
121 		}
122 
123 		for (Object object : objects) {
124 			analyzers.add((IAnalyzer)object);
125 		}
126 		return analyzers;
127 	}
128 
129 	/*----------------------------------------------------------------------------------------------------------*/
130 }