Project

General

Profile

Revision 812af3d0

ID812af3d071da080547ca3fc1981f3e036bb1008f
Parent 3989c5bc
Child 1d3f5c87

Added by Patricia Kelbert over 8 years ago

debug ABCD import
new boolean names in configurator
new class for User Interaction

View differences:

.gitattributes
448 448
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/out/SDDExportConfigurator.java -text
449 449
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/out/SDDExportState.java -text
450 450
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportBase.java -text
451
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenUserInteraction.java -text
451 452
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/UnitsGatheringArea.java -text
452 453
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/UnitsGatheringEvent.java -text
453 454
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206DataHolder.java -text
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenUserInteraction.java
1
// $Id$
2
/**
3
 * Copyright (C) 2013 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.cdm.io.specimen;
11

  
12
import java.awt.Dimension;
13
import java.util.ArrayList;
14
import java.util.Collections;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.UUID;
19

  
20
import javax.swing.JOptionPane;
21
import javax.swing.JScrollPane;
22
import javax.swing.JTextArea;
23

  
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.model.taxon.Classification;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29

  
30
/**
31
 * @author pkelbert
32
 * @date 21 juin 2013
33
 *
34
 */
35
public class SpecimenUserInteraction {
36

  
37
    public Classification askForClassification(Map<String, Classification> classMap){
38
        List<String> possibilities = new ArrayList<String>(classMap.keySet());
39
        Collections.sort(possibilities);
40

  
41
        if (classMap.keySet().size()>0) {
42
            classMap.put("Nothing matches, create a new classification",null);
43
            possibilities.add(0, "Nothing matches, create a new classification");
44
        } else {
45
            return null;
46
        }
47

  
48
        JTextArea textArea = new JTextArea("Which existing classification should be used ?");
49
        JScrollPane scrollPane = new JScrollPane(textArea);
50
        textArea.setLineWrap(true);
51
        textArea.setWrapStyleWord(true);
52
        scrollPane.setPreferredSize( new Dimension( 500, 50 ) );
53

  
54
        String s = null;
55
        while (s == null) {
56
            s= (String)JOptionPane.showInputDialog(
57
                    null,
58
                    scrollPane,
59
                    "Please select a classification in the list",
60
                    JOptionPane.PLAIN_MESSAGE,
61
                    null,
62
                    possibilities.toArray(),
63
                    "Nothing matches, create a new classification");
64
        }
65
        return classMap.get(s);
66
    }
67

  
68

  
69

  
70
    /**
71
     * @return the name for the new Classification
72
     */
73
    public String createNewClassification() {
74
        JTextArea textArea = new JTextArea("How should the classification be named ?");
75
        JScrollPane scrollPane = new JScrollPane(textArea);
76
        textArea.setLineWrap(true);
77
        textArea.setWrapStyleWord(true);
78
        scrollPane.setPreferredSize( new Dimension( 500, 50 ) );
79

  
80
        String s = null;
81
        while (s == null) {
82
            s=(String)JOptionPane.showInputDialog(
83
                    null,
84
                    scrollPane,
85
                    "Get full classification name",
86
                    JOptionPane.PLAIN_MESSAGE,
87
                    null,
88
                    null,
89
                    "ABCD Import");
90
        }
91
        return s;
92
    }
93

  
94

  
95
    /**
96
     * @param refMap
97
     * @return
98
     */
99
    @SuppressWarnings("rawtypes")
100
    public Reference<?> askForReference(Map<String, Reference> refMap) {
101
        List<String>  possibilities = new ArrayList<String> (refMap.keySet());
102
        Collections.sort(possibilities);
103
        if (refMap.keySet().size()>0) {
104
            refMap.put("Nothing matches, create a new reference",null);
105
            possibilities.add(0, "Nothing matches, create a new reference");
106
        } else {
107
            return null;
108
        }
109

  
110
        JTextArea textArea = new JTextArea("Which existing reference should be used?");
111
        JScrollPane scrollPane = new JScrollPane(textArea);
112
        textArea.setLineWrap(true);
113
        textArea.setWrapStyleWord(true);
114
        scrollPane.setPreferredSize( new Dimension( 700, 50 ) );
115

  
116
        String s = null;
117
        while (s == null) {
118
            s= (String)JOptionPane.showInputDialog(
119
                    null,
120
                    scrollPane,
121
                    "Please select a reference in the list",
122
                    JOptionPane.PLAIN_MESSAGE,
123
                    null,
124
                    possibilities.toArray(),
125
                    "ABCD reference");
126
        }
127
        return refMap.get(s);
128
    }
129

  
130

  
131

  
132
    /**
133
     * @return
134
     */
135
    public String createNewReference() {
136
        JTextArea textArea = new JTextArea("How should the reference be named ?");
137
        JScrollPane scrollPane = new JScrollPane(textArea);
138
        textArea.setLineWrap(true);
139
        textArea.setWrapStyleWord(true);
140
        scrollPane.setPreferredSize( new Dimension( 500, 50 ) );
141

  
142
        String s = null;
143
        while (s == null) {
144
            s= (String)JOptionPane.showInputDialog(
145
                    null,
146
                    scrollPane,
147
                    "Get full reference name",
148
                    JOptionPane.PLAIN_MESSAGE,
149
                    null,
150
                    null,
151
                    "ABCD Import from XML");
152
        }
153
        return s;
154
    }
155

  
156

  
157
    /**
158
     * Look if the same name already exists in the ALL classifications and ask the user to select one or none.
159
     * @param scientificName
160
     * @param taxonList
161
     * @return null if not found, or the selected Taxon
162
     */
163
    @SuppressWarnings("rawtypes")
164
    public Taxon askWhereToFixData(String scientificName, List<TaxonBase> taxonList, Classification classification) {
165
        Map<String,TaxonNode> classMap = new HashMap<String, TaxonNode>();
166
        boolean sameClassif=false;
167
        Taxon n = null;
168
        Taxon cc =null;
169
        for (TaxonBase cb: taxonList){
170
            cc = (Taxon)cb;
171
            for (TaxonNode node : cc.getTaxonNodes()){
172
                classMap.put("Reuse the one from the classification \""+node.getClassification().getTitleCache()+"\"", node);
173
                if (node.getClassification().getUuid().equals(classification.getUuid())) {
174
                    sameClassif=true;
175
                    n=node.getTaxon();
176
                }
177
            }
178
        }
179
        if (classMap.keySet().size()==1 && sameClassif) {
180
            return n;
181
        }
182

  
183
        JTextArea textArea = new JTextArea("The same taxon ("+scientificName+") already exists in an other classification.");
184
        JScrollPane scrollPane = new JScrollPane(textArea);
185
        textArea.setLineWrap(true);
186
        textArea.setWrapStyleWord(true);
187
        scrollPane.setPreferredSize( new Dimension( 700, 50 ) );
188

  
189
        List<String>  possibilities = new ArrayList<String> (classMap.keySet());
190
        if (possibilities.size()==0) {
191
            return null;
192
        }
193
        Collections.sort(possibilities);
194
        if(!sameClassif){
195
            classMap.put("Add a brand new Taxon to the current classification, no recycling please", null);
196
            possibilities.add(0, "Add a brand new Taxon to the current classification, no recycling please");
197
        }
198
        String s = null;
199
        while (s == null) {
200
            s= (String)JOptionPane.showInputDialog(
201
                    null,
202
                    scrollPane,
203
                    "What should be done? ",
204
                    JOptionPane.PLAIN_MESSAGE,
205
                    null,
206
                    possibilities.toArray(),
207
                    "Add a brand new Taxon to the current classification, no recycling please");
208
        }
209

  
210
        if (classMap.get(s) !=null) {
211
            return classMap.get(s).getTaxon();
212
        } else {
213
            return null;
214
        }
215
    }
216

  
217
    /**
218
     * Look if the same TaxonBase already exists in the SAME classification
219
     * @param taxonBaseList
220
     * @return null if not found, or the corresponding Taxon
221
     */
222
    @SuppressWarnings("rawtypes")
223
    public Taxon lookForTaxaIntoCurrentClassification(List<TaxonBase> taxonBaseList, Classification classification) {
224
        Taxon taxon =null;
225
        Taxon cc =null;
226
        for (TaxonBase c:taxonBaseList){
227
            cc = (Taxon)c;
228
            for (TaxonNode node : cc.getTaxonNodes()){
229
                UUID classUuid = node.getClassification().getUuid();
230
                if (classification.getUuid().equals(classUuid)){
231
                    taxon=cc;
232
                }
233
            }
234
        }
235
        return taxon;
236
    }
237

  
238
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)