Project

General

Profile

« Previous | Next » 

Revision f94802df

Added by Alex Theys about 12 years ago

AT: Commit missing files from the branch

View differences:

.gitattributes
479 479
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java -text
480 480
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesViewPart.java -text
481 481
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/CreateUseHandler.java -text
482
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/CreateUseRecordHandler.java -text
482 483
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/DeleteUseHandler.java -text
483 484
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/DynamicFeatureMenu.java -text
484 485
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateTaxonUseOperation.java -text
486
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateUseRecordOperation.java -text
485 487
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/DeleteTaxonUseOperation.java -text
486 488
eu.etaxonomy.taxeditor.editor/src/main/resources/TaonDescriptionEditor.screen -text
487 489
eu.etaxonomy.taxeditor.editor/src/main/resources/log4j.properties -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/CreateUseRecordHandler.java
1
package eu.etaxonomy.taxeditor.editor.view.uses.handler;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.core.commands.common.NotDefinedException;
7
import org.eclipse.jface.viewers.ISelection;
8
import org.eclipse.jface.viewers.IStructuredSelection;
9
import org.eclipse.jface.viewers.ITreeSelection;
10
import org.eclipse.jface.viewers.TreePath;
11
import org.eclipse.swt.widgets.Event;
12
import org.eclipse.ui.IEditorInput;
13
import org.eclipse.ui.IEditorPart;
14
import org.eclipse.ui.IWorkbenchPart;
15
import org.eclipse.ui.forms.editor.FormEditor;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

  
18
import eu.etaxonomy.cdm.model.description.Feature;
19
import eu.etaxonomy.cdm.model.description.TaxonDescription;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.taxeditor.editor.EditorUtil;
22
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
23
import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateUseRecordOperation;
24
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26

  
27
public class CreateUseRecordHandler extends AbstractHandler {
28
	public Object execute(ExecutionEvent event) throws ExecutionException {
29
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
30
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part
31
				: null;
32

  
33
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
34
		if (editor instanceof FormEditor) {
35
			editor = ((FormEditor) editor).getActiveEditor();
36
		}
37
		IEditorInput input = editor.getEditorInput();
38
		if (input instanceof TaxonEditorInput) {
39
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
40

  
41
			TaxonDescription description = null;
42

  
43
			ISelection selection = HandlerUtil.getActiveMenuSelection(event);
44
			if (selection instanceof ITreeSelection) {
45
				TreePath[] paths = ((ITreeSelection) selection).getPaths();
46
				Object firstSegment = paths[0].getFirstSegment();
47
				if (firstSegment instanceof TaxonDescription) {
48
					description = (TaxonDescription) firstSegment;
49
				}
50
			}else if (selection instanceof IStructuredSelection) {
51
				Object selectedElement = ((IStructuredSelection) selection)
52
						.getFirstElement();
53
				if (selectedElement instanceof TaxonDescription){
54
					description = (TaxonDescription) selectedElement;
55
				}
56
			} 
57

  
58
			if (description != null) {
59

  
60
				Feature feature = (Feature) ((Event) event.getTrigger()).data;
61

  
62
				AbstractPostOperation operation = null;
63
				try {
64
					// TODO use undo context specific to editor
65
					operation = new CreateUseRecordOperation(event
66
							.getCommand().getName(),
67
							EditorUtil.getUndoContext(), taxon,
68
							description, element, postOperationEnabled);
69
					EditorUtil.executeOperation(operation);
70
				} catch (NotDefinedException e) {
71
					EditorUtil.warn(getClass(), "Command name not set");
72
				}
73
			} else {
74
				EditorUtil.error(getClass(), new IllegalArgumentException("Could not determine the taxon description"));
75
				return null;
76
			}
77
		}
78
		return null;
79

  
80
	}
81
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateUseRecordOperation.java
1
package eu.etaxonomy.taxeditor.editor.view.uses.operation;
2

  
3
import org.eclipse.core.commands.ExecutionException;
4
import org.eclipse.core.commands.operations.IUndoContext;
5
import org.eclipse.core.runtime.IAdaptable;
6
import org.eclipse.core.runtime.IProgressMonitor;
7
import org.eclipse.core.runtime.IStatus;
8

  
9
import eu.etaxonomy.cdm.model.description.CategoricalData;
10
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
11
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
12
import eu.etaxonomy.cdm.model.description.Distribution;
13
import eu.etaxonomy.cdm.model.description.Feature;
14
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
15
import eu.etaxonomy.cdm.model.description.QuantitativeData;
16
import eu.etaxonomy.cdm.model.description.TaxonDescription;
17
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
18
import eu.etaxonomy.cdm.model.description.TextData;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
21
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22

  
23
public class CreateUseRecordOperation extends AbstractPostOperation {
24
	
25
	public static final String ID = "eu.etaxonomy.taxeditor.editor.use.createUseRecord";
26
	
27
	private TaxonDescription description;
28
	private Feature feature;
29
	private DescriptionElementBase element;
30

  
31
	
32
	public CreateUseRecordOperation(String label, IUndoContext undoContext,
33
			Taxon taxon, TaxonDescription description, DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
34
		super(label, undoContext, taxon, postOperationEnabled);
35
		
36
		this.description = description;
37
		this.element = element;
38
	}
39

  
40
	public CreateUseRecordOperation(String label,
41
			IUndoContext undoContext, Taxon taxon,
42
			TaxonDescription description, Feature feature,
43
			DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
44
		this(label, undoContext, taxon, description, element, postOperationEnabled);
45
		
46
		this.element = element;
47
	}
48

  
49
	@Override
50
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
51
			throws ExecutionException {
52
		monitor.worked(20);
53
		if (element == null) {
54
			if (feature.isSupportsCommonTaxonName()) {
55
				element = CommonTaxonName.NewInstance("", null);
56
			} 
57
			else if (feature.isSupportsDistribution()) {
58
				element = Distribution.NewInstance();
59
			} 
60
			else if(feature.isSupportsTaxonInteraction()){
61
				element = TaxonInteraction.NewInstance();
62
			}
63
			else if(feature.isSupportsIndividualAssociation()){
64
				element = IndividualsAssociation.NewInstance();
65
			}
66
			else if(feature.isSupportsCategoricalData()){
67
				element = CategoricalData.NewInstance();
68
			}
69
			else if(feature.isSupportsQuantitativeData()){
70
				element = QuantitativeData.NewInstance();
71
			}
72
			else {
73
				element = TextData.NewInstance();
74
			}
75
		}
76

  
77
		
78
		element.setFeature(feature);
79
		description.addElement(element);
80
		monitor.worked(40);
81

  
82
		return postExecute(element);
83
	}
84

  
85
	@Override
86
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
87
			throws ExecutionException {
88
		
89
		description.addElement(element);
90
		
91
		return postExecute(element);
92
	}
93

  
94
	@Override
95
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
96
			throws ExecutionException {
97
		description.removeElement(element);
98
		
99
		return postExecute(null);
100
	}
101
}

Also available in: Unified diff