Revision b0ce5b17
Added by Patrick Plitzner over 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
28 | 28 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
29 | 29 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
30 | 30 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
31 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
31 | 32 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider; |
32 | 33 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
33 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
34 | 34 |
|
35 | 35 |
/** |
36 | 36 |
* <p>Abstract AbstractCdmViewPart class.</p> |
... | ... | |
40 | 40 |
* @version 1.0 |
41 | 41 |
*/ |
42 | 42 |
public abstract class AbstractCdmViewPart extends ViewPart implements ISelectionListener, IPostOperationEnabled, IConversationEnabled, IDirtyMarkableSelectionProvider{ |
43 |
|
|
43 |
|
|
44 | 44 |
protected ISelectionService selectionService; |
45 | 45 |
|
46 | 46 |
public static IStructuredSelection EMPTY_SELECTION = new StructuredSelection(); |
47 |
|
|
47 |
|
|
48 | 48 |
protected IWorkbenchPart part; |
49 |
|
|
49 |
|
|
50 | 50 |
private PageBook pageBook; |
51 | 51 |
|
52 | 52 |
private Label emptySelectionLabel; |
53 | 53 |
|
54 | 54 |
private Composite viewerComposite; |
55 |
|
|
55 |
|
|
56 | 56 |
/** {@inheritDoc} */ |
57 | 57 |
@Override |
58 | 58 |
public void createPartControl(Composite parent) { |
59 | 59 |
selectionService = getSite().getWorkbenchWindow().getSelectionService(); |
60 | 60 |
selectionService.addSelectionListener(this); |
61 |
|
|
61 |
|
|
62 | 62 |
pageBook = new PageBook(parent, SWT.NULL); |
63 |
createViewerComposite(pageBook); |
|
63 |
//create viewerComposite |
|
64 |
viewerComposite = new SashForm(pageBook, SWT.HORIZONTAL); |
|
64 | 65 |
createViewer(viewerComposite); |
65 |
|
|
66 |
|
|
66 | 67 |
// Page 2: Nothing selected |
67 | 68 |
emptySelectionLabel = new Label(pageBook, SWT.TOP + SWT.LEFT + SWT.WRAP); |
68 |
|
|
69 |
|
|
69 | 70 |
setInitialSelection(); |
70 | 71 |
} |
71 |
|
|
72 |
|
|
72 | 73 |
/** |
73 |
*
|
|
74 |
* |
|
74 | 75 |
*/ |
75 | 76 |
private void setInitialSelection() { |
76 |
selectionChanged(StoreUtil.getActivePart(), getInitialSelection());
|
|
77 |
selectionChanged(AbstractUtility.getActivePart(), getInitialSelection());
|
|
77 | 78 |
} |
78 | 79 |
|
79 | 80 |
/** |
... | ... | |
84 | 85 |
protected ISelection getInitialSelection() { |
85 | 86 |
return selectionService.getSelection(); |
86 | 87 |
} |
87 |
|
|
88 |
|
|
88 | 89 |
private void createViewerComposite(Composite parent) { |
89 | 90 |
viewerComposite = new SashForm(parent, SWT.HORIZONTAL); |
90 | 91 |
} |
91 |
|
|
92 |
|
|
92 | 93 |
/** |
93 | 94 |
* <p>showEmptyPage</p> |
94 | 95 |
*/ |
95 | 96 |
public void showEmptyPage(){ |
96 | 97 |
pageBook.showPage(emptySelectionLabel); |
97 | 98 |
} |
98 |
|
|
99 |
|
|
99 | 100 |
/** |
100 | 101 |
* <p>showViewer</p> |
101 | 102 |
* |
... | ... | |
103 | 104 |
* @param selection a {@link org.eclipse.jface.viewers.ISelection} object. |
104 | 105 |
*/ |
105 | 106 |
public void showViewer(IWorkbenchPart part, IStructuredSelection selection){ |
106 |
this.part = part;
|
|
107 |
|
|
107 |
this.part = part; |
|
108 |
|
|
108 | 109 |
Object element = selection.getFirstElement(); |
109 |
|
|
110 |
|
|
110 | 111 |
getViewer().setInput(element); |
111 |
|
|
112 |
|
|
112 | 113 |
showViewer(); |
113 | 114 |
} |
114 |
|
|
115 |
|
|
115 | 116 |
/** |
116 | 117 |
* <p>getViewer</p> |
117 | 118 |
* |
... | ... | |
125 | 126 |
public void showViewer(){ |
126 | 127 |
pageBook.showPage(viewerComposite); |
127 | 128 |
} |
128 |
|
|
129 |
|
|
129 | 130 |
public void setEnabled(boolean enabled){ |
130 | 131 |
pageBook.setEnabled(enabled); |
131 | 132 |
} |
132 |
|
|
133 |
|
|
133 | 134 |
/** {@inheritDoc} */ |
134 | 135 |
@Override |
135 | 136 |
public void setFocus() { |
136 | 137 |
if(getConversationHolder() != null){ |
137 | 138 |
getConversationHolder().bind(); |
138 |
}
|
|
139 |
getViewer().getControl().setFocus();
|
|
139 |
} |
|
140 |
getViewer().getControl().setFocus(); |
|
140 | 141 |
} |
141 |
|
|
142 |
|
|
142 | 143 |
/** |
143 | 144 |
* <p>createViewer</p> |
144 | 145 |
* |
145 | 146 |
* @param parent a {@link org.eclipse.swt.widgets.Composite} object. |
146 | 147 |
*/ |
147 | 148 |
public abstract void createViewer(Composite parent); |
148 |
|
|
149 |
|
|
149 | 150 |
/** {@inheritDoc} */ |
150 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
151 |
@Override |
|
152 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
151 | 153 |
changed(objectAffectedByOperation); |
152 | 154 |
return true; |
153 | 155 |
} |
154 |
|
|
156 |
|
|
155 | 157 |
/** {@inheritDoc} */ |
156 |
public abstract void changed(Object object); |
|
157 |
|
|
158 |
@Override |
|
159 |
public abstract void changed(Object object); |
|
160 |
|
|
158 | 161 |
/** |
159 | 162 |
* <p>getConversationHolder</p> |
160 | 163 |
* |
161 | 164 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
162 | 165 |
*/ |
163 |
public ConversationHolder getConversationHolder() { |
|
164 |
if(part != null) |
|
165 |
return ((IConversationEnabled) part).getConversationHolder(); |
|
166 |
|
|
166 |
@Override |
|
167 |
public ConversationHolder getConversationHolder() { |
|
168 |
if(part != null) { |
|
169 |
//FIXME what if part is not an IConversationEnabled? ClassCastException? |
|
170 |
return ((IConversationEnabled) part).getConversationHolder(); |
|
171 |
} |
|
172 |
|
|
167 | 173 |
return null; |
168 | 174 |
} |
169 |
|
|
175 |
|
|
170 | 176 |
/** {@inheritDoc} */ |
171 |
public void update(CdmDataChangeMap changeEvents) { |
|
172 |
|
|
177 |
@Override |
|
178 |
public void update(CdmDataChangeMap changeEvents) { |
|
179 |
|
|
173 | 180 |
} |
174 |
|
|
181 |
|
|
175 | 182 |
/** {@inheritDoc} */ |
176 | 183 |
@Override |
177 | 184 |
public void dispose() { |
Also available in: Unified diff
merged trunk into branch