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