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
.e4
;
11 import javax
.annotation
.PostConstruct
;
12 import javax
.annotation
.PreDestroy
;
13 import javax
.inject
.Inject
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.e4
.ui
.di
.Focus
;
17 import org
.eclipse
.e4
.ui
.di
.Persist
;
18 import org
.eclipse
.e4
.ui
.model
.application
.ui
.MDirtyable
;
19 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.layout
.FillLayout
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
28 import eu
.etaxonomy
.taxeditor
.editor
.group
.authority
.CdmAuthorityEditorInput
;
29 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
31 import eu
.etaxonomy
.taxeditor
.ui
.group
.grantedauthority
.CdmAuthorityCompositeViewer
;
34 * Editor responsible for editing authorities related to a particular {@link Group} entity.
37 * @created Mar 28, 2013
40 public class CdmAuthorityEditorE4
implements IConversationEnabled
, IDirtyMarkable
{
42 public static final String ID
= "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
45 private MDirtyable dirty
;
46 private ConversationHolder conversation
;
47 private CdmAuthorityCompositeViewer viewer
;
49 private CdmAuthorityEditorInput input
;
52 private MPart thisPart
;
54 private Composite container
;
57 public CdmAuthorityEditorE4() {
62 * Create contents of the editor part.
66 public void createPartControl(Composite parent
) {
67 container
= new Composite(parent
, SWT
.NONE
);
68 container
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
73 public void setFocus() {
80 public void doSave(IProgressMonitor monitor
) {
82 monitor
.beginTask(Messages
.CdmAuthorityEditor_SAVING_AUTHORITY_EDITOR
, 1);
83 getConversationHolder().commit(true);
85 dirty
.setDirty(false);
93 public void init(CdmAuthorityEditorInput input
) {
96 conversation
= input
.getConversationHolder();
98 this.viewer
= new CdmAuthorityCompositeViewer(container
, this,input
.getGroup());
100 thisPart
.setLabel(input
.getName());
104 public boolean isDirty() {
105 return dirty
.isDirty();
109 public void update(CdmDataChangeMap changeEvents
) {
113 public void changed(Object element
) {
114 //FIXME : should be optimised to split changes into adding / removing authorities
115 // vs updating authorites
116 dirty
.setDirty(viewer
.isDirty());
117 // if the change has happened on the group then refresh the table
118 if(element
instanceof Group
) {
119 //FIXME: activating (setting focus) on the editor happens on every change
120 // This should be changed to only when the drop is successful
121 //FIXME E4 migrate/delete
122 // getSite().getPage().activate(this);
128 public void forceDirty() {
133 public ConversationHolder
getConversationHolder() {
138 public void dispose() {
139 if(conversation
!=null){
140 conversation
.unregisterForDataStoreChanges(this);
141 conversation
.close();
145 input
.getCdmEntitySession().dispose();