Revision 017f41a2
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java | ||
---|---|---|
7 | 7 |
import org.eclipse.e4.core.di.annotations.Optional; |
8 | 8 |
import org.eclipse.e4.ui.di.UISynchronize; |
9 | 9 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
10 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
10 | 11 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
11 | 12 |
import org.eclipse.e4.ui.services.IServiceConstants; |
13 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
12 | 14 |
|
13 | 15 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
14 | 16 |
import eu.etaxonomy.cdm.model.media.Media; |
... | ... | |
23 | 25 |
|
24 | 26 |
@Execute |
25 | 27 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
26 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MMenuItem menuItem,
|
|
28 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
|
|
27 | 29 |
UISynchronize sync) { |
28 | 30 |
|
29 | 31 |
MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject(); |
30 | 32 |
|
31 |
if(description != null){ |
|
32 |
AbstractPostOperation operation = null; |
|
33 |
//select media |
|
34 |
Media media = MediaSelectionDialog.select(AbstractUtility.getShell(),// null, |
|
35 |
null); |
|
36 |
if(media!=null){ |
|
37 |
// TODO use undo context specific to editor |
|
38 |
operation = new AddExistingMediaToImageGalleryOperation(media, menuItem.getLocalizedLabel(), |
|
39 |
EditorUtil.getUndoContext(), description, mediaView); |
|
40 |
AbstractUtility.executeOperation(operation, sync); |
|
41 |
} |
|
33 |
AbstractPostOperation operation = null; |
|
34 |
//select media |
|
35 |
Media media = MediaSelectionDialog.select(AbstractUtility.getShell(),// null, |
|
36 |
null); |
|
37 |
if(media!=null){ |
|
38 |
// TODO use undo context specific to editor |
|
39 |
operation = new AddExistingMediaToImageGalleryOperation(media, menuItem.getLocalizedLabel(), |
|
40 |
EditorUtil.getUndoContext(), (DescriptionBase<?>) selection.getFirstElement(), mediaView); |
|
41 |
AbstractUtility.executeOperation(operation, sync); |
|
42 | 42 |
} |
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
@CanExecute |
46 |
private boolean canExecute(){ |
|
47 |
return true; |
|
46 |
private boolean canExecute(MHandledMenuItem menuItem, |
|
47 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){ |
|
48 |
boolean canExecute = false; |
|
49 |
canExecute = selection.size()==1 && selection.getFirstElement() instanceof DescriptionBase; |
|
50 |
menuItem.setVisible(canExecute); |
|
51 |
return canExecute; |
|
48 | 52 |
} |
49 | 53 |
|
50 | 54 |
} |
Also available in: Unified diff
ref #7010 Adapt media view handlers for multiple selection