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
.editor
.l10n
.Messages
;
26 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
27 import eu
.etaxonomy
.taxeditor
.ui
.group
.grantedauthority
.CdmAuthorityCompositeViewer
;
30 * Editor responsible for editing authorities related to a particular {@link Group} entity.
33 * @created Mar 28, 2013
36 public class CdmAuthorityEditor
extends EditorPart
implements IConversationEnabled
, IDirtyMarkable
{
38 public static final String ID
= "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
40 private boolean dirty
;
41 private ConversationHolder conversation
;
42 private CdmAuthorityCompositeViewer viewer
;
44 public CdmAuthorityEditor() {
49 * Create contents of the editor part.
53 public void createPartControl(Composite parent
) {
54 Composite container
= new Composite(parent
, SWT
.NONE
);
55 container
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
57 this.viewer
= new CdmAuthorityCompositeViewer(container
, this,((CdmAuthorityEditorInput
) getEditorInput()).getGroup());
59 conversation
= ((CdmAuthorityEditorInput
) getEditorInput()).getConversationHolder();
60 setPartName(getEditorInput().getName());
65 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
68 public void setFocus() {
69 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();
70 ((CdmAuthorityEditorInput
) getEditorInput()).bind();
74 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
77 public void doSave(IProgressMonitor monitor
) {
79 monitor
.beginTask(Messages
.CdmAuthorityEditor_SAVING_AUTHORITY_EDITOR
, 1);
80 getConversationHolder().commit(true);
81 ((CdmAuthorityEditorInput
) getEditorInput()).merge();
83 firePropertyChange(PROP_DIRTY
);
92 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
95 public void doSaveAs() {
96 // Do the Save As operation
100 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
103 public void init(IEditorSite site
, IEditorInput input
)
104 throws PartInitException
{
110 * @see org.eclipse.ui.part.EditorPart#isDirty()
113 public boolean isDirty() {
118 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
121 public boolean isSaveAsAllowed() {
126 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
129 public void update(CdmDataChangeMap changeEvents
) {
130 // TODO Auto-generated method stub
135 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
138 public void changed(Object element
) {
139 //FIXME : should be optimised to split changes into adding / removing authorities
140 // vs updating authorites
141 dirty
= viewer
.isDirty();
142 firePropertyChange(PROP_DIRTY
);
143 // if the change has happened on the group then refresh the table
144 if(element
instanceof Group
) {
146 //FIXME: activating (setting focus) on the editor happens on every change
147 // This should be changed to only when the drop is successful
148 getSite().getPage().activate(this);
154 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
157 public void forceDirty() {
162 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
165 public ConversationHolder
getConversationHolder() {
172 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
175 public void dispose() {
176 conversation
.unregisterForDataStoreChanges(this);
177 conversation
.close();
178 ((CdmAuthorityEditorInput
) getEditorInput()).getCdmEntitySession().dispose();