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