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
.SWT
;
19 import org
.eclipse
.swt
.widgets
.FileDialog
;
21 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
22 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultExport
;
23 import eu
.etaxonomy
.cdm
.io
.jaxb
.JaxbExportConfigurator
;
24 import eu
.etaxonomy
.taxeditor
.UiUtil
;
25 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
32 public class ExportAction
extends Action
{
33 private static final Logger logger
= Logger
.getLogger(ExportAction
.class);
35 private static String text
= "Export as ...";
36 private ImageDescriptor image
= null;
37 public static final String ID
= "eu.etaxonomy.taxeditor.actions.io.exportaction"; //$NON-NLS-1$
39 public static final String JAXB
= "JAXB";
41 private FileDialog dialog
;
44 private String exportType
;
46 public ExportAction() {
48 setImageDescriptor(image
);
52 public ExportAction(String exportType
) {
55 this.exportType
= exportType
;
61 // Use same title "Export FORMAT" for all message dialogs
62 String title
= "Export " + getText();
65 dialog
= new FileDialog(UiUtil
.getShell(), SWT
.SAVE
);
66 dialog
.setFileName("export.xml");
67 String filePath
= dialog
.open();
68 file
= new File(filePath
);
70 // Get current data source
71 ICdmDataSource source
= CdmDataSourceRepository
.getDefault().getCurrentDataSource();
74 String destination
= null;
75 // destination = file.toURI().toURL().toString();
76 destination
= file
.toString();
78 JaxbExportConfigurator configurator
= JaxbExportConfigurator
.NewInstance(source
, destination
);
79 CdmDefaultExport
<JaxbExportConfigurator
> jaxbExport
=
80 new CdmDefaultExport
<JaxbExportConfigurator
>();
83 boolean isSuccessfulExport
= jaxbExport
.invoke(configurator
);
85 // Tell user whether import was a success or a dismal failure
86 if (isSuccessfulExport
) {
87 MessageDialog
.openInformation(UiUtil
.getShell(), title
, "Export successful");
89 MessageDialog
.openError(UiUtil
.getShell(), title
, "Export was unsuccessful.");