Project

General

Profile

Revision 83655786

ID83655786bf3329da1dbf1b187a6c76adfd726cba
Parent 538ca0d5
Child c1e3b617

Added by Niels Hoffmann over 10 years ago

Fixes #2357

View differences:

.gitattributes
344 344
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractGraphKeyEditor.java -text
345 345
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractIdentificationEditorInput.java -text
346 346
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java -text
347
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditorDataChangeBehaviour.java -text
347 348
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/handler/ApplyLayoutHandler.java -text
348 349
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/IPolytomousKeyEditorPage.java -text
349 350
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyContentProvider.java -text
......
516 517
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyContentProvider.java -text
517 518
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyLabelProvider.java -text
518 519
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java -text
520
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java -text
519 521
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java -text
520 522
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditHandler.java -text
521 523
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/operation/DeleteOperation.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractGraphKeyEditor.java
51 51

  
52 52
	private CdmFormFactory formFactory;
53 53
	private Composite container;
54
	private GraphViewer graphViewer;
54
	protected GraphViewer viewer;
55 55

  
56 56
	private LayoutAlgorithm layoutAlgoritm;
57 57
	private ZoomContributionViewItem zoomContributionViewItem;
......
69 69
	public void doSave(IProgressMonitor monitor) {
70 70
		getConversationHolder().commit(true);
71 71
		setDirty(false);
72
		graphViewer.refresh();
72
		viewer.refresh();
73 73
	}
74 74

  
75 75
	/*
......
128 128
		container = formFactory.createComposite(parent);
129 129

  
130 130
		container.setLayout(new FillLayout());
131
		graphViewer = new GraphViewer(container, SWT.NONE);
132
		getSite().setSelectionProvider(graphViewer);
131
		viewer = new GraphViewer(container, SWT.NONE);
132
		getSite().setSelectionProvider(viewer);
133 133

  
134
		graphViewer.setContentProvider(getContentProvider());
135
		graphViewer.setLabelProvider(getLabelProvider());
134
		viewer.setContentProvider(getContentProvider());
135
		viewer.setLabelProvider(getLabelProvider());
136 136

  
137
		graphViewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
137
		viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
138 138

  
139
		graphViewer.setLayoutAlgorithm(getLayoutAlgoritm(), false);
139
		viewer.setLayoutAlgorithm(getLayoutAlgoritm(), false);
140 140

  
141 141
		createMenu();
142 142

  
143 143
		createToolbar();
144 144

  
145
		graphViewer.setInput(getKey());
145
		viewer.setInput(getKey());
146 146

  
147 147
		container.addControlListener(new ControlListener() {
148 148

  
......
173 173

  
174 174
		ZoomContributionViewItem zoomItem = getZoomContributionViewItem();
175 175
		menuMgr.add(zoomItem);
176
		getSite().registerContextMenu(menuMgr, graphViewer);
176
		getSite().registerContextMenu(menuMgr, viewer);
177 177

  
178
		Control control = graphViewer.getGraphControl();
178
		Control control = viewer.getGraphControl();
179 179
		Menu menu = menuMgr.createContextMenu(control);
180 180

  
181 181
		control.setMenu(menu);
......
195 195

  
196 196
	@Override
197 197
	public void setFocus() {
198
		graphViewer.getControl().setFocus();
198
		viewer.getControl().setFocus();
199 199
	}
200 200

  
201 201
	public void refresh() {
202
		graphViewer.refresh();
202
		viewer.refresh();
203 203
		// graphViewer.applyLayout();
204 204
	}
205 205

  
......
210 210

  
211 211
	@Override
212 212
	public AbstractZoomableViewer getZoomableViewer() {
213
		return graphViewer;
213
		return viewer;
214 214
	}
215 215

  
216 216
	private LayoutAlgorithm getLayoutAlgoritm() {
......
243 243
		refresh();
244 244

  
245 245
		if (objectAffectedByOperation instanceof PolytomousKeyNode) {
246
			graphViewer.setSelection(new StructuredSelection(
246
			viewer.setSelection(new StructuredSelection(
247 247
					objectAffectedByOperation), true);
248 248
		}
249 249

  
......
259 259
	}
260 260

  
261 261
	public void applyLayout() {
262
		graphViewer.applyLayout();
262
		viewer.applyLayout();
263 263
	}
264 264

  
265 265
	@Override
......
282 282
	@Override
283 283
	public void changed(Object element) {
284 284
		setDirty(true);
285
		graphViewer.update(element, null);
285
		viewer.update(element, null);
286 286
	}
287 287

  
288 288
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java
22 22
import eu.etaxonomy.taxeditor.editor.EditorUtil;
23 23
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyGraphEditor;
24 24
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
25
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
25 26
import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
26 27
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
27 28

  
......
39 40

  
40 41
	private boolean dirty;
41 42

  
43
	private KeyEditorDataChangeBehaviour dataChangeBehavior;
44

  
42 45
	/*
43 46
	 * (non-Javadoc)
44 47
	 * 
......
85 88
	 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
86 89
	 */
