Project

General

Profile

« Previous | Next » 

Revision 7dc8bc92

Added by Patrick Plitzner about 4 years ago

ref #6913 Remove data import editor

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/DataImportEditor.java
1
/**
2
* Copyright (C) 2013 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
package eu.etaxonomy.taxeditor.view.dataimport;
10

  
11
import java.util.Collection;
12

  
13
import org.apache.log4j.Logger;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.jface.action.MenuManager;
16
import org.eclipse.jface.viewers.TableViewer;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Menu;
21
import org.eclipse.swt.widgets.Table;
22
import org.eclipse.swt.widgets.TableItem;
23
import org.eclipse.ui.IEditorInput;
24
import org.eclipse.ui.IEditorSite;
25
import org.eclipse.ui.IMemento;
26
import org.eclipse.ui.PartInitException;
27
import org.eclipse.ui.part.EditorPart;
28

  
29
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
30
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
31
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
32
import eu.etaxonomy.taxeditor.model.IContextListener;
33
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
34
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
35
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
36
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
37
import eu.etaxonomy.taxeditor.store.CdmStore;
38

  
39
/**
40
 * Editor which shows a list of "data" that can be imported into the CDM
41
 * @author pplitzner
42
 * @date 20.09.2013
43
 *
44
 */
45
public abstract class DataImportEditor<T> extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
46
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener{
47

  
48
    protected Logger logger = Logger.getLogger(DataImportEditor.class);
49

  
50
    private ConversationHolder conversation;
51

  
52
    private TableViewer tableViewer;
53

  
54
    /**
55
     * Constructs a new DataImportEditor and registers it to listen to context changes
56
     */
57
    public DataImportEditor() {
58
    }
59

  
60
    /* (non-Javadoc)
61
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
62
     */
63
    @Override
64
    public void createPartControl(Composite parent) {
65

  
66
        Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
67
        table.setHeaderVisible(true);//TODO: set header title as query
68
        table.setLinesVisible(true);
69
        tableViewer = new TableViewer(table);
70

  
71
        // Propagate selection from viewer
72
        getSite().setSelectionProvider(tableViewer);
73

  
74
        //create context menu
75
        MenuManager menuManager = new MenuManager();
76
        getSite().registerContextMenu(menuManager, tableViewer);
77
        Control control = tableViewer.getControl();
78
        Menu menu = menuManager.createContextMenu(control);
79
        control.setMenu(menu);
80
    }
81

  
82
    /* (non-Javadoc)
83
     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
84
     */
85
    @Override
86
    public void setFocus() {
87
        if (!tableViewer.getControl().isDisposed()) {
88
            tableViewer.getControl().setFocus();
89
        }
90
        //make sure to bind again if maybe in another view the conversation was unbound
91
        if(!conversation.isBound()){
92
            conversation.bind();
93
        }
94
    }
95

  
96

  
97
    /* (non-Javadoc)
98
     * @see org.eclipse.ui.texteditor.AbstractTextEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
99
     */
100
    @Override
101
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
102
        CdmStore.getContextManager().addContextListener(this);
103
        setSite(site);
104
        setInput(input);
105
        setPartName(input.getName());
106
        setTitleToolTip(input.getName());
107
        conversation = ((DataImportEditorInput<T>)input).getConversationHolder();
108
    }
109

  
110
    /* (non-Javadoc)
111
     * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#dispose()
112
     */
113
    @Override
114
    public void dispose() {
115
        super.dispose();
116
        CdmStore.getContextManager().removeContextListener(this);
117
    }
118

  
119
    /* (non-Javadoc)
120
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
121
     */
122
    @Override
123
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
124
        //nothing
125
    }
126

  
127
    /* (non-Javadoc)
128
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
129
     */
130
    @Override
131
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
132
        //nothing
133
    }
134

  
135
    /* (non-Javadoc)
136
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
137
     */
138
    @Override
139
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
140
        //nothing
141
    }
142

  
143
    /* (non-Javadoc)
144
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
145
     */
146
    @Override
147
    public void contextRefresh(IProgressMonitor monitor) {
148
        IEditorInput editorInput = getEditorInput();
149
        setInput(editorInput);
150
        if(editorInput instanceof DataImportEditorInput){
151
            tableViewer.getTable().removeAll();
152
            Collection<T> results = ((DataImportEditorInput<T>) editorInput).getResults();
153
            if(results!=null){
154
                for(T item:results){
155
                    TableItem tableItem = new TableItem(tableViewer.getTable(), SWT.NONE);
156
                    tableItem.setText(getTextForTableItem(item));
157
                    tableItem.setData(item);
158
                }
159
            }
160
        }
161
    }
