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;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import org.eclipse.jface.viewers.ISelection;
|
17
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
18
|
import org.eclipse.jface.viewers.StructuredSelection;
|
19
|
import org.eclipse.jface.viewers.Viewer;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.custom.SashForm;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
import org.eclipse.swt.widgets.Label;
|
24
|
import org.eclipse.ui.ISelectionListener;
|
25
|
import org.eclipse.ui.ISelectionService;
|
26
|
import org.eclipse.ui.part.PageBook;
|
27
|
import org.eclipse.ui.part.ViewPart;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
30
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
33
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
34
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
35
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
36
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
37
|
|
38
|
/**
|
39
|
* <p>Abstract AbstractCdmViewPart class.</p>
|
40
|
*
|
41
|
* @author n.hoffmann
|
42
|
* @created Jun 15, 2010
|
43
|
* @version 1.0
|
44
|
*/
|
45
|
public abstract class AbstractCdmViewPart extends ViewPart implements ISelectionListener, IPostOperationEnabled, IConversationEnabled, ICdmEntitySessionEnabled, IDirtyMarkable{
|
46
|
|
47
|
protected ISelectionService selectionService;
|
48
|
|
49
|
public static IStructuredSelection EMPTY_SELECTION = new StructuredSelection();
|
50
|
|
51
|
protected Object part;
|
52
|
|
53
|
private PageBook pageBook;
|
54
|
|
55
|
private Label emptySelectionLabel;
|
56
|
|
57
|
private Composite viewerComposite;
|
58
|
|
59
|
/** {@inheritDoc} */
|
60
|
@Override
|
61
|
public void createPartControl(Composite parent) {
|
62
|
selectionService = getSite().getWorkbenchWindow().getSelectionService();
|
63
|
selectionService.addSelectionListener(this);
|
64
|
|
65
|
pageBook = new PageBook(parent, SWT.NULL);
|
66
|
//create viewerComposite
|
67
|
viewerComposite = new SashForm(pageBook, SWT.HORIZONTAL);
|
68
|
createViewer(viewerComposite);
|
69
|
|
70
|
// Page 2: Nothing selected
|
71
|
emptySelectionLabel = new Label(pageBook, SWT.TOP + SWT.LEFT + SWT.WRAP);
|
72
|
|
73
|
setInitialSelection();
|
74
|
}
|
75
|
|
76
|
private void setInitialSelection() {
|
77
|
// selectionChanged(AbstractUtility.getActiveWorkbenchPart(), getInitialSelection());
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* <p>getInitialSelection</p>
|
82
|
*
|
83
|
* @return a {@link org.eclipse.jface.viewers.ISelection} object.
|
84
|
*/
|
85
|
protected ISelection getInitialSelection() {
|
86
|
return selectionService.getSelection();
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* <p>showEmptyPage</p>
|
91
|
*/
|
92
|
public void showEmptyPage(){
|
93
|
setPartName(createPartTitle(null));
|
94
|
pageBook.showPage(emptySelectionLabel);
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* <p>showViewer</p>
|
99
|
*
|
100
|
* @param part a {@link org.eclipse.ui.IWorkbenchPart} object.
|
101
|
* @param selection a {@link org.eclipse.jface.viewers.ISelection} object.
|
102
|
*/
|
103
|
public void showViewer(Object part, IStructuredSelection selection){
|
104
|
this.part = part;
|
105
|
|
106
|
Object element = selection.getFirstElement();
|
107
|
//avoid widget is disposed exceptions
|
108
|
if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){
|
109
|
return;
|
110
|
}
|
111
|
|
112
|
setPartName(createPartTitle(element));
|
113
|
getViewer().setInput(element);
|
114
|
showViewer();
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* <p>getViewer</p>
|
119
|
*
|
120
|
* @return a {@link org.eclipse.jface.viewers.Viewer} object.
|
121
|
*/
|
122
|
public abstract Viewer getViewer();
|
123
|
|
124
|
/**
|
125
|
* <p>showViewer</p>
|
126
|
*/
|
127
|
public void showViewer(){
|
128
|
pageBook.showPage(viewerComposite);
|
129
|
}
|
130
|
|
131
|
public void setEnabled(boolean enabled){
|
132
|
pageBook.setEnabled(enabled);
|
133
|
}
|
134
|
|
135
|
/** {@inheritDoc} */
|
136
|
@Override
|
137
|
public void setFocus() {
|
138
|
if(getConversationHolder() != null){
|
139
|
getConversationHolder().bind();
|
140
|
}
|
141
|
if(getCdmEntitySession() != null){
|
142
|
getCdmEntitySession().bind();
|
143
|
}
|
144
|
getViewer().getControl().setFocus();
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* <p>createViewer</p>
|
149
|
*
|
150
|
* @param parent a {@link org.eclipse.swt.widgets.Composite} object.
|
151
|
*/
|
152
|
public abstract void createViewer(Composite parent);
|
153
|
|
154
|
/** {@inheritDoc} */
|
155
|
@Override
|
156
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
157
|
changed(objectAffectedByOperation);
|
158
|
return true;
|
159
|
}
|
160
|
|
161
|
/** {@inheritDoc} */
|
162
|
@Override
|
163
|
public abstract void changed(Object object);
|
164
|
|
165
|
/**
|
166
|
* <p>getConversationHolder</p>
|
167
|
*
|
168
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
169
|
*/
|
170
|
@Override
|
171
|
public ConversationHolder getConversationHolder() {
|
172
|
if(part != null && part instanceof IConversationEnabled) {
|
173
|
return ((IConversationEnabled) part).getConversationHolder();
|
174
|
}
|
175
|
|
176
|
return null;
|
177
|
}
|
178
|
|
179
|
@Override
|
180
|
public ICdmEntitySession getCdmEntitySession() {
|
181
|
if(part != null && part instanceof ICdmEntitySessionEnabled) {
|
182
|
return ((ICdmEntitySessionEnabled) part).getCdmEntitySession();
|
183
|
}
|
184
|
return null;
|
185
|
}
|
186
|
|
187
|
@Override
|
188
|
public List<? extends CdmBase> getRootEntities() {
|
189
|
return Arrays.asList((CdmBase)getViewer().getInput());
|
190
|
}
|
191
|
|
192
|
/** {@inheritDoc} */
|
193
|
@Override
|
194
|
public void update(CdmDataChangeMap changeEvents) {
|
195
|
|
196
|
}
|
197
|
|
198
|
/** {@inheritDoc} */
|
199
|
@Override
|
200
|
public void dispose() {
|
201
|
selectionService.removeSelectionListener(this);
|
202
|
super.dispose();
|
203
|
}
|
204
|
|
205
|
/* (non-Javadoc)
|
206
|
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
|
207
|
*/
|
208
|
@Override
|
209
|
public void forceDirty() {
|
210
|
changed(null);
|
211
|
}
|
212
|
|
213
|
|
214
|
/* (non-Javadoc)
|
215
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
|
216
|
*/
|
217
|
@Override
|
218
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
219
|
// TODO Auto-generated method stub
|
220
|
return null;
|
221
|
}
|
222
|
|
223
|
protected String createPartTitle(Object selectedObject){
|
224
|
if(selectedObject!=null){
|
225
|
return getViewName()+": "+selectedObject; //$NON-NLS-1$
|
226
|
}
|
227
|
return getViewName();
|
228
|
}
|
229
|
|
230
|
protected abstract String getViewName();
|
231
|
}
|