Project

General

Profile

Download (5.61 KB) Statistics
| Branch: | Tag: | Revision:
1 877628fe Patric Plitzner
// $Id$
2
/**
3
* Copyright (C) 2013 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10 298cf041 Katja Luther
package eu.etaxonomy.taxeditor.view.dataimport;
11 877628fe Patric Plitzner
12 5f7fd72e Patric Plitzner
import org.apache.log4j.Logger;
13 2b3380bd Patric Plitzner
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.core.runtime.jobs.Job;
17 877628fe Patric Plitzner
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.wizard.Wizard;
19 5f152d2b Patric Plitzner
import org.eclipse.swt.widgets.Display;
20 877628fe Patric Plitzner
import org.eclipse.ui.IImportWizard;
21
import org.eclipse.ui.IWorkbench;
22
23 298cf041 Katja Luther
import eu.etaxonomy.cdm.database.DbSchemaValidation;
24 bce192f4 Patric Plitzner
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
25 298cf041 Katja Luther
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
26 89fdf8a2 Patric Plitzner
import eu.etaxonomy.taxeditor.store.CdmStore;
27 c7af639c Patric Plitzner
28 877628fe Patric Plitzner
/**
29 bce192f4 Patric Plitzner
 * Wizard for querying specimen provider.
30 877628fe Patric Plitzner
 * @author pplitzner
31
 * @date 11.09.2013
32
 *
33
 */
34
public class SpecimenSearchWizard extends Wizard implements IImportWizard {
35 5f7fd72e Patric Plitzner
    private static final Logger logger = Logger.getLogger(SpecimenSearchWizard.class);
36 877628fe Patric Plitzner
37 bce192f4 Patric Plitzner
    private OccurenceQuery query = null;
38 6a14c1c4 Patric Plitzner
    private SpecimenProviderSelectionWizardPage providerSelectionPage;
39 ab287c7e Patric Plitzner
    private SpecimenSearchWizardPage searchPage;
40 c7af639c Patric Plitzner
41
    /**
42 3ee20195 Patric Plitzner
     * Creates a new SpecimenSearchWizard
43 c7af639c Patric Plitzner
     */
44
    public SpecimenSearchWizard() {
45 3ee20195 Patric Plitzner
        //default constructor needed for RCP extension points
46 89fdf8a2 Patric Plitzner
47
        //check if connected to a data source. If not this will open an error dialog
48
        CdmStore.getCurrentApplicationConfiguration();
49 42580bdf Patric Plitzner
        this.setWindowTitle("Search Specimens");
50 c7af639c Patric Plitzner
    }
51
52
53 877628fe Patric Plitzner
    /* (non-Javadoc)
54
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
55
     */
56
    @Override
57
    public boolean performFinish() {
58 b9d3a4d8 Patric Plitzner
        searchPage.getController().saveLastSate();
59 6ebea0b9 Patric Plitzner
        providerSelectionPage.getController().saveLastState();
60
61 5da1d38c Patric Plitzner
        DataImportView<?> dataImportView = null;
62 5f152d2b Patric Plitzner
        query = searchPage.getQuery();
63 298cf041 Katja Luther
        Abcd206ImportConfigurator configurator =  CdmStore.getImportManager().AbcdConfigurator();
64
        configurator.setOccurenceQuery(query);
65
        configurator.setSourceUri(providerSelectionPage.getEndPoint());
66
        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
67
        if(CdmStore.getCurrentSessionManager().isRemoting()) {
68
            //Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
69
            //CdmStore.getImportManager().run(job);
70
71
            CdmStore.getImportManager().run(configurator);
72 5da1d38c Patric Plitzner
        }
73 298cf041 Katja Luther
//        try {
74
//            switch (providerSelectionPage.getQueryType()) {
75
//            case BIOCASE:
76
//                SpecimenImportView specimenImportView = (SpecimenImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
77
//                        .showView(SpecimenImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
78
//                specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
79
//                dataImportView = specimenImportView;
80
//                break;
81
//            case GBIF:
82
//                dataImportView = (GbifResponseImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
83
//                .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
84
//                break;
85
//            }
86
//        } catch ( PartInitException e ) {
87
//            logger.error("Could not open import view for query: " + query.toString(), e);
88
//        }
89
//        if(dataImportView!=null){
90
//            dataImportView.setQuery(query);
91
////            dataImportView.query();
92
////            Display.getDefault().asyncExec(new Runnable() {
93
////
94
////                @Override
95
////                public void run() {
96
////                    CdmStore.getContextManager().notifyContextRefresh();
97
////                }
98
////            });
99 5da1d38c Patric Plitzner
            Job queryJob = new QueryJob("Query specimen provider", dataImportView);
100
            queryJob.schedule();
101 298cf041 Katja Luther
102 5f7fd72e Patric Plitzner
        return true;
103 877628fe Patric Plitzner
    }
104
105
    /* (non-Javadoc)
106
     * @see org.eclipse.jface.wizard.Wizard#addPages()
107
     */
108
    @Override
109
    public void addPages() {
110 6a14c1c4 Patric Plitzner
        addPage(providerSelectionPage);
111 ab287c7e Patric Plitzner
        addPage(searchPage);
112 c7af639c Patric Plitzner
    }
113 602b224c Patric Plitzner
114 877628fe Patric Plitzner
    /* (non-Javadoc)
115
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
116
     */
117
    @Override
118
    public void init(IWorkbench workbench, IStructuredSelection selection) {
119 6a14c1c4 Patric Plitzner
        providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
120 ab287c7e Patric Plitzner
        searchPage = new SpecimenSearchWizardPage("Specimen Search");
121 c7af639c Patric Plitzner
    }
122
123 5f152d2b Patric Plitzner
    private class QueryJob extends Job{
124
125 5da1d38c Patric Plitzner
        private final DataImportView<?> view;
126 5f152d2b Patric Plitzner
127
        /**
128
         * @param name
129
         */
130 5da1d38c Patric Plitzner
        public QueryJob(String name, DataImportView<?> view) {
131 5f152d2b Patric Plitzner
            super(name);
132 5da1d38c Patric Plitzner
            this.view = view;
133 5f152d2b Patric Plitzner
        }
134
135
        /* (non-Javadoc)
136
         * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
137
         */
138
        @Override
139
        protected IStatus run(IProgressMonitor monitor) {
140 5da1d38c Patric Plitzner
            view.getConversationHolder().bind();
141
            view.query();
142 5f152d2b Patric Plitzner
            Display.getDefault().asyncExec(new Runnable() {
143
144
                @Override
145
                public void run() {
146
                    CdmStore.getContextManager().notifyContextRefresh();
147
                }
148
            });
149
            return Status.OK_STATUS;
150
        }
151
152
    }
153 877628fe Patric Plitzner
}