162

  
163
    /**
164
     * Returns the text label of the given item.
165
     * @param item the item for which the label should be returnes
166
     * @return the label of the item
167
     */
168
    protected abstract String getTextForTableItem(T item);
169

  
170
    /* (non-Javadoc)
171
     * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
172
     */
173
    @Override
174
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
175
        if(conversation!=null && conversation.isBound() && !conversation.isClosed()) {
176
            conversation.close();
177
        }
178
    }
179

  
180
    /* (non-Javadoc)
181
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
182
     */
183
    @Override
184
    public void update(CdmDataChangeMap changeEvents) {
185
        //nothing
186
    }
187

  
188
    /* (non-Javadoc)
189
     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
190
     */
191
    @Override
192
    public ConversationHolder getConversationHolder() {
193
        return conversation;
194
    }
195

  
196
    /* (non-Javadoc)
197
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
198
     */
199
    @Override
200
    public void changed(Object element) {
201
        // cannot be changed
202
    }
203

  
204
    /* (non-Javadoc)
205
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
206
     */
207
    @Override
208
    public void forceDirty() {
209
        // cannot be dirty
210
    }
211

  
212
    /* (non-Javadoc)
213
     * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
214
     */
215
    @Override
216
    public void doSave(IProgressMonitor monitor) {
217
    }
218

  
219
    /* (non-Javadoc)
220
     * @see org.eclipse.ui.part.EditorPart#doSaveAs()
221
     */
222
    @Override
223
    public void doSaveAs() {
224
    }
225

  
226
    /* (non-Javadoc)
227
     * @see org.eclipse.ui.part.EditorPart#isDirty()
228
     */
229
    @Override
230
    public boolean isDirty() {
231
        return false;
232
    }
233

  
234
    /* (non-Javadoc)
235
     * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
236
     */
237
    @Override
238
    public boolean isSaveAsAllowed() {
239
        return false;
240
    }
241

  
242
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/DataImportEditorContextMenu.java
1
package eu.etaxonomy.taxeditor.view.dataimport;
2

  
3
import java.io.IOException;
4
import java.util.HashSet;
5
import java.util.Set;
6

  
7
import org.apache.http.client.ClientProtocolException;
8
import org.apache.log4j.Logger;
9
import org.eclipse.jface.action.ContributionItem;
10
import org.eclipse.jface.action.IContributionItem;
11
import org.eclipse.jface.viewers.ISelection;
12
import org.eclipse.jface.viewers.StructuredSelection;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.widgets.Event;
15
import org.eclipse.swt.widgets.Listener;
16
import org.eclipse.swt.widgets.Menu;
17
import org.eclipse.swt.widgets.MenuItem;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.actions.CompoundContributionItem;
21

  
22
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
23
import eu.etaxonomy.cdm.ext.occurrence.gbif.DataSetResponse;
24
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol;
25
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
26
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
27
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
28
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

  
31
public class DataImportEditorContextMenu extends CompoundContributionItem {
32

  
33
    private final Logger logger = Logger.getLogger(DataImportEditorContextMenu.class);
34

  
35
    /* (non-Javadoc)
36
     * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
37
     */
38
    @Override
39
    protected IContributionItem[] getContributionItems() {
40
        IContributionItem[] contributionItems = new IContributionItem[] {
41
                new ContributionItem() {
42
                    @Override
43
                    public void fill(Menu menu, int index) {
44
                        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
45
                        final Object activeEditor = AbstractUtility.getActiveEditor();
46
                        final ISelection selection = window.getActivePage().getSelection();
47
                        if(selection instanceof StructuredSelection){
48
                            final StructuredSelection structuredSelection = (StructuredSelection)selection;
49

  
50
                            //Save Specimen
51
                            MenuItem saveSpecimenItem = new MenuItem(menu, SWT.NONE);
52
                            saveSpecimenItem.setText("Save Specimen");
53
                            saveSpecimenItem.addListener(SWT.Selection, new Listener() {
54

  
55
                                @Override
56
                                public void handleEvent(Event event) {
57
                                    if(structuredSelection.iterator().hasNext()){
58
                                        Object next = structuredSelection.iterator().next();
59
                                        if(next instanceof GbifResponse){
60
                                            //unwrap DerivedUnit from GbifResponse
61
                                            next = ((GbifResponse) next).getDerivedUnitFacade().innerDerivedUnit();
62
                                        }
63
                                        if(next instanceof SpecimenOrObservationBase){
64
                                            if(activeEditor instanceof DataImportEditor){
65
                                                DataImportEditor<?> dataImportEditor = (DataImportEditor<?>)activeEditor;
66
                                                CdmStore.getService(IOccurrenceService.class).saveOrUpdate((SpecimenOrObservationBase<?>) next);
67
                                                dataImportEditor.getConversationHolder().commit(true);
68
                                            }
69
                                        }
70
                                    }
71
                                }
72
                            });
73

  
74
                            //Query original data provider
75
                            if(structuredSelection.size()==1
76
                                    && structuredSelection.iterator().next() instanceof GbifResponse
77
                                    && ((GbifResponse)structuredSelection.iterator().next()).getDataSetProtocol()!=null
78
                                    && ((GbifResponse)structuredSelection.iterator().next()).getDataSetProtocol()==GbifDataSetProtocol.BIOCASE){
79
                                final GbifResponse gbifResponse = (GbifResponse)structuredSelection.iterator().next();
80
                                MenuItem queryOriginalItem = new MenuItem(menu, SWT.NONE);
81
                                queryOriginalItem.setText("Query original data provider");
82
                                queryOriginalItem.addListener(SWT.Selection, new Listener() {
83

  
84
                                    @Override
85
                                    public void handleEvent(Event event) {
86
                                        try{
87
                                            DataSetResponse response = new GbifQueryServiceWrapper().queryOriginalDataSet(gbifResponse);
88
                                            Set<String[]> unitIds = new HashSet<String[]>();
89
                                            String[] tripleId = {response.getUnitId()};
90
                                            unitIds.add(tripleId);
91
                                           /* final BioCaseEditorInput input = new BioCaseEditorInput(new OccurenceQuery(unitIds), response.getEndpoint());
92
                                           // EditorUtil.open(input);
93
                                            Job queryJob = new Job("Querying for original record...") {
94

  
95
                                                @Override
96
                                                protected IStatus run(IProgressMonitor monitor) {
97
                                                    input.query();
98
                                                    return Status.OK_STATUS;
99
                                                }
100
                                            };
101
                                            queryJob.schedule();*/
102
                                        } catch (ClientProtocolException e) {
103
                                            logger.error("Query for single record failed.", e);
104
                                        } catch (IOException e) {
105
                                            logger.error("Query for single record failed.", e);
106
                                        }
107
//                                        } catch (PartInitException e) {
108
//                                            logger.error("Could not open editor.", e);
109
//                                        }
110
                                    }
111
                                });
112
                            }
113
                        }
114
                    }
115
                }};
116
        return contributionItems;
117
    }
118

  
119
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/GbifImportEditor.java
1
/**
2
* Copyright (C) 2014 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
package eu.etaxonomy.taxeditor.view.dataimport;
10

  
11
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
12

  
13
/**
14
 * @author pplitzner
15
 * @date 27.05.2014
16
 *
17
 */
18
public class GbifImportEditor extends DataImportEditor<GbifResponse>{
19

  
20
    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.GbifImportEditor";
21

  
22
    /**
23
     * Required for extension point
24
     */
25
    public GbifImportEditor() {
26
        super();
27
    }
28

  
29
    /* (non-Javadoc)
30
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportEditor#getTextForTableItem(java.lang.Object)
31
     */
32
    @Override
33
    protected String getTextForTableItem(GbifResponse item) {
34
        String text = "";
35
        if(item.getDataSetProtocol()!=null){
36
            text += "["+item.getDataSetProtocol()+"] ";
37
        }
38
        text += item.getDerivedUnitFacade().innerDerivedUnit().generateTitle();
39
        return text;
40
    }
41

  
42
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportEditor.java
1
/**
2
* Copyright (C) 2013 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
package eu.etaxonomy.taxeditor.view.dataimport;
10

  
11
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
12

  
13
/**
14
 * Extension of {@link DataImportEditor} to display and import objects of type {@link SpecimenOrObservationBase}.
15
 * @author pplitzner
16
 * @date 20.09.2013
17
 *
18
 */
19
public class SpecimenImportEditor extends DataImportEditor<SpecimenOrObservationBase<?>> {
20

  
21
    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportEditor";
22

  
23
    /**
24
     * Required for extension point
25
     */
26
    public SpecimenImportEditor() {
27
        super();
28
    }
29

  
30
    /* (non-Javadoc)
31
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportEditor#getTextForTableItem(eu.etaxonomy.cdm.model.common.IIdentifiableEntity)
32
     */
33
    @Override
34
    protected String getTextForTableItem(SpecimenOrObservationBase<?> item) {
35
        return item.generateTitle();
36
    }
37
}

Also available in: Unified diff