ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / ReferenceSelectionDialog.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12 import java.util.UUID;
13
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.swt.widgets.Text;
17
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.cdm.strategy.cache.reference.DefaultReferenceCacheStrategy;
22 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23 import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * <p>FilteredReferenceSelectionDialog class.</p>
28 *
29 * @author n.hoffmann
30 * @created 04.06.2009
31 * @version 1.0
32 */
33 public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<Reference> {
34
35 /**
36 * <p>select</p>
37 *
38 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
39 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
40 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
41 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
42 */
43 public static Reference select(Shell shell, ConversationHolder conversation, Reference reference) {
44 ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, conversation,
45 "Choose a reference", false, reference);
46 return getSelectionFromDialog(dialog);
47 }
48
49
50 /**
51 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
52 *
53 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
54 * @param title a {@link java.lang.String} object.
55 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
56 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
57 * @param multi a boolean.
58 */
59 protected ReferenceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, Reference reference) {
60 super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
61 }
62
63
64 /* (non-Javadoc)
65 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
66 */
67 /** {@inheritDoc} */
68 @Override
69 protected Reference getPersistentObject(UUID cdmUuid) {
70 return CdmStore.getService(IReferenceService.class).load(cdmUuid);
71 }
72
73 /* (non-Javadoc)
74 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
75 */
76 /** {@inheritDoc} */
77 @Override
78 protected void initModel() {
79 Control control = getPatternControl();
80 String pattern = null;
81 if (control != null){
82 pattern = ((Text)control).getText();
83 }
84
85
86 model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern);
87 }
88
89
90 /** {@inheritDoc} */
91 @Override
92 protected String getTitle(Reference cdmObject) {
93 if(cdmObject == null){
94 return "";
95 }else{
96 return super.getTitle(cdmObject);
97 }
98 // }else{
99 // return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
100 // }
101 }
102
103 /** {@inheritDoc} */
104 @Override
105 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
106 return new NewReferenceWizard();
107 }
108
109 /** {@inheritDoc} */
110 @Override
111 protected String getNewWizardLinkText() {
112 return String.format("Create a new <a>%1s</a>", "Reference ");
113 }
114
115 }