Project

General

Profile

Download (3.34 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.model.permission.Group;
25
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
26
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
27
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
28
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
29
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
30

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

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

    
42
	@Inject
43
	private MDirtyable dirty;
44
	private CdmAuthorityCompositeViewer viewer;
45

    
46
	private CdmAuthorityEditorInput input;
47

    
48
	@Inject
49
	private MPart thisPart;
50

    
51
    private Composite container;
52

    
53
	@Inject
54
	public CdmAuthorityEditorE4() {
55

    
56
	}
57

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

    
67
	}
68

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

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

    
89
	public void init(CdmAuthorityEditorInput input) {
90
	    this.input = input;
91
        this.viewer = new CdmAuthorityCompositeViewer(container, this,input.getGroup());
92

    
93
        thisPart.setLabel(input.getName());
94
        container.layout();
95
	}
96

    
97
	public boolean isDirty() {
98
		return dirty.isDirty();
99
	}
100

    
101
    public CdmAuthorityEditorInput getInput() {
102
        return input;
103
    }
104

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

    
118
	}
119

    
120
	@Override
121
	public void forceDirty() {
122
	    changed(null);
123
	}
124

    
125
	@PreDestroy
126
	public void dispose() {
127
	    
128
		if(input!=null){
129
		    input.getCdmEntitySession().dispose();
130
		}
131
		dirty.setDirty(false);
132
	}
133
}
    (1-1/1)