2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.swt
.widgets
.Shell
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
29 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
30 import eu
.etaxonomy
.taxeditor
.newWizard
.NewReferenceWizard
;
31 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
32 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
42 public class ExtReferenceSelectionDialog
extends
43 AbstractFilteredCdmResourceSelectionDialog
<Reference
> {
45 protected static boolean isInReference
= false;
46 private Reference currentReference
;
47 ICdmRepository controller
;
48 ICdmRemoteSource remoteSource
;
49 Reference remoteSourceRef
;
50 IReferenceService service
= null;
56 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
57 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
58 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
59 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
61 public static Reference
select(Shell shell
, ConversationHolder conversation
, Reference reference
, boolean isInReference
) {
62 ExtReferenceSelectionDialog dialog
= new ExtReferenceSelectionDialog(shell
, conversation
,
63 "Choose a reference", false, reference
, isInReference
);
64 return getSelectionFromDialog(dialog
);
70 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
71 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
72 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
73 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
75 public static Reference
select(Shell shell
, ConversationHolder conversation
, Reference reference
) {
76 ExtReferenceSelectionDialog dialog
= new ExtReferenceSelectionDialog(shell
, conversation
,
77 "Choose a reference", false, reference
);
78 return getSelectionFromDialog(dialog
);
87 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
89 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
90 * @param title a {@link java.lang.String} object.
91 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
92 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
93 * @param multi a boolean.
95 protected ExtReferenceSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, Reference reference
) {
96 super(shell
, conversation
, title
, multi
, ExtReferenceSelectionDialog
.class.getCanonicalName(), null);
97 this.currentReference
= reference
;
99 // controller = CdmStore.getCurrentApplicationConfiguration();
100 // String currentValue = System.getProperty("cdm.server.dev.port");
101 System
.setProperty("cdm.server.dev.port", "8080");
102 remoteSource
= CdmServerInfo
.getDevServerRemoteSource();
103 remoteSourceRef
= ReferenceFactory
.newDatabase();
104 remoteSourceRef
.setTitle(remoteSource
.getName());
105 System
.setProperty("cdm.server.dev.port", "80");
112 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
114 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
115 * @param title a {@link java.lang.String} object.
116 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
117 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
118 * @param multi a boolean.
120 protected ExtReferenceSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, Reference reference
, boolean isInReference
) {
121 super(shell
, conversation
, title
, multi
, ExtReferenceSelectionDialog
.class.getCanonicalName(), null);
122 this.isInReference
= isInReference
;
123 this.currentReference
= reference
;
125 // controller = CdmStore.getCurrentApplicationConfiguration();
126 // CdmServerInfoConfig parameterObject = new CdmServerInfoConfig("localhost", "localhost", 8080, "cdmserver/", true);
127 // CdmServerInfo selectedCsii = new CdmServerInfo(parameterObject);
128 // CdmInstanceInfo selectedCdmInstance = selectedCsii.getInstanceFromName("local-cuba") ;
130 // remoteSource = selectedCsii.getCdmRemoteSource(selectedCdmInstance, 80);
137 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
141 protected Reference
getPersistentObject(UUID cdmUuid
) {
142 Reference extRef
= service
.load(cdmUuid
);
144 Reference newRef
= ReferenceFactory
.newReference( extRef
.getType());
145 if (extRef
.getTitle() != null){
146 newRef
.setTitle(extRef
.getTitle());
148 newRef
.setTitleCache(extRef
.getTitleCache(), true);
150 if (extRef
.getAbbrevTitle() != null){
151 newRef
.setAbbrevTitle(extRef
.getAbbrevTitle());
153 newRef
.setAbbrevTitleCache(extRef
.getAbbrevTitleCache(), true);
156 if (extRef
.getInReference() != null){
157 Reference inRef
= extRef
.getInReference();
158 Reference newRefInRef
= ReferenceFactory
.newReference( extRef
.getInBook().getType());
159 if (inRef
.getTitle() != null){
160 newRefInRef
.setTitle(inRef
.getTitle());
162 newRefInRef
.setTitleCache(inRef
.getTitleCache(), true);
164 if (inRef
.getAbbrevTitle() != null){
165 newRefInRef
.setAbbrevTitle(inRef
.getAbbrevTitle());
167 newRefInRef
.setAbbrevTitleCache(inRef
.getAbbrevTitleCache(), true);
169 newRefInRef
.addSource(OriginalSourceType
.Other
, String
.valueOf(newRefInRef
.getId()), "Reference", remoteSourceRef
, null);
170 newRef
.setInReference(newRefInRef
);
171 newRef
.setProtectedTitleCache(false);
172 newRef
.setProtectedAbbrevTitleCache(false);
173 newRef
.addSource(OriginalSourceType
.Other
, String
.valueOf(newRef
.getId()), "Reference", remoteSourceRef
, null);
175 TeamOrPersonBase author
;
176 if (extRef
.getAuthorship() != null){
177 if (extRef
.getAuthorship() instanceof Person
){
178 author
= Person
.NewTitledInstance(extRef
.getAuthorship().getTitleCache());
179 author
.setProtectedTitleCache(true);
181 author
= Team
.NewInstance();
184 for (Person member
:((Team
)extRef
.getAuthorship()).getTeamMembers()){
185 newMember
= Person
.NewTitledInstance(member
.getTitleCache());
186 ((Team
)author
).addTeamMember(newMember
);
190 newRef
.setAuthorship(author
);
193 newRef
= CdmStore
.getService(IReferenceService
.class).save(newRef
);
199 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#search
203 protected void search() {
204 Control control
=getSearchField();
205 String pattern
= null;
206 if (control
!= null){
207 pattern
= ((Text
)control
).getText();
210 if (remoteSource
!= null){
211 // if (service == null){
212 // service = CdmApplicationRemoteConfiguration.getExtReferenceService(remoteSource);
214 if (pattern
== null || pattern
.equals("?")){ //$NON-NLS-1$
215 if (isInReference
&& currentReference
!= null){
216 model
= service
.getUuidAndTitleCache(null, null, currentReference
.getType());
218 model
= service
.getUuidAndTitleCache(null, null);
221 if (isInReference
&& currentReference
!= null){
222 model
= service
.getUuidAndTitleCache(limitOfInitialElements
, pattern
, currentReference
.getType());
224 model
= service
.getUuidAndTitleCache(limitOfInitialElements
,pattern
);
234 protected String
getTitle(Reference cdmObject
) {
235 if(cdmObject
== null){
238 return super.getTitle(cdmObject
);
241 // return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
247 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
248 return new NewReferenceWizard();
253 protected String
[] getNewWizardText() {
254 return new String
[]{"Reference "};