Project

General

Profile

« Previous | Next » 

Revision 5d3fd02f

Added by Patrick Plitzner over 7 years ago

ref #4867 Implement "Clone Classification" functionality

  • availabel via context menu in taxon navigator
  • parameters available: classification name, taxon relation from cloned taxa to original taxa
  • sec reference

View differences:

eu.etaxonomy.taxeditor.navigation/plugin.xml
150 150
               </and>
151 151
            </visibleWhen>
152 152
         </command>
153
         <command
154
               commandId="eu.etaxonomy.taxeditor.navigation.cloneClassification"
155
               label="Clone Classification"
156
               style="push">
157
            <visibleWhen
158
                  checkEnabled="true">
159
               <and>
160
                  <reference
161
                        definitionId="isShowExperimentalFeatures">
162
                  </reference>
163
                  <reference
164
                        definitionId="isClassification">
165
                  </reference>
166
               </and>
167
            </visibleWhen>
168
         </command>
153 169
         <separator
154 170
               name="taxeditor-navigation.separator1"
155 171
               visible="true">
......
451 467
            id="eu.etaxonomy.taxeditor.navigation.key.polytomous.command.delete"
452 468
            name="%command.name.11">
453 469
      </command>
470
      <command
471
            defaultHandler="eu.etaxonomy.taxeditor.navigation.navigator.handler.CloneClassificationHandler"
472
            id="eu.etaxonomy.taxeditor.navigation.cloneClassification"
473
            name="Clone Classification">
474
      </command>
454 475
   </extension>
455 476
   <extension
456 477
         point="org.eclipse.ui.handlers">
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CloneClassificationHandler.java
1
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
2

  
3
import org.apache.log4j.Logger;
4
import org.eclipse.core.commands.AbstractHandler;
5
import org.eclipse.core.commands.ExecutionEvent;
6
import org.eclipse.core.commands.ExecutionException;
7
import org.eclipse.jface.viewers.ISelection;
8
import org.eclipse.jface.viewers.IStructuredSelection;
9
import org.eclipse.jface.wizard.WizardDialog;
10
import org.eclipse.swt.widgets.Display;
11
import org.eclipse.ui.handlers.HandlerUtil;
12

  
13
import eu.etaxonomy.cdm.model.reference.Reference;
14
import eu.etaxonomy.cdm.model.taxon.Classification;
15
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
16
import eu.etaxonomy.taxeditor.model.AbstractUtility;
17
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
18
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
19
import eu.etaxonomy.taxeditor.navigation.operation.CloneClassificationOperation;
20
import eu.etaxonomy.taxeditor.store.StoreUtil;
21
import eu.etaxonomy.taxeditor.ui.section.classification.CloneClassificationWizard;
22

  
23
public class CloneClassificationHandler extends AbstractHandler {
24

  
25
    @SuppressWarnings("unused")
26
    private static final Logger logger = Logger.getLogger(CloneClassificationHandler.class);
27

  
28
    @Override
29
    public Object execute(ExecutionEvent event) throws ExecutionException {
30
        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
31
        if (currentSelection instanceof IStructuredSelection) {
32
            Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
33
            if (selectedElement instanceof Classification) {
34
                Classification classification = (Classification) selectedElement;
35
                TaxonNavigator taxonNavigator = (TaxonNavigator)AbstractUtility.showView(TaxonNavigator.ID);
36
                CloneClassificationWizard wizard = new CloneClassificationWizard(classification);
37
                WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
38
                dialog.open();
39

  
40
                String classificationName = wizard.getClassificationName();
41
                TaxonRelationshipType relationType = wizard.getRelationType();
42
                Reference reference = wizard.getReference();
43

  
44
                CloneClassificationOperation operation = new CloneClassificationOperation("Clone classification",
45
                        StoreUtil.getUndoContext(), classification, classificationName, reference, relationType,
46
                        NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
47

  
48
                AbstractUtility.executeOperation(operation);
49
                taxonNavigator.refresh();
50
            }
51
        }
52
        return null;
53
    }
54

  
55
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CloneClassificationOperation.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.operation;
11

  
12
import org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17

  
18
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19
import eu.etaxonomy.cdm.api.service.IClassificationService;
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21
import eu.etaxonomy.cdm.model.reference.Reference;
22
import eu.etaxonomy.cdm.model.taxon.Classification;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
25
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

  
28
/**
29
 *
30
 * @author pplitzner
31
 *
32
 */
33
public class CloneClassificationOperation extends AbstractPersistentPostOperation {
34

  
35
    private final Classification classification;
36

  
37
    private final IClassificationService service;
38

  
39
    private String classificationName;
40

  
41
    private Reference sec;
42

  
43
    private TaxonRelationshipType relationType;
44

  
45
    public CloneClassificationOperation(String label, IUndoContext undoContext, Classification classification,
46
            String classificationName, Reference sec, TaxonRelationshipType relationType,
47
            IPostOperationEnabled postOperationEnabled,
48
            IConversationEnabled conversationEnabled) {
49
        super(label, undoContext, postOperationEnabled, conversationEnabled);
50

  
51
        this.classification = classification;
52
        this.classificationName = classificationName;
53
        this.sec = sec;
54
        this.relationType = relationType;
55
        this.service = CdmStore.getService(IClassificationService.class);
56

  
57
    }
58

  
59
    @Override
60
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
61

  
62
        UpdateResult result = service.cloneClassification(classification.getUuid(), classificationName, sec, relationType);
63
        return postExecute(result.getCdmEntity());
64
    }
65

  
66
    @Override
67
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
68
        return null;
69
    }
70

  
71
    @Override
72
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
73
        return null;
74
    }
