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.IDirtyMarkableSelectionProvider;
|
32
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
33
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
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, IDirtyMarkableSelectionProvider{
|
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
|
createViewerComposite(pageBook);
|
64
|
createViewer(viewerComposite);
|
65
|
|
66
|
// Page 2: Nothing selected
|
67
|
emptySelectionLabel = new Label(pageBook, SWT.TOP + SWT.LEFT + SWT.WRAP);
|
68
|
|
69
|
setInitialSelection();
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
*
|
74
|
*/
|
75
|
private void setInitialSelection() {
|
76
|
selectionChanged(StoreUtil.getActivePart(), getInitialSelection());
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* <p>getInitialSelection</p>
|
81
|
*
|
82
|
* @return a {@link org.eclipse.jface.viewers.ISelection} object.
|
83
|
*/
|
84
|
protected ISelection getInitialSelection() {
|
85
|
return selectionService.getSelection();
|
86
|
}
|
87
|
|
88
|
private void createViewerComposite(Composite parent) {
|
89
|
viewerComposite = new SashForm(parent, SWT.HORIZONTAL);
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* <p>showEmptyPage</p>
|
94
|
*/
|
95
|
public void showEmptyPage(){
|
96
|
pageBook.showPage(emptySelectionLabel);
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* <p>showViewer</p>
|
101
|
*
|
102
|
* @param part a {@link org.eclipse.ui.IWorkbenchPart} object.
|
103
|
* @param selection a {@link org.eclipse.jface.viewers.ISelection} object.
|
104
|
*/
|
105
|
public void showViewer(IWorkbenchPart part, IStructuredSelection selection){
|
106
|
this.part = part;
|
107
|
|
108
|
Object element = selection.getFirstElement();
|
109
|
|
110
|
getViewer().setInput(element);
|
111
|
|
112
|
showViewer();
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* <p>getViewer</p>
|
117
|
*
|
118
|
* @return a {@link org.eclipse.jface.viewers.Viewer} object.
|
119
|
*/
|
120
|
public abstract Viewer getViewer();
|
121
|
|
122
|
/**
|
123
|
* <p>showViewer</p>
|
124
|
*/
|
125
|
public void showViewer(){
|
126
|
pageBook.showPage(viewerComposite);
|
127
|
}
|
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
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
148
|
changed(objectAffectedByOperation);
|
149
|
return true;
|
150
|
}
|
151
|
|
152
|
/** {@inheritDoc} */
|
153
|
public abstract void changed(Object object);
|
154
|
|
155
|
/**
|
156
|
* <p>getConversationHolder</p>
|
157
|
*
|
158
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
159
|
*/
|
160
|
public ConversationHolder getConversationHolder() {
|
161
|
if(part != null)
|
162
|
return ((IConversationEnabled) part).getConversationHolder();
|
163
|
|
164
|
return null;
|
165
|
}
|
166
|
|
167
|
/** {@inheritDoc} */
|
168
|
public void update(CdmDataChangeMap changeEvents) {
|
169
|
|
170
|
}
|
171
|
|
172
|
/** {@inheritDoc} */
|
173
|
@Override
|
174
|
public void dispose() {
|
175
|
selectionService.removeSelectionListener(this);
|
176
|
super.dispose();
|
177
|
}
|
178
|
}
|