1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.bulkeditor.e4;
|
11
|
|
12
|
import javax.annotation.PostConstruct;
|
13
|
import javax.inject.Inject;
|
14
|
|
15
|
import org.eclipse.e4.ui.di.Persist;
|
16
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
17
|
import org.eclipse.e4.ui.services.EMenuService;
|
18
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
19
|
import org.eclipse.jface.dialogs.MessageDialog;
|
20
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
21
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
22
|
import org.eclipse.jface.viewers.LabelProvider;
|
23
|
import org.eclipse.jface.viewers.TableViewer;
|
24
|
import org.eclipse.swt.SWT;
|
25
|
import org.eclipse.swt.layout.FillLayout;
|
26
|
import org.eclipse.swt.layout.GridData;
|
27
|
import org.eclipse.swt.layout.GridLayout;
|
28
|
import org.eclipse.swt.widgets.Composite;
|
29
|
|
30
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
31
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
32
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
33
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
34
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
|
35
|
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
|
36
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
37
|
import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
|
38
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
39
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
40
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
41
|
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
|
42
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
43
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
44
|
|
45
|
/**
|
46
|
*
|
47
|
* @author pplitzner
|
48
|
* @since Sep 8, 2017
|
49
|
*
|
50
|
*/
|
51
|
public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnabled, IPostOperationEnabled,
|
52
|
IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData, IPartContentHasMedia {
|
53
|
|
54
|
private BulkEditorSearchE4 searchBar = null;
|
55
|
|
56
|
@Inject
|
57
|
private MDirtyable dirty;
|
58
|
|
59
|
private AbstractBulkEditorInput<?> input;
|
60
|
|
61
|
private Composite topComposite;
|
62
|
|
63
|
private TableViewer viewer;
|
64
|
|
65
|
private ConversationHolder conversation;
|
66
|
|
67
|
@Inject
|
68
|
private ESelectionService selService;
|
69
|
|
70
|
private ISelectionChangedListener selectionChangedListener;
|
71
|
|
72
|
@Inject
|
73
|
public BulkEditorE4() {
|
74
|
}
|
75
|
|
76
|
public void init(AbstractBulkEditorInput<?> input){
|
77
|
this.input = input;
|
78
|
AbstractBulkEditorInput<?> bulkEditorInput = input;
|
79
|
if(bulkEditorInput.getEntityUuid()!=null){
|
80
|
bulkEditorInput.performSearch(new BulkEditorQuery(bulkEditorInput.getEntityUuid().toString(), null));
|
81
|
}
|
82
|
searchBar = new BulkEditorSearchE4(this, topComposite, SWT.NONE);
|
83
|
|
84
|
}
|
85
|
|
86
|
/** {@inheritDoc} */
|
87
|
@PostConstruct
|
88
|
public void createPartControl(Composite parent, EMenuService menuService) {
|
89
|
if (CdmStore.isActive()){
|
90
|
if(conversation == null){
|
91
|
conversation = CdmStore.createConversation();
|
92
|
}
|
93
|
}
|
94
|
else{
|
95
|
return;
|
96
|
}
|
97
|
|
98
|
parent.setLayout(new GridLayout());
|
99
|
|
100
|
topComposite = new Composite(parent, SWT.NONE);
|
101
|
topComposite.setLayout(new GridLayout());
|
102
|
|
103
|
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
|
104
|
topComposite.setLayoutData(gridData);
|
105
|
|
106
|
Composite bottomComposite = new Composite(parent, SWT.NONE);
|
107
|
bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
108
|
bottomComposite.setLayout(new FillLayout());
|
109
|
viewer = new TableViewer(bottomComposite);
|
110
|
viewer.setContentProvider(new ArrayContentProvider());
|
111
|
viewer.setLabelProvider(new LabelProvider());
|
112
|
|
113
|
|
114
|
//propagate selection
|
115
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
116
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
117
|
|
118
|
//create context menu
|
119
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor");
|
120
|
|
121
|
}
|
122
|
|
123
|
@Persist
|
124
|
public void save() {
|
125
|
dirty.setDirty(false);
|
126
|
|
127
|
this.searchBar.updateEditorInput();
|
128
|
|
129
|
}
|
130
|
|
131
|
/** {@inheritDoc} */
|
132
|
public void performSearch(BulkEditorQuery query) {
|
133
|
if (query != null) {
|
134
|
|
135
|
// TODO check if dirty, prompt save
|
136
|
if (isDirty()) {
|
137
|
String[] labels = {"Save (and Search)", "Don't save (and Search)","Cancel"};
|
138
|
MessageDialog dialog =new MessageDialog(topComposite.getShell(), "Save changes", null, "You have made changes that must be saved before this query can be executed. Would you like to proceed?", MessageDialog.QUESTION,labels, 0);
|
139
|
int result = dialog.open();
|
140
|
if (result == 0) {
|
141
|
save();
|
142
|
} else if (result == 2){
|
143
|
return;
|
144
|
}
|
145
|
}
|
146
|
|
147
|
getEditorInput().performSearch(query);
|
148
|
|
149
|
refresh();
|
150
|
}
|
151
|
}
|
152
|
|
153
|
private void refresh() {
|
154
|
viewer.setInput(getEditorInput().getModel());
|
155
|
viewer.refresh();
|
156
|
}
|
157
|
|
158
|
private boolean isDirty() {
|
159
|
return dirty.isDirty();
|
160
|
}
|
161
|
|
162
|
public AbstractBulkEditorInput getEditorInput() {
|
163
|
return input;
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* {@inheritDoc}
|
168
|
*/
|
169
|
@Override
|
170
|
public void update(CdmDataChangeMap arg0) {
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* {@inheritDoc}
|
175
|
*/
|
176
|
@Override
|
177
|
public boolean canAttachMedia() {
|
178
|
return true;
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* {@inheritDoc}
|
183
|
*/
|
184
|
@Override
|
185
|
public void changed(Object element) {
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* {@inheritDoc}
|
190
|
*/
|
191
|
@Override
|
192
|
public void forceDirty() {
|
193
|
dirty.setDirty(true);
|
194
|
}
|
195
|
|
196
|
/**
|
197
|
* {@inheritDoc}
|
198
|
*/
|
199
|
@Override
|
200
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
201
|
return false;
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* {@inheritDoc}
|
206
|
*/
|
207
|
@Override
|
208
|
public boolean onComplete() {
|
209
|
return false;
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* {@inheritDoc}
|
214
|
*/
|
215
|
@Override
|
216
|
public ConversationHolder getConversationHolder() {
|
217
|
return conversation;
|
218
|
}
|
219
|
|
220
|
}
|