Project

General

Profile

Download (3.92 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.permission.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

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

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

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

    
96
        conversation = input.getConversationHolder();
97

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

    
100
        thisPart.setLabel(input.getName());
101
        container.layout();
102
	}
103

    
104
	public boolean isDirty() {
105
		return dirty.isDirty();
106
	}
107

    
108
    public CdmAuthorityEditorInput getInput() {
109
        return input;
110
    }
111

    
112
	@Override
113
	public void update(CdmDataChangeMap changeEvents) {
114
	}
115

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

    
129
	}
130

    
131
	@Override
132
	public void forceDirty() {
133
	    changed(null);
134
	}
135

    
136
	@Override
137
	public ConversationHolder getConversationHolder() {
138
		return conversation;
139
	}
140

    
141
	@PreDestroy
142
	public void dispose() {
143
	    if(conversation!=null){
144
	        conversation.unregisterForDataStoreChanges(this);
145
	        conversation.close();
146
	        conversation = null;
147
	    }
148
		if(input!=null){
149
		    input.getCdmEntitySession().dispose();
150
		}
151
		dirty.setDirty(false);
152
	}
153
}
    (1-1/1)