75

  
76
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/CloneClassificationDetailElement.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.ui.dialog;
11

  
12
import eu.etaxonomy.cdm.model.common.TermType;
13
import eu.etaxonomy.cdm.model.reference.Reference;
14
import eu.etaxonomy.cdm.model.taxon.Classification;
15
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
16
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
17
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
18
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
19
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
20
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
21
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
22

  
23
/**
24
 * @author pplitzner
25
 * @date Nov 6, 2016
26
 *
27
 */
28
public class CloneClassificationDetailElement  extends
29
AbstractCdmDetailElement<Classification>{
30

  
31
    private TextWithLabelElement txtClassificationName;
32
    private TermComboElement<TaxonRelationshipType> comboRelationType;
33
    private EntitySelectionElement<Reference> selectReference;
34

  
35
    public CloneClassificationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
36
        super(formFactory, formElement);
37
    }
38

  
39
     @Override
40
    protected void createControls(ICdmFormElement formElement, Classification entity, int style) {
41
         txtClassificationName = formFactory.createTextWithLabelElement(formElement, "Classification name", null, style);
42
         comboRelationType = formFactory.createDefinedTermComboElement(TermType.TaxonRelationshipType, formElement, "Taxon relation", null, style);
43
         selectReference = formFactory.createSelectionElement(Reference.class, getConversationHolder(), formElement, "Reference", null, EntitySelectionElement.SELECTABLE, style);
44
    }
45

  
46
     @Override
47
    public void handleEvent(Object eventSource) {
48
    }
49

  
50
    public String getClassificationName(){
51
        return txtClassificationName.getText();
52
    }
53

  
54
    public TaxonRelationshipType getRelationType(){
55
        return comboRelationType.getSelection();
56
    }
57

  
58
    public Reference getReference(){
59
        return selectReference.getSelection();
60
    }
61

  
62
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
110 110
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
111 111
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
112 112
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
113
import eu.etaxonomy.taxeditor.ui.dialog.CloneClassificationDetailElement;
113 114
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection.UnitType;
114 115
import eu.etaxonomy.taxeditor.ui.mvc.element.DateElement;
115 116
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
......
944 945
		parentElement.addElement(element);
945 946
		return element;
946 947
	}
947
    
948

  
948 949

  
949 950
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
950 951
            TermVocabulary<?> termVocabulary,
......
2050 2051
        return element;
2051 2052
    }
2052 2053

  
2054
    public CloneClassificationDetailElement createCloneClassificationDetailElement(ICdmFormElement parentElement){
2055
        CloneClassificationDetailElement element = new CloneClassificationDetailElement(this, parentElement);
2056
        addAndAdaptElement(parentElement, element);
2057
        return element;
2058
    }
