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
.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
;
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
;
29 * Editor responsible for editing authorities related to a particular {@link Group} entity.
32 * @created Mar 28, 2013
35 public class CdmAuthorityEditor
extends EditorPart
implements IConversationEnabled
, IDirtyMarkable
{
37 public static final String ID
= "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
39 private boolean dirty
;
40 private ConversationHolder conversation
;
41 private CdmAuthorityCompositeViewer viewer
;
43 public CdmAuthorityEditor() {
48 * Create contents of the editor part.
52 public void createPartControl(Composite parent
) {
53 Composite container
= new Composite(parent
, SWT
.NONE
);
54 container
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
56 this.viewer
= new CdmAuthorityCompositeViewer(container
, this,((CdmAuthorityEditorInput
) getEditorInput()).getGroup());
58 conversation
= ((CdmAuthorityEditorInput
) getEditorInput()).getConversationHolder();
59 setPartName(getEditorInput().getName());
64 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
67 public void setFocus() {
68 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();
69 ((CdmAuthorityEditorInput
) getEditorInput()).bind();
73 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
76 public void doSave(IProgressMonitor monitor
) {
78 monitor
.beginTask("Saving CDM Authority Editor", 1);
79 getConversationHolder().commit(true);
80 ((CdmAuthorityEditorInput
) getEditorInput()).merge();
82 firePropertyChange(PROP_DIRTY
);
91 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
94 public void doSaveAs() {
95 // Do the Save As operation
99 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
102 public void init(IEditorSite site
, IEditorInput input
)
103 throws PartInitException
{
109 * @see org.eclipse.ui.part.EditorPart#isDirty()
112 public boolean isDirty() {
117 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
120 public boolean isSaveAsAllowed() {
125 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
128 public void update(CdmDataChangeMap changeEvents
) {
129 // TODO Auto-generated method stub
134 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
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
) {
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);
153 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
156 public void forceDirty() {
161 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
164 public ConversationHolder
getConversationHolder() {
171 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
174 public void dispose() {
175 conversation
.unregisterForDataStoreChanges(this);
176 conversation
.close();
177 ((CdmAuthorityEditorInput
) getEditorInput()).getCdmEntitySession().dispose();