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.view.datasource.e4.handler;
|
11
|
|
12
|
import javax.inject.Named;
|
13
|
|
14
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
15
|
import org.eclipse.e4.core.di.annotations.Execute;
|
16
|
import org.eclipse.e4.core.di.annotations.Optional;
|
17
|
import org.eclipse.e4.ui.di.UISynchronize;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
20
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
21
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
22
|
import org.eclipse.swt.widgets.Shell;
|
23
|
|
24
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
25
|
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
|
26
|
|
27
|
/**
|
28
|
*
|
29
|
* @author pplitzner
|
30
|
* @date 22.08.2017
|
31
|
*
|
32
|
*/
|
33
|
public abstract class AbstractDataSourceHandlerE4 {
|
34
|
|
35
|
protected UISynchronize sync;
|
36
|
|
37
|
@Execute
|
38
|
public void execute(
|
39
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
40
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
41
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
42
|
UISynchronize sync) {
|
43
|
|
44
|
this.sync = sync;
|
45
|
|
46
|
CdmDataSourceViewPartE4 view = (CdmDataSourceViewPartE4) thisPart.getObject();
|
47
|
|
48
|
boolean refresh = specificExecute(view,
|
49
|
(CdmMetaDataAwareDataSourceContainer) selection.getFirstElement(), shell);
|
50
|
|
51
|
if(refresh) {
|
52
|
view.refresh();
|
53
|
}
|
54
|
}
|
55
|
|
56
|
@CanExecute
|
57
|
public boolean canExecute(
|
58
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
59
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
60
|
MHandledMenuItem menuItem) {
|
61
|
boolean canExecute = false;
|
62
|
canExecute = thisPart.getObject() instanceof CdmDataSourceViewPartE4
|
63
|
&& selection!=null
|
64
|
&& selection.size()==1
|
65
|
&& selection.getFirstElement() instanceof CdmMetaDataAwareDataSourceContainer;
|
66
|
menuItem.setVisible(canExecute);
|
67
|
return canExecute;
|
68
|
}
|
69
|
|
70
|
public abstract boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell);
|
71
|
}
|