2059

  
2053 2060
    public FeatureDistributionDetailElement createFeatureDistributionDetailElement(ICdmFormElement parentElement){
2054 2061
        FeatureDistributionDetailElement element = new FeatureDistributionDetailElement(this, parentElement);
2055 2062
        addAndAdaptElement(parentElement, element);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizard.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.taxeditor.ui.section.classification;
12

  
13
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.swt.widgets.Display;
15

  
16
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
17
import eu.etaxonomy.cdm.model.reference.Reference;
18
import eu.etaxonomy.cdm.model.taxon.Classification;
19
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22

  
23
/**
24
 *
25
 * @author pplitzner
26
 * @date Nov 6, 2016
27
 *
28
 */
29

  
30
public class CloneClassificationWizard extends Wizard{
31

  
32
	private CloneClassificationWizardPage cloneClassificationWizardPage;
33

  
34
    private ConversationHolder conversationHolder;
35

  
36
    private CdmFormFactory formFactory;
37

  
38
    private String classificationName;
39

  
40
    private TaxonRelationshipType relationType;
41

  
42
    private Reference reference;
43

  
44
    public CloneClassificationWizard(Classification classification) {
45
        super();
46
        conversationHolder = CdmStore.createConversation();
47
        formFactory = new CdmFormFactory(Display.getCurrent(), null);
48
        cloneClassificationWizardPage = new CloneClassificationWizardPage(formFactory, conversationHolder, classification);
49
        addPage(cloneClassificationWizardPage);
50
    }
51

  
52

  
53
    @Override
54
    public boolean canFinish() {
55
        return cloneClassificationWizardPage.getClassificationName()!=null
56
                && cloneClassificationWizardPage.getRelationType()!=null &&
57
                        cloneClassificationWizardPage.getReference()!=null;
58
    }
59

  
60
    @Override
61
    public boolean performFinish() {
62
        classificationName = cloneClassificationWizardPage.getClassificationName();
63
        relationType = cloneClassificationWizardPage.getRelationType();
64
        reference = cloneClassificationWizardPage.getReference();
65
        return true;
66
    }
67

  
68

  
69
    public String getClassificationName(){
70
        return classificationName;
71
    }
72

  
73
    public TaxonRelationshipType getRelationType(){
74
        return relationType;
75
    }
76

  
77
    public Reference getReference(){
78
        return reference;
79
    }
80

  
81
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizardPage.java
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

  
11
package eu.etaxonomy.taxeditor.ui.section.classification;
12

  
13
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
14
import eu.etaxonomy.cdm.model.reference.Reference;
15
import eu.etaxonomy.cdm.model.taxon.Classification;
16
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
17
import eu.etaxonomy.taxeditor.ui.dialog.CloneClassificationDetailElement;
18
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21

  
22
/**
23
 *
24
 * @author pplitzner
25
 * @date Nov 6, 2016
26
 *
27
 */
28
public class CloneClassificationWizardPage extends
29
		AbstractCdmEntityWizardPage<Classification> {
30

  
31
	private CloneClassificationDetailElement detailElement;
32

  
33
    public CloneClassificationWizardPage(CdmFormFactory formFactory,
34
			ConversationHolder conversation, Classification entity) {
35
		super(formFactory, conversation, entity);
36
		setTitle("Clone Classification");
37
	}
38

  
39
    /** {@inheritDoc} */
40
    @Override
41
    public CloneClassificationDetailElement createElement(ICdmFormElement rootElement) {
42
        detailElement = formFactory.createCloneClassificationDetailElement(rootElement);
43
        detailElement.setEntity(getEntity());
44
        return detailElement;
45
    }
46

  
47
    public String getClassificationName(){
48
        return detailElement.getClassificationName();
49
    }
50

  
51
    public TaxonRelationshipType getRelationType(){
52
        return detailElement.getRelationType();
53
    }
54

  
55
    public Reference getReference(){
56
        return detailElement.getReference();
57
    }
58

  
59
}

Also available in: Unified diff