2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
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
.part
.PageBook
;
27 import org
.eclipse
.ui
.part
.ViewPart
;
29 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
30 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
32 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
33 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
34 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
36 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
39 * <p>Abstract AbstractCdmViewPart class.</p>
42 * @created Jun 15, 2010
45 public abstract class AbstractCdmViewPart
extends ViewPart
implements ISelectionListener
, IPostOperationEnabled
, IConversationEnabled
, ICdmEntitySessionEnabled
, IDirtyMarkable
{
47 protected ISelectionService selectionService
;
49 public static IStructuredSelection EMPTY_SELECTION
= new StructuredSelection();
51 protected Object part
;
53 private PageBook pageBook
;
55 private Label emptySelectionLabel
;
57 private Composite viewerComposite
;
61 public void createPartControl(Composite parent
) {
62 selectionService
= getSite().getWorkbenchWindow().getSelectionService();
63 selectionService
.addSelectionListener(this);
65 pageBook
= new PageBook(parent
, SWT
.NULL
);
66 //create viewerComposite
67 viewerComposite
= new SashForm(pageBook
, SWT
.HORIZONTAL
);
68 createViewer(viewerComposite
);
70 // Page 2: Nothing selected
71 emptySelectionLabel
= new Label(pageBook
, SWT
.TOP
+ SWT
.LEFT
+ SWT
.WRAP
);
73 setInitialSelection();
76 private void setInitialSelection() {
77 // selectionChanged(AbstractUtility.getActiveWorkbenchPart(), getInitialSelection());
81 * <p>getInitialSelection</p>
83 * @return a {@link org.eclipse.jface.viewers.ISelection} object.
85 protected ISelection
getInitialSelection() {
86 return selectionService
.getSelection();
90 * <p>showEmptyPage</p>
92 public void showEmptyPage(){
93 setPartName(createPartTitle(null));
94 pageBook
.showPage(emptySelectionLabel
);
100 * @param part a {@link org.eclipse.ui.IWorkbenchPart} object.
101 * @param selection a {@link org.eclipse.jface.viewers.ISelection} object.
103 public void showViewer(Object part
, IStructuredSelection selection
){
106 Object element
= selection
.getFirstElement();
107 //avoid widget is disposed exceptions
108 if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){
112 setPartName(createPartTitle(element
));
113 getViewer().setInput(element
);
120 * @return a {@link org.eclipse.jface.viewers.Viewer} object.
122 public abstract Viewer
getViewer();
127 public void showViewer(){
128 pageBook
.showPage(viewerComposite
);
131 public void setEnabled(boolean enabled
){
132 pageBook
.setEnabled(enabled
);
137 public void setFocus() {
138 if(getConversationHolder() != null){
139 getConversationHolder().bind();
141 if(getCdmEntitySession() != null){
142 getCdmEntitySession().bind();
144 getViewer().getControl().setFocus();
148 * <p>createViewer</p>
150 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
152 public abstract void createViewer(Composite parent
);
156 public boolean postOperation(CdmBase objectAffectedByOperation
) {
157 changed(objectAffectedByOperation
);
163 public abstract void changed(Object object
);
166 * <p>getConversationHolder</p>
168 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
171 public ConversationHolder
getConversationHolder() {
172 if(part
!= null && part
instanceof IConversationEnabled
) {
173 return ((IConversationEnabled
) part
).getConversationHolder();
180 public ICdmEntitySession
getCdmEntitySession() {
181 if(part
!= null && part
instanceof ICdmEntitySessionEnabled
) {
182 return ((ICdmEntitySessionEnabled
) part
).getCdmEntitySession();
188 public List
<?
extends CdmBase
> getRootEntities() {
189 return Arrays
.asList((CdmBase
)getViewer().getInput());
194 public void update(CdmDataChangeMap changeEvents
) {
200 public void dispose() {
201 selectionService
.removeSelectionListener(this);
206 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
209 public void forceDirty() {
215 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
218 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
219 // TODO Auto-generated method stub
223 protected String
createPartTitle(Object selectedObject
){
224 if(selectedObject
!=null){
225 return getViewName()+": "+selectedObject
; //$NON-NLS-1$
227 return getViewName();
230 protected abstract String
getViewName();