Revision 06aef3d4
Added by Patrick Plitzner almost 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractGraphKeyEditor.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.key; |
|
5 |
|
|
6 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
7 |
import org.eclipse.jface.action.GroupMarker; |
|
8 |
import org.eclipse.jface.action.IToolBarManager; |
|
9 |
import org.eclipse.jface.action.MenuManager; |
|
10 |
import org.eclipse.jface.viewers.IBaseLabelProvider; |
|
11 |
import org.eclipse.jface.viewers.IContentProvider; |
|
12 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
13 |
import org.eclipse.swt.SWT; |
|
14 |
import org.eclipse.swt.events.ControlEvent; |
|
15 |
import org.eclipse.swt.events.ControlListener; |
|
16 |
import org.eclipse.swt.layout.FillLayout; |
|
17 |
import org.eclipse.swt.widgets.Composite; |
|
18 |
import org.eclipse.swt.widgets.Control; |
|
19 |
import org.eclipse.swt.widgets.Menu; |
|
20 |
import org.eclipse.ui.IEditorInput; |
|
21 |
import org.eclipse.ui.IEditorSite; |
|
22 |
import org.eclipse.ui.IWorkbenchActionConstants; |
|
23 |
import org.eclipse.ui.PartInitException; |
|
24 |
import org.eclipse.ui.part.EditorPart; |
|
25 |
import org.eclipse.zest.core.viewers.AbstractZoomableViewer; |
|
26 |
import org.eclipse.zest.core.viewers.GraphViewer; |
|
27 |
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart; |
|
28 |
import org.eclipse.zest.core.viewers.ZoomContributionViewItem; |
|
29 |
import org.eclipse.zest.core.widgets.ZestStyles; |
|
30 |
import org.eclipse.zest.layouts.LayoutAlgorithm; |
|
31 |
import org.eclipse.zest.layouts.LayoutStyles; |
|
32 |
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; |
|
33 |
|
|
34 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
35 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
36 |
import eu.etaxonomy.cdm.model.description.IIdentificationKey; |
|
37 |
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; |
|
38 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
39 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
|
40 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
41 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
|
42 |
|
|
43 |
/** |
|
44 |
* @author n.hoffmann |
|
45 |
* |
|
46 |
*/ |
|
47 |
public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey> |
|
48 |
extends EditorPart implements IConversationEnabled, |
|
49 |
IZoomableWorkbenchPart, IPostOperationEnabled, |
|
50 |
IDirtyMarkable { |
|
51 |
|
|
52 |
private CdmFormFactory formFactory; |
|
53 |
private Composite container; |
|
54 |
protected GraphViewer viewer; |
|
55 |
|
|
56 |
private LayoutAlgorithm layoutAlgoritm; |
|
57 |
private ZoomContributionViewItem zoomContributionViewItem; |
|
58 |
|
|
59 |
private boolean dirty = false; |
|
60 |
private IToolBarManager toolBarManager; |
|
61 |
|
|
62 |
/* |
|
63 |
* (non-Javadoc) |
|
64 |
* |
|
65 |
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime. |
|
66 |
* IProgressMonitor) |
|
67 |
*/ |
|
68 |
@Override |
|
69 |
public void doSave(IProgressMonitor monitor) { |
|
70 |
getConversationHolder().commit(true); |
|
71 |
setDirty(false); |
|
72 |
viewer.refresh(); |
|
73 |
} |
|
74 |
|
|
75 |
/* |
|
76 |
* (non-Javadoc) |
|
77 |
* |
|
78 |
* @see org.eclipse.ui.part.EditorPart#doSaveAs() |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public void doSaveAs() { |
|
82 |
doSave(null); |
|
83 |
} |
|
84 |
|
|
85 |
/* |
|
86 |
* (non-Javadoc) |
|
87 |
* |
|
88 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, |
|
89 |
* org.eclipse.ui.IEditorInput) |
|
90 |
*/ |
|
91 |
@Override |
|
92 |
public void init(IEditorSite site, IEditorInput input) |
|
93 |
throws PartInitException { |
|
94 |
setSite(site); |
|
95 |
setInput(input); |
|
96 |
// formFactory = new CdmFormFactory(site.getShell().getDisplay()); |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* |
|
102 |
* @see org.eclipse.ui.part.EditorPart#isDirty() |
|
103 |
*/ |
|
104 |
@Override |
|
105 |
public boolean isDirty() { |
|
106 |
return dirty; |
|
107 |
} |
|
108 |
|
|
109 |
/* |
|
110 |
* (non-Javadoc) |
|
111 |
* |
|
112 |
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() |
|
113 |
*/ |
|
114 |
@Override |
|
115 |
public boolean isSaveAsAllowed() { |
|
116 |
return false; |
|
117 |
} |
|
118 |
|
|
119 |
/* |
|
120 |
* (non-Javadoc) |
|
121 |
* |
|
122 |
* @see |
|
123 |
* org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets |
|
124 |
* .Composite) |
|
125 |
*/ |
|
126 |
@Override |
|
127 |
public void createPartControl(Composite parent) { |
|
128 |
container = formFactory.createComposite(parent); |
|
129 |
|
|
130 |
container.setLayout(new FillLayout()); |
|
131 |
viewer = new GraphViewer(container, SWT.NONE); |
|
132 |
getSite().setSelectionProvider(viewer); |
|
133 |
|
|
134 |
viewer.setContentProvider(getContentProvider()); |
|
135 |
viewer.setLabelProvider(getLabelProvider()); |
|
136 |
|
|
137 |
viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); |
|
138 |
|
|
139 |
viewer.setLayoutAlgorithm(getLayoutAlgoritm(), false); |
|
140 |
|
|
141 |
createMenu(); |
|
142 |
|
|
143 |
createToolbar(); |
|
144 |
|
|
145 |
viewer.setInput(getKey()); |
|
146 |
|
|
147 |
container.addControlListener(new ControlListener() { |
|
148 |
|
|
149 |
@Override |
|
150 |
public void controlResized(ControlEvent e) { |
|
151 |
// applyLayout(); |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public void controlMoved(ControlEvent e) { |
|
156 |
// TODO Auto-generated method stub |
|
157 |
|
|
158 |
} |
|
159 |
}); |
|
160 |
} |
|
161 |
|
|
162 |
private void createToolbar() { |
|
163 |
getToolBarManager().add(getZoomContributionViewItem()); |
|
164 |
} |
|
165 |
|
|
166 |
private void createMenu() { |
|
167 |
// Add context menu to tree |
|
168 |
MenuManager menuMgr = new MenuManager(); |
|
169 |
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
170 |
|
|
171 |
// MenuManager zoomMenu = new MenuManager("Zoom"); |
|
172 |
// zoomMenu.add(getZoomContributionViewItem()); |
|
173 |
|
|
174 |
ZoomContributionViewItem zoomItem = getZoomContributionViewItem(); |
|
175 |
menuMgr.add(zoomItem); |
|
176 |
getSite().registerContextMenu(menuMgr, viewer); |
|
177 |
|
|
178 |
Control control = viewer.getGraphControl(); |
|
179 |
Menu menu = menuMgr.createContextMenu(control); |
|
180 |
|
|
181 |
control.setMenu(menu); |
|
182 |
|
|
183 |
} |
|
184 |
|
|
185 |
protected abstract IBaseLabelProvider getLabelProvider(); |
|
186 |
|
|
187 |
protected abstract IContentProvider getContentProvider(); |
|
188 |
|
|
189 |
/** |
|
190 |
* Return the key that this editor |
|
191 |
* |
|
192 |
* @return |
|
193 |
*/ |
|
194 |
public abstract T getKey(); |
|
195 |
|
|
196 |
@Override |
|
197 |
public void setFocus() { |
|
198 |
viewer.getControl().setFocus(); |
|
199 |
} |
|
200 |
|
|
201 |
public void refresh() { |
|
202 |
viewer.refresh(); |
|
203 |
// graphViewer.applyLayout(); |
|
204 |
} |
|
205 |
|
|
206 |
@Override |
|
207 |
public void update(CdmDataChangeMap changeEvents) { |
|
208 |
|
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 |
public AbstractZoomableViewer getZoomableViewer() { |
|
213 |
return viewer; |
|
214 |
} |
|
215 |
|
|
216 |
private LayoutAlgorithm getLayoutAlgoritm() { |
|
217 |
if (layoutAlgoritm == null) { |
|
218 |
// layoutAlgoritm = new CompositeLayoutAlgorithm( |
|
219 |
// LayoutStyles.NO_LAYOUT_NODE_RESIZING, |
|
220 |
// new LayoutAlgorithm[] { |
|
221 |
// new TreeLayoutAlgorithm( |
|
222 |
// LayoutStyles.NO_LAYOUT_NODE_RESIZING), |
|
223 |
// new HorizontalShift( |
|
224 |
// LayoutStyles.NO_LAYOUT_NODE_RESIZING) }); |
|
225 |
|
|
226 |
layoutAlgoritm = new TreeLayoutAlgorithm( |
|
227 |
LayoutStyles.NO_LAYOUT_NODE_RESIZING); |
|
228 |
layoutAlgoritm.setEntityAspectRatio(0.5); |
|
229 |
} |
|
230 |
return layoutAlgoritm; |
|
231 |
} |
|
232 |
|
|
233 |
private ZoomContributionViewItem getZoomContributionViewItem() { |
|
234 |
if (zoomContributionViewItem == null) { |
|
235 |
zoomContributionViewItem = new ZoomContributionViewItem(this); |
|
236 |
} |
|
237 |
return new ZoomContributionViewItem(this); |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
242 |
setDirty(true); |
|
243 |
refresh(); |
|
244 |
|
|
245 |
if (objectAffectedByOperation instanceof PolytomousKeyNode) { |
|
246 |
viewer.setSelection(new StructuredSelection( |
|
247 |
objectAffectedByOperation), true); |
|
248 |
} |
|
249 |
|
|
250 |
return true; |
|
251 |
} |
|
252 |
|
|
253 |
private IToolBarManager getToolBarManager() { |
|
254 |
if (toolBarManager == null) { |
|
255 |
toolBarManager = getEditorSite().getActionBars() |
|
256 |
.getToolBarManager(); |
|
257 |
} |
|
258 |
return toolBarManager; |
|
259 |
} |
|
260 |
|
|
261 |
public void applyLayout() { |
|
262 |
viewer.applyLayout(); |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
266 |
public boolean onComplete() { |
|
267 |
return true; |
|
268 |
} |
|
269 |
|
|
270 |
public void setDirty(boolean dirty) { |
|
271 |
this.dirty = dirty; |
|
272 |
firePropertyChange(PROP_DIRTY); |
|
273 |
} |
|
274 |
|
|
275 |
/* |
|
276 |
* (non-Javadoc) |
|
277 |
* |
|
278 |
* @see |
|
279 |
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed( |
|
280 |
* java.lang.Object) |
|
281 |
*/ |
|
282 |
@Override |
|
283 |
public void changed(Object element) { |
|
284 |
setDirty(true); |
|
285 |
viewer.update(element, null); |
|
286 |
} |
|
287 |
|
|
288 |
/* (non-Javadoc) |
|
289 |
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty() |
|
290 |
*/ |
|
291 |
@Override |
|
292 |
public void forceDirty() { |
|
293 |
changed(null); |
|
294 |
} |
|
295 |
|
|
296 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/e4/handler/ApplyLayoutHandlerE4.java | ||
---|---|---|
9 | 9 |
import org.eclipse.ui.IEditorPart; |
10 | 10 |
import org.eclipse.ui.handlers.HandlerUtil; |
11 | 11 |
|
12 |
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
|
|
12 |
import eu.etaxonomy.taxeditor.editor.key.e4.AbstractGraphKeyEditorE4;
|
|
13 | 13 |
|
14 | 14 |
/** |
15 | 15 |
* @author n.hoffmann |
... | ... | |
21 | 21 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
22 | 22 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
23 | 23 |
|
24 |
if(editor instanceof AbstractGraphKeyEditor){ |
|
25 |
((AbstractGraphKeyEditor) editor).applyLayout(); |
|
24 |
if(editor instanceof AbstractGraphKeyEditorE4){
|
|
25 |
((AbstractGraphKeyEditorE4) editor).applyLayout();
|
|
26 | 26 |
} |
27 | 27 |
|
28 | 28 |
return null; |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/handler/ApplyLayoutHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.key.handler; |
|
5 |
|
|
6 |
import org.eclipse.core.commands.AbstractHandler; |
|
7 |
import org.eclipse.core.commands.ExecutionEvent; |
|
8 |
import org.eclipse.core.commands.ExecutionException; |
|
9 |
import org.eclipse.ui.IEditorPart; |
|
10 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
11 |
|
|
12 |
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor; |
|
13 |
|
|
14 |
/** |
|
15 |
* @author n.hoffmann |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class ApplyLayoutHandler extends AbstractHandler { |
|
19 |
|
|
20 |
/* (non-Javadoc) |
|
21 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
22 |
*/ |
|
23 |
@Override |
|
24 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
25 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
26 |
|
|
27 |
if(editor instanceof AbstractGraphKeyEditor){ |
|
28 |
((AbstractGraphKeyEditor) editor).applyLayout(); |
|
29 |
} |
|
30 |
|
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyGraphEditor.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.key.polytomous; |
|
5 |
|
|
6 |
import org.eclipse.jface.viewers.IBaseLabelProvider; |
|
7 |
import org.eclipse.jface.viewers.IContentProvider; |
|
8 |
|
|
9 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
10 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
|
11 |
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor; |
|
12 |
import eu.etaxonomy.taxeditor.editor.key.KeyEditor; |
|
13 |
|
|
14 |
/** |
|
15 |
* @author n.hoffmann |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class PolytomousKeyGraphEditor extends |
|
19 |
AbstractGraphKeyEditor<PolytomousKey> implements |
|
20 |
IPolytomousKeyEditorPage { |
|
21 |
|
|
22 |
public static final String ID = "eu.etaxonomy.taxeditor.editor.key.polytomous.graph"; //$NON-NLS-1$ |
|
23 |
private final KeyEditor editor; |
|
24 |
|
|
25 |
/** |
|
26 |
* @param keyEditor |
|
27 |
*/ |
|
28 |
public PolytomousKeyGraphEditor(KeyEditor editor) { |
|
29 |
this.editor = editor; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public ConversationHolder getConversationHolder() { |
|
34 |
return ((PolytomousKeyEditorInput) getEditorInput()) |
|
35 |
.getConversationHolder(); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public PolytomousKey getKey() { |
|
40 |
return ((PolytomousKeyEditorInput) getEditorInput()).getKey(); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected IBaseLabelProvider getLabelProvider() { |
|
45 |
return new PolytomousKeyLabelProvider(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected IContentProvider getContentProvider() { |
|
50 |
return new PolytomousKeyGraphContentProvider(); |
|
51 |
} |
|
52 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/ConceptViewPartE4.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
26 | 26 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
27 |
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
|
|
27 |
import eu.etaxonomy.taxeditor.editor.key.e4.AbstractGraphKeyEditorE4;
|
|
28 | 28 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
29 | 29 |
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptContentProvider; |
30 | 30 |
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider; |
... | ... | |
63 | 63 |
// description selected in this view |
64 | 64 |
return; |
65 | 65 |
} |
66 |
else if(partObject instanceof AbstractGraphKeyEditor){ |
|
66 |
else if(partObject instanceof AbstractGraphKeyEditorE4){
|
|
67 | 67 |
showEmptyPage(); |
68 | 68 |
} |
69 | 69 |
else if(selection!=null){ |
Also available in: Unified diff
ref #6913 Remove graph key editor