2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
12 import java
.util
.UUID
;
14 import org
.eclipse
.swt
.widgets
.Control
;
15 import org
.eclipse
.swt
.widgets
.Shell
;
16 import org
.eclipse
.swt
.widgets
.Text
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
21 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
22 import eu
.etaxonomy
.taxeditor
.newWizard
.NewReferenceWizard
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 * <p>FilteredReferenceSelectionDialog class.</p>
32 public class ReferenceSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<Reference
> {
34 protected static boolean isInReference
= false;
35 private Reference currentReference
;
39 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
40 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
41 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
42 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
44 public static Reference
select(Shell shell
, ConversationHolder conversation
, Reference reference
, boolean isInReference
) {
45 ReferenceSelectionDialog dialog
= new ReferenceSelectionDialog(shell
, conversation
,
46 "Choose a reference", false, reference
, isInReference
);
47 return getSelectionFromDialog(dialog
);
53 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
54 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
55 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
56 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
58 public static Reference
select(Shell shell
, ConversationHolder conversation
, Reference reference
) {
59 ReferenceSelectionDialog dialog
= new ReferenceSelectionDialog(shell
, conversation
,
60 "Choose a reference", false, reference
);
61 return getSelectionFromDialog(dialog
);
67 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
69 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
70 * @param title a {@link java.lang.String} object.
71 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
72 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
73 * @param multi a boolean.
75 protected ReferenceSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, Reference reference
) {
76 super(shell
, conversation
, title
, multi
, ReferenceSelectionDialog
.class.getCanonicalName(), null);
77 this.currentReference
= reference
;
84 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
86 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
87 * @param title a {@link java.lang.String} object.
88 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
89 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
90 * @param multi a boolean.
92 protected ReferenceSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, Reference reference
, boolean isInReference
) {
93 super(shell
, conversation
, title
, multi
, ReferenceSelectionDialog
.class.getCanonicalName(), null);
94 this.isInReference
= isInReference
;
95 this.currentReference
= reference
;
100 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
104 protected Reference
getPersistentObject(UUID cdmUuid
) {
105 return CdmStore
.getService(IReferenceService
.class).load(cdmUuid
);
109 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
113 protected void initModel() {
114 Control control
= getPatternControl();
115 String pattern
= null;
116 if (control
!= null){
117 pattern
= ((Text
)control
).getText();
120 if (pattern
== null || pattern
.equals("?")){
121 if (isInReference
&& currentReference
!= null){
122 model
= CdmStore
.getService(IReferenceService
.class).getUuidAndTitleCache(null,null,currentReference
.getType());
124 model
= CdmStore
.getService(IReferenceService
.class).getUuidAndTitleCache(null,null);
127 if (isInReference
&& currentReference
!= null){
128 model
= CdmStore
.getService(IReferenceService
.class).getUuidAndTitleCache(limitOfInitialElements
,pattern
, currentReference
.getType());
130 model
= CdmStore
.getService(IReferenceService
.class).getUuidAndTitleCache(limitOfInitialElements
,pattern
);
138 protected String
getTitle(Reference cdmObject
) {
139 if(cdmObject
== null){
142 return super.getTitle(cdmObject
);
145 // return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
151 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
152 return new NewReferenceWizard();
157 protected String
getNewWizardLinkText() {
158 return String
.format("Create a new <a>%1s</a>", "Reference ");