87 90
	@Override
88
	public void update(CdmDataChangeMap arg0) {
89
		// TODO Auto-generated method stub
91
	public void update(CdmDataChangeMap map) {
92
		if(dataChangeBehavior == null){
93
			dataChangeBehavior = new KeyEditorDataChangeBehaviour(this);
94
		}
95
		DataChangeBridge.handleDataChange(map, dataChangeBehavior);
90 96
	}
91 97

  
92 98
	/*
......
112 118
	public void changed(Object element) {
113 119
		editorDirtyStateChanged();
114 120
		IEditorPart activeEditor = getActiveEditor();
115
		if (activeEditor instanceof PolytomousKeyListEditor) {
116
			((PolytomousKeyListEditor) activeEditor).changed(element);
121
		if (activeEditor instanceof IDirtyMarkableSelectionProvider) {
122
			((IDirtyMarkableSelectionProvider) activeEditor).changed(element);
117 123
		}
118 124
	}
119 125

  
......
183 189
			EditorUtil.error(getClass(), e);
184 190
		}
185 191

  
186
		PolytomousKey key = (PolytomousKey) input.getKey();
192
		
187 193

  
188
		setPartName(key.getTitleCache());
194
		setPartName();
195

  
196
	}
189 197

  
198
	/**
199
	 * 
200
	 */
201
	public void setPartName() {
202
		AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
203
		PolytomousKey key = (PolytomousKey) input.getKey();
204
		setPartName(key.getTitleCache());
190 205
	}
191 206
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditorDataChangeBehaviour.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.taxeditor.editor.key;
12

  
13
import java.util.Vector;
14

  
15
import eu.etaxonomy.cdm.model.description.PolytomousKey;
16
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent;
17
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
18
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
19
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
20
import eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour;
21

  
22
/**
23
 * @author n.hoffmann
24
 * @created May 5, 2011
25
 * @version 1.0
26
 */
27
public class KeyEditorDataChangeBehaviour extends AbstractDataChangeBehaviour {
28

  
29
	private final KeyEditor source;
30
	private PolytomousKeyEditorInput input;
31

  
32
	/**
33
	 * @param keyEditor
34
	 */
35
	public KeyEditorDataChangeBehaviour(KeyEditor keyEditor) {
36
		source = keyEditor;
37
	}
38

  
39
	/* (non-Javadoc)
40
	 * @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
41
	 */
42
	@Override
43
	public void reactOnDataChange(CdmDataChangeMap changeEvents) {
44
		input = (PolytomousKeyEditorInput) source.getEditorInput();
45
		
46
		if(changeEvents.sizeByEventType(EventType.UPDATE) > 0){
47
			reactOnUpdate(changeEvents.getEvents(EventType.UPDATE));
48
		}
49
	}
50

  
51
	/** {@inheritDoc} */
52
	@Override
53
	public void reactOnUpdate(Vector<CdmDataChangeEvent> events){
54

  
55
		for(CdmDataChangeEvent event : events){
56
			
57
			// update editor title
58
			if(event.getEntity() instanceof PolytomousKey){
59
				if(input.getKey().equals(event.getEntity())){
60
					// set the name of the editor window
61
					source.setPartName();
62
				}
63
			}
64
		}
65
	}
66
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyGraphEditor.java
28 28
	public PolytomousKeyGraphEditor(KeyEditor editor) {
29 29
		this.editor = editor;
30 30
	}
31

  
31
	
32 32
	@Override
33 33
	public ConversationHolder getConversationHolder() {
34 34
		return ((PolytomousKeyEditorInput) getEditorInput())
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
191 191
	 */
192 192
	@Override
193 193
	public boolean isDirty() {
194
		// TODO Auto-generated method stub
195 194
		return false;
196 195
	}
197 196

  
......
277 276
	 */
278 277
	@Override
279 278
	public void setFocus() {
280
		setPartName("Test");
279
		
281 280
	}
282 281

  
283 282
	/*
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
38 38
import eu.etaxonomy.cdm.model.description.PolytomousKey;
39 39
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
40 40
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
41
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
41 42
import eu.etaxonomy.taxeditor.model.IContextListener;
42 43
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
43 44
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
......
104 105
	private ListViewer viewer;
105 106
	private ConversationHolder conversation;
106 107
	private IContextListener contextListener;
107
	private CdmFormFactory formFactory;
108
	private final CdmFormFactory formFactory;
108 109
	private Text text_filter;
109 110

  
111
	private PolytomousKeyViewPartDataChangeBehavior dataChangeBehavior;
112

  
110 113
	public PolytomousKeyViewPart(){
111 114
		formFactory = new CdmFormFactory(Display.getDefault());
112 115
	}
......
177 180

  
178 181
	private void setInput() {
179 182
		conversation = CdmStore.createConversation();
183
		conversation.registerForDataStoreChanges(this);
180 184
		List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);			
181 185
		viewer.setInput(input);
182 186
	}
......
193 197
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
194 198
	 */
195 199
	@Override
196
	public void update(CdmDataChangeMap changeEvents) {}
200
	public void update(CdmDataChangeMap changeEvents) {
201
		if (dataChangeBehavior == null) {
202
			dataChangeBehavior = new PolytomousKeyViewPartDataChangeBehavior(this);
203
		}
204

  
205
		DataChangeBridge.handleDataChange(changeEvents, dataChangeBehavior);
206
	}
197 207

  
198 208
	/* (non-Javadoc)
199 209
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
......
208 218
	 */
209 219
	@Override
210 220
	public void dispose() {
221
		conversation.unregisterForDataStoreChanges(this);
222
		conversation.close();
211 223
		CdmStore.getContextManager().removeContextListener(contextListener);
212 224
		super.dispose();
213 225
	}
......
229 241
		return true;
230 242
	}
231 243

  
244
	/**
245
	 * 
246
	 */
247
	public void refresh() {
248
		getConversationHolder().bind();
249
		List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);			
250
		viewer.setInput(input);
251
	}
252

  
232 253
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.taxeditor.navigation.key.polytomous;
12

  
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.core.runtime.jobs.Job;
17
import org.eclipse.swt.widgets.Display;
18

  
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.model.description.PolytomousKey;
21
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent;
22
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
23
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
24
import eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour;
25

  
26
/**
27
 * @author n.hoffmann
28
 * @created May 5, 2011
29
 * @version 1.0
30
 */
31
public class PolytomousKeyViewPartDataChangeBehavior extends
32
		AbstractDataChangeBehaviour {
33

  
34
	private final PolytomousKeyViewPart source;
35

  
36
	/**
37
	 * @param polytomousKeyViewPart
38
	 */
39
	public PolytomousKeyViewPartDataChangeBehavior(
40
			PolytomousKeyViewPart polytomousKeyViewPart) {
41
		source = polytomousKeyViewPart;
42
	}
43

  
44
	/* (non-Javadoc)
45
	 * @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
46
	 */
47
	@Override
48
	public void reactOnDataChange(CdmDataChangeMap changeEvents) {
49
		if(isRelevant(changeEvents)){
50
			final Display display = Display.getCurrent();
51
			Job job = new Job("Updating Polytomous Key Viewer") {
52
				
53
				@Override
54
				protected IStatus run(IProgressMonitor monitor) {
55
					monitor.beginTask("Updating Polytomous Key Viewer", 3);
56
					monitor.worked(1);
57
					
58
					// clear the session completely
59
					monitor.subTask("Clearing Polytomous Key Viewer session");
60
					display.asyncExec(new Runnable() {
61
						 public void run() {
62
							 source.getConversationHolder().clear();
63
						 }
64
					});					
65
					// FIXME completely clearing the session is a brute force approach. 
66
					// It would be much more elegant to clear only those elements that have been changed.
67
					// I could not get that to work but we should consider workin on this because we might
68
					// run into serious performance issues, especially when it comes to large trees
69
					//
70
					// at least, we moved this to a job so it can run in a background thred
71
					// seems to improve the situation but not sure if final solution
72
					monitor.worked(1);
73
					
74
					monitor.subTask("Refreshing viewer");
75
					
76
					display.asyncExec(new Runnable() {
77
					    public void run() {
78
					    	source.refresh();
79
					    }
80
					});
81
					
82
					
83
					
84
					monitor.worked(1);
85
					monitor.done();
86
					return Status.OK_STATUS;
87
				}
88
			};
89
			
90
			job.setPriority(Job.SHORT);
91
			job.schedule();
92
			
93
		}
94
	}
95
	
96
	/**
97
	 * @return
98
	 */
99
	private boolean isRelevant(CdmDataChangeMap changeEvents) {
100
		for(CdmDataChangeEvent event : changeEvents.getAllEvents()){
101
			EventType eventType = event.getEventType();
102
			CdmBase eventEntity = event.getEntity();
103
			
104
			// all poyltomous key changes are relevant
105
			if((eventType == EventType.INSERT || eventType == EventType.DELETE || eventType == EventType.UPDATE) 
106
					&& eventEntity instanceof PolytomousKey){
107
				return true;
108
			}
109
		}
110
		return false;
111
	}
112
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/PolytomousKeyDetailElement.java
7 7

  
8 8
import eu.etaxonomy.cdm.model.description.PolytomousKey;
9 9
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
10
import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
10 11
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
11 12
import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
12 13
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
......
45 46
		if (eventSource == text_title) {
46 47
			getEntity().setTitleCache(text_title.getText());
47 48
		}
49
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
48 50
	}
49 51
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)