Project

General

Profile

Download (2.18 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.validation;
2

    
3
import java.util.List;
4

    
5
import org.apache.log4j.Logger;
6
import org.eclipse.core.runtime.IProgressMonitor;
7
import org.eclipse.core.runtime.IStatus;
8
import org.eclipse.core.runtime.Status;
9
import org.eclipse.core.runtime.jobs.Job;
10

    
11
import eu.etaxonomy.cdm.api.service.IEntityValidationService;
12
import eu.etaxonomy.cdm.model.validation.EntityValidation;
13
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
14
import eu.etaxonomy.taxeditor.model.MessagingUtils;
15
import eu.etaxonomy.taxeditor.store.CdmStore;
16

    
17
/**
18
 * A job that repeatedly checks the error tables and refreshes the problem
19
 * markers created from them.
20
 *
21
 * @author ayco_holleman
22
 *
23
 */
24
public class ValidationDaemon extends Job {
25
	@SuppressWarnings("unused")
26
	private static final Logger logger = Logger.getLogger(ValidationDaemon.class);
27

    
28
	private final IEntityValidationService entityValidationService;
29

    
30
	// Might want to make this configurable:
31
	private int SLEEP_TIME = 5000;
32
	
33
	private boolean cancelRequested = false;
34

    
35

    
36

    
37
	public ValidationDaemon(){
38
		super(Messages.ValidationDaemon_RUNNING_DAEMON);
39
		entityValidationService = CdmStore.getService(IEntityValidationService.class);
40
	}
41

    
42

    
43
	@Override
44
	protected void canceling(){
45
		cancelRequested = true;
46
	}
47

    
48

    
49
	/**
50
	 * This method is called by {@link ValidationContextListener} rather than
51
	 * {@link Job#cancel()}, because that method does not have the desired
52
	 * effect.
53
	 */
54
	public void setCancelRequested(){
55
		cancelRequested = true;
56
	}
57

    
58

    
59
	@Override
60
	protected IStatus run(IProgressMonitor monitor){
61
		MarkerManager markerManager;
62
		List<EntityValidation> results;
63
		try {
64
			while (!cancelRequested) {
65
				results = entityValidationService.getValidationResults();
66
				markerManager = new MarkerManager(results);
67
				markerManager.deleteObsoleteMarkers();
68
				markerManager.createMarkers();
69
				Thread.sleep(SLEEP_TIME);
70
			}
71
			MessagingUtils.info(Messages.ValidationDaemon_VALIDATION_STOPPED);
72
			return Status.OK_STATUS;
73
		}
74
		catch (Throwable t) {
75
			MessagingUtils.info(Messages.ValidationDaemon_VALIDATION_EXCEPTION + t.getMessage());
76
			return Status.CANCEL_STATUS;
77
		}
78
	}
79

    
80
}
(3-3/3)