Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.molecular / src / main / java / eu / etaxonomy / taxeditor / molecular / editor / AlignmentEditorInput.java
1 /**
2 * Copyright (C) 2014 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 package eu.etaxonomy.taxeditor.molecular.editor;
10
11
12 import java.util.Arrays;
13 import java.util.List;
14 import java.util.UUID;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.ui.IEditorInput;
18 import org.eclipse.ui.IPersistableElement;
19
20 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
21 import eu.etaxonomy.cdm.model.molecular.Sequence;
22 import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25
26
27 /**
28 * @author pplitzner
29 * @author Ben Stöver
30 * @date 04.08.2014
31 */
32 public class AlignmentEditorInput extends CdmEntitySessionInput implements IEditorInput {
33 private static final String name = "AlignmentEditor";
34
35
36 private final UUID sequenceNodeUuid;
37 private Sequence sequenceNode;
38
39 public AlignmentEditorInput(UUID sequenceNodeUuid) {
40 super(false);
41 this.sequenceNodeUuid = sequenceNodeUuid;
42 initSession();
43 }
44
45
46 /* (non-Javadoc)
47 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
48 */
49 @Override
50 public Object getAdapter(Class adapter) {
51 // TODO Auto-generated method stub
52 return null;
53 }
54
55
56 /* (non-Javadoc)
57 * @see org.eclipse.ui.IEditorInput#exists()
58 */
59 @Override
60 public boolean exists() {
61 // TODO Auto-generated method stub
62 return false;
63 }
64
65
66 /* (non-Javadoc)
67 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
68 */
69 @Override
70 public ImageDescriptor getImageDescriptor() {
71 // TODO Auto-generated method stub
72 return null;
73 }
74
75
76 /* (non-Javadoc)
77 * @see org.eclipse.ui.IEditorInput#getName()
78 */
79 @Override
80 public String getName() {
81 return name;
82 }
83
84
85 /* (non-Javadoc)
86 * @see org.eclipse.ui.IEditorInput#getPersistable()
87 */
88 @Override
89 public IPersistableElement getPersistable() {
90 return null;
91 }
92
93
94 /* (non-Javadoc)
95 * @see org.eclipse.ui.IEditorInput#getToolTipText()
96 */
97 @Override
98 public String getToolTipText() {
99 return name;
100 }
101
102
103 /**
104 * Returns the {@link UUID} of the sequence CDM node that should be edited by the {@link AlignmentEditor} this object
105 * is used with.
106 *
107 * @return the uuid of the CDM node to work on
108 */
109 public UUID getSequenceNodeUuid() {
110 return sequenceNodeUuid;
111 }
112
113
114 @Override
115 public int hashCode() {
116 final int prime = 31;
117 int result = 1;
118 result = prime * result
119 + ((sequenceNodeUuid == null) ? 0 : sequenceNodeUuid.hashCode());
120 return result;
121 }
122
123
124 @Override
125 public boolean equals(Object obj) {
126 if (this == obj) {
127 return true;
128 }
129 if (obj == null) {
130 return false;
131 }
132 if (getClass() != obj.getClass()) {
133 return false;
134 }
135 AlignmentEditorInput other = (AlignmentEditorInput) obj;
136 if (sequenceNodeUuid == null) {
137 if (other.sequenceNodeUuid != null) {
138 return false;
139 }
140 } else if (!sequenceNodeUuid.equals(other.sequenceNodeUuid)) {
141 return false;
142 }
143 return true;
144 }
145
146
147 public void setSequenceNode(Sequence sequenceNode) {
148 this.sequenceNode = sequenceNode;
149 }
150
151 /* (non-Javadoc)
152 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
153 */
154 @Override
155 public List<Sequence> getRootEntities() {
156 return Arrays.asList(sequenceNode);
157 }
158
159
160 /* (non-Javadoc)
161 * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
162 */
163 @Override
164 public void merge() {
165 CdmStore.getService(ISequenceService.class).merge(sequenceNode, true);
166
167 }
168 }