migrating to cdmlib-plugin 2.0.0.20 including new term loading
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / actions / io / ImportAction.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.actions.io;
11
12 import java.io.File;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.swt.widgets.FileDialog;
19
20 import eu.etaxonomy.cdm.database.ICdmDataSource;
21 import eu.etaxonomy.taxeditor.controller.GlobalController;
22 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
23
24 /**
25 * @author p.ciardelli
26 * @created 05.11.2008
27 * @version 1.0
28 */
29 public class ImportAction extends Action {
30 private static final Logger logger = Logger.getLogger(ImportAction.class);
31
32 private static String text = "Import ...";
33 private ImageDescriptor image = null;
34 public static final String ID = "eu.etaxonomy.taxeditor.actions.io.importaction"; //$NON-NLS-1$
35
36 private FileDialog dialog;
37 private File file;
38 // private ImportWrapper importWrapper;
39
40 private ImportAction() {
41 super(text);
42 setImageDescriptor(image);
43 setId(ID);
44 }
45
46 // public ImportAction(ImportWrapper importWrapper) {
47 // this();
48 //
49 // this.importWrapper = importWrapper;
50 // setText(importWrapper.getLabel());
51 // }
52
53
54
55 public void run() {
56
57 // Use same title "Import FORMAT" for all message dialogs
58 String title = "Import " + getText();
59
60 // Make sure user is aware of the implications of an import
61 boolean doProceed = MessageDialog.openConfirm(GlobalController.getShell(), title,
62 "Import may require a great deal of time and system resources.\n\n" +
63 "Are you sure you would like to proceed?");
64 if (!doProceed) {
65 return;
66 }
67
68 // Get file from user
69 dialog = new FileDialog(GlobalController.getShell());
70 String filePath = dialog.open();
71 file = new File(filePath);
72
73 // Get current data source
74 ICdmDataSource destination = CdmDataSourceRepository.getDefault().getCurrentDataSource();
75
76 // Get plugin application controller - from Anahit
77 // CdmApplicationController app = TaxEditorPlugin.getDefault().getCdmApp();
78 // TaxEditorPlugin.getDefault().commitTransaction();
79 // TaxEditorPlugin.getDefault().getCdmApp().close();
80
81 // Format file path
82 String source = null;
83 try {
84 source = file.toURI().toURL().toString();
85 //source = file.toString();
86 } catch (/*MalformedURL*/Exception e) {
87 MessageDialog.openError(GlobalController.getShell(), title, "File could not be read.");
88 return;
89 }
90
91 // Start import
92 // boolean isSuccessfulImport = importWrapper.invoke(source, destination, null);
93 //
94 // // Tell user whether import was a success or a dismal failure
95 // if (isSuccessfulImport) {
96 // MessageDialog.openInformation(GlobalController.getShell(), title, "Import successful");
97 // TreeController.getTreeViewer().refresh();
98 // } else {
99 // MessageDialog.openError(GlobalController.getShell(), title, "Import was unsuccessful.");
100 // }
101
102 }
103 }