Project

General

Profile

« Previous | Next » 

Revision dea7cd9c

Added by Patrick Plitzner over 9 years ago

  • added command, handler, double click listener to open taxa from associated taxa section in details view
    • caught runtime exception for orphaned taxa

View differences:

.gitattributes
386 386
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenChecklistEditorHandler.java -text
387 387
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java -text
388 388
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenParentHandler.java -text
389
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenTaxonEditorHandler.java -text
389 390
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/SaveAllHandler.java -text
390 391
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/SaveTaxonHandler.java -text
392
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/TaxonParameterConverter.java -text
391 393
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/create/NewNameHandler.java -text
392 394
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/create/NewPersonHandler.java -text
393 395
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/create/NewReferenceHandler.java -text
......
959 961
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/NewClassificationHandler.java -text
960 962
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/NewTaxonNodeHandler.java -text
961 963
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RefreshTreeHandler.java -text
964
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/TaxonParameterConverter.java -text
962 965
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java -text
963 966
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/CopyOperation.java -text
964 967
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java -text
eu.etaxonomy.taxeditor.editor/plugin.xml
1249 1249
            id="eu.etaxonomy.taxeditor.editor.handler.showOnlyIndividualAssociations"
1250 1250
            name="Show Only Individual Associations">
1251 1251
      </command>
1252
      <command
1253
            defaultHandler="eu.etaxonomy.taxeditor.editor.handler.OpenTaxonEditorHandler"
1254
            id="eu.etaxonomy.taxeditor.editor.openTaxonEditor"
1255
            name="Open Taxon Editor">
1256
         <commandParameter
1257
               id="eu.etaxonomy.taxeditor.editor.taxonParameter"
1258
               name="taxonUUID"
1259
               optional="false"
1260
               typeId="eu.etaxonomy.taxeditor.editor.taxonParameterType">
1261
         </commandParameter>
1262
      </command>
1263
      <commandParameterType
1264
            converter="eu.etaxonomy.taxeditor.editor.handler.TaxonParameterConverter"
1265
            id="eu.etaxonomy.taxeditor.editor.taxonParameterType"
1266
            type="eu.etaxonomy.cdm.model.taxon.TaxonBase">
1267
      </commandParameterType>
1252 1268
   </extension>
1253 1269
   <extension
1254 1270
         point="org.eclipse.core.expressions.definitions">
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
27 27
import org.eclipse.ui.PartInitException;
28 28
import org.eclipse.ui.handlers.HandlerUtil;
29 29

  
30
import eu.etaxonomy.cdm.api.service.ITaxonService;
30 31
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
31 32
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
32 33
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
34
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
33 35
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
34 36
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
35 37
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
36 38
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
37 39
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
38
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
39 40
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
41
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
40 42
import eu.etaxonomy.taxeditor.editor.view.dataimport.BioCaseEditorInput;
41 43
import eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportEditor;
42 44
import eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportEditorInput;
......
46 48
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
47 49
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
48 50
import eu.etaxonomy.taxeditor.model.AbstractUtility;
51
import eu.etaxonomy.taxeditor.model.MessagingUtils;
52
import eu.etaxonomy.taxeditor.store.CdmStore;
49 53

  
50 54
/**
51 55
 * Utility for the editor package
......
157 161
	 */
158 162
	public static void openTaxonBase(UUID taxonBaseUuid)
159 163
			throws PartInitException {
164
	    TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
165
        if (taxonBase != null && taxonBase.isOrphaned()) {
166
                MessagingUtils.warningDialog("Orphaned Taxon", TaxonEditorInput.class, "This is an orphaned taxon i.e. a taxon that is not connected to a classification and not having any taxonomic relationships. Editing of orphaned taxon is currently not supported.");
167
                return;
168
        }
160 169
		TaxonEditorInput input = TaxonEditorInput
161 170
				.NewInstanceFromTaxonBase(taxonBaseUuid);
162 171
		open(input);
......
433 442
        }
434 443
        return null;
435 444
    }
