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: ImportWizardAction.java
13   * Created: 2008-06-17
14   * Author: kpietak
15   * $Id: ImportWizardAction.java 3266 2009-08-27 15:28:45Z tmilos $
16   */
17  
18  package pl.edu.agh.cast.data.ui.importer.action;
19  
20  import org.eclipse.core.resources.IProject;
21  import org.eclipse.core.runtime.CoreException;
22  import org.eclipse.jface.action.IAction;
23  import org.eclipse.jface.wizard.WizardDialog;
24  import org.eclipse.osgi.util.NLS;
25  import org.eclipse.ui.PlatformUI;
26  
27  import pl.edu.agh.cast.CastApplication;
28  import pl.edu.agh.cast.data.ui.importer.wizard.ImportWizard;
29  import pl.edu.agh.cast.data.util.Messages;
30  import pl.edu.agh.cast.navigator.ui.action.CreateProjectAction;
31  import pl.edu.agh.cast.ui.util.MsgBoxHelper;
32  
33  /**
34   * Action of creating and displaying the import wizard, which is contributed via an extension point.
35   *
36   * @author AGH CAST Team
37   */
38  public class ImportWizardAction {
39  
40  	private IProject project = null;
41  
42  	/**
43  	 * {@inheritDoc}
44  	 *
45  	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
46  	 */
47  	public void run(IAction action) {
48  		if (project == null) {
49  			project = CastApplication.getActiveProject();
50  		}
51  
52  		if (project == null) {
53  			new CreateProjectAction().run(null);
54  			IProject proj = CastApplication.getActiveProject();
55  			if (proj == null) {
56  				return;
57  			}
58  			setProject(proj);
59  		}
60  
61  		ImportWizard wizard = null;
62  		try {
63  			// Create the wizard
64  			wizard = new ImportWizard(project);
65  		} catch (CoreException e) {
66  			MsgBoxHelper.showErrorBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
67  			        Messages.ImportWizardAction_2, NLS.bind(Messages.ImportWizardAction_3, e.getMessage()));
68  			return;
69  		}
70  		// Create the wizard dialog
71  		WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
72  		// Open the wizard dialog
73  
74  		dialog.setTitle(Messages.ImportBillingAction_0);
75  		dialog.open();
76  	}
77  
78  	/**
79  	 * @return project value
80  	 */
81  	protected IProject getProject() {
82  		return project;
83  	}
84  
85  	/**
86  	 * @param project
87  	 *            project value to set
88  	 */
89  	protected void setProject(IProject project) {
90  		this.project = project;
91  	}
92  }