Revision 6c0e98ad
Added by Cherian Mathew over 9 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceViewPart.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 |
*/ |
... | ... | |
47 | 47 |
import org.eclipse.ui.handlers.IHandlerService; |
48 | 48 |
import org.eclipse.ui.part.ViewPart; |
49 | 49 |
import org.eclipse.ui.progress.IWorkbenchSiteProgressService; |
50 |
import org.springframework.security.core.GrantedAuthority; |
|
51 | 50 |
|
52 | 51 |
import eu.etaxonomy.cdm.config.ICdmSource; |
53 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
54 | 52 |
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; |
55 | 53 |
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter; |
56 | 54 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
... | ... | |
66 | 64 |
* @version 1.0 |
67 | 65 |
*/ |
68 | 66 |
public class CdmDataSourceViewPart extends ViewPart{ |
69 |
|
|
67 |
|
|
70 | 68 |
private static final Logger logger = Logger.getLogger(CdmDataSourceViewPart.class); |
71 |
|
|
69 |
|
|
72 | 70 |
private class ContextListener extends ContextListenerAdapter{ |
73 | 71 |
/* (non-Javadoc) |
74 | 72 |
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
... | ... | |
76 | 74 |
@Override |
77 | 75 |
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) { |
78 | 76 |
monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$ |
79 |
viewer.refresh();
|
|
77 |
viewer.refresh(); |
|
80 | 78 |
} |
81 | 79 |
|
82 | 80 |
/* (non-Javadoc) |
... | ... | |
85 | 83 |
@Override |
86 | 84 |
public void contextStop(IMemento memento, IProgressMonitor monitor) { |
87 | 85 |
monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$ |
88 |
viewer.refresh();
|
|
86 |
viewer.refresh(); |
|
89 | 87 |
} |
90 | 88 |
|
91 | 89 |
/* (non-Javadoc) |
... | ... | |
97 | 95 |
viewer.refresh(); |
98 | 96 |
} |
99 | 97 |
} |
100 |
|
|
98 |
|
|
101 | 99 |
private class DataSourceJob extends Job{ |
102 | 100 |
|
103 |
private List<ICdmSource> cdmSources; |
|
101 |
private final List<ICdmSource> cdmSources;
|
|
104 | 102 |
|
105 | 103 |
/** |
106 | 104 |
* @param name |
... | ... | |
118 | 116 |
try{ |
119 | 117 |
logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$ |
120 | 118 |
monitor.beginTask("Retrieving datasources", cdmSources.size() + 1); //$NON-NLS-1$ |
121 |
|
|
119 |
|
|
122 | 120 |
final List<CdmMetaDataAwareDataSourceContainer> containers = new ArrayList<CdmMetaDataAwareDataSourceContainer>(); |
123 |
|
|
121 |
|
|
124 | 122 |
for(ICdmSource cdmSource : cdmSources){ |
125 | 123 |
containers.add(new CdmMetaDataAwareDataSourceContainer(cdmSource)); |
126 | 124 |
} |
127 |
|
|
125 |
|
|
128 | 126 |
Display.getDefault().asyncExec(new Runnable() { |
129 |
|
|
127 |
|
|
130 | 128 |
@Override |
131 | 129 |
public void run() { |
132 | 130 |
viewer.setInput(containers); |
133 | 131 |
} |
134 | 132 |
}); |
135 | 133 |
monitor.worked(1); |
136 |
|
|
134 |
|
|
137 | 135 |
for(final CdmMetaDataAwareDataSourceContainer container : containers){ |
138 |
|
|
139 |
|
|
140 |
if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " : next DataSourceContainer"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
136 |
if(logger.isDebugEnabled()) { |
|
137 |
logger.debug(" #" + container.hashCode() + " : next DataSourceContainer"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
138 |
}
|
|
141 | 139 |
container.getMetaDataFromDataSource(); |
142 |
if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " : metadata retrieved, creating new runnable ..."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
140 |
if(logger.isDebugEnabled()) |
|
141 |
{ |
|
142 |
logger.debug(" #" + container.hashCode() + " : metadata retrieved, creating new runnable ..."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
143 |
} |
|
143 | 144 |
Display.getDefault().asyncExec(new Runnable() { |
144 |
|
|
145 |
|
|
145 | 146 |
@Override |
146 | 147 |
public void run() { |
147 |
if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " starting sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
148 |
if(logger.isDebugEnabled()) |
|
149 |
{ |
|
150 |
logger.debug(" #" + container.hashCode() + " starting sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
151 |
} |
|
148 | 152 |
viewer.update(container, null); |
149 |
if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " end of sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
153 |
if(logger.isDebugEnabled()) |
|
154 |
{ |
|
155 |
logger.debug(" #" + container.hashCode() + " end of sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
156 |
} |
|
150 | 157 |
} |
151 | 158 |
}); |
152 |
if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " done"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
159 |
if(logger.isDebugEnabled()) |
|
160 |
{ |
|
161 |
logger.debug(" #" + container.hashCode() + " done"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
162 |
} |
|
153 | 163 |
monitor.worked(1); |
154 | 164 |
} |
155 |
|
|
165 |
|
|
156 | 166 |
}finally{ |
157 | 167 |
monitor.done(); |
158 | 168 |
} |
159 | 169 |
return Status.OK_STATUS; |
160 | 170 |
} |
161 | 171 |
} |
162 |
|
|
172 |
|
|
163 | 173 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code> */ |
164 | 174 |
public static String ID = "eu.etaxonomy.taxeditor.view.datasource"; //$NON-NLS-1$ |
165 |
|
|
175 |
|
|
166 | 176 |
private TableViewer viewer; |
167 | 177 |
|
168 | 178 |
private String partNameCache; |
169 | 179 |
|
170 | 180 |
private IWorkbenchSiteProgressService service; |
171 |
|
|
181 |
|
|
172 | 182 |
private IContextListener contextListener; |
173 | 183 |
|
174 | 184 |
private CdmDataSourceViewerComparator comparator; |
175 |
|
|
185 |
|
|
176 | 186 |
/** |
177 | 187 |
* <p>Constructor for CdmDataSourceViewPart.</p> |
178 | 188 |
*/ |
179 | 189 |
public CdmDataSourceViewPart(){ |
180 | 190 |
} |
181 |
|
|
191 |
|
|
182 | 192 |
/** {@inheritDoc} */ |
183 | 193 |
@Override |
184 | 194 |
public void createPartControl(Composite parent) { |
185 | 195 |
service = (IWorkbenchSiteProgressService) getSite().getAdapter(IWorkbenchSiteProgressService.class); |
186 | 196 |
contextListener = new ContextListener(); |
187 | 197 |
CdmStore.getContextManager().addContextListener(contextListener); |
188 |
|
|
198 |
|
|
189 | 199 |
// Create top composite |
190 | 200 |
FillLayout fillLayout = new FillLayout(); |
191 | 201 |
fillLayout.marginWidth = 0; |
192 | 202 |
fillLayout.marginHeight = 0; |
193 |
fillLayout.type = SWT.VERTICAL;
|
|
203 |
fillLayout.type = SWT.VERTICAL; |
|
194 | 204 |
parent.setLayout(fillLayout); |
195 |
|
|
205 |
|
|
196 | 206 |
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
197 | 207 |
| SWT.V_SCROLL | SWT.FULL_SELECTION); |
198 | 208 |
getSite().setSelectionProvider(viewer); |
199 |
|
|
209 |
|
|
200 | 210 |
createColumns(viewer); |
201 |
|
|
211 |
|
|
202 | 212 |
viewer.setContentProvider(new CdmDataSourceContentProvider()); |
203 | 213 |
viewer.setLabelProvider(new CdmDataSourceLabelProvider()); |
204 | 214 |
comparator = new CdmDataSourceViewerComparator(); |
205 | 215 |
viewer.setComparator(comparator); |
206 |
|
|
207 |
|
|
216 |
|
|
217 |
|
|
208 | 218 |
// register context menu |
209 | 219 |
MenuManager menuMgr = new MenuManager(); |
210 | 220 |
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
... | ... | |
212 | 222 |
|
213 | 223 |
Control control = viewer.getControl(); |
214 | 224 |
Menu menu = menuMgr.createContextMenu(control); |
215 |
control.setMenu(menu);
|
|
216 |
|
|
225 |
control.setMenu(menu); |
|
226 |
|
|
217 | 227 |
// connect on doubleclick |
218 | 228 |
viewer.addDoubleClickListener(new IDoubleClickListener() { |
219 | 229 |
|
220 |
public void doubleClick(DoubleClickEvent event) { |
|
230 |
@Override |
|
231 |
public void doubleClick(DoubleClickEvent event) { |
|
221 | 232 |
if (event.getSelection() instanceof StructuredSelection) { |
222 |
|
|
233 |
|
|
223 | 234 |
Object element = ((StructuredSelection) event |
224 | 235 |
.getSelection()).getFirstElement(); |
225 | 236 |
if (element instanceof CdmMetaDataAwareDataSourceContainer) { |
226 | 237 |
String commandId = "eu.etaxonomy.taxeditor.store.datasource.change"; //$NON-NLS-1$ |
227 |
|
|
238 |
|
|
228 | 239 |
ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class); |
229 |
|
|
230 |
Command command = commandService.getCommand(commandId);
|
|
240 |
|
|
241 |
Command command = commandService.getCommand(commandId); |
|
231 | 242 |
if(command.isEnabled()) { |
232 |
|
|
243 |
|
|
233 | 244 |
IHandlerService handlerService = (IHandlerService) StoreUtil.getService(IHandlerService.class); |
234 |
|
|
245 |
|
|
235 | 246 |
try { |
236 | 247 |
handlerService.executeCommand(commandId, null); |
237 | 248 |
} catch (ExecutionException e) { |
... | ... | |
248 | 259 |
} |
249 | 260 |
} |
250 | 261 |
}); |
251 |
|
|
262 |
|
|
252 | 263 |
refresh(); |
253 | 264 |
} |
254 | 265 |
|
255 |
|
|
266 |
|
|
256 | 267 |
// This will create the columns for the table |
257 | 268 |
private void createColumns(TableViewer viewer) { |
258 | 269 |
Table table = viewer.getTable(); |
... | ... | |
273 | 284 |
table.setHeaderVisible(true); |
274 | 285 |
table.setLinesVisible(true); |
275 | 286 |
table.setSortDirection(SWT.UP); |
276 |
|
|
287 |
|
|
277 | 288 |
} |
278 |
|
|
289 |
|
|
279 | 290 |
/** |
280 | 291 |
* <p>refresh</p> |
281 | 292 |
*/ |
282 |
public void refresh(){
|
|
293 |
public void refresh(){ |
|
283 | 294 |
getService().schedule(new DataSourceJob(Messages.CdmDataSourceViewPart_1, CdmDataSourceRepository.getAll()), Job.LONG); |
284 | 295 |
} |
285 | 296 |
|
... | ... | |
296 | 307 |
viewer.getControl().setFocus(); |
297 | 308 |
} |
298 | 309 |
|
299 |
|
|
310 |
|
|
300 | 311 |
/* (non-Javadoc) |
301 | 312 |
* @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean) |
302 | 313 |
*/ |
... | ... | |
332 | 343 |
public IWorkbenchSiteProgressService getService() { |
333 | 344 |
return service; |
334 | 345 |
} |
335 |
|
|
346 |
|
|
336 | 347 |
private SelectionAdapter getSelectionAdapter(final TableColumn column, |
337 | 348 |
final int index) { |
338 | 349 |
SelectionAdapter selectionAdapter = new SelectionAdapter() { |
Also available in: Unified diff
eclipse preference changes