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: ValidationPage.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.jface.wizard.IWizardPage;
23  import org.eclipse.swt.SWT;
24  import org.eclipse.swt.widgets.Composite;
25  
26  import pl.edu.agh.cast.importer.base.stat.AbstractErrorLogData;
27  import pl.edu.agh.cast.importer.base.stat.ErrorsLog;
28  import pl.edu.agh.cast.importer.wizard.util.Messages;
29  import pl.edu.agh.cast.ui.util.MsgBoxHelper;
30  
31  /**
32   * Page of the import wizard, which serves for import data validation after the parsing process.
33   * 
34   * @author AGH CAST Team
35   */
36  public class ValidationPage extends AbstractImportWizardPage {
37  
38  	private ValidationPageComposite composite;
39  
40  	/**
41  	 * The default constructor.
42  	 */
43  	public ValidationPage() {
44  		super(Messages.ImporterWizard_ValidationPageTitle, Messages.ImporterWizard_ValidationPageDescription);
45  	}
46  
47  	/**
48  	 * {@inheritDoc}
49  	 * 
50  	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
51  	 */
52  	public void createControl(Composite parent) {
53  		composite = new ValidationPageComposite(parent, SWT.NULL, this);
54  		setControl(composite);
55  
56  		initPage();
57  	}
58  
59  	/**
60  	 * {@inheritDoc}
61  	 * 
62  	 * @see pl.edu.agh.cast.importer.wizard.page.AbstractValidationPage#isComplete()
63  	 */
64  	protected boolean isComplete() {
65  		return !composite.isDataEmpty();
66  	}
67  
68  	/*
69  	 * -----------------------------------------------------------------------------------------------------------
70  	 * --------------------------OVERRIDED METHODS-------------------------------------------------------
71  	 * -----------------------------------------------------------------------------------------------------------
72  	 */
73  
74  	/**
75  	 * {@inheritDoc}
76  	 * 
77  	 * @see pl.edu.agh.cast.importer.wizard.page.AbstractImportWizardPage#initPage()
78  	 */
79  	@Override
80  	public void initPage() {
81  		if (composite != null && getImportProcess().shouldParse()) {
82  			getImportWizard().performTokenization();
83  			getImportWizard().performParsing();
84  
85  			composite.refreshPage(getImportProcess().getParsedData().get(0), getImportProcess().getErrorsLog());
86  		}
87  	}
88  
89  	/**
90  	 * {@inheritDoc}
91  	 * 
92  	 * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
93  	 */
94  	@Override
95  	public IWizardPage getNextPage() {
96  		if (composite != null && composite.isErrorsPresent()) {
97  			if (MsgBoxHelper.showWarningBox(composite, Messages.ValidationPage_ErrorsPresentTitle,
98  			        Messages.ValidationPage_ErrorsPresentMsg) != SWT.OK) {
99  				return null;
100 			}
101 		}
102 		return super.getNextPage();
103 	}
104 
105 	/*----------------------------------------------------------------------------------------------------------*/
106 
107 	/*
108 	 * -----------------------------------------------------------------------------------------------------------
109 	 * --------------------------HELPER METHODS------------------------------------------------------------
110 	 * -----------------------------------------------------------------------------------------------------------
111 	 */
112 
113 	/**
114 	 * Retrieves the errors log.
115 	 * 
116 	 * @return errors log
117 	 */
118 	public ErrorsLog getErrorsLog() {
119 		return getImportProcess().getErrorsLog();
120 	}
121 
122 	/**
123 	 * Delegate method.
124 	 * 
125 	 * {@inheritDoc}
126 	 * 
127 	 * @see pl.edu.agh.cast.importer.wizard.page.ValidationPageComposite#deleteRowsWithErrors(List)
128 	 */
129 	public void deleteErrors(List<AbstractErrorLogData> errorsToDelete) {
130 		composite.deleteRowsWithErrors(errorsToDelete);
131 	}
132 
133 	/*----------------------------------------------------------------------------------------------------------*/
134 }