Project

General

Profile

Download (10.2 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.ui.dialog.selection;
10

    
11
 import java.util.UUID;
12

    
13
import org.eclipse.swt.widgets.Shell;
14

    
15
import eu.etaxonomy.cdm.api.application.ICdmRepository;
16
import eu.etaxonomy.cdm.api.service.IReferenceService;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
20
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
21
import eu.etaxonomy.cdm.model.reference.Reference;
22
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
23
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
24
import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
25
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
26
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29

    
30
/**
31
 * @author k.luther
32
 * @date 02.05.2017
33
 */
34
public class ExtReferenceSelectionDialog extends
35
    AbstractFilteredCdmResourceSelectionDialog<Reference> {
36

    
37
        protected static boolean isInReference = false;
38
        private Reference currentReference;
39
        ICdmRepository controller;
40
        ICdmRemoteSource remoteSource ;
41
        Reference remoteSourceRef;
42
        IReferenceService service = null;
43

    
44

    
45
        /**
46
         * <p>select</p>
47
         *
48
         * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
49
         * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
50
         * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
51
         * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
52
         */
53
        public static Reference select(Shell shell, //ConversationHolder conversation,
54
                Reference reference, boolean isInReference) {
55
            ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
56
                    "Choose a reference", false, reference, isInReference);
57
            return getSelectionFromDialog(dialog);
58
        }
59

    
60
        /**
61
         * <p>select</p>
62
         *
63
         * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
64
         * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
65
         * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
66
         * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
67
         */
68
        public static Reference select(Shell shell, //ConversationHolder conversation,
69
                Reference reference) {
70
            ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
71
                    "Choose a reference", false, reference);
72
            return getSelectionFromDialog(dialog);
73
        }
74

    
75

    
76

    
77

    
78

    
79

    
80
        /**
81
         * <p>Constructor for FilteredReferenceSelectionDialog.</p>
82
         *
83
         * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
84
         * @param title a {@link java.lang.String} object.
85
         * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
86
         * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
87
         * @param multi a boolean.
88
         */
89
        protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
90
                String title, boolean multi, Reference reference) {
91
            super(shell, //conversation,
92
                    title, multi, ExtReferenceSelectionDialog.class.getCanonicalName(), null);
93
            this.currentReference = reference;
94

    
95
//            controller = CdmStore.getCurrentApplicationConfiguration();
96
//            String currentValue = System.getProperty("cdm.server.dev.port");
97
            System.setProperty("cdm.server.dev.port", "8080");
98
            remoteSource = CdmServerInfo.getDevServerRemoteSource();
99
            remoteSourceRef = ReferenceFactory.newDatabase();
100
            remoteSourceRef.setTitle(remoteSource.getName());
101
         System.setProperty("cdm.server.dev.port", "80");
102
        }
103

    
104

    
105

    
106

    
107
        /**
108
         * <p>Constructor for FilteredReferenceSelectionDialog.</p>
109
         *
110
         * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
111
         * @param title a {@link java.lang.String} object.
112
         * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
113
         * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
114
         * @param multi a boolean.
115
         */
116
        protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
117
                String title, boolean multi, Reference reference, boolean isInReference) {
118
            super(shell, //conversation,
119
                    title, multi, ExtReferenceSelectionDialog.class.getCanonicalName(), null);
120
            this.isInReference = isInReference;
121
            this.currentReference = reference;
122

    
123
//            controller = CdmStore.getCurrentApplicationConfiguration();
124
//            CdmServerInfoConfig parameterObject = new CdmServerInfoConfig("localhost", "localhost", 8080, "cdmserver/", true);
125
//            CdmServerInfo selectedCsii = new CdmServerInfo(parameterObject);
126
//            CdmInstanceInfo selectedCdmInstance = selectedCsii.getInstanceFromName("local-cuba") ;
127
//            Integer port;
128
//            remoteSource = selectedCsii.getCdmRemoteSource(selectedCdmInstance, 80);
129

    
130

    
131
        }
132

    
133

    
134
        /* (non-Javadoc)
135
         * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
136
         */
137
        /** {@inheritDoc} */
138
        @Override
139
        protected Reference getPersistentObject(UUID cdmUuid) {
140
            Reference extRef = service.load(cdmUuid);
141

    
142
            Reference newRef = ReferenceFactory.newReference( extRef.getType());
143
            if (extRef.getTitle() != null){
144
                newRef.setTitle(extRef.getTitle());
145
            }else{
146
                newRef.setTitleCache(extRef.getTitleCache(), true);
147
            }
148
            if (extRef.getAbbrevTitle() != null){
149
                newRef.setAbbrevTitle(extRef.getAbbrevTitle());
150
            }else{
151
                newRef.setAbbrevTitleCache(extRef.getAbbrevTitleCache(), true);
152
            }
153

    
154
            if (extRef.getInReference() != null){
155
                Reference inRef = extRef.getInReference();
156
                Reference newRefInRef = ReferenceFactory.newReference( extRef.getInBook().getType());
157
                if (inRef.getTitle() != null){
158
                    newRefInRef.setTitle(inRef.getTitle());
159
                }else{
160
                    newRefInRef.setTitleCache(inRef.getTitleCache(), true);
161
                }
162
                if (inRef.getAbbrevTitle() != null){
163
                    newRefInRef.setAbbrevTitle(inRef.getAbbrevTitle());
164
                }else{
165
                    newRefInRef.setAbbrevTitleCache(inRef.getAbbrevTitleCache(), true);
166
                }
167
                newRefInRef.addSource(OriginalSourceType.Other, String.valueOf(newRefInRef.getId()), "Reference", remoteSourceRef, null);
168
                newRef.setInReference(newRefInRef);
169
                newRef.setProtectedTitleCache(false);
170
                newRef.setProtectedAbbrevTitleCache(false);
171
                newRef.addSource(OriginalSourceType.Other, String.valueOf(newRef.getId()), "Reference", remoteSourceRef, null);
172
            }
173
            TeamOrPersonBase author;
174
            if (extRef.getAuthorship() != null){
175
                if (extRef.getAuthorship() instanceof Person){
176
                     author = Person.NewTitledInstance(extRef.getAuthorship().getTitleCache());
177
                     author.setProtectedTitleCache(true);
178
                }else{
179
                   author = Team.NewInstance();
180
                   Person newMember;
181

    
182
                   for (Person member:((Team)extRef.getAuthorship()).getTeamMembers()){
183
                       newMember = Person.NewTitledInstance(member.getTitleCache());
184
                       ((Team)author).addTeamMember(newMember);
185
                   }
186

    
187
                }
188
                newRef.setAuthorship(author);
189
            }
190

    
191
            newRef = CdmStore.getService(IReferenceService.class).save(newRef);
192

    
193
            return newRef;
194
        }
195

    
196
        /** {@inheritDoc} */
197
        @Override
198
        protected void callService(String pattern) {
199

    
200

    
201
            if (remoteSource != null){
202
//               if (service == null){
203
//                   service = CdmApplicationRemoteConfiguration.getExtReferenceService(remoteSource);
204
//               }
205
               if (pattern.equals("?")){ //$NON-NLS-1$
206
                    if (isInReference && currentReference != null){
207
                        model = service.getUuidAndTitleCache(null, null, currentReference.getType());
208
                    }else{
209
                        model = service.getUuidAndTitleCache(null, null);
210
                    }
211
                }else{
212
                    if (isInReference && currentReference != null){
213
                        model = service.getUuidAndTitleCache(limitOfInitialElements, pattern, currentReference.getType());
214
                    }else{
215
                        model = service.getUuidAndTitleCache(limitOfInitialElements,pattern);
216

    
217
                    }
218
                }
219
             }
220
        }
221

    
222

    
223
        /** {@inheritDoc} */
224
        @Override
225
        protected String getTitle(Reference cdmObject) {
226
            if(cdmObject == null){
227
                return "";
228
            }else{
229
                return super.getTitle(cdmObject);
230
            }
231
//          }else{
232
//              return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
233
//          }
234
        }
235

    
236
        /** {@inheritDoc} */
237
        @Override
238
        protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
239
            return new NewReferenceWizard();
240
        }
241

    
242
        /** {@inheritDoc} */
243
        @Override
244
        protected String[] getNewWizardText() {
245
            return new String[]{"Reference "};
246
        }
247

    
248
    }
249

    
250

    
(13-13/44)