Project

General

Profile

« Previous | Next » 

Revision 6fb20daf

Added by Niels Hoffmann over 12 years ago

Solving a problem where the datasource view would hang and thus render the whole editor unusable

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceViewPart.java
110 110
		@Override
111 111
		public IStatus run(final IProgressMonitor monitor) {
112 112
			try{
113
				monitor.beginTask("Retrieving datasources", dataSources.size());
113
				monitor.beginTask("Retrieving datasources", dataSources.size() + 1);
114 114
			
115 115
				List<ICdmDataSource> dataSources = CdmDataSourceRepository.getAll();
116 116
				
117 117
				final List<CdmMetaDataAwareDataSourceContainer> containers = new ArrayList<CdmMetaDataAwareDataSourceContainer>();
118 118
				
119 119
				for(ICdmDataSource dataSource : dataSources){
120
					containers.add(new CdmMetaDataAwareDataSourceContainer(dataSource, CdmDataSourceViewPart.this));
121
					monitor.worked(1);
120
					containers.add(new CdmMetaDataAwareDataSourceContainer(dataSource));
122 121
				}
123 122
				
124 123
				Display.getDefault().asyncExec(new Runnable() {
......
127 126
					public void run() {
128 127
						viewer.setInput(containers);
129 128
					}
130
				});				
131
//				viewer.setInput(containers);
129
				});
130
				monitor.worked(1);
131
				
132
				for(final CdmMetaDataAwareDataSourceContainer container : containers){
133
					
134
					container.getMetaDataFromDataSource();
135
					Display.getDefault().asyncExec(new Runnable() {
136
						
137
						@Override
138
						public void run() {
139
							viewer.update(container, null);
140
						}
141
					});
142
					monitor.worked(1);
143
				}
132 144
				
133 145
			}finally{
134 146
				monitor.done();
......
257 269
	 * <p>refresh</p>
258 270
	 */
259 271
	public void refresh(){		
260
		getService().schedule(new DataSourceJob("Loading datasources", CdmDataSourceRepository.getAll()), Job.SHORT);
272
		getService().schedule(new DataSourceJob("Loading datasources", CdmDataSourceRepository.getAll()), Job.LONG);
261 273
	}
262 274

  
263 275
	/** {@inheritDoc} */
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmMetaDataAwareDataSourceContainer.java
14 14
import java.util.HashMap;
15 15
import java.util.Map;
16 16

  
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.jface.viewers.StructuredViewer;
22
import org.eclipse.swt.widgets.Display;
23

  
24 17
import eu.etaxonomy.cdm.database.ICdmDataSource;
25 18
import eu.etaxonomy.cdm.model.common.CdmMetaData;
26 19
import eu.etaxonomy.cdm.model.common.CdmMetaData.MetaDataPropertyName;
......
35 28
 */
36 29
public class CdmMetaDataAwareDataSourceContainer {
37 30
	
38
	private class MetaDataJob extends Job{
39

  
40
		/**
41
		 * @param name
42
		 */
43
		public MetaDataJob(String dataSourceName) {
44
			super("Retrieving meta data for datasource: " + dataSourceName);
45
		}
46

  
47
		/* (non-Javadoc)
48
		 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
49
		 */
50
		@Override
51
		protected IStatus run(IProgressMonitor monitor) {
52
			if(!monitor.isCanceled()){
53
				try {
54
					running = dataSource.testConnection();
55
				} catch (Exception e) {
56
					running = false;
57
				}
58
			}
59
			
60
			if(!monitor.isCanceled()){
61
				getMetaDataFromDataSource(dataSource);
62
			}
63
			
64
			if(!monitor.isCanceled()){
65
				Display.getDefault().asyncExec(new Runnable(){
66 31
	
67
					@Override
68
					public void run() {
69
						viewer.update(CdmMetaDataAwareDataSourceContainer.this, null);
70
					}
71
					
72
				});
73
			}
74
			
75
			return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
76
		}
77
		
78
	}
79 32
	
80 33
	/** Constant <code>DEFAULT_ENTRY="-"</code> */
81 34
	public static final String DEFAULT_ENTRY = "-";
......
85 38
	private boolean running;
86 39
	
87 40
	private Map<MetaDataPropertyName, String> metaDataMap;
88

  
89
	private StructuredViewer viewer;
90

  
91
	private MetaDataJob job;
92 41
	
93 42
	/**
94 43
	 * <p>Constructor for CdmMetaDataAwareDataSourceContainer.</p>
......
96 45
	 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
97 46
	 * @param view a {@link eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart} object.
98 47
	 */
99
	public CdmMetaDataAwareDataSourceContainer(ICdmDataSource dataSource, CdmDataSourceViewPart view){
48
	public CdmMetaDataAwareDataSourceContainer(ICdmDataSource dataSource){
100 49
		this.dataSource = dataSource;
101
		this.viewer = view.getViewer();
102 50
		
103 51
		metaDataMap = getDefaultMetaDataMap();
104 52
		
105
		job = new MetaDataJob(dataSource.getName());
106
		job.setPriority(Job.DECORATE);
107
		view.getService().schedule(job);
108 53
	}
109 54

  
110 55
	/**
......
116 61
		return dataSource;
117 62
	}
118 63
	
119
	private void getMetaDataFromDataSource(ICdmDataSource dataSource){
64
	public void getMetaDataFromDataSource(){
65
		try {
66
			running = dataSource.testConnection();
67
		} catch (Exception e) {
68
			running = false;
69
		}
70
		
120 71
		try {
121 72
			if(isRunning()){
122 73
			
......
194 145
	public String toString() {
195 146
		return dataSource.getName();
196 147
	}
197
	
198
	/**
199
	 * <p>dispose</p>
200
	 */
201
	public void dispose(){
202
		job.cancel();
203
	}
204 148
}

Also available in: Unified diff