Project

General

Profile

« Previous | Next » 

Revision 24fd1426

Added by Patrick Plitzner almost 6 years ago

ref #7362 Add vocabulary chooser when importing term into feature tree

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDropAdapter.java
22 22
import org.eclipse.swt.dnd.TransferData;
23 23

  
24 24
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25 26
import eu.etaxonomy.cdm.model.description.Feature;
26 27
import eu.etaxonomy.cdm.model.description.FeatureNode;
27 28
import eu.etaxonomy.cdm.model.description.FeatureTree;
......
30 31
import eu.etaxonomy.taxeditor.l10n.Messages;
31 32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 33
import eu.etaxonomy.taxeditor.store.CdmStore;
34
import eu.etaxonomy.taxeditor.ui.dialog.selection.TermVocabularySelectionDialog;
33 35
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
34 36

  
35 37
public class FeatureNodeDropAdapter extends ViewerDropAdapter {
......
51 53
		else if(currentTarget instanceof FeatureNode){
52 54
		    target = (FeatureNode) currentTarget;
53 55
		}
54
		else{
55
		    MessagingUtils.warningDialog(Messages.FeatureNodeDropAdapter_INVALID_TARGET, this, Messages.FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE);
56
		    return false;
57
		}
58 56
		int position = 0;
59 57

  
60 58
		if (target != null) {
......
71 69
			}
72 70
		}
73 71

  
72
        if(target==null){
73
            MessagingUtils.warningDialog(Messages.FeatureNodeDropAdapter_INVALID_TARGET, this, Messages.FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE);
74
            return false;
75
        }
76

  
74 77
		Collection<Object> droppedObjects = Collections.emptyList();
75 78
		if(data instanceof Object[]){
76 79
		    droppedObjects = Arrays.asList((Object[])data);
......
98 101
		    }
99 102
		    else if(droppedObject instanceof OntologyTermWrapper){
100 103
		        OntologyTermWrapper wrapper = (OntologyTermWrapper)droppedObject;
101
		        Feature feature = Feature.NewInstance(wrapper.getLabel(), wrapper.getLabel(), wrapper.getLabel());
102
		        feature.setUri(URI.create(wrapper.getUri()));
103
		        CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(target, feature);
104
		        TermVocabulary vocabulary = TermVocabularySelectionDialog.select(
105
		                "Choose vocabulary for import", viewer.getControl().getShell(), null);
106
		        if(vocabulary!=null){
107
		            Feature feature = Feature.NewInstance(wrapper.getLabel(), wrapper.getLabel(), wrapper.getLabel());
108
		            feature.setUri(URI.create(wrapper.getUri()));
109
		            vocabulary.addTerm(feature);
110
		            CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(target, feature);
111
		        }
104 112
		    }
105 113
		}
106 114
		dirtyable.setDirty(true);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/TermVocabularySelectionDialog.java
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.ui.dialog.selection;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.eclipse.swt.widgets.Shell;
17

  
18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
19
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
21
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23

  
24
/**
25
 *
26
 * @author pplitzner
27
 * @since Jun 1, 2018
28
 *
29
 */
30
public class TermVocabularySelectionDialog extends
31
		AbstractFilteredCdmResourceSelectionDialog<TermVocabulary> {
32

  
33
    public static TermVocabulary select(String dialogTitle, Shell shell, TermVocabulary voc){
34
        return select_internal(dialogTitle, shell, voc);
35
    }
36

  
37
    public static TermVocabulary select(Shell shell, TermVocabulary voc){
38
        return select_internal("Choose Vocabulary", shell, voc);
39
    }
40

  
41
	private static TermVocabulary select_internal(String dialogTitle, Shell shell, TermVocabulary voc){
42
		TermVocabularySelectionDialog dialog = new TermVocabularySelectionDialog(shell,
43
				dialogTitle!=null?dialogTitle:"Choose Vocabulary",
44
				false,
45
				TermVocabularySelectionDialog.class.getCanonicalName(),
46
				voc);
47
		return getSelectionFromDialog(dialog);
48
	}
49

  
50
	protected TermVocabularySelectionDialog(Shell shell,
51
			 String title, boolean multi,
52
			String settings, TermVocabulary cdmObject) {
53
		super(shell, title, multi, settings, cdmObject);
54
	}
55

  
56
	@Override
57
	protected TermVocabulary getPersistentObject(UUID uuid) {
58
		return CdmStore.getService(IVocabularyService.class).load(uuid);
59
	}
60

  
61
	@Override
62
	protected void callService(String pattern) {
63
		List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).list(TermVocabulary.class, null, null, null, null);
64

  
65
		List<UuidAndTitleCache<TermVocabulary>> featureUuidAndTitleCache = new ArrayList<>();
66

  
67
		for(TermVocabulary voc : vocabularies){
68
			UuidAndTitleCache<TermVocabulary> uuidAndTitleCache = new UuidAndTitleCache<>(TermVocabulary.class, voc.getUuid(), voc.getId(), voc.getTitleCache());
69
			if (pattern == null || uuidAndTitleCache.getTitleCache().matches("(?i)"+pattern + ".*")) {
70
                featureUuidAndTitleCache.add(uuidAndTitleCache);
71
            }
72
		}
73
		model =  featureUuidAndTitleCache;
74
	}
75

  
76
	@Override
77
	protected String[] getNewWizardText() {
78
		return null;
79
	}
80

  
81
	@Override
82
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
83
		return null;
84
	}
85

  
86
}

Also available in: Unified diff