445

  
446
    /**
447
     * Opens a taxon editor for the given object if the given object is a valid input.
448
     * @param object the object for which the editor will be opened
449
     * @throws PartInitException
450
     */
451
    public static void openTaxonEditor(Object object) throws PartInitException {
452
        if(object instanceof TaxonBase<?>){
453
            openTaxonBase(((TaxonBase<?>) object).getUuid());
454
        }
455
    }
436 456
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java
48 48
 */
49 49
public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPersistableElement {
50 50

  
51
	private ConversationHolder conversation;
51
	private final ConversationHolder conversation;
52 52

  
53
	private TaxonNode taxonNode;
53
	private final TaxonNode taxonNode;
54 54

  
55 55
	private TaxonEditorInputDataChangeBehaviour dataChangeBehavior;
56 56

  
......
111 111

  
112 112
    	TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
113 113
    	if (taxonBase != null){
114
	    	if(taxonBase.isOrphaned()) {
115
	    		MessagingUtils.warningDialog("Orphaned Taxon", TaxonEditorInput.class, "This is an orphaned taxon i.e. a taxon that is not connected to a classification and not having any taxonomic relationships. Editing of orphaned taxon is currently not supported.");
116
	    	}
117
	    	else if(taxonBase.isInstanceOf(Taxon.class)){
114
	    	if(taxonBase.isInstanceOf(Taxon.class)){
118 115
	    		Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
119
	
116

  
120 117
	    		if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){
121 118
	    			// TODO get accepted taxon
122 119
	    			MessagingUtils.info("trying to open Mispplied Name ");
123
	
120

  
124 121
	    			Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
125 122
	    			Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
126 123
	    			for(TaxonRelationship relation : relations){
......
129 126
	    				}
130 127
	    			}
131 128
	    			input =  getInputForMultipleTaxa(conversation, acceptedTaxa);
132
	
129

  
133 130
	    		}else{
134 131
	    			input = getInputForMultipleNodes(conversation, taxon.getTaxonNodes());
135 132
	    		}
136 133
	    	}else if(taxonBase instanceof Synonym){
137 134
	    		Synonym synonym = (Synonym) taxonBase;
138
	
135

  
139 136
	    		Set<Taxon> taxa = synonym.getAcceptedTaxa();
140 137
	    		input = getInputForMultipleTaxa(conversation, taxa);
141 138
	    	}
......
143 140
	    		input.setInitiallySelectedTaxonBase(taxonBase);
144 141
	    	}
145 142
    	}
146
    	
143

  
147 144

  
148 145
    	return input;
