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