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();
72 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
75 public void doSave(IProgressMonitor monitor
) {
77 monitor
.beginTask("Saving CDM Authority Editor", 1);
78 getConversationHolder().commit(true);
80 firePropertyChange(PROP_DIRTY
);
89 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
92 public void doSaveAs() {
93 // Do the Save As operation
97 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
100 public void init(IEditorSite site
, IEditorInput input
)
101 throws PartInitException
{
107 * @see org.eclipse.ui.part.EditorPart#isDirty()
110 public boolean isDirty() {
115 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
118 public boolean isSaveAsAllowed() {
123 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
126 public void update(CdmDataChangeMap changeEvents
) {
127 // TODO Auto-generated method stub
132 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
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
) {
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);
151 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
154 public void forceDirty() {
159 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
162 public ConversationHolder
getConversationHolder() {
169 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
172 public void dispose() {
173 conversation
.unregisterForDataStoreChanges(this);
174 conversation
.close();