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
.bulkeditor
.e4
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import javax
.annotation
.PostConstruct
;
16 import javax
.inject
.Inject
;
18 import org
.eclipse
.e4
.ui
.di
.Persist
;
19 import org
.eclipse
.e4
.ui
.model
.application
.ui
.MDirtyable
;
20 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
21 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
22 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
23 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
24 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
25 import org
.eclipse
.jface
.viewers
.TableViewer
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.layout
.FillLayout
;
28 import org
.eclipse
.swt
.layout
.GridData
;
29 import org
.eclipse
.swt
.layout
.GridLayout
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
32 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
33 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
34 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
35 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
38 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
39 import eu
.etaxonomy
.taxeditor
.model
.IDerivedUnitFacadePart
;
40 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
41 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
42 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
43 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
44 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
45 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
53 public class BulkEditorE4
implements IPartContentHasDetails
, IConversationEnabled
, IPostOperationEnabled
,
54 IDirtyMarkable
, IDerivedUnitFacadePart
, IPartContentHasFactualData
, IPartContentHasMedia
{
56 private BulkEditorSearchE4 searchBar
= null;
59 private MDirtyable dirty
;
61 private AbstractBulkEditorInput
<?
> input
;
63 private Composite topComposite
;
65 private TableViewer viewer
;
67 private ConversationHolder conversation
;
70 private ESelectionService selService
;
72 private ISelectionChangedListener selectionChangedListener
;
75 public BulkEditorE4() {
78 public void init(AbstractBulkEditorInput
<?
> input
){
80 AbstractBulkEditorInput
<?
> bulkEditorInput
= input
;
81 if(bulkEditorInput
.getEntityUuid()!=null){
82 bulkEditorInput
.performSearch(new BulkEditorQuery(bulkEditorInput
.getEntityUuid().toString(), null));
84 searchBar
= new BulkEditorSearchE4(this, topComposite
, SWT
.NONE
);
90 public void createPartControl(Composite parent
, EMenuService menuService
) {
91 if (CdmStore
.isActive()){
92 if(conversation
== null){
93 conversation
= CdmStore
.createConversation();
100 parent
.setLayout(new GridLayout());
102 topComposite
= new Composite(parent
, SWT
.NONE
);
103 topComposite
.setLayout(new GridLayout());
105 GridData gridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
106 topComposite
.setLayoutData(gridData
);
108 Composite bottomComposite
= new Composite(parent
, SWT
.NONE
);
109 bottomComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
110 bottomComposite
.setLayout(new FillLayout());
111 viewer
= new TableViewer(bottomComposite
);
112 viewer
.setContentProvider(new ArrayContentProvider());
113 viewer
.setLabelProvider(new BulkEditorLabelProvider());
116 //propagate selection
117 selectionChangedListener
= (event
-> selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
)));
118 viewer
.addSelectionChangedListener(selectionChangedListener
);
120 //create context menu
121 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor");
127 dirty
.setDirty(false);
129 this.searchBar
.updateEditorInput();
134 public void performSearch(BulkEditorQuery query
) {
137 // TODO check if dirty, prompt save
139 String
[] labels
= {"Save (and Search)", "Don't save (and Search)","Cancel"};
140 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);
141 int result
= dialog
.open();
144 } else if (result
== 2){
149 getEditorInput().performSearch(query
);
151 viewer
.setInput(getEditorInput().getWrappedModel());
156 public void refresh() {
160 public boolean isDirty() {
161 return dirty
.isDirty();
164 public AbstractBulkEditorInput
getEditorInput() {
168 public List
<AnnotatedTableItem
> getMergeCandidates(){
169 List
<AnnotatedTableItem
> mergeCandidates
= new ArrayList
<>();
170 for(AnnotatedTableItem item
: (List
<AnnotatedTableItem
>)viewer
.getInput()){
171 if(item
.isMergeCandidate()){
172 mergeCandidates
.add(item
);
175 return mergeCandidates
;
178 public AnnotatedTableItem
getMergeTarget(){
179 for(AnnotatedTableItem item
: (List
<AnnotatedTableItem
>)viewer
.getInput()){
180 if(item
.isMergeTarget()){
187 public void removeAllAnnotations(){
188 for(AnnotatedTableItem item
: (List
<AnnotatedTableItem
>)viewer
.getInput()){
189 item
.setMergeCandidate(false);
190 item
.setMergeTarget(false);
198 public void update(CdmDataChangeMap arg0
) {
205 public boolean canAttachMedia() {
213 public void changed(Object element
) {
220 public void forceDirty() {
221 dirty
.setDirty(true);
228 public boolean postOperation(CdmBase objectAffectedByOperation
) {
236 public boolean onComplete() {
244 public ConversationHolder
getConversationHolder() {