Revision fb019605
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java | ||
---|---|---|
6 | 6 |
import javax.inject.Named; |
7 | 7 |
|
8 | 8 |
import org.eclipse.core.runtime.IStatus; |
9 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
|
9 | 10 |
import org.eclipse.e4.core.di.annotations.Execute; |
10 | 11 |
import org.eclipse.e4.ui.di.UISynchronize; |
11 | 12 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
13 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
12 | 14 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
13 | 15 |
import org.eclipse.e4.ui.services.IServiceConstants; |
14 | 16 |
import org.eclipse.jface.dialogs.MessageDialog; |
... | ... | |
16 | 18 |
import org.eclipse.jface.viewers.TreePath; |
17 | 19 |
import org.eclipse.jface.viewers.TreeSelection; |
18 | 20 |
import org.eclipse.swt.widgets.Shell; |
19 |
import org.eclipse.ui.IEditorInput; |
|
20 |
import org.eclipse.ui.IEditorPart; |
|
21 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
22 | 21 |
|
23 | 22 |
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator; |
24 | 23 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
... | ... | |
26 | 25 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
27 | 26 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
28 | 27 |
import eu.etaxonomy.cdm.model.media.Media; |
29 |
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput; |
|
30 | 28 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
31 | 29 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
32 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
30 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteSpecimenDescriptionOperation; |
|
31 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation; |
|
33 | 32 |
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4; |
34 | 33 |
import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation; |
35 | 34 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
36 | 35 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
37 | 36 |
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog; |
38 |
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; |
|
39 | 37 |
|
40 | 38 |
/** |
41 | 39 |
* |
... | ... | |
47 | 45 |
|
48 | 46 |
@Execute |
49 | 47 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
50 |
@Named(IServiceConstants.ACTIVE_SELECTION) Media media,
|
|
48 |
@Named(IServiceConstants.ACTIVE_SELECTION) Object object,
|
|
51 | 49 |
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, |
52 | 50 |
MMenuItem menuItem, |
53 | 51 |
UISynchronize sync) { |
54 | 52 |
|
55 | 53 |
MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject(); |
56 | 54 |
|
57 |
|
|
58 |
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart());
|
|
59 |
if (e4WrappedPart instanceof FormEditor) {
|
|
60 |
IEditorPart editor = null;
|
|
61 |
editor = (FormEditor) e4WrappedPart;
|
|
62 |
IEditorInput input = editor.getEditorInput();
|
|
63 |
if (input instanceof CdmEntitySessionInput) {
|
|
64 |
ISelection selection = mediaView.getViewer().getSelection();
|
|
65 |
if (selection instanceof TreeSelection) {
|
|
66 |
TreePath[] paths = ((TreeSelection) selection).getPaths();
|
|
67 |
int count = paths[0].getSegmentCount();
|
|
68 |
DescriptionBase description = null;
|
|
69 |
for (int i = 0; i < count; i++ ) {
|
|
70 |
if (paths[0].getSegment(i) instanceof DescriptionBase) { |
|
71 |
description = (DescriptionBase) paths[0].getSegment(i);
|
|
72 |
break;
|
|
73 |
} |
|
74 |
}
|
|
75 |
// TODO use undo context specific to editor
|
|
76 |
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
|
|
77 |
|
|
78 |
config.setDeleteFromDescription(true);
|
|
79 |
config.setOnlyRemoveFromGallery(false);
|
|
80 |
|
|
81 |
if (description instanceof SpecimenDescription){
|
|
82 |
config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation());
|
|
83 |
} else if (description instanceof TaxonDescription){
|
|
84 |
config.setDeleteFrom(((TaxonDescription)description).getTaxon());
|
|
85 |
}else if (description instanceof TaxonNameDescription){
|
|
86 |
config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName());
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
DeleteConfiguratorDialog dialog;
|
|
91 |
dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
|
|
92 |
int result_dialog= dialog.open();
|
|
93 |
if (result_dialog != IStatus.OK){
|
|
94 |
return;
|
|
95 |
}
|
|
96 |
AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView);
|
|
97 |
AbstractUtility.executeOperation(operation, sync);
|
|
98 |
|
|
55 |
ISelection selection = mediaView.getViewer().getSelection(); |
|
56 |
if (selection instanceof TreeSelection) {
|
|
57 |
TreePath[] paths = ((TreeSelection) selection).getPaths();
|
|
58 |
int count = paths[0].getSegmentCount();
|
|
59 |
DescriptionBase description = null;
|
|
60 |
for (int i = 0; i < count; i++ ) {
|
|
61 |
if (paths[0].getSegment(i) instanceof DescriptionBase) {
|
|
62 |
description = (DescriptionBase) paths[0].getSegment(i);
|
|
63 |
break;
|
|
64 |
}
|
|
65 |
}
|
|
66 |
// TODO use undo context specific to editor
|
|
67 |
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
|
|
68 |
|
|
69 |
config.setDeleteFromDescription(true);
|
|
70 |
config.setOnlyRemoveFromGallery(false);
|
|
71 |
|
|
72 |
if (description instanceof SpecimenDescription){
|
|
73 |
config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation());
|
|
74 |
} else if (description instanceof TaxonDescription){
|
|
75 |
config.setDeleteFrom(((TaxonDescription)description).getTaxon()); |
|
76 |
}else if (description instanceof TaxonNameDescription){
|
|
77 |
config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName());
|
|
78 |
} |
|
79 |
DeleteConfiguratorDialog dialog;
|
|
80 |
dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
|
|
81 |
int result_dialog= dialog.open();
|
|
82 |
if (result_dialog != IStatus.OK){
|
|
83 |
return;
|
|
84 |
}
|
|
85 |
if(object instanceof Media){
|
|
86 |
AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, (Media) object, config, mediaView); |
|
87 |
AbstractUtility.executeOperation(operation, sync); |
|
88 |
}
|
|
89 |
if(object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery()){
|
|
90 |
if(object instanceof TaxonDescription){
|
|
91 |
DeleteTaxonDescriptionOperation deleteTaxonDescriptionOperation = new DeleteTaxonDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (TaxonDescription)object, mediaView, null);
|
|
92 |
AbstractUtility.executeOperation(deleteTaxonDescriptionOperation, sync);
|
|
93 |
} |
|
94 |
else if(object instanceof SpecimenDescription){
|
|
95 |
DeleteSpecimenDescriptionOperation deleteTaxonDescriptionOperation = new DeleteSpecimenDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (SpecimenDescription)object, mediaView, null);
|
|
96 |
AbstractUtility.executeOperation(deleteTaxonDescriptionOperation, sync); |
|
99 | 97 |
} |
100 | 98 |
} |
101 |
} else if (e4WrappedPart instanceof DerivateView){ |
|
102 |
DerivateView view = (DerivateView) e4WrappedPart; |
|
103 |
|
|
104 |
ISelection selection = mediaView.getViewer().getSelection(); |
|
105 |
if (selection instanceof TreeSelection) { |
|
106 |
TreePath[] paths = ((TreeSelection) selection).getPaths(); |
|
107 |
int count = paths[0].getSegmentCount(); |
|
108 |
DescriptionBase description = null; |
|
109 |
for (int i = 0; i < count; i++ ) { |
|
110 |
if (paths[0].getSegment(i) instanceof DescriptionBase) { |
|
111 |
description = (DescriptionBase) paths[0].getSegment(i); |
|
112 |
break; |
|
113 |
} |
|
114 |
} |
|
115 |
// TODO use undo context specific to editor |
|
116 |
MediaDeletionConfigurator config = new MediaDeletionConfigurator(); |
|
117 |
|
|
118 |
config.setDeleteFromDescription(true); |
|
119 |
config.setOnlyRemoveFromGallery(false); |
|
120 |
|
|
121 |
if (description instanceof SpecimenDescription){ |
|
122 |
config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation()); |
|
123 |
} else if (description instanceof TaxonDescription){ |
|
124 |
config.setDeleteFrom(((TaxonDescription)description).getTaxon()); |
|
125 |
}else if (description instanceof TaxonNameDescription){ |
|
126 |
config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName()); |
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
DeleteConfiguratorDialog dialog; |
|
131 |
dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0); |
|
132 |
int result_dialog= dialog.open(); |
|
133 |
if (result_dialog != IStatus.OK){ |
|
134 |
return; |
|
135 |
} |
|
136 |
AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView); |
|
137 |
AbstractUtility.executeOperation(operation, sync); |
|
138 | 99 |
|
139 |
} |
|
140 |
} |
|
141 | 100 |
} |
101 |
} |
|
102 |
|
|
103 |
@CanExecute |
|
104 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) Object object, |
|
105 |
MHandledMenuItem menuItem){ |
|
106 |
boolean canExecute = false; |
|
107 |
canExecute = object instanceof Media |
|
108 |
|| (object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery()); |
|
109 |
menuItem.setVisible(canExecute); |
|
110 |
return canExecute; |
|
111 |
} |
|
112 |
|
|
142 | 113 |
|
143 | 114 |
|
144 | 115 |
} |
Also available in: Unified diff
ref #6906 Fix Delete and move handler for media view