Project

General

Profile

Revision 124382f7

ID124382f76c5260f98a34fea494528e4f0eb33aea
Parent 250453cf
Child b4e7b7b0

Added by Patrick Plitzner over 5 years ago

Applied generic framework for opening objects to classifications in
taxon navigator

View differences:

eu.etaxonomy.taxeditor.navigation/plugin.xml
190 190
               </or>
191 191
            </visibleWhen>
192 192
         </command>
193
         <command
194
               commandId="eu.etaxonomy.taxeditor.store.open"
195
               label="Edit"
196
               style="push">
197
            <visibleWhen
198
                  checkEnabled="true">
199
               <with
200
                     variable="selection">
201
                  <reference
202
                        definitionId="isClassification">
203
                  </reference>
204
               </with>
205
            </visibleWhen>
206
         </command>
193
         <dynamic
194
               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
195
               id="eu.etaxonomy.taxeditor.navigation.cdmViewerContextMenu">
196
         </dynamic>
207 197
         <command
208 198
               commandId="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym"
209 199
               label="%command.label.6"
......
903 893
         </test>
904 894
      </definition>
905 895
   </extension>
906
   <extension
907
         point="eu.etaxonomy.taxeditor.store.cdmViewer">
908
      <cdmViewer
909
            class="eu.etaxonomy.taxeditor.navigation.NavigationCdmViewer">
910
      </cdmViewer>
911
   </extension>
912 896
</plugin>
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java
1
package eu.etaxonomy.taxeditor.navigation;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
import org.apache.log4j.Logger;
7
import org.eclipse.jface.wizard.WizardDialog;
8
import org.eclipse.ui.PlatformUI;
9

  
10
import eu.etaxonomy.cdm.model.taxon.Classification;
11
import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
12
import eu.etaxonomy.taxeditor.view.ICdmViewer;
13

  
14
public class NavigationCdmViewer implements ICdmViewer {
15

  
16

  
17
    @SuppressWarnings("unused")
18
    private final Logger logger = Logger.getLogger(NavigationCdmViewer.class);
19

  
20
    @Override
21
    public void show(Object input, Class<?> viewerClass) {
22
        if(viewerClass.equals(NewClassificationWizard.class)){
23
            if(input instanceof Classification){
24
                Classification classification = (Classification)input;
25
                NewClassificationWizard classificationWizard = new NewClassificationWizard();
26
                classificationWizard.init(null, null);
27
                classificationWizard.setEntity(classification);
28
                WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
29
                dialog.open();
30
            }
31
        }
32
    }
33

  
34
    @Override
35
    public Map<Class<?>, String> getViewerClasses(Object input) {
36
        Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>();
37
        if(input instanceof Classification){
38
            viewerNameMap.put(NewClassificationWizard.class, "Classification Wizard");
39
        }
40
        return viewerNameMap;
41
    }
42

  
43
}
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
15 15
 eu.etaxonomy.taxeditor.editor.definedterm.input,
16 16
 eu.etaxonomy.taxeditor.featuretree,
17 17
 eu.etaxonomy.taxeditor.handler,
18
 eu.etaxonomy.taxeditor.handler.defaultHandler,
18 19
 eu.etaxonomy.taxeditor.io,
19 20
 eu.etaxonomy.taxeditor.io.wizard,
20 21
 eu.etaxonomy.taxeditor.labels,
eu.etaxonomy.taxeditor.store/plugin.xml
756 756
            id="eu.etaxonomy.taxeditor.store.open"
757 757
            name="%command.name.15">
758 758
      </command>
759
      <command
760
            defaultHandler="eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenClassificationWizardHandler"
761
            id="eu.etaxonomy.taxeditor.command.openClassificationWizard"
762
            name="Open Classification Wizard">
763
         <commandParameter
764
               id="eu.etaxonomy.taxeditor.command.openClassificationWizard.uuid"
765
               name="Classification Uuid"
766
               optional="true"
767
               typeId="eu.etaxonomy.taxeditor.uuidParameterType">
768
         </commandParameter>
769
      </command>
770
   </extension>
771
   <extension
772
         point="org.eclipse.ui.commands">
773
      <commandParameterType
774
            converter="eu.etaxonomy.taxeditor.handler.UuidsParameterTypeConverter"
775
            id="eu.etaxonomy.taxeditor.uuidParameterType"
776
            type="java.util.UUID">
777
      </commandParameterType>
