Merge branch 'release/3.12.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / group / authority / CdmAuthorityEditor.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 package eu.etaxonomy.taxeditor.editor.group.authority;
10
11 import org.eclipse.core.runtime.IProgressMonitor;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.layout.FillLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IEditorSite;
17 import org.eclipse.ui.PartInitException;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.part.EditorPart;
20
21 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23 import eu.etaxonomy.cdm.model.common.Group;
24 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
25 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
26 import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
27
28 /**
29 * Editor responsible for editing authorities related to a particular {@link Group} entity.
30 *
31 * @author cmathew
32 * @created Mar 28, 2013
33 *
34 */
35 public class CdmAuthorityEditor extends EditorPart implements IConversationEnabled, IDirtyMarkable {
36
37 public static final String ID = "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
38
39 private boolean dirty;
40 private ConversationHolder conversation;
41 private CdmAuthorityCompositeViewer viewer;
42
43 public CdmAuthorityEditor() {
44
45 }
46
47 /**
48 * Create contents of the editor part.
49 * @param parent
50 */
51 @Override
52 public void createPartControl(Composite parent) {
53 Composite container = new Composite(parent, SWT.NONE);
54 container.setLayout(new FillLayout(SWT.HORIZONTAL));
55
56 this.viewer = new CdmAuthorityCompositeViewer(container, this,((CdmAuthorityEditorInput) getEditorInput()).getGroup());
57
58 conversation = ((CdmAuthorityEditorInput) getEditorInput()).getConversationHolder();
59 setPartName(getEditorInput().getName());
60
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
65 */
66 @Override
67 public void setFocus() {
68 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();
69 ((CdmAuthorityEditorInput) getEditorInput()).bind();
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
74 */
75 @Override
76 public void doSave(IProgressMonitor monitor) {
77 try {
78 monitor.beginTask("Saving CDM Authority Editor", 1);
79 getConversationHolder().commit(true);
80 ((CdmAuthorityEditorInput) getEditorInput()).merge();
81 dirty = false;
82 firePropertyChange(PROP_DIRTY);
83 monitor.worked(1);
84 } finally {
85 monitor.done();
86 viewer.save();
87 }
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
92 */
93 @Override
94 public void doSaveAs() {
95 // Do the Save As operation
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
100 */
101 @Override
102 public void init(IEditorSite site, IEditorInput input)
103 throws PartInitException {
104 setSite(site);
105 setInput(input);
106 }
107
108 /* (non-Javadoc)
109 * @see org.eclipse.ui.part.EditorPart#isDirty()
110 */
111 @Override
112 public boolean isDirty() {
113 return dirty;
114 }
115
116 /* (non-Javadoc)
117 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
118 */
119 @Override
120 public boolean isSaveAsAllowed() {
121 return false;
122 }
123
124 /* (non-Javadoc)
125 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
126 */
127 @Override
128 public void update(CdmDataChangeMap changeEvents) {
129 // TODO Auto-generated method stub
130
131 }
132
133 /* (non-Javadoc)
134 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
135 */
136 @Override
137 public void changed(Object element) {
138 //FIXME : should be optimised to split changes into adding / removing authorities
139 // vs updating authorites
140 dirty = viewer.isDirty();
141 firePropertyChange(PROP_DIRTY);
142 // if the change has happened on the group then refresh the table
143 if(element instanceof Group) {
144
145 //FIXME: activating (setting focus) on the editor happens on every change
146 // This should be changed to only when the drop is successful
147 getSite().getPage().activate(this);
148 }
149
150 }
151
152 /* (non-Javadoc)
153 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
154 */
155 @Override
156 public void forceDirty() {
157 changed(null);
158 }
159
160 /* (non-Javadoc)
161 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
162 */
163 @Override
164 public ConversationHolder getConversationHolder() {
165 return conversation;
166 }
167
168 /*
169 * (non-Javadoc)
170 *
171 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
172 */
173 @Override
174 public void dispose() {
175 conversation.unregisterForDataStoreChanges(this);
176 conversation.close();
177 ((CdmAuthorityEditorInput) getEditorInput()).getCdmEntitySession().dispose();
178 super.dispose();
179 }
180 }