2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.group
.authority
;
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
;
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
;
28 * Editor responsible for editing authorities related to a particular {@link Group} entity.
31 * @created Mar 28, 2013
34 public class CdmAuthorityEditor
extends EditorPart
implements IConversationEnabled
, IDirtyMarkableSelectionProvider
{
36 public static final String ID
= "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
38 private boolean dirty
;
39 private ConversationHolder conversation
;
40 private CdmAuthorityCompositeViewer viewer
;
42 public CdmAuthorityEditor() {
47 * Create contents of the editor part.
51 public void createPartControl(Composite parent
) {
52 Composite container
= new Composite(parent
, SWT
.NONE
);
53 container
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
55 this.viewer
= new CdmAuthorityCompositeViewer(container
, this,((CdmAuthorityEditorInput
) getEditorInput()).getGroup());
57 conversation
= ((CdmAuthorityEditorInput
) getEditorInput()).getConversationHolder();
58 setPartName(getEditorInput().getName());
63 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
66 public void setFocus() {
71 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
74 public void doSave(IProgressMonitor monitor
) {
76 monitor
.beginTask("Saving CDM Authority Editor", 1);
77 getConversationHolder().commit(true);
79 firePropertyChange(PROP_DIRTY
);
88 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
91 public void doSaveAs() {
92 // Do the Save As operation
96 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
99 public void init(IEditorSite site
, IEditorInput input
)
100 throws PartInitException
{
106 * @see org.eclipse.ui.part.EditorPart#isDirty()
109 public boolean isDirty() {
114 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
117 public boolean isSaveAsAllowed() {
122 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
125 public void update(CdmDataChangeMap changeEvents
) {
126 // TODO Auto-generated method stub
131 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
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
) {
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);
150 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
153 public ConversationHolder
getConversationHolder() {
160 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
163 public void dispose() {
164 conversation
.unregisterForDataStoreChanges(this);
165 conversation
.close();