759 778
   </extension>
760 779
   <extension
761 780
         point="org.eclipse.ui.importWizards">
......
1365 1384
      </variable>
1366 1385
   </sourceProvider>
1367 1386
</extension>
1387
<extension
1388
      point="eu.etaxonomy.taxeditor.store.cdmViewer">
1389
   <viewCommandMapping
1390
         commandId="eu.etaxonomy.taxeditor.command.openClassificationWizard"
1391
         selection="eu.etaxonomy.cdm.model.taxon.Classification"
1392
         viewerName="Classification Wizard">
1393
   </viewCommandMapping>
1394
</extension>
1368 1395
</plugin>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java
1
package eu.etaxonomy.taxeditor.handler;
2

  
3
import java.util.UUID;
4

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

  
8
public class UuidParameterConverter extends AbstractParameterValueConverter {
9

  
10
    public UuidParameterConverter() {
11
        // TODO Auto-generated constructor stub
12
    }
13

  
14
    @Override
15
    public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
16
        return UUID.fromString(parameterValue);
17
    }
18

  
19
    @Override
20
    public String convertToString(Object parameterValue) throws ParameterValueConversionException {
21
        return parameterValue.toString();
22
    }
23

  
24
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java
1
package eu.etaxonomy.taxeditor.handler;
2

  
3
import java.util.UUID;
4

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

  
8
/**
9
 * Converts {@link UUID}s to a string representation
10
 * and vica versa.
11
 *
12
 * @author pplitzner
13
 * @date Sep 15, 2015
14
 *
15
 */
16
public class UuidsParameterTypeConverter extends AbstractParameterValueConverter {
17

  
18
    public UuidsParameterTypeConverter() {
19
    }
20

  
21
    @Override
22
    public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
23
        return UUID.fromString(parameterValue);
24
    }
25

  
26
    @Override
27
    public String convertToString(Object parameterValue) throws ParameterValueConversionException {
28
        return parameterValue.toString();
29
    }
30

  
31
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java
1
package eu.etaxonomy.taxeditor.handler.defaultHandler;
2

  
3
import java.util.UUID;
4

  
5
import org.eclipse.core.commands.AbstractHandler;
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.core.commands.ParameterType;
9
import org.eclipse.core.commands.common.NotDefinedException;
10
import org.eclipse.jface.viewers.ISelection;
11
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.jface.wizard.WizardDialog;
13
import org.eclipse.ui.PlatformUI;
14
import org.eclipse.ui.handlers.HandlerUtil;
15

  
16
import eu.etaxonomy.cdm.api.service.IClassificationService;
17
import eu.etaxonomy.cdm.model.taxon.Classification;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

  
22
public class DefaultOpenClassificationWizardHandler extends AbstractHandler {
23

  
24
    @Override
25
    public Object execute(ExecutionEvent event) throws ExecutionException {
26
        String commandId = event.getCommand().getId();
27
        String uuidParameterId = commandId+".uuid";
28
        //check if uuid parameter is set
29
        if(event.getParameter(uuidParameterId)!=null){
30
            Object object = event.getObjectParameterForExecution(uuidParameterId);
31
            ParameterType parameterType;
32
            try {
33
                parameterType = event.getCommand().getParameterType(uuidParameterId);
34
                if(parameterType.isCompatible(object)){
35
                    Classification classification = CdmStore.getService(IClassificationService.class).load((UUID) object);
36
                    openClassificationWizard(event, classification);
37
                }
38
            } catch (NotDefinedException e) {
39
                MessagingUtils.error(DefaultOpenClassificationWizardHandler.class, "Error while opening classification!", e);
40
            }
41
        }
42
        //if not try current selection
43
        else{
44
            ISelection selection = HandlerUtil.getCurrentSelection(event);
45

  
46
            if(selection instanceof IStructuredSelection){
47
                final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
48

  
49
                if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
50
                    Classification classification = (Classification) structuredSelection.getFirstElement();
51
                    openClassificationWizard(event, classification);
52
                }
53
            }
54
        }
55
        return null;
56
    }
57

  
58
    private void openClassificationWizard(ExecutionEvent event, Classification classification) {
59
        NewClassificationWizard classificationWizard = new NewClassificationWizard();
60
        classificationWizard.init(null, null);
61
        classificationWizard.setEntity(classification);
62
        WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
63
        dialog.open();
64
    }
65

  
66
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)