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: WithoutTemplateWizardStrategy.java
13   * Created: 2009-09-10
14   * Author: entrop
15   * $Id$
16   */
17  
18  package pl.edu.agh.cast.importer.wizard.strategy;
19  
20  import java.util.List;
21  
22  import org.eclipse.swt.SWT;
23  
24  import pl.edu.agh.cast.data.model.IDataSet;
25  import pl.edu.agh.cast.data.model.domain.IDomainElement;
26  import pl.edu.agh.cast.importer.wizard.util.Messages;
27  import pl.edu.agh.cast.ui.util.MsgBoxHelper;
28  
29  /**
30   * Wizard strategy used for importing data without choosing template.
31   * 
32   * @author AGH CAST Team
33   */
34  public class WithoutTemplateWizardStrategy extends AbstractStepByStepImportStrategy {
35  
36  	/**
37  	 * {@inheritDoc}
38  	 * 
39  	 * @see pl.edu.agh.cast.importer.wizard.strategy.IImportWizardStrategy#performFinish()
40  	 */
41  	@Override
42  	public boolean performFinish() {
43  		int msgBoxResult = conversionRulesSelectionPage.showWarningMsgBox();
44  
45  		if (msgBoxResult < 0 || msgBoxResult == SWT.YES) {
46  			if (conversionRulesSelectionPage.isSaveTemplateSelected()) {
47  				if (!saveTemplate()) {
48  					return false;
49  				}
50  			}
51  			return convertData();
52  		}
53  
54  		return false;
55  	}
56  
57  	private boolean convertData() {
58  		importerWizard.performConversion();
59  
60  		final List<IDataSet<IDomainElement>> dataSets = importerWizard.getImportProcess().getConvertedData();
61  		if (dataSets != null) {
62  			// save data sets
63  			if (importerWizard.saveDataSet()) {
64  				MsgBoxHelper.showInfoBox(importerWizard.getShell(),
65  				        Messages.ImporterWizard_ImportSuccessfulTitle, Messages.ImporterWizard_ImportSuccessfulMsg);
66  				LOG.debug("Import successful."); //$NON-NLS-1$
67  			}
68  			return true;
69  
70  		} else {
71  			MsgBoxHelper.showErrorBox(importerWizard.getShell(),
72  			        Messages.ImporterWizard_ImportFailedTitle, Messages.ImporterWizard_ImportFailedMsg);
73  			LOG.debug("Import failed."); //$NON-NLS-1$
74  			return false;
75  		}
76  	}
77  }