3 |
3 |
*/
|
4 |
4 |
package eu.etaxonomy.taxeditor.editor.view.media.handler;
|
5 |
5 |
|
|
6 |
import java.util.ArrayList;
|
6 |
7 |
import java.util.Iterator;
|
|
8 |
import java.util.List;
|
7 |
9 |
import java.util.Set;
|
8 |
10 |
|
9 |
11 |
import javax.inject.Named;
|
... | ... | |
68 |
70 |
break;
|
69 |
71 |
}
|
70 |
72 |
}
|
71 |
|
// TODO use undo context specific to editor
|
72 |
|
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
|
73 |
|
|
74 |
|
config.setDeleteFromDescription(true);
|
75 |
|
config.setOnlyRemoveFromGallery(false);
|
76 |
|
|
77 |
|
if (description instanceof SpecimenDescription){
|
78 |
|
config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation());
|
79 |
|
} else if (description instanceof TaxonDescription){
|
80 |
|
config.setDeleteFrom(((TaxonDescription)description).getTaxon());
|
81 |
|
}else if (description instanceof TaxonNameDescription){
|
82 |
|
config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName());
|
83 |
|
}
|
84 |
|
DeleteConfiguratorDialog dialog;
|
85 |
|
dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
|
86 |
|
int result_dialog= dialog.open();
|
87 |
|
if (result_dialog != IStatus.OK){
|
88 |
|
return;
|
89 |
|
}
|
90 |
|
if(object instanceof Media){
|
91 |
|
AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, (Media) object, config, mediaView);
|
92 |
|
if (mediaView.getSelectionProvidingPart().getObject() instanceof TaxonNameEditorE4){
|
93 |
|
if (!config.isOnlyRemoveFromGallery()){
|
94 |
|
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).getEditorInput().addOperation(operation);
|
95 |
|
}
|
96 |
|
Media media = (Media)object;
|
97 |
|
if (description.isImageGallery()){
|
98 |
|
Set<DescriptionElementBase> elements = description.getElements();
|
99 |
|
if (elements.size() == 1){
|
100 |
|
DescriptionElementBase element = elements.iterator().next();
|
101 |
|
element.removeMedia(media);
|
102 |
|
if (element.getMedia().isEmpty()){
|
103 |
|
description.removeElement(element);
|
104 |
|
}
|
105 |
|
}
|
106 |
|
}
|
107 |
73 |
|
108 |
|
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).setDirty();
|
109 |
|
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).redraw();
|
110 |
|
}else{
|
111 |
|
AbstractUtility.executeOperation(operation, sync);
|
|
74 |
if(object instanceof Media){
|
|
75 |
// TODO use undo context specific to editor
|
|
76 |
MediaDeletionConfigurator config = fillDeleteConfigurator(shell, description, Messages.DeleteMediaHandler_CONFIRM_MESSAGE_MEDIA);
|
|
77 |
if (config == null){
|
|
78 |
return;
|
112 |
79 |
}
|
|
80 |
List<Media> mediaList = new ArrayList<>();
|
|
81 |
mediaList.add((Media)object);
|
|
82 |
createMediaDeleteOperation(menuItem.getLocalizedLabel(), sync, mediaView, mediaList, description, config);
|
113 |
83 |
}
|
114 |
84 |
if(object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery()){
|
|
85 |
if (!((DescriptionBase)object).getElements().isEmpty()){
|
|
86 |
MediaDeletionConfigurator config = fillDeleteConfigurator(shell, description, Messages.DeleteMediaHandler_CONFIRM_MESSAGE_DESCRIPTION);
|
|
87 |
if (config == null){
|
|
88 |
return;
|
|
89 |
}
|
|
90 |
Iterator<DescriptionElementBase> elements = ((DescriptionBase)object).getElements().iterator();
|
|
91 |
DescriptionElementBase element = elements.next();
|
|
92 |
createMediaDeleteOperation(menuItem.getLocalizedLabel(), sync, mediaView, element.getMedia(), description, config);
|
|
93 |
}
|
|
94 |
|
115 |
95 |
if(object instanceof TaxonDescription){
|
|
96 |
|
116 |
97 |
DeleteTaxonDescriptionOperation deleteTaxonDescriptionOperation = new DeleteTaxonDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (TaxonDescription)object, mediaView, null);
|
117 |
98 |
if (mediaView.getSelectionProvidingPart().getObject() instanceof TaxonNameEditorE4){
|
|
99 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).getTaxon().removeDescription((TaxonDescription)description);
|
118 |
100 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).getEditorInput().addOperation(deleteTaxonDescriptionOperation);
|
119 |
101 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).setDirty();
|
120 |
102 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).redraw();
|
... | ... | |
137 |
119 |
}
|
138 |
120 |
}
|
139 |
121 |
|
|
122 |
public void createMediaDeleteOperation(String menuLabel, UISynchronize sync, MediaViewPartE4 mediaView,
|
|
123 |
List<Media> media, DescriptionBase description, MediaDeletionConfigurator config) {
|
|
124 |
AbstractPostOperation<?> operation = new DeleteMediaOperation(menuLabel, EditorUtil.getUndoContext(), description, media, config, mediaView);
|
|
125 |
if (mediaView.getSelectionProvidingPart().getObject() instanceof TaxonNameEditorE4){
|
|
126 |
if (!config.isOnlyRemoveFromGallery()){
|
|
127 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).getEditorInput().addOperation(operation);
|
|
128 |
}
|
|
129 |
|
|
130 |
if (description.isImageGallery()){
|
|
131 |
Set<DescriptionElementBase> elements = description.getElements();
|
|
132 |
if (elements.size() == 1){
|
|
133 |
DescriptionElementBase element = elements.iterator().next();
|
|
134 |
for (Media mediaElement:media){
|
|
135 |
element.removeMedia(mediaElement);
|
|
136 |
}
|
|
137 |
if (element.getMedia().isEmpty()){
|
|
138 |
description.removeElement(element);
|
|
139 |
}
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).setDirty();
|
|
144 |
((TaxonNameEditorE4)mediaView.getSelectionProvidingPart().getObject()).redraw();
|
|
145 |
}else{
|
|
146 |
AbstractUtility.executeOperation(operation, sync);
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
public MediaDeletionConfigurator fillDeleteConfigurator(Shell shell, DescriptionBase description, String message) {
|
|
151 |
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
|
|
152 |
|
|
153 |
config.setDeleteFromDescription(true);
|
|
154 |
config.setOnlyRemoveFromGallery(false);
|
|
155 |
|
|
156 |
if (description instanceof SpecimenDescription){
|
|
157 |
config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation());
|
|
158 |
} else if (description instanceof TaxonDescription){
|
|
159 |
config.setDeleteFrom(((TaxonDescription)description).getTaxon());
|
|
160 |
}else if (description instanceof TaxonNameDescription){
|
|
161 |
config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName());
|
|
162 |
}
|
|
163 |
DeleteConfiguratorDialog dialog;
|
|
164 |
dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, message, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
|
|
165 |
int result_dialog= dialog.open();
|
|
166 |
if (result_dialog != IStatus.OK){
|
|
167 |
return null;
|
|
168 |
}
|
|
169 |
return config;
|
|
170 |
}
|
|
171 |
|
140 |
172 |
@CanExecute
|
141 |
173 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
142 |
174 |
MHandledMenuItem menuItem){
|
ref #8198: show media delete config wizard only for galleries with media