144b469f0b65376dc2870624412e3778eaf1042e
[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.BulkEditorInputTypeValues.BulkEditorInputType;
23 import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.NameCreator;
24 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27 /**
28 * <p>NameEditorInput class.</p>
29 *
30 * @author p.ciardelli
31 * @created 20.08.2009
32 * @version 1.0
33 */
34 public class NameEditorInput extends AbstractBulkEditorInput<TaxonNameBase> {
35
36 /**
37 *
38 */
39 private static final long serialVersionUID = -3085029575759626823L;
40 private static NameEditorInput instance;
41
42 /** Constant <code>ID="bulkeditor.input.name"</code> */
43 public static final String ID = "bulkeditor.input.name";
44
45 /**
46 * <p>Getter for the field <code>instance</code>.</p>
47 *
48 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
49 */
50 public static AbstractBulkEditorInput getInstance() {
51 if (instance == null) {
52 instance = new NameEditorInput();
53 }
54 return instance;
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.ui.IEditorInput#getName()
59 */
60 /**
61 * <p>getName</p>
62 *
63 * @return a {@link java.lang.String} object.
64 */
65 public String getName() {
66 return BulkEditorInputType.NAME.label;
67 }
68
69 /* (non-Javadoc)
70 * @see org.eclipse.ui.IEditorInput#getToolTipText()
71 */
72 /**
73 * <p>getToolTipText</p>
74 *
75 * @return a {@link java.lang.String} object.
76 */
77 public String getToolTipText() {
78 return getName();
79 }
80
81 /**
82 * <p>getID</p>
83 *
84 * @return a {@link java.lang.Object} object.
85 */
86 public static Object getID() {
87 return ID;
88 }
89
90 /* (non-Javadoc)
91 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
92 */
93 /** {@inheritDoc} */
94 @Override
95 public boolean isMergingEnabled() {
96 return false;
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
102 return CdmStore.getSearchManager().findNames(configurator);
103 }
104
105 /** {@inheritDoc} */
106 @Override
107 public TaxonNameBase loadEntity(UUID uuid) {
108 List<String> propertyPaths = Arrays.asList(new String[]{});
109 return CdmStore.getService(INameService.class).load(uuid, propertyPaths);
110 }
111
112 /** {@inheritDoc} */
113 public boolean delete(TaxonNameBase entity) {
114 return CdmStore.getService(INameService.class).delete(entity) != null;
115 }
116
117 /** {@inheritDoc} */
118 public boolean save(TaxonNameBase entity) {
119 return CdmStore.getService(INameService.class).saveOrUpdate(entity) != null;
120 }
121
122 /* (non-Javadoc)
123 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
124 */
125 @Override
126 protected IEntityCreator<TaxonNameBase> createEntityCreator() {
127 return new NameCreator();
128 }
129
130 /* (non-Javadoc)
131 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
132 */
133 @Override
134 public List<IBulkEditorSortProvider<TaxonNameBase>> getSortProviders() {
135 List<IBulkEditorSortProvider<TaxonNameBase>> sortProviders = super.getSortProviders();
136
137 sortProviders.add(0, new IdentifiableEntitySortProvider<TaxonNameBase>());
138
139 return sortProviders;
140 }
141
142 /* (non-Javadoc)
143 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getTypeText(java.lang.Object)
144 */
145 @Override
146 public String getTypeText(Object entity) {
147 if(entity instanceof TaxonNameBase){
148 return ((TaxonNameBase) entity).getNomenclaturalCode().getTitleCache();
149 }
150 return super.getTypeText(entity);
151 }
152
153 /* (non-Javadoc)
154 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getText(eu.etaxonomy.cdm.model.common.ICdmBase)
155 */
156 @Override
157 public String getText(TaxonNameBase entity) {
158 return (entity).getFullTitleCache();
159 }
160
161
162 }