2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.actions
.io
;
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
;
20 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
21 import eu
.etaxonomy
.cdm
.io
.common
.ImportWrapper
;
22 import eu
.etaxonomy
.taxeditor
.UiUtil
;
23 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
30 public class ImportAction
extends Action
{
31 private static final Logger logger
= Logger
.getLogger(ImportAction
.class);
33 private static String text
= "Import ...";
34 private ImageDescriptor image
= null;
35 public static final String ID
= "eu.etaxonomy.taxeditor.actions.io.importaction"; //$NON-NLS-1$
37 private FileDialog dialog
;
39 private ImportWrapper importWrapper
;
41 private ImportAction() {
43 setImageDescriptor(image
);
47 public ImportAction(ImportWrapper importWrapper
) {
50 this.importWrapper
= importWrapper
;
51 setText(importWrapper
.getLabel());
56 // Use same title "Import FORMAT" for all message dialogs
57 String title
= "Import " + getText();
59 // Make sure user is aware of the implications of an import
60 boolean doProceed
= MessageDialog
.openConfirm(UiUtil
.getShell(), title
,
61 "Import may require a great deal of time and system resources.\n\n" +
62 "Are you sure you would like to proceed?");
68 dialog
= new FileDialog(UiUtil
.getShell());
69 String filePath
= dialog
.open();
70 file
= new File(filePath
);
72 // Get current data source
73 ICdmDataSource destination
= CdmDataSourceRepository
.getDefault().getCurrentDataSource();
75 // Get plugin application controller - from Anahit
76 // CdmApplicationController app = TaxEditorPlugin.getDefault().getCdmApp();
77 // TaxEditorPlugin.getDefault().commitTransaction();
78 // TaxEditorPlugin.getDefault().getCdmApp().close();
83 source
= file
.toURI().toURL().toString();
84 //source = file.toString();
85 } catch (/*MalformedURL*/Exception e
) {
86 MessageDialog
.openError(UiUtil
.getShell(), title
, "File could not be read.");
91 boolean isSuccessfulImport
= importWrapper
.invoke(source
, destination
, null);
93 // Tell user whether import was a success or a dismal failure
94 if (isSuccessfulImport
) {
95 MessageDialog
.openInformation(UiUtil
.getShell(), title
, "Import successful");
96 UiUtil
.getTreeViewer().refresh();
98 MessageDialog
.openError(UiUtil
.getShell(), title
, "Import was unsuccessful.");