149 146
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenTaxonEditorHandler.java
1
package eu.etaxonomy.taxeditor.editor.handler;
2
import org.eclipse.core.commands.AbstractHandler;
3
import org.eclipse.core.commands.ExecutionEvent;
4
import org.eclipse.core.commands.ExecutionException;
5
import org.eclipse.core.commands.ParameterType;
6
import org.eclipse.core.commands.common.NotDefinedException;
7
import org.eclipse.ui.PartInitException;
8

  
9
import eu.etaxonomy.taxeditor.editor.EditorUtil;
10
import eu.etaxonomy.taxeditor.model.MessagingUtils;
11

  
12

  
13
public class OpenTaxonEditorHandler extends AbstractHandler {
14

  
15
    @Override
16
    public Object execute(ExecutionEvent event) throws ExecutionException {
17
        Object object = event.getObjectParameterForExecution("eu.etaxonomy.taxeditor.editor.taxonParameter");
18

  
19
        try {
20
            ParameterType parameterType = event.getCommand().getParameterType("eu.etaxonomy.taxeditor.editor.taxonParameter");
21
            if(parameterType.isCompatible(object)){
22
                EditorUtil.openTaxonEditor(object);
23
            }
24
        } catch (NotDefinedException e) {
25
            MessagingUtils.error(this.getClass(), "Parameter type not defined", e);
26
        } catch (PartInitException e) {
27
            MessagingUtils.error(OpenTaxonEditorHandler.class, "Error opening the editor", e);
28
        }
29
        return null;
30
    }
31

  
32
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/TaxonParameterConverter.java
1
package eu.etaxonomy.taxeditor.editor.handler;
2

  
3
import java.util.UUID;
4

  
5
import org.eclipse.core.commands.AbstractParameterValueConverter;
6
import org.eclipse.core.commands.ParameterValueConversionException;
7

  
8
import eu.etaxonomy.cdm.api.service.ITaxonService;
9
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
10
import eu.etaxonomy.taxeditor.store.CdmStore;
11

  
12
public class TaxonParameterConverter extends AbstractParameterValueConverter {
13

  
14
    public TaxonParameterConverter() {
15
    }
16

  
17
    @Override
18
    public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
19
        return CdmStore.getService(ITaxonService.class).load(UUID.fromString(parameterValue));
20
    }
21

  
22
    @Override
23
    public String convertToString(Object parameterValue) throws ParameterValueConversionException {
24
        if(parameterValue instanceof TaxonBase<?>){
25
            return ((TaxonBase<?>) parameterValue).getUuid().toString();
26
        }
27
        return null;
28
    }
29

  
30
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/TaxonParameterConverter.java
1
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
2

  
3
import java.util.UUID;
4

  
5
import org.eclipse.core.commands.AbstractParameterValueConverter;
6
import org.eclipse.core.commands.ParameterValueConversionException;
7

  
8
import eu.etaxonomy.cdm.api.service.ITaxonService;
9
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
10
import eu.etaxonomy.taxeditor.store.CdmStore;
11

  
12
public class TaxonParameterConverter extends AbstractParameterValueConverter {
13

  
14
    public TaxonParameterConverter() {
15
    }
16

  
17
    @Override
18
    public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
19
        return CdmStore.getService(ITaxonService.class).load(UUID.fromString(parameterValue));
20
    }
21

  
22
    @Override
23
    public String convertToString(Object parameterValue) throws ParameterValueConversionException {
24
        if(parameterValue instanceof TaxonBase<?>){
25
            return ((TaxonBase) parameterValue).getUuid().toString();
26
        }
27
        return null;
28
    }
29

  
30
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
9 9
 */
10 10
package eu.etaxonomy.taxeditor.ui.section.occurrence.association;
11 11

  
12
import java.util.ArrayList;
12 13
import java.util.Collection;
13 14

  
15
import org.eclipse.core.commands.Command;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.commands.IParameter;
18
import org.eclipse.core.commands.NotEnabledException;
19
import org.eclipse.core.commands.NotHandledException;
20
import org.eclipse.core.commands.Parameterization;
21
import org.eclipse.core.commands.ParameterizedCommand;
22
import org.eclipse.core.commands.common.NotDefinedException;
14 23
import org.eclipse.jface.viewers.ArrayContentProvider;
15 24
import org.eclipse.jface.viewers.DoubleClickEvent;
16 25
import org.eclipse.jface.viewers.IDoubleClickListener;
26
import org.eclipse.jface.viewers.IStructuredSelection;
17 27
import org.eclipse.jface.viewers.TableViewer;
18 28
import org.eclipse.swt.SWT;
19 29
import org.eclipse.swt.widgets.Label;
30
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.commands.ICommandService;
33
import org.eclipse.ui.handlers.IHandlerService;
20 34

  
21 35
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
22 36
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
23 37
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
38
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24 39
import eu.etaxonomy.taxeditor.store.CdmStore;
25 40
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26 41
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
......
35 50
public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> implements IDoubleClickListener{
36 51

  
37 52

  
53
    private TableViewer associationsViewer;
54
    private TableViewer typeDesignationViewer;
55

  
38 56
    public TaxonAssociationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
39 57
        super(formFactory, formElement);
40 58
    }
......
43 61
    @Override
44 62
    protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
45 63

  
64
        //TODO add context menu for deleting associations
65

  
46 66
        Label associationsLabel = formFactory.createLabel(getLayoutComposite(), "Individuals Associations");
47 67
        associationsLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
48 68

  
49
        TableViewer associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
69
        associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
50 70
        associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
51 71
        associationsViewer.setContentProvider(new ArrayContentProvider());
52 72
        Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(entity.innerDerivedUnit(), null, null, null, null);
......
56 76
        Label typeLabel = formFactory.createLabel(getLayoutComposite(), "Type Designations");
57 77
        typeLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
58 78

  
59
        TableViewer typeDesignationViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
79
        typeDesignationViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
60 80
        typeDesignationViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
61 81
        typeDesignationViewer.setContentProvider(new ArrayContentProvider());
62 82
        Collection<TaxonBase<?>> typedTaxa = CdmStore.getService(IOccurrenceService.class).listTypedTaxa(entity.innerDerivedUnit(), null, null, null, null);
......
67 87
    /** {@inheritDoc} */
68 88
    @Override
69 89
    public void handleEvent(Object eventSource) {
70

  
90
        //empty
71 91
    }
72 92

  
73 93
    /* (non-Javadoc)
......
75 95
     */
76 96
    @Override
77 97
    public void doubleClick(DoubleClickEvent event) {
78
//        String commandId = "eu.etaxonomy.taxeditor.navigation.command.update.editSelection";
79
//
80
//        IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
81
//        try {
82
//            handlerService.executeCommand(commandId, null);
83
//        } catch (ExecutionException e) {
84
//            // TODO Auto-generated catch block
85
//            e.printStackTrace();
86
//        } catch (NotDefinedException e) {
87
//            // TODO Auto-generated catch block
88
//            e.printStackTrace();
89
//        } catch (NotEnabledException e) {
90
//            // TODO Auto-generated catch block
91
//            e.printStackTrace();
92
//        } catch (NotHandledException e) {
93
//            // TODO Auto-generated catch block
94
//            e.printStackTrace();
95
//        }
96

  
97

  
98
//        if(event.getSelection() instanceof StructuredSelection){
99
//            StructuredSelection selection = (StructuredSelection)event.getSelection();
100
//            if(selection.getFirstElement() instanceof TaxonBase<?>){
101
//                UUID taxonBaseUUID = ((TaxonBase<?>) selection.getFirstElement()).getUuid();
102
//            }
103
//        }
98
        if(associationsViewer.getSelection() instanceof IStructuredSelection){
99
            Object firstElement = ((IStructuredSelection) associationsViewer.getSelection()).getFirstElement();
100
            if(firstElement instanceof TaxonBase<?>){
101
                TaxonBase<?> taxonBase = (TaxonBase<?>)firstElement;
102
                String commandId = "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
103

  
104

  
105
                ArrayList parameters = new ArrayList();
106
                IParameter iparam = null;
107

  
108
                //get the command from plugin.xml
109
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
110
                ICommandService cmdService = (ICommandService)window.getService(ICommandService.class);
111
                Command cmd = cmdService.getCommand(commandId);
112

  
113
                //get the parameter
114
                try {
115
                    iparam = cmd.getParameter("eu.etaxonomy.taxeditor.editor.taxonParameter");
116
                } catch (NotDefinedException e1) {
117
                    MessagingUtils.error(this.getClass(), "Command not defined", e1);
118
                }
119
                Parameterization params = new Parameterization(iparam, (taxonBase).getUuid().toString());
120
                parameters.add(params);
121

  
122
                //build the parameterized command
123
                ParameterizedCommand pc = new ParameterizedCommand(cmd, (Parameterization[]) parameters.toArray(new Parameterization[parameters.size()]));
124

  
125
                //execute the command
126
                IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
127
                try {
128
                    handlerService.executeCommand(pc, null);
129
                } catch (ExecutionException e) {
130
                    MessagingUtils.error(TaxonAssociationDetailElement.class, e);
131
                } catch (NotDefinedException e) {
132
                    MessagingUtils.error(TaxonAssociationDetailElement.class, e);
133
                } catch (NotEnabledException e) {
134
                    MessagingUtils.error(TaxonAssociationDetailElement.class, e);
135
                } catch (NotHandledException e) {
136
                    MessagingUtils.error(TaxonAssociationDetailElement.class, e);
137
                }
138
            }
139
        }
104 140
    }
105 141

  
106 142
}

Also available in: Unified diff