Project

General

Profile

« Previous | Next » 

Revision e382ff8f

Added by Patrick Plitzner almost 9 years ago

  • added context menu entry for editing classifications
    • used generic extension point for cdmViewer in navigation project (#4865)

View differences:

.gitattributes
949 949
eu.etaxonomy.taxeditor.navigation/p2.inf -text
950 950
eu.etaxonomy.taxeditor.navigation/plugin.xml -text
951 951
eu.etaxonomy.taxeditor.navigation/pom.xml -text
952
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java -text
952 953
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java -text
953 954
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigatorStateManager.java -text
954 955
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/RecentNamesContributionItem.java -text
......
1261 1262
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizard.java -text
1262 1263
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java -text
1263 1264
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDistributionEditorWizardHandler.java -text
1265
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java -text
1264 1266
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java -text
1265 1267
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowLoginWindowHandler.java -text
1266 1268
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/identificationkey/AbstractIdentificaitonKeyWizard.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
13 13
import java.util.Map;
14 14

  
15 15
import org.apache.log4j.Logger;
16
import org.eclipse.core.commands.ExecutionEvent;
16 17
import org.eclipse.ui.PartInitException;
17 18

  
18 19
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
......
34 35
     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
35 36
     */
36 37
    @Override
37
    public void show(Object input, Class<?> viewerClass) {
38
    public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
38 39
        try {
39 40
            if(viewerClass.equals(MultiPageTaxonEditor.class)){
40 41
                if(input instanceof TaxonBase){
eu.etaxonomy.taxeditor.navigation/plugin.xml
163 163
               </or>
164 164
            </visibleWhen>
165 165
         </command>
166
         <command
167
               commandId="eu.etaxonomy.taxeditor.store.open"
168
               label="Edit"
169
               style="push">
170
            <visibleWhen
171
                  checkEnabled="true">
172
               <with
173
                     variable="selection">
174
                  <reference
175
                        definitionId="isClassification">
176
                  </reference>
177
               </with>
178
            </visibleWhen>
179
         </command>
166 180
         <command
167 181
               commandId="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym"
168 182
               label="%command.label.6"
......
764 778
         </with>
765 779
      </definition>
766 780
   </extension>
781
   <extension
782
         point="eu.etaxonomy.taxeditor.store.cdmViewer">
783
      <cdmViewer
784
            class="eu.etaxonomy.taxeditor.navigation.NavigationCdmViewer">
785
      </cdmViewer>
786
   </extension>
767 787
</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.core.commands.ExecutionEvent;
8
import org.eclipse.jface.wizard.WizardDialog;
9
import org.eclipse.ui.handlers.HandlerUtil;
10

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

  
15
public class NavigationCdmViewer implements ICdmViewer {
16

  
17

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

  
21
    /* (non-Javadoc)
22
     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
23
     */
24
    @Override
25
    public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
26
        if(viewerClass.equals(NewClassificationWizard.class)){
27
            if(input instanceof Classification){
28
                Classification classification = (Classification)input;
29
                NewClassificationWizard classificationWizard = new NewClassificationWizard();
30
                classificationWizard.init(null, null);
31
                classificationWizard.setEntity(classification);
32
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
33
                dialog.open();
34
            }
35
        }
36
    }
37

  
38
    /* (non-Javadoc)
39
     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
40
     */
41
    @Override
42
    public Map<Class<?>, String> getViewerClasses(Object input) {
43
        Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>();
44
        if(input instanceof Classification){
45
            viewerNameMap.put(NewClassificationWizard.class, "Classification Wizard");
46
        }
47
        return viewerNameMap;
48
    }
49

  
50
}
eu.etaxonomy.taxeditor.store/plugin.xml
697 697
            id="eu.etaxonomy.taxeditor.editor.definedTerms.delete"
698 698
            name="%command.name.14">
699 699
      </command>
700
      <command
701
            defaultHandler="eu.etaxonomy.taxeditor.handler.OpenHandler"
702
            id="eu.etaxonomy.taxeditor.store.open"
703
            name="Open">
704
      </command>
700 705
   </extension>
701 706
   <extension
702 707
         point="org.eclipse.ui.importWizards">
eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd
16 16
            <meta.element />
17 17
         </appInfo>
18 18
         <documentation>
19
            Extensions must provide and ICdmViewer which maps input elements to viewers which are able to display information for them.
19
            Extensions must provide an ICdmViewer which maps input elements to viewers which are able to display information for them.
20 20
         </documentation>
21 21
      </annotation>
22 22
      <complexType>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java
1
package eu.etaxonomy.taxeditor.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.jface.viewers.ISelection;
7
import org.eclipse.jface.viewers.IStructuredSelection;
8
import org.eclipse.ui.handlers.HandlerUtil;
9

  
10
import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
11

  
12
public class OpenHandler extends AbstractHandler {
13

  
14
    @Override
15
    public Object execute(ExecutionEvent event) throws ExecutionException {
16
        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
17
        if(currentSelection instanceof IStructuredSelection){
18
            Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement();
19
            CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event));
20
            viewerChooser.chooseViewer(firstElement, event);
21
        }
22
        return null;
23
    }
24

  
25
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
13 13
import java.util.Map;
14 14
import java.util.Map.Entry;
15 15

  
16
import org.eclipse.core.commands.ExecutionEvent;
16 17
import org.eclipse.core.runtime.CoreException;
17 18
import org.eclipse.core.runtime.IConfigurationElement;
18 19
import org.eclipse.core.runtime.IExtensionRegistry;
......
50 51

  
51 52
    private Object input;
52 53
    private Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap;
54
    private ExecutionEvent executionEvent;
53 55

  
54 56
    public CdmViewerChooser(Shell parentShell) {
55 57
        this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
......
66 68
    /**
67 69
     * Opens a popup dialog with all possible viewers for the given input.
68 70
     * @param input the input for which the viewers are listed
71
     * @param event the {@link ExecutionEvent} if invoked via command/handler
69 72
     */
70
    public void chooseViewer(Object input){
73
    public void chooseViewer(Object input, ExecutionEvent event){
71 74
        this.input = input;
75
        this.executionEvent = event;
72 76
        this.nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
73 77

  
74 78
        IExtensionRegistry reg = Platform.getExtensionRegistry();
......
95 99
        if(nameViewerMap.size()==1){
96 100
            Entry<Class<?>, String> next = nameViewerMap.keySet().iterator().next();
97 101
            ICdmViewer cdmViewer = nameViewerMap.get(next);
98
            cdmViewer.show(input, next.getKey());
102
            cdmViewer.show(input, next.getKey(), event);
99 103
        }
100 104
        else{
101 105
            if(nameViewerMap.isEmpty()){
......
129 133
            if(nameViewerMap.containsKey(firstElement)){
130 134
                Entry<Class<?>, String> entry = (Entry<Class<?>, String>)firstElement;
131 135
                ICdmViewer cdmViewer = nameViewerMap.get(entry);
132
                cdmViewer.show(input, entry.getKey());
136
                cdmViewer.show(input, entry.getKey(), this.executionEvent);
133 137
                this.close();
134 138
            }
135 139
        }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
11 11

  
12 12
import java.util.Map;
13 13

  
14
import org.eclipse.core.commands.ExecutionEvent;
15

  
14 16

  
15 17
/**
16 18
 * Implementors of this interface provide a mapping of input elements to views
......
38 40
     * Opens the viewer defined by the given viewerClass for the given input.
39 41
     * @param input the input for which a viewer should be opened
40 42
     * @param viewerClass the qualified class name of the viewer
43
     * @param event the {@link ExecutionEvent} if invoked via command/handler
41 44
     */
42
    public void show(Object input, Class<?> viewerClass);
45
    public void show(Object input, Class<?> viewerClass, ExecutionEvent event);
43 46

  
44 47
}

Also available in: Unified diff