Revision 12f992a2
Added by Patrick Plitzner almost 8 years ago
- added null check (fixes #4351)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java | ||
---|---|---|
1 | 1 |
/** |
2 |
*
|
|
2 |
* |
|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.taxeditor.navigation.key.polytomous; |
5 | 5 |
|
... | ... | |
14 | 14 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
15 | 15 |
import org.eclipse.jface.viewers.ISelection; |
16 | 16 |
import org.eclipse.jface.viewers.ListViewer; |
17 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
18 | 17 |
import org.eclipse.jface.viewers.Viewer; |
19 | 18 |
import org.eclipse.jface.viewers.ViewerFilter; |
20 | 19 |
import org.eclipse.swt.SWT; |
... | ... | |
63 | 62 |
@Override |
64 | 63 |
public boolean select(Viewer viewer, Object parentElement, |
65 | 64 |
Object element) { |
66 |
|
|
65 |
|
|
67 | 66 |
if(element instanceof PolytomousKey){ |
68 | 67 |
PolytomousKey key = (PolytomousKey) element; |
69 | 68 |
if(key.getTitleCache().contains(text_filter.getText())){ |
70 | 69 |
return true; |
71 | 70 |
} |
72 | 71 |
} |
73 |
|
|
72 |
|
|
74 | 73 |
return false; |
75 | 74 |
} |
76 |
|
|
75 |
|
|
77 | 76 |
}; |
78 |
|
|
77 |
|
|
79 | 78 |
viewer.setFilters(new ViewerFilter[]{filter}); |
80 | 79 |
} |
81 | 80 |
} |
82 |
|
|
83 |
|
|
81 |
|
|
82 |
|
|
84 | 83 |
public static final String ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.polytomousKeyViewPart"; |
85 | 84 |
|
86 | 85 |
public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.editNodes"; |
87 |
|
|
86 |
|
|
88 | 87 |
private class ContextListener extends ContextListenerAdapter{ |
89 | 88 |
/* (non-Javadoc) |
90 | 89 |
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
... | ... | |
94 | 93 |
monitor.subTask("Shutting down Polytomous Key Viewer"); |
95 | 94 |
viewer.setInput(null); |
96 | 95 |
} |
97 |
|
|
96 |
|
|
98 | 97 |
/* (non-Javadoc) |
99 | 98 |
* @see eu.etaxonomy.taxeditor.model.ContextListenerAdapter#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
100 | 99 |
*/ |
... | ... | |
104 | 103 |
setInput(); |
105 | 104 |
} |
106 | 105 |
} |
107 |
|
|
106 |
|
|
108 | 107 |
private ListViewer viewer; |
109 | 108 |
private ConversationHolder conversation; |
110 | 109 |
private IContextListener contextListener; |
... | ... | |
116 | 115 |
public PolytomousKeyViewPart(){ |
117 | 116 |
formFactory = new CdmFormFactory(Display.getDefault()); |
118 | 117 |
} |
119 |
|
|
118 |
|
|
120 | 119 |
/* (non-Javadoc) |
121 | 120 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
122 | 121 |
*/ |
... | ... | |
125 | 124 |
|
126 | 125 |
Composite container = new Composite(parent, SWT.NONE); |
127 | 126 |
container.setLayout(new GridLayout()); |
128 |
|
|
127 |
|
|
129 | 128 |
contextListener = new ContextListener(); |
130 | 129 |
CdmStore.getContextManager().addContextListener(contextListener); |
131 |
|
|
130 |
|
|
132 | 131 |
text_filter = formFactory.createText(container, ""); |
133 | 132 |
text_filter.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); |
134 | 133 |
text_filter.addModifyListener(new FilterModifyListener()); |
135 |
|
|
134 |
|
|
136 | 135 |
viewer = new ListViewer(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); |
137 | 136 |
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
138 |
|
|
137 |
|
|
139 | 138 |
viewer.setContentProvider(new PolytomousKeyContentProvider()); |
140 | 139 |
viewer.setLabelProvider(new PolytomousKeyLabelProvider()); |
141 |
|
|
140 |
|
|
142 | 141 |
viewer.addDoubleClickListener(new IDoubleClickListener() { |
143 |
|
|
142 |
|
|
144 | 143 |
@Override |
145 |
public void doubleClick(DoubleClickEvent event) {
|
|
144 |
public void doubleClick(DoubleClickEvent event) { |
|
146 | 145 |
openSelectedKeyNodes(); |
147 | 146 |
} |
148 | 147 |
}); |
149 |
|
|
150 |
|
|
148 |
|
|
149 |
|
|
151 | 150 |
getSite().setSelectionProvider(viewer); |
152 |
|
|
151 |
|
|
153 | 152 |
createMenu(); |
154 |
|
|
153 |
|
|
155 | 154 |
if(CdmStore.isActive()){ |
156 | 155 |
setInput(); |
157 | 156 |
} |
158 | 157 |
} |
159 |
|
|
158 |
|
|
160 | 159 |
public void openSelectedKeyNodes() { |
161 | 160 |
ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class); |
162 |
|
|
163 |
Command command = commandService.getCommand(OPEN_COMMAND_ID);
|
|
161 |
|
|
162 |
Command command = commandService.getCommand(OPEN_COMMAND_ID); |
|
164 | 163 |
if(command.isEnabled()) { |
165 | 164 |
IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class); |
166 |
try {
|
|
167 |
handlerService.executeCommand(OPEN_COMMAND_ID, null);
|
|
165 |
try { |
|
166 |
handlerService.executeCommand(OPEN_COMMAND_ID, null); |
|
168 | 167 |
} catch (NotDefinedException e) { |
169 | 168 |
throw new RuntimeException("Could not find open command: " + OPEN_COMMAND_ID); |
170 | 169 |
} catch (Exception e) { |
... | ... | |
172 | 171 |
} |
173 | 172 |
} |
174 | 173 |
} |
175 |
|
|
176 |
public void setViewerSelection(ISelection selection, boolean reveal) {
|
|
177 |
getSite().setSelectionProvider(viewer);
|
|
178 |
viewer.setSelection(selection,reveal);
|
|
179 |
viewer.getList().notifyListeners(SWT.Selection,new Event());
|
|
174 |
|
|
175 |
public void setViewerSelection(ISelection selection, boolean reveal) { |
|
176 |
getSite().setSelectionProvider(viewer); |
|
177 |
viewer.setSelection(selection,reveal); |
|
178 |
viewer.getList().notifyListeners(SWT.Selection,new Event()); |
|
180 | 179 |
} |
181 |
|
|
180 |
|
|
182 | 181 |
private void createMenu(){ |
183 | 182 |
MenuManager menuManager = new MenuManager(); |
184 | 183 |
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
185 |
|
|
184 |
|
|
186 | 185 |
getSite().registerContextMenu(menuManager, viewer); |
187 |
|
|
186 |
|
|
188 | 187 |
Control control = viewer.getControl(); |
189 | 188 |
Menu menu = menuManager.createContextMenu(control); |
190 |
|
|
191 |
control.setMenu(menu);
|
|
189 |
|
|
190 |
control.setMenu(menu); |
|
192 | 191 |
} |
193 | 192 |
|
194 | 193 |
private void setInput() { |
195 | 194 |
conversation = CdmStore.createConversation(); |
196 | 195 |
conversation.registerForDataStoreChanges(this); |
197 |
List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);
|
|
196 |
List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null); |
|
198 | 197 |
viewer.setInput(input); |
199 | 198 |
} |
200 | 199 |
|
... | ... | |
205 | 204 |
public void setFocus() { |
206 | 205 |
viewer.getControl().setFocus(); |
207 | 206 |
} |
208 |
|
|
207 |
|
|
209 | 208 |
/* (non-Javadoc) |
210 | 209 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
211 | 210 |
*/ |
... | ... | |
225 | 224 |
public ConversationHolder getConversationHolder() { |
226 | 225 |
return conversation; |
227 | 226 |
} |
228 |
|
|
227 |
|
|
229 | 228 |
/* (non-Javadoc) |
230 | 229 |
* @see org.eclipse.ui.part.WorkbenchPart#dispose() |
231 | 230 |
*/ |
232 | 231 |
@Override |
233 | 232 |
public void dispose() { |
234 |
conversation.unregisterForDataStoreChanges(this); |
|
235 |
conversation.close(); |
|
236 |
CdmStore.getContextManager().removeContextListener(contextListener); |
|
233 |
if(conversation!=null){ |
|
234 |
conversation.unregisterForDataStoreChanges(this); |
|
235 |
conversation.close(); |
|
236 |
CdmStore.getContextManager().removeContextListener(contextListener); |
|
237 |
} |
|
237 | 238 |
super.dispose(); |
238 | 239 |
} |
239 | 240 |
|
... | ... | |
255 | 256 |
} |
256 | 257 |
|
257 | 258 |
/** |
258 |
*
|
|
259 |
* |
|
259 | 260 |
*/ |
260 | 261 |
public void refresh() { |
261 | 262 |
getConversationHolder().bind(); |
262 | 263 |
//FIXME : Need to make sure this is a stable fix (ticket 3822) |
263 | 264 |
getConversationHolder().commit(); |
264 |
List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);
|
|
265 |
List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null); |
|
265 | 266 |
viewer.setInput(input); |
266 | 267 |
} |
267 |
|
|
268 |
|
|
268 | 269 |
public List<PolytomousKey> getKeys() { |
269 | 270 |
return (List<PolytomousKey>)viewer.getInput(); |
270 | 271 |
} |
Also available in: Unified diff