Project

General

Profile

Download (3.79 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.taxeditor.editor.group.authority.e4;
10

    
11
import javax.annotation.PostConstruct;
12
import javax.annotation.PreDestroy;
13
import javax.inject.Inject;
14

    
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;
23

    
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;
32

    
33
/**
34
 * Editor responsible for editing authorities related to a particular {@link Group} entity.
35
 *
36
 * @author cmathew
37
 * @created Mar 28, 2013
38
 *
39
 */
40
public class CdmAuthorityEditorE4 implements IConversationEnabled, IDirtyMarkable {
41

    
42
	public static final String ID = "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
43

    
44
	@Inject
45
	private MDirtyable dirty;
46
	private ConversationHolder conversation;
47
	private CdmAuthorityCompositeViewer viewer;
48

    
49
	private CdmAuthorityEditorInput input;
50

    
51
	@Inject
52
	private MPart thisPart;
53

    
54
    private Composite container;
55

    
56
	@Inject
57
	public CdmAuthorityEditorE4() {
58

    
59
	}
60

    
61
	/**
62
	 * Create contents of the editor part.
63
	 * @param parent
64
	 */
65
	@PostConstruct
66
	public void createPartControl(Composite parent) {
67
		container = new Composite(parent, SWT.NONE);
68
		container.setLayout(new FillLayout(SWT.HORIZONTAL));
69
	}
70

    
71
	@Focus
72
	public void setFocus() {
73
	    if(input!=null){
74
	        input.bind();
75
	    }
76
	}
77

    
78
	@Persist
79
	public void doSave(IProgressMonitor monitor) {
80
		try {
81
			monitor.beginTask(Messages.CdmAuthorityEditor_SAVING_AUTHORITY_EDITOR, 1);
82
			getConversationHolder().commit(true);
83
			input.merge();
84
			dirty.setDirty(false);
85
			monitor.worked(1);
86
		} finally {
87
			monitor.done();
88
			viewer.save();
89
		}
90
	}
91

    
92
	public void init(CdmAuthorityEditorInput input) {
93
	    this.input = input;
94

    
95
        conversation = input.getConversationHolder();
96

    
97
        this.viewer = new CdmAuthorityCompositeViewer(container, this,input.getGroup());
98

    
99
        thisPart.setLabel(input.getName());
100
	}
101

    
102
	public boolean isDirty() {
103
		return dirty.isDirty();
104
	}
105

    
106
	@Override
107
	public void update(CdmDataChangeMap changeEvents) {
108
	}
109

    
110
	@Override
111
	public void changed(Object element) {
112
		//FIXME : should be optimised to split changes into adding / removing authorities
113
		//        vs updating authorites
114
		dirty.setDirty(viewer.isDirty());
115
		// if the change has happened on the group then refresh the table
116
		if(element instanceof Group) {
117
			//FIXME: activating (setting focus) on the editor happens on every change
118
			//       This should be changed to only when the drop is successful
119
		    //FIXME E4 migrate/delete
120
//			getSite().getPage().activate(this);
121
		}
122

    
123
	}
124

    
125
	@Override
126
	public void forceDirty() {
127
	    changed(null);
128
	}
129

    
130
	@Override
131
	public ConversationHolder getConversationHolder() {
132
		return conversation;
133
	}
134

    
135
	@PreDestroy
136
	public void dispose() {
137
	    if(conversation!=null){
138
	        conversation.unregisterForDataStoreChanges(this);
139
	        conversation.close();
140
	        conversation = null;
141
	    }
142
		if(input!=null){
143
		    input.getCdmEntitySession().dispose();
144
		}
145
	}
146
}
    (1-1/1)