Project

General

Profile

Download (3.87 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
10

    
11
import java.util.UUID;
12

    
13
import org.apache.log4j.Logger;
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.ui.progress.IProgressConstants;
22

    
23
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
24
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
25
import eu.etaxonomy.cdm.api.service.UpdateResult;
26
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
27
import eu.etaxonomy.cdm.io.common.SetSecundumForSubtreeConfigurator;
28
import eu.etaxonomy.cdm.io.service.IIOService;
29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
30
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
31
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
32
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
33

    
34
/**
35
 * @author k.luther
36
 * @date 10.02.2017
37
 *
38
 */
39
public class SetSecundumForSubtreeOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled{
40

    
41
    private final static String LABEL = Messages.SetSecundumForSubtreeOperation_CHANGE_SEC_OP;
42
    private static final Logger logger = Logger
43
            .getLogger(SetSecundumForSubtreeOperation.class);
44
    UUID parentUuid;
45
    SetSecundumForSubtreeConfigurator config;
46
    UpdateResult updateResult = new UpdateResult();
47

    
48
    /**
49
     * @param label
50
     * @param action
51
     * @param source
52
     * @param async
53
     */
54
    public SetSecundumForSubtreeOperation(Object source,
55
            boolean async,
56
            UUID taxonNodeUuid,
57
            SetSecundumForSubtreeConfigurator config) {
58
        super(LABEL, Action.Update, source, async);
59
        parentUuid = taxonNodeUuid;
60
        this.config = config;
61
    }
62

    
63
    /**
64
     * {@inheritDoc}
65
     */
66
    @Override
67
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
68
        Job job = createJob(monitor);
69
        // configure the job
70
        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
71
        job.setUser(true);
72
        // schedule job
73
        job.schedule();
74

    
75
        return updateResult;
76

    
77

    
78
    }
79

    
80

    
81
    private Job createJob(IProgressMonitor monitor){
82
        Assert.isNotNull(config, "Configuration may not be null");
83

    
84
        final Display display = Display.getDefault();
85

    
86
        Job job = new Job(Messages.SetSecundumForSubtreeOperation_SET_SEC_TASK) {
87

    
88

    
89
            @Override
90
            protected IStatus run(IProgressMonitor monitor) {
91
                                  IIOService ioService = CdmApplicationState.getIOService();
92
                   final UUID uuid = ioService.monitUpdateData(config);
93
                   Display.getDefault().asyncExec(new Runnable() {
94
                       @Override
95
                       public void run() {
96
                           AbstractUtility.executeMoniteredOperation("Update: " + config.getClass().getSimpleName(),
97
                                   uuid,
98
                                   1000,
99
                                   false,
100
                                   SetSecundumForSubtreeOperation.this,
101
                                   null);
102
                       }
103
                   });
104
                   return Status.OK_STATUS;
105

    
106
            }
107
        };
108
            return job;
109
        }
110

    
111

    
112

    
113

    
114

    
115
    /**
116
     * {@inheritDoc}
117
     */
118
    @Override
119
    public void postOperation(IRemotingProgressMonitor monitor) {
120
        // TODO Auto-generated method stub
121

    
122
    }
123
 }
(10-10/10)