Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/MergeGroupHandler.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
package eu.etaxonomy.taxeditor.bulkeditor.handler;
11

  
12
import java.util.Set;
13

  
14
import org.apache.log4j.Logger;
15
import org.eclipse.core.commands.AbstractHandler;
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.text.source.Annotation;
20
import org.eclipse.ui.IEditorInput;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.handlers.HandlerUtil;
23
import org.eclipse.ui.texteditor.IDocumentProvider;
24

  
25
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer;
26
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
27
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
28
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
29
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
30
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
31

  
32
/**
33
 * @author p.ciardelli
34
 * @created 25.06.2009
35
 * @version 1.0
36
 */
37
public class MergeGroupHandler extends AbstractHandler {
38
	private static final Logger logger = Logger
39
			.getLogger(MergeGroupHandler.class);
40

  
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43
	 */
44
	public Object execute(ExecutionEvent event) throws ExecutionException {
45
				
46
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
47
		IEditorInput input = editor.getEditorInput();
48
		if (editor instanceof BulkEditor && input instanceof AbstractBulkEditorInput) {
49

  
50
			IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
51
			LineAnnotationModel model = 
52
					(LineAnnotationModel) provider.getAnnotationModel(input);
53
			
54
			// Check whether there are any group annotations
55
			Set<LineAnnotation> candidateAnnotations = model.getAllAnnotationsOfType(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
56
			if (candidateAnnotations.size() == 0) {
57
				MessageDialog.openWarning(HandlerUtil.getActiveShell(event), 
58
						"No merge candidates", "No objects have been chosen for merging.");
59
				return null;				
60
			}
61
			
62
			// Check whether group merge target has been set
63
			Annotation targetAnnotation = model.getFirstAnnotationOfType(IBulkEditorConstants.TYPE_MERGE_TARGET);
64
			if (targetAnnotation == null) {
65
				MessageDialog.openWarning(HandlerUtil.getActiveShell(event), 
66
						"No group merge target set", "No group merge target has been set.");
67
				return null;
68
			}			
69
			Object targetEntity = ((IEntityContainer<?>) targetAnnotation).getEntity();
70
			
71
			logger.info("Merging group");
72
//			model.printAnnotations();
73
			for (LineAnnotation annotation : candidateAnnotations) {
74
				
75
				((BulkEditor) editor).removeAnnotatedLine(annotation);
76
				
77
				// Mark entity container for merging with target entity
78
				((IEntityContainer) annotation).markAsMerged(targetEntity);
79
				logger.info("Merging " + annotation + " with " + targetAnnotation);
80
				
81
				// Remove annotation from model
82
				model.removeAnnotation(annotation);
83
			}
84
//			model.printAnnotations();	
85
			
86
			model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
87
			model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET);
88
		}
89
		return null;
90
	}
91
}
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
package eu.etaxonomy.taxeditor.bulkeditor.handler;
11

  
12
import java.util.Set;
13

  
14
import org.apache.log4j.Logger;
15
import org.eclipse.core.commands.AbstractHandler;
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.text.source.Annotation;
20
import org.eclipse.ui.IEditorInput;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.handlers.HandlerUtil;
23
import org.eclipse.ui.texteditor.IDocumentProvider;
24

  
25
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer;
26
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
27
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
28
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
29
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
30
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
31

  
32
/**
33
 * <p>MergeGroupHandler class.</p>
34
 *
35
 * @author p.ciardelli
36
 * @created 25.06.2009
37
 * @version 1.0
38
 */
39
public class MergeGroupHandler extends AbstractHandler {
40
	private static final Logger logger = Logger
41
			.getLogger(MergeGroupHandler.class);
42

  
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
45
	 */
46
	/** {@inheritDoc} */
47
	public Object execute(ExecutionEvent event) throws ExecutionException {
48
				
49
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
50
		IEditorInput input = editor.getEditorInput();
51
		if (editor instanceof BulkEditor && input instanceof AbstractBulkEditorInput) {
52

  
53
			IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
54
			LineAnnotationModel model = 
55
					(LineAnnotationModel) provider.getAnnotationModel(input);
56
			
57
			// Check whether there are any group annotations
58
			Set<LineAnnotation> candidateAnnotations = model.getAllAnnotationsOfType(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
59
			if (candidateAnnotations.size() == 0) {
60
				MessageDialog.openWarning(HandlerUtil.getActiveShell(event), 
61
						"No merge candidates", "No objects have been chosen for merging.");
62
				return null;				
63
			}
64
			
65
			// Check whether group merge target has been set
66
			Annotation targetAnnotation = model.getFirstAnnotationOfType(IBulkEditorConstants.TYPE_MERGE_TARGET);
67
			if (targetAnnotation == null) {
68
				MessageDialog.openWarning(HandlerUtil.getActiveShell(event), 
69
						"No group merge target set", "No group merge target has been set.");
70
				return null;
71
			}			
72
			Object targetEntity = ((IEntityContainer<?>) targetAnnotation).getEntity();
73
			
74
			logger.info("Merging group");
75
//			model.printAnnotations();
76
			for (LineAnnotation annotation : candidateAnnotations) {
77
				
78
				((BulkEditor) editor).removeAnnotatedLine(annotation);
79
				
80
				// Mark entity container for merging with target entity
81
				((IEntityContainer) annotation).markAsMerged(targetEntity);
82
				logger.info("Merging " + annotation + " with " + targetAnnotation);
83
				
84
				// Remove annotation from model
85
				model.removeAnnotation(annotation);
86
			}
87
//			model.printAnnotations();	
88
			
89
			model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
90
			model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET);
91
		}
92
		return null;
93
	}
94
}

Also available in: Unified diff