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
;
11 import java
.util
.UUID
;
13 import org
.eclipse
.swt
.widgets
.Shell
;
15 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
16 import eu
.etaxonomy
.cdm
.config
.ICdmSource
;
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
.reference
.OriginalSourceType
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
23 import eu
.etaxonomy
.taxeditor
.newWizard
.NewReferenceWizard
;
24 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 public class ExtReferenceSelectionDialog
extends
32 AbstractFilteredCdmResourceSelectionDialog
<Reference
> {
34 protected static boolean isInReference
= false;
35 private Reference currentReference
;
36 private ICdmSource remoteSource
;
37 private Reference remoteSourceRef
;
38 private IReferenceService service
= null;
43 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
44 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
45 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
46 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
48 public static Reference
select(Shell shell
, //ConversationHolder conversation,
49 Reference reference
, boolean isInReference
) {
50 ExtReferenceSelectionDialog dialog
= new ExtReferenceSelectionDialog(shell
, //conversation,
51 "Choose a reference", false, reference
, isInReference
);
52 return getSelectionFromDialog(dialog
);
58 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
59 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
60 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
61 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
63 public static Reference
select(Shell shell
, //ConversationHolder conversation,
64 Reference reference
) {
65 ExtReferenceSelectionDialog dialog
= new ExtReferenceSelectionDialog(shell
, //conversation,
66 "Choose a reference", false, reference
);
67 return getSelectionFromDialog(dialog
);
71 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
73 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
74 * @param title a {@link java.lang.String} object.
75 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
76 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
77 * @param multi a boolean.
79 protected ExtReferenceSelectionDialog(Shell shell
, //ConversationHolder conversation,
80 String title
, boolean multi
, Reference reference
) {
81 super(shell
, //conversation,
82 title
, multi
, ExtReferenceSelectionDialog
.class.getCanonicalName());
83 this.currentReference
= reference
;
84 // controller = CdmStore.getCurrentApplicationConfiguration();
85 remoteSource
= CdmServerInfo
.getDevServerRemoteSource();
86 remoteSourceRef
= ReferenceFactory
.newDatabase();
87 remoteSourceRef
.setTitle(remoteSource
.getName());
91 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
93 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
94 * @param title a {@link java.lang.String} object.
95 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
96 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
97 * @param multi a boolean.
99 protected ExtReferenceSelectionDialog(Shell shell
, //ConversationHolder conversation,
100 String title
, boolean multi
, Reference reference
, boolean isInReference
) {
101 super(shell
, //conversation,
102 title
, multi
, ExtReferenceSelectionDialog
.class.getCanonicalName());
103 ExtReferenceSelectionDialog
.isInReference
= isInReference
;
104 this.currentReference
= reference
;
106 // controller = CdmStore.getCurrentApplicationConfiguration();
107 // CdmServerInfoConfig parameterObject = new CdmServerInfoConfig("localhost", "localhost", 8080, "cdmserver/", true);
108 // CdmServerInfo selectedCsii = new CdmServerInfo(parameterObject);
109 // CdmInstanceInfo selectedCdmInstance = selectedCsii.getInstanceFromName("local-cuba") ;
111 // remoteSource = selectedCsii.getCdmRemoteSource(selectedCdmInstance, 80);
115 protected Reference
getPersistentObject(UUID cdmUuid
) {
116 Reference extRef
= service
.load(cdmUuid
);
118 Reference newRef
= ReferenceFactory
.newReference( extRef
.getType());
119 if (extRef
.getTitle() != null){
120 newRef
.setTitle(extRef
.getTitle());
122 newRef
.setTitleCache(extRef
.getTitleCache(), true);
124 if (extRef
.getAbbrevTitle() != null){
125 newRef
.setAbbrevTitle(extRef
.getAbbrevTitle());
127 newRef
.setAbbrevTitleCache(extRef
.getAbbrevTitleCache(), true);
130 if (extRef
.getInReference() != null){
131 Reference inRef
= extRef
.getInReference();
132 Reference newRefInRef
= ReferenceFactory
.newReference( extRef
.getInBook().getType());
133 if (inRef
.getTitle() != null){
134 newRefInRef
.setTitle(inRef
.getTitle());
136 newRefInRef
.setTitleCache(inRef
.getTitleCache(), true);
138 if (inRef
.getAbbrevTitle() != null){
139 newRefInRef
.setAbbrevTitle(inRef
.getAbbrevTitle());
141 newRefInRef
.setAbbrevTitleCache(inRef
.getAbbrevTitleCache(), true);
143 newRefInRef
.addSource(OriginalSourceType
.Other
, String
.valueOf(newRefInRef
.getId()), "Reference", remoteSourceRef
, null);
144 newRef
.setInReference(newRefInRef
);
145 newRef
.setProtectedTitleCache(false);
146 newRef
.setProtectedAbbrevTitleCache(false);
147 newRef
.addSource(OriginalSourceType
.Other
, String
.valueOf(newRef
.getId()), "Reference", remoteSourceRef
, null);
149 TeamOrPersonBase
<?
> author
;
150 if (extRef
.getAuthorship() != null){
151 if (extRef
.getAuthorship() instanceof Person
){
152 author
= Person
.NewTitledInstance(extRef
.getAuthorship().getTitleCache());
153 author
.setProtectedTitleCache(true);
155 author
= Team
.NewInstance();
158 for (Person member
:((Team
)extRef
.getAuthorship()).getTeamMembers()){
159 newMember
= Person
.NewTitledInstance(member
.getTitleCache());
160 ((Team
)author
).addTeamMember(newMember
);
163 newRef
.setAuthorship(author
);
165 newRef
= CdmStore
.getService(IReferenceService
.class).save(newRef
);
170 protected void callService(String pattern
) {
172 if (remoteSource
!= null){
173 // if (service == null){
174 // service = CdmApplicationRemoteConfiguration.getExtReferenceService(remoteSource);
176 if (pattern
.equals("?")){ //$NON-NLS-1$
177 if (isInReference
&& currentReference
!= null){
178 model
= service
.getUuidAndTitleCache(null, null, currentReference
.getType());
180 model
= service
.getUuidAndTitleCache(null, null);
183 if (isInReference
&& currentReference
!= null){
184 model
= service
.getUuidAndTitleCache(limitOfInitialElements
, pattern
, currentReference
.getType());
186 model
= service
.getUuidAndTitleCache(limitOfInitialElements
,pattern
);
193 protected String
getTitle(Reference cdmObject
) {
194 if(cdmObject
== null){
197 return super.getTitle(cdmObject
);
200 // return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
205 protected NewReferenceWizard
getNewEntityWizard(String parameter
) {
206 return new NewReferenceWizard(null);
210 protected String
[] getNewWizardText() {
211 return new String
[]{"Reference "};