Project

General

Profile

Download (7.34 KB) Statistics
| Branch: | Tag: | Revision:
1
// $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
package eu.etaxonomy.taxeditor.editor.view.dataimport;
11

    
12
import java.util.Collection;
13

    
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.IDirtyMarkableSelectionProvider;
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, IDirtyMarkableSelectionProvider,
46
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener{
47

    
48
    private ConversationHolder conversation;
49

    
50
    private TableViewer tableViewer;
51

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

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

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

    
69
        // Propagate selection from viewer
70
        getSite().setSelectionProvider(tableViewer);
71

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

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

    
92

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

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

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

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

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

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

    
159
    protected abstract String getTextForTableItem(T item);
160

    
161
    /* (non-Javadoc)
162
     * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
163
     */
164
    @Override
165
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
166
        if(conversation!=null && conversation.isBound() && !conversation.isClosed()) {
167
            conversation.close();
168
        }
169
    }
170

    
171
    /* (non-Javadoc)
172
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
173
     */
174
    @Override
175
    public void update(CdmDataChangeMap changeEvents) {
176
        //nothing
177
    }
178

    
179
    /* (non-Javadoc)
180
     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
181
     */
182
    @Override
183
    public ConversationHolder getConversationHolder() {
184
        return conversation;
185
    }
186

    
187
    /* (non-Javadoc)
188
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
189
     */
190
    @Override
191
    public void changed(Object element) {
192
        // cannot be changed
193
    }
194

    
195
    /* (non-Javadoc)
196
     * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
197
     */
198
    @Override
199
    public void doSave(IProgressMonitor monitor) {
200
    }
201

    
202
    /* (non-Javadoc)
203
     * @see org.eclipse.ui.part.EditorPart#doSaveAs()
204
     */
205
    @Override
206
    public void doSaveAs() {
207
    }
208

    
209
    /* (non-Javadoc)
210
     * @see org.eclipse.ui.part.EditorPart#isDirty()
211
     */
212
    @Override
213
    public boolean isDirty() {
214
        return false;
215
    }
216

    
217
    /* (non-Javadoc)
218
     * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
219
     */
220
    @Override
221
    public boolean isSaveAsAllowed() {
222
        return false;
223
    }
224

    
225
}
(2-2/11)