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