// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
-import org.springframework.security.core.GrantedAuthority;
import eu.etaxonomy.cdm.config.ICdmSource;
-import eu.etaxonomy.cdm.database.ICdmDataSource;
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
import eu.etaxonomy.taxeditor.model.IContextListener;
* @version 1.0
*/
public class CdmDataSourceViewPart extends ViewPart{
-
+
private static final Logger logger = Logger.getLogger(CdmDataSourceViewPart.class);
-
+
private class ContextListener extends ContextListenerAdapter{
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
@Override
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$
- viewer.refresh();
+ viewer.refresh();
}
/* (non-Javadoc)
@Override
public void contextStop(IMemento memento, IProgressMonitor monitor) {
monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$
- viewer.refresh();
+ viewer.refresh();
}
/* (non-Javadoc)
viewer.refresh();
}
}
-
+
private class DataSourceJob extends Job{
- private List<ICdmSource> cdmSources;
+ private final List<ICdmSource> cdmSources;
/**
* @param name
try{
logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
monitor.beginTask("Retrieving datasources", cdmSources.size() + 1); //$NON-NLS-1$
-
+
final List<CdmMetaDataAwareDataSourceContainer> containers = new ArrayList<CdmMetaDataAwareDataSourceContainer>();
-
+
for(ICdmSource cdmSource : cdmSources){
containers.add(new CdmMetaDataAwareDataSourceContainer(cdmSource));
}
-
+
Display.getDefault().asyncExec(new Runnable() {
-
+
@Override
public void run() {
viewer.setInput(containers);
}
});
monitor.worked(1);
-
+
for(final CdmMetaDataAwareDataSourceContainer container : containers){
-
-
- if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " : next DataSourceContainer"); //$NON-NLS-1$ //$NON-NLS-2$
+ if(logger.isDebugEnabled()) {
+ logger.debug(" #" + container.hashCode() + " : next DataSourceContainer"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
container.getMetaDataFromDataSource();
- if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " : metadata retrieved, creating new runnable ..."); //$NON-NLS-1$ //$NON-NLS-2$
+ if(logger.isDebugEnabled())
+ {
+ logger.debug(" #" + container.hashCode() + " : metadata retrieved, creating new runnable ..."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
Display.getDefault().asyncExec(new Runnable() {
-
+
@Override
public void run() {
- if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " starting sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$
+ if(logger.isDebugEnabled())
+ {
+ logger.debug(" #" + container.hashCode() + " starting sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
viewer.update(container, null);
- if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " end of sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$
+ if(logger.isDebugEnabled())
+ {
+ logger.debug(" #" + container.hashCode() + " end of sub thread to update ..."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
});
- if(logger.isDebugEnabled()) logger.debug(" #" + container.hashCode() + " done"); //$NON-NLS-1$ //$NON-NLS-2$
+ if(logger.isDebugEnabled())
+ {
+ logger.debug(" #" + container.hashCode() + " done"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
monitor.worked(1);
}
-
+
}finally{
monitor.done();
}
return Status.OK_STATUS;
}
}
-
+
/** Constant <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code> */
public static String ID = "eu.etaxonomy.taxeditor.view.datasource"; //$NON-NLS-1$
-
+
private TableViewer viewer;
private String partNameCache;
private IWorkbenchSiteProgressService service;
-
+
private IContextListener contextListener;
private CdmDataSourceViewerComparator comparator;
-
+
/**
* <p>Constructor for CdmDataSourceViewPart.</p>
*/
public CdmDataSourceViewPart(){
}
-
+
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
service = (IWorkbenchSiteProgressService) getSite().getAdapter(IWorkbenchSiteProgressService.class);
contextListener = new ContextListener();
CdmStore.getContextManager().addContextListener(contextListener);
-
+
// Create top composite
FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = 0;
fillLayout.marginHeight = 0;
- fillLayout.type = SWT.VERTICAL;
+ fillLayout.type = SWT.VERTICAL;
parent.setLayout(fillLayout);
-
+
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION);
getSite().setSelectionProvider(viewer);
-
+
createColumns(viewer);
-
+
viewer.setContentProvider(new CdmDataSourceContentProvider());
viewer.setLabelProvider(new CdmDataSourceLabelProvider());
comparator = new CdmDataSourceViewerComparator();
viewer.setComparator(comparator);
-
-
+
+
// register context menu
MenuManager menuMgr = new MenuManager();
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
Control control = viewer.getControl();
Menu menu = menuMgr.createContextMenu(control);
- control.setMenu(menu);
-
+ control.setMenu(menu);
+
// connect on doubleclick
viewer.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
if (event.getSelection() instanceof StructuredSelection) {
-
+
Object element = ((StructuredSelection) event
.getSelection()).getFirstElement();
if (element instanceof CdmMetaDataAwareDataSourceContainer) {
String commandId = "eu.etaxonomy.taxeditor.store.datasource.change"; //$NON-NLS-1$
-
+
ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class);
-
- Command command = commandService.getCommand(commandId);
+
+ Command command = commandService.getCommand(commandId);
if(command.isEnabled()) {
-
+
IHandlerService handlerService = (IHandlerService) StoreUtil.getService(IHandlerService.class);
-
+
try {
handlerService.executeCommand(commandId, null);
} catch (ExecutionException e) {
}
}
});
-
+
refresh();
}
-
+
// This will create the columns for the table
private void createColumns(TableViewer viewer) {
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setSortDirection(SWT.UP);
-
+
}
-
+
/**
* <p>refresh</p>
*/
- public void refresh(){
+ public void refresh(){
getService().schedule(new DataSourceJob(Messages.CdmDataSourceViewPart_1, CdmDataSourceRepository.getAll()), Job.LONG);
}
viewer.getControl().setFocus();
}
-
+
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
*/
public IWorkbenchSiteProgressService getService() {
return service;
}
-
+
private SelectionAdapter getSelectionAdapter(final TableColumn column,
final int index) {
SelectionAdapter selectionAdapter = new SelectionAdapter() {