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