Project

General

Profile

Download (2.75 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.navigation.key.polytomous.e4.handler;
11

    
12
import java.util.List;
13

    
14
import javax.inject.Named;
15

    
16
import org.eclipse.core.commands.operations.IUndoContext;
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.e4.core.di.annotations.Execute;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23
import org.eclipse.e4.ui.services.IServiceConstants;
24
import org.eclipse.swt.widgets.Display;
25

    
26
import eu.etaxonomy.cdm.model.description.PolytomousKey;
27
import eu.etaxonomy.taxeditor.model.AbstractUtility;
28
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
29
import eu.etaxonomy.taxeditor.navigation.key.polytomous.e4.PolytomousKeyViewPartE4;
30
import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RefreshNodesOperation;
31
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
32
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33

    
34

    
35
/**
36
 * <p>RefreshPolytomousKeyNodesHandler class, which refreshes each key node in the polytomous key navigation view</p>
37
 *
38
 * @author c.mathew
39
 * @created Jan 17 2013
40
 * @version 1.0
41
 */
42
public class RefreshPolytomousKeyNodesHandlerE4 {
43

    
44
    private static final String REFRESHING_POLYTOMOUS_KEY_NODES = Messages.RefreshPolytomousKeyNodesHandler_REFRESHING;
45

    
46
    @Execute
47
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
48

    
49
        PolytomousKeyViewPartE4 view = (PolytomousKeyViewPartE4) activePart.getObject();
50

    
51
        final List<PolytomousKey> keys = view.getKeys();
52

    
53
		final String label = Messages.RefreshPolytomousKeyNodesHandler_REFRESH;
54

    
55
		final IUndoContext undoContext = NavigationUtil.getUndoContext();
56
		if (keys.size() > 0) {
57
			Job job = new Job(REFRESHING_POLYTOMOUS_KEY_NODES){
58

    
59
					@Override
60
					protected IStatus run(IProgressMonitor monitor) {
61
						monitor.beginTask(REFRESHING_POLYTOMOUS_KEY_NODES, keys.size());
62

    
63

    
64
							for (final PolytomousKey key : keys) {
65
								if(key.getRoot() != null) {
66

    
67
									Display.getDefault().asyncExec(new Runnable(){
68

    
69
										@Override
70
										public void run() {
71
											AbstractPostOperation operation = new RefreshNodesOperation(label, undoContext, key, view);
72
											AbstractUtility.executeOperation(operation);
73
										}
74

    
75
									});
76
									monitor.worked(1);
77
								}
78
							}
79
							monitor.done();
80
							return Status.OK_STATUS;
81
						}
82

    
83
					};
84

    
85
					job.setPriority(Job.SHORT);
86
					job.schedule();
87

    
88
				}
89
			}
90
		}
91

    
(3-3/6)