1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2017 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.view.e4.details;
|
11
|
|
12
|
import javax.annotation.PostConstruct;
|
13
|
import javax.annotation.PreDestroy;
|
14
|
import javax.inject.Inject;
|
15
|
import javax.inject.Named;
|
16
|
|
17
|
import org.eclipse.e4.core.di.annotations.Optional;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
import org.eclipse.jface.viewers.StructuredSelection;
|
22
|
import org.eclipse.jface.viewers.Viewer;
|
23
|
import org.eclipse.swt.widgets.Composite;
|
24
|
import org.eclipse.ui.IEditorPart;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
27
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
28
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
29
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
30
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
31
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
32
|
|
33
|
/**
|
34
|
* @author pplitzner
|
35
|
* @date 18.07.2017
|
36
|
*
|
37
|
*/
|
38
|
public class DetailsPartE4 implements IConversationEnabled, IDirtyMarkable{
|
39
|
|
40
|
private DetailsViewerE4 viewer;
|
41
|
|
42
|
private MPart selectionProvidingPart;
|
43
|
|
44
|
@Inject
|
45
|
public DetailsPartE4() {
|
46
|
}
|
47
|
|
48
|
@PostConstruct
|
49
|
public void create(Composite parent) {
|
50
|
viewer = new DetailsViewerE4(parent, this);
|
51
|
}
|
52
|
|
53
|
@Inject
|
54
|
@Optional
|
55
|
public void selectionChanged(
|
56
|
@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
|
57
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
58
|
MPart thisPart){
|
59
|
if(activePart==thisPart){
|
60
|
return;
|
61
|
}
|
62
|
if(selection instanceof IStructuredSelection){
|
63
|
showViewer((IStructuredSelection) selection, activePart, thisPart);
|
64
|
}
|
65
|
else{
|
66
|
showViewer(new StructuredSelection(selection), activePart, thisPart);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
protected String getViewName(){
|
71
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
72
|
}
|
73
|
|
74
|
public Viewer getViewer() {
|
75
|
return viewer;
|
76
|
}
|
77
|
|
78
|
|
79
|
@PreDestroy
|
80
|
public void dispose() {
|
81
|
}
|
82
|
|
83
|
public void showViewer(IStructuredSelection selection, MPart activePart, MPart thisPart){
|
84
|
if(getViewer()!=null){
|
85
|
Object element = selection.getFirstElement();
|
86
|
if(selection.getFirstElement()!=null){
|
87
|
getViewer().setInput(element);
|
88
|
selectionProvidingPart = activePart;
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* {@inheritDoc}
|
95
|
*/
|
96
|
@Override
|
97
|
public void update(CdmDataChangeMap arg0) {
|
98
|
// TODO Auto-generated method stub
|
99
|
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* {@inheritDoc}
|
104
|
*/
|
105
|
@Override
|
106
|
public ConversationHolder getConversationHolder() {
|
107
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof IConversationEnabled) {
|
108
|
return ((IConversationEnabled) selectionProvidingPart).getConversationHolder();
|
109
|
}
|
110
|
return null;
|
111
|
}
|
112
|
|
113
|
/** {@inheritDoc} */
|
114
|
@Override
|
115
|
public void changed(Object object) {
|
116
|
Object part = selectionProvidingPart.getObject();
|
117
|
if(part instanceof IDirtyMarkable){
|
118
|
((IDirtyMarkable) part).changed(object);
|
119
|
}
|
120
|
else {
|
121
|
IEditorPart editor = AbstractUtility.getActiveEditor();
|
122
|
if (editor != null && editor instanceof IDirtyMarkable) {
|
123
|
((IDirtyMarkable) editor).changed(object);
|
124
|
}
|
125
|
}
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* {@inheritDoc}
|
130
|
*/
|
131
|
@Override
|
132
|
public void forceDirty() {
|
133
|
// TODO Auto-generated method stub
|
134
|
|
135
|
}
|
136
|
}
|