a5bf4e6bedcf4aa0357509d06b8f6214c8ea451c
[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 }
70
71 /* (non-Javadoc)
72 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
73 */
74 @Override
75 public void doSave(IProgressMonitor monitor) {
76 try {
77 monitor.beginTask("Saving CDM Authority Editor", 1);
78 getConversationHolder().commit(true);
79 dirty = false;
80 firePropertyChange(PROP_DIRTY);
81 monitor.worked(1);
82 } finally {
83 monitor.done();
84 viewer.save();
85 }
86 }
87
88 /* (non-Javadoc)
89 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
90 */
91 @Override
92 public void doSaveAs() {
93 // Do the Save As operation
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
98 */
99 @Override
100 public void init(IEditorSite site, IEditorInput input)
101 throws PartInitException {
102 setSite(site);
103 setInput(input);
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.ui.part.EditorPart#isDirty()
108 */
109 @Override
110 public boolean isDirty() {
111 return dirty;
112 }
113
114 /* (non-Javadoc)
115 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
116 */
117 @Override
118 public boolean isSaveAsAllowed() {
119 return false;
120 }
121
122 /* (non-Javadoc)
123 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
124 */
125 @Override
126 public void update(CdmDataChangeMap changeEvents) {
127 // TODO Auto-generated method stub
128
129 }
130
131 /* (non-Javadoc)
132 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
133 */
134 @Override
135 public void changed(Object element) {
136 //FIXME : should be optimised to split changes into adding / removing authorities
137 // vs updating authorites
138 dirty = viewer.isDirty();
139 firePropertyChange(PROP_DIRTY);
140 // if the change has happened on the group then refresh the table
141 if(element instanceof Group) {
142
143 //FIXME: activating (setting focus) on the editor happens on every change
144 // This should be changed to only when the drop is successful
145 getSite().getPage().activate(this);
146 }
147
148 }
149
150 /* (non-Javadoc)
151 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
152 */
153 @Override
154 public void forceDirty() {
155 changed(null);
156 }
157
158 /* (non-Javadoc)
159 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
160 */
161 @Override
162 public ConversationHolder getConversationHolder() {
163 return conversation;
164 }
165
166 /*
167 * (non-Javadoc)
168 *
169 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
170 */
171 @Override
172 public void dispose() {
173 conversation.unregisterForDataStoreChanges(this);
174 conversation.close();
175 super.dispose();
176 }
177 }