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
|
package eu.etaxonomy.taxeditor.editor.group.authority;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.Collection;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.jface.resource.ImageDescriptor;
|
16
|
import org.eclipse.ui.IEditorInput;
|
17
|
import org.eclipse.ui.IPersistableElement;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
22
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
23
|
import eu.etaxonomy.cdm.model.common.Group;
|
24
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
25
|
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* Editor input for the {@link CdmAuthorityEditor}.
|
30
|
*
|
31
|
* @author cmathew
|
32
|
* @created Mar 28, 2013
|
33
|
*
|
34
|
*/
|
35
|
|
36
|
public class CdmAuthorityEditorInput extends CdmEntitySessionInput implements IEditorInput, IConversationEnabled {
|
37
|
private ConversationHolder conversation;
|
38
|
private Group group;
|
39
|
|
40
|
protected CdmAuthorityEditorInput(ConversationHolder conversation, Group group) {
|
41
|
super(true);
|
42
|
this.conversation = conversation;
|
43
|
this.group = CdmApplicationState.getCurrentAppConfig().getGroupService().load(group.getUuid());
|
44
|
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Creates a new instance of the input for a given group.
|
49
|
*
|
50
|
* @param groupUuid
|
51
|
* @return
|
52
|
* @throws Exception
|
53
|
*/
|
54
|
public static CdmAuthorityEditorInput NewInstance(UUID groupUuid) throws Exception{
|
55
|
ConversationHolder conversation = CdmStore.createConversation();
|
56
|
Group group = CdmStore.getService(IGroupService.class).load(groupUuid, null);
|
57
|
return new CdmAuthorityEditorInput(conversation, group);
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
62
|
*/
|
63
|
@Override
|
64
|
public Object getAdapter(Class adapter) {
|
65
|
if (adapter == Group.class) {
|
66
|
return this.group;
|
67
|
}
|
68
|
|
69
|
return null;
|
70
|
}
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
73
|
*/
|
74
|
@Override
|
75
|
public void update(CdmDataChangeMap changeEvents) {
|
76
|
// TODO Auto-generated method stub
|
77
|
|
78
|
}
|
79
|
/* (non-Javadoc)
|
80
|
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
|
81
|
*/
|
82
|
@Override
|
83
|
public ConversationHolder getConversationHolder() {
|
84
|
return this.conversation;
|
85
|
}
|
86
|
/* (non-Javadoc)
|
87
|
* @see org.eclipse.ui.IEditorInput#exists()
|
88
|
*/
|
89
|
@Override
|
90
|
public boolean exists() {
|
91
|
return group != null;
|
92
|
}
|
93
|
/* (non-Javadoc)
|
94
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
95
|
*/
|
96
|
@Override
|
97
|
public ImageDescriptor getImageDescriptor() {
|
98
|
// TODO Auto-generated method stub
|
99
|
return null;
|
100
|
}
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.ui.IEditorInput#getName()
|
103
|
*/
|
104
|
@Override
|
105
|
public String getName() {
|
106
|
return group.getName();
|
107
|
}
|
108
|
/* (non-Javadoc)
|
109
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
110
|
*/
|
111
|
@Override
|
112
|
public IPersistableElement getPersistable() {
|
113
|
// TODO Auto-generated method stub
|
114
|
return null;
|
115
|
}
|
116
|
/* (non-Javadoc)
|
117
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
118
|
*/
|
119
|
@Override
|
120
|
public String getToolTipText() {
|
121
|
return getName();
|
122
|
}
|
123
|
|
124
|
/* (non-Javadoc)
|
125
|
* @see java.lang.Object#equals(java.lang.Object)
|
126
|
*/
|
127
|
@Override
|
128
|
public boolean equals(Object object) {
|
129
|
if (object instanceof CdmAuthorityEditorInput
|
130
|
&& getGroup() != null
|
131
|
&& getGroup().equals(((CdmAuthorityEditorInput) object).getGroup())
|
132
|
){
|
133
|
return true;
|
134
|
}
|
135
|
return super.equals(object);
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Getter method for group member.
|
140
|
*
|
141
|
* @return
|
142
|
*/
|
143
|
public Group getGroup() {
|
144
|
return this.group;
|
145
|
}
|
146
|
|
147
|
/* (non-Javadoc)
|
148
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
149
|
*/
|
150
|
@Override
|
151
|
public Collection<Group> getRootEntities() {
|
152
|
return Arrays.asList(group);
|
153
|
}
|
154
|
|
155
|
/* (non-Javadoc)
|
156
|
* @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
|
157
|
*/
|
158
|
@Override
|
159
|
public void merge() {
|
160
|
if(CdmStore.getCurrentSessionManager().isRemoting()) {
|
161
|
group = CdmStore.getService(IGroupService.class).merge(group, true);
|
162
|
}
|
163
|
}
|
164
|
}
|