617fccf59c57ee66c32f74800d97bab13cada3ca
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / NameEditorInput.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.bulkeditor.input;
12
13 import java.util.Arrays;
14 import java.util.List;
15 import java.util.UUID;
16
17 import eu.etaxonomy.cdm.api.service.INameService;
18 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
19 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
20 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
21 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
22 import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.NameCreator;
23 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * <p>NameEditorInput class.</p>
28 *
29 * @author p.ciardelli
30 * @created 20.08.2009
31 * @version 1.0
32 */
33 public class NameEditorInput extends AbstractBulkEditorInput<TaxonNameBase> {
34
35 /**
36 *
37 */
38 private static final long serialVersionUID = -3085029575759626823L;
39 private static NameEditorInput instance;
40
41 /** Constant <code>ID="bulkeditor.input.name"</code> */
42 public static final String ID = "bulkeditor.input.name";
43
44 /**
45 * <p>Getter for the field <code>instance</code>.</p>
46 *
47 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
48 */
49 public static AbstractBulkEditorInput getInstance() {
50 if (instance == null) {
51 instance = new NameEditorInput();
52 }
53 return instance;
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.ui.IEditorInput#getName()
58 */
59 /**
60 * <p>getName</p>
61 *
62 * @return a {@link java.lang.String} object.
63 */
64 public String getName() {
65 return BulkEditorInputType.NAME.label;
66 }
67
68 /* (non-Javadoc)
69 * @see org.eclipse.ui.IEditorInput#getToolTipText()
70 */
71 /**
72 * <p>getToolTipText</p>
73 *
74 * @return a {@link java.lang.String} object.
75 */
76 public String getToolTipText() {
77 return getName();
78 }
79
80 /**
81 * <p>getID</p>
82 *
83 * @return a {@link java.lang.Object} object.
84 */
85 public static Object getID() {
86 return ID;
87 }
88
89 /* (non-Javadoc)
90 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
91 */
92 /** {@inheritDoc} */
93 @Override
94 public boolean isMergingEnabled() {
95 return false;
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
101 return CdmStore.getSearchManager().findNames(configurator);
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 public TaxonNameBase loadEntity(UUID uuid) {
107 List<String> propertyPaths = Arrays.asList(new String[]{});
108 return CdmStore.getService(INameService.class).load(uuid, propertyPaths);
109 }
110
111 /** {@inheritDoc} */
112 public boolean delete(TaxonNameBase entity) {
113 return CdmStore.getService(INameService.class).delete(entity) != null;
114 }
115
116 /** {@inheritDoc} */
117 public boolean save(TaxonNameBase entity) {
118 return CdmStore.getService(INameService.class).saveOrUpdate(entity) != null;
119 }
120
121 /* (non-Javadoc)
122 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
123 */
124 @Override
125 protected IEntityCreator<TaxonNameBase> createEntityCreator() {
126 return new NameCreator();
127 }
128
129 /* (non-Javadoc)
130 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
131 */
132 @Override
133 public List<IBulkEditorSortProvider<TaxonNameBase>> getSortProviders() {
134 List<IBulkEditorSortProvider<TaxonNameBase>> sortProviders = super.getSortProviders();
135
136 sortProviders.add(0, new IdentifiableEntitySortProvider<TaxonNameBase>());
137
138 return sortProviders;
139 }
140
141 /* (non-Javadoc)
142 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getTypeText(java.lang.Object)
143 */
144 @Override
145 public String getTypeText(Object entity) {
146 if((entity instanceof TaxonNameBase) && (((TaxonNameBase) entity).getNomenclaturalCode() != null)){
147 return ((TaxonNameBase) entity).getNomenclaturalCode().getTitleCache();
148 }
149 return super.getTypeText(entity);
150 }
151
152 /* (non-Javadoc)
153 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getText(eu.etaxonomy.cdm.model.common.ICdmBase)
154 */
155 @Override
156 public String getText(TaxonNameBase entity) {
157 return (entity).getFullTitleCache();
158 }
159
160
161 }