Revision be9600f6
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditor.java | ||
---|---|---|
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; |
|
10 |
|
|
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; |
|
20 |
|
|
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; |
|
28 |
|
|
29 |
/** |
|
30 |
* Editor responsible for editing authorities related to a particular {@link Group} entity. |
|
31 |
* |
|
32 |
* @author cmathew |
|
33 |
* @created Mar 28, 2013 |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class CdmAuthorityEditor extends EditorPart implements IConversationEnabled, IDirtyMarkable { |
|
37 |
|
|
38 |
public static final String ID = "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$ |
|
39 |
|
|
40 |
private boolean dirty; |
|
41 |
private ConversationHolder conversation; |
|
42 |
private CdmAuthorityCompositeViewer viewer; |
|
43 |
|
|
44 |
public CdmAuthorityEditor() { |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* Create contents of the editor part. |
|
50 |
* @param parent |
|
51 |
*/ |
|
52 |
@Override |
|
53 |
public void createPartControl(Composite parent) { |
|
54 |
Composite container = new Composite(parent, SWT.NONE); |
|
55 |
container.setLayout(new FillLayout(SWT.HORIZONTAL)); |
|
56 |
|
|
57 |
this.viewer = new CdmAuthorityCompositeViewer(container, this,((CdmAuthorityEditorInput) getEditorInput()).getGroup()); |
|
58 |
|
|
59 |
conversation = ((CdmAuthorityEditorInput) getEditorInput()).getConversationHolder(); |
|
60 |
setPartName(getEditorInput().getName()); |
|
61 |
|
|
62 |
} |
|
63 |
|
|
64 |
/* (non-Javadoc) |
|
65 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
66 |
*/ |
|
67 |
@Override |
|
68 |
public void setFocus() { |
|
69 |
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus(); |
|
70 |
((CdmAuthorityEditorInput) getEditorInput()).bind(); |
|
71 |
} |
|
72 |
|
|
73 |
/* (non-Javadoc) |
|
74 |
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) |
|
75 |
*/ |
|
76 |
@Override |
|
77 |
public void doSave(IProgressMonitor monitor) { |
|
78 |
try { |
|
79 |
monitor.beginTask(Messages.CdmAuthorityEditor_SAVING_AUTHORITY_EDITOR, 1); |
|
80 |
getConversationHolder().commit(true); |
|
81 |
((CdmAuthorityEditorInput) getEditorInput()).merge(); |
|
82 |
dirty = false; |
|
83 |
firePropertyChange(PROP_DIRTY); |
|
84 |
monitor.worked(1); |
|
85 |
} finally { |
|
86 |
monitor.done(); |
|
87 |
viewer.save(); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
/* (non-Javadoc) |
|
92 |
* @see org.eclipse.ui.part.EditorPart#doSaveAs() |
|
93 |
*/ |
|
94 |
@Override |
|
95 |
public void doSaveAs() { |
|
96 |
// Do the Save As operation |
|
97 |
} |
|
98 |
|
|
99 |
/* (non-Javadoc) |
|
100 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) |
|
101 |
*/ |
|
102 |
@Override |
|
103 |
public void init(IEditorSite site, IEditorInput input) |
|
104 |
throws PartInitException { |
|
105 |
setSite(site); |
|
106 |
setInput(input); |
|
107 |
} |
|
108 |
|
|
109 |
/* (non-Javadoc) |
|
110 |
* @see org.eclipse.ui.part.EditorPart#isDirty() |
|
111 |
*/ |
|
112 |
@Override |
|
113 |
public boolean isDirty() { |
|
114 |
return dirty; |
|
115 |
} |
|
116 |
|
|
117 |
/* (non-Javadoc) |
|
118 |
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() |
|
119 |
*/ |
|
120 |
@Override |
|
121 |
public boolean isSaveAsAllowed() { |
|
122 |
return false; |
|
123 |
} |
|
124 |
|
|
125 |
/* (non-Javadoc) |
|
126 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
127 |
*/ |
|
128 |
@Override |
|
129 |
public void update(CdmDataChangeMap changeEvents) { |
|
130 |
// TODO Auto-generated method stub |
|
131 |
|
|
132 |
} |
|
133 |
|
|
134 |
/* (non-Javadoc) |
|
135 |
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object) |
|
136 |
*/ |
|
137 |
@Override |
|
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) { |
|
145 |
|
|
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); |
|
149 |
} |
|
150 |
|
|
151 |
} |
|
152 |
|
|
153 |
/* (non-Javadoc) |
|
154 |
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty() |
|
155 |
*/ |
|
156 |
@Override |
|
157 |
public void forceDirty() { |
|
158 |
changed(null); |
|
159 |
} |
|
160 |
|
|
161 |
/* (non-Javadoc) |
|
162 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
163 |
*/ |
|
164 |
@Override |
|
165 |
public ConversationHolder getConversationHolder() { |
|
166 |
return conversation; |
|
167 |
} |
|
168 |
|
|
169 |
/* |
|
170 |
* (non-Javadoc) |
|
171 |
* |
|
172 |
* @see org.eclipse.ui.forms.editor.FormEditor#dispose() |
|
173 |
*/ |
|
174 |
@Override |
|
175 |
public void dispose() { |
|
176 |
conversation.unregisterForDataStoreChanges(this); |
|
177 |
conversation.close(); |
|
178 |
((CdmAuthorityEditorInput) getEditorInput()).getCdmEntitySession().dispose(); |
|
179 |
super.dispose(); |
|
180 |
} |
|
181 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/e4/handler/EditCdmAuthoritiesHandlerE4.java | ||
---|---|---|
21 | 21 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
22 | 22 |
import eu.etaxonomy.cdm.model.common.Group; |
23 | 23 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
24 |
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor; |
|
25 | 24 |
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput; |
25 |
import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4; |
|
26 | 26 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
27 | 27 |
|
28 | 28 |
/** |
29 |
* Handler which opens an instance of the {@link CdmAuthorityEditor} for a2 |
|
29 |
* Handler which opens an instance of the {@link CdmAuthorityEditorE4} for a2
|
|
30 | 30 |
* particluar group. |
31 | 31 |
* |
32 | 32 |
* @author cmathew |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java | ||
---|---|---|
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.handler; |
|
10 |
|
|
11 |
import org.eclipse.core.commands.AbstractHandler; |
|
12 |
import org.eclipse.core.commands.ExecutionEvent; |
|
13 |
import org.eclipse.core.commands.ExecutionException; |
|
14 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
15 |
import org.eclipse.core.runtime.IStatus; |
|
16 |
import org.eclipse.core.runtime.Status; |
|
17 |
import org.eclipse.core.runtime.jobs.Job; |
|
18 |
import org.eclipse.jface.viewers.ISelection; |
|
19 |
import org.eclipse.swt.widgets.Display; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.common.Group; |
|
22 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
23 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
24 |
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor; |
|
25 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
26 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
27 |
import eu.etaxonomy.taxeditor.model.LineSelection; |
|
28 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
29 |
|
|
30 |
|
|
31 |
/** |
|
32 |
* Handler which opens an instance of the {@link CdmAuthorityEditor} for a particluar group. |
|
33 |
* |
|
34 |
* @author cmathew |
|
35 |
* @created Mar 28, 2013 |
|
36 |
* |
|
37 |
*/ |
|
38 |
|
|
39 |
public class EditCdmAuthoritiesHandler extends AbstractHandler { |
|
40 |
|
|
41 |
private static final String OPENING_CDM_AUTHORITIES = Messages.EditCdmAuthoritiesHandler_OPEN_AUTHORITIES; |
|
42 |
|
|
43 |
/* (non-Javadoc) |
|
44 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
45 |
*/ |
|
46 |
@Override |
|
47 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
48 |
BulkEditor editor = (BulkEditor) AbstractUtility.getActiveEditor(); |
|
49 |
|
|
50 |
ISelection selection = editor.getSite().getSelectionProvider().getSelection(); |
|
51 |
if(selection instanceof LineSelection){ |
|
52 |
|
|
53 |
final LineSelection lineSelection = (LineSelection) selection; |
|
54 |
|
|
55 |
Job job = new Job(OPENING_CDM_AUTHORITIES){ |
|
56 |
|
|
57 |
@Override |
|
58 |
protected IStatus run(IProgressMonitor monitor) { |
|
59 |
monitor.beginTask(OPENING_CDM_AUTHORITIES, lineSelection.size()); |
|
60 |
|
|
61 |
for(final Object selectedObject : lineSelection.toArray()){ |
|
62 |
if(selectedObject instanceof Group){ |
|
63 |
|
|
64 |
Display.getDefault().asyncExec(new Runnable(){ |
|
65 |
|
|
66 |
@Override |
|
67 |
public void run() { |
|
68 |
try { |
|
69 |
// EditorUtil.openCdmAuthorities(((Group)selectedObject).getUuid()); |
|
70 |
} catch (Exception e) { |
|
71 |
MessagingUtils.warningDialog(Messages.EditCdmAuthoritiesHandler_COULD_NOT_OPEN_AUTHORITIES, EditorUtil.class, e.getMessage()); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
}); |
|
76 |
monitor.worked(1); |
|
77 |
} |
|
78 |
} |
|
79 |
monitor.done(); |
|
80 |
return Status.OK_STATUS; |
|
81 |
} |
|
82 |
|
|
83 |
}; |
|
84 |
|
|
85 |
job.setPriority(Job.SHORT); |
|
86 |
job.schedule(); |
|
87 |
|
|
88 |
} |
|
89 |
return null; |
|
90 |
} |
|
91 |
|
|
92 |
} |
|
93 |
|
Also available in: Unified diff
ref #6913 Remove authority editor