Project

General

Profile

« Previous | Next » 

Revision 3dba9fc4

Added by Patrick Plitzner about 9 years ago

  • implemented framework which links an input element to viewers/editors which are able to display information about the element
    • added ICdmViewer interface
    • added extension point to register ICdmViewer
    • registered EditorCdmViewer for the taxeditor.editor plugin

View differences:

.gitattributes
371 371
eu.etaxonomy.taxeditor.editor/pom.xml -text
372 372
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java -text
373 373
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java -text
374
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java -text
374 375
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorStateManager.java -text
375 376
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java -text
376 377
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/IDropTargetable.java -text
......
1207 1208
eu.etaxonomy.taxeditor.store/p2.inf -text
1208 1209
eu.etaxonomy.taxeditor.store/plugin.xml -text
1209 1210
eu.etaxonomy.taxeditor.store/pom.xml -text
1211
eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd -text
1210 1212
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java -text
1211 1213
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceCredentialsWizardPage.java -text
1212 1214
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceH2WizardPage.java -text
......
1764 1766
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java -text
1765 1767
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java -text
1766 1768
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractSplitableViewPart.java -text
1769
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java -text
1770
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java -text
1767 1771
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceContentProvider.java -text
1768 1772
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceLabelProvider.java -text
1769 1773
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceViewPart.java -text
eu.etaxonomy.taxeditor.editor/plugin.xml
1613 1613
         </description>
1614 1614
      </wizard>
1615 1615
   </extension>
1616
    <extension
1617
          point="eu.etaxonomy.taxeditor.store.cdmViewer">
1618
       <cdmViewer
1619
             class="eu.etaxonomy.taxeditor.editor.EditorCdmViewer">
1620
          <input
1621
                class="eu.etaxonomy.cdm.model.taxon.TaxonBase">
1622
             <part
1623
                   class="eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor"
1624
                   name="Taxon Editor">
1625
             </part>
1626
          </input>
1627
       </cdmViewer>
1628
    </extension>
1616 1629
</plugin>
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.editor;
11

  
12
import org.apache.log4j.Logger;
13
import org.eclipse.ui.PartInitException;
14

  
15
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
16
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.view.ICdmViewer;
20

  
21
/**
22
 * @author pplitzner
23
 * @date Feb 23, 2015
24
 *
25
 */
26
public class EditorCdmViewer implements ICdmViewer {
27

  
28
    private final Logger logger = Logger.getLogger(EditorCdmViewer.class);
29

  
30
    /* (non-Javadoc)
31
     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
32
     */
33
    @Override
34
    public void show(Object input, Class<?> viewerClass) {
35
        try {
36
            if(viewerClass.equals(MultiPageTaxonEditor.class)){
37
                if(input instanceof TaxonBase){
38
                    TaxonEditorInput editorInput = TaxonEditorInput.NewInstanceFromTaxonBase(((TaxonBase<?>) input).getUuid());
39
                    EditorUtil.open(editorInput);
40
                }
41
            }
42
            else if(viewerClass.equals(DerivateView.class)){
43
                if(input instanceof SpecimenOrObservationBase){
44
                }
45
            }
46
        } catch (PartInitException e) {
47
            String errorMessage = "Could not open editor";
48
            logger.error(errorMessage, e);
49
            MessagingUtils.error(EditorCdmViewer.class, errorMessage, e);
50
        }
51
    }
52

  
53
}
eu.etaxonomy.taxeditor.store/plugin.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<?eclipse version="3.2"?>
3 3
<plugin>
4
   <extension-point id="eu.etaxonomy.taxeditor.store.cdmViewer" name="Cdm Viewer" schema="schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd"/>
4 5
   <extension
5 6
         point="org.eclipse.ui.preferencePages">
6 7
      <page
eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="eu.etaxonomy.taxeditor.store" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="eu.etaxonomy.taxeditor.store" id="eu.etaxonomy.taxeditor.store.cdmViewer" name="Cdm Viewer"/>
7
      </appInfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence minOccurs="1" maxOccurs="unbounded">
21
            <element ref="cdmViewer"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="att" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute kind="java"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="cdmViewer">
51
      <annotation>
52
         <documentation>
53
            A Cdm Viewer knows what viewer or editor can show which input.
54
         </documentation>
55
      </annotation>
56
      <complexType>
57
         <sequence>
58
            <element ref="input"/>
59
         </sequence>
60
         <attribute name="class" type="string" use="required">
61
            <annotation>
62
               <documentation>
63
                  The class of the viewer.
64
               </documentation>
65
               <appInfo>
66
                  <meta.attribute kind="java" basedOn=":eu.etaxonomy.taxeditor.view.ICdmViewer"/>
67
               </appInfo>
68
            </annotation>
69
         </attribute>
70
      </complexType>
71
   </element>
72

  
73
   <element name="input">
74
      <annotation>
75
         <documentation>
76
            The input element which can be shown by the cdmViewer.
77
         </documentation>
78
      </annotation>
79
      <complexType>
80
         <sequence>
81
            <element ref="part"/>
82
         </sequence>
83
         <attribute name="class" type="string" use="required">
84
            <annotation>
85
               <documentation>
86
                  The class of the input element.
87
               </documentation>
88
               <appInfo>
89
                  <meta.attribute kind="java"/>
90
               </appInfo>
91
            </annotation>
92
         </attribute>
93
      </complexType>
94
   </element>
95

  
96
   <element name="part">
97
      <annotation>
98
         <documentation>
99
            The part which can be opened for the given input.
100
         </documentation>
101
      </annotation>
102
      <complexType>
103
         <attribute name="class" type="string" use="required">
104
            <annotation>
105
               <documentation>
106
                  The class of the part.
107
               </documentation>
108
               <appInfo>
109
                  <meta.attribute kind="java"/>
110
               </appInfo>
111
            </annotation>
112
         </attribute>
113
         <attribute name="name" type="string">
114
            <annotation>
115
               <documentation>
116
                  The name of the part.
117
               </documentation>
118
            </annotation>
119
         </attribute>
120
      </complexType>
121
   </element>
122

  
123
   <annotation>
124
      <appInfo>
125
         <meta.section type="since"/>
126
      </appInfo>
127
      <documentation>
128
         [Enter the first release in which this extension point appears.]
129
      </documentation>
130
   </annotation>
131

  
132
   <annotation>
133
      <appInfo>
134
         <meta.section type="examples"/>
135
      </appInfo>
136
      <documentation>
137
         [Enter extension point usage example here.]
138
      </documentation>
139
   </annotation>
140

  
141
   <annotation>
142
      <appInfo>
143
         <meta.section type="apiinfo"/>
144
      </appInfo>
145
      <documentation>
146
         [Enter API information here.]
147
      </documentation>
148
   </annotation>
149

  
150
   <annotation>
151
      <appInfo>
152
         <meta.section type="implementation"/>
153
      </appInfo>
154
      <documentation>
155
         [Enter information about supplied implementation of this extension point.]
156
      </documentation>
157
   </annotation>
158

  
159

  
160
</schema>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
1
// $Id$
2
/**
3
 * Copyright (C) 2015 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.view;
11

  
12
import java.util.HashMap;
13
import java.util.Map;
14

  
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.IExtensionRegistry;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.jface.dialogs.PopupDialog;
19
import org.eclipse.jface.viewers.ArrayContentProvider;
20
import org.eclipse.jface.viewers.ColumnLabelProvider;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.ISelectionChangedListener;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.SelectionChangedEvent;
25
import org.eclipse.jface.viewers.TableViewer;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.swt.widgets.Table;
31

  
32
/**
33
 * @author pplitzner
34
 * @date Feb 23, 2015
35
 *
36
 */
37
public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener{
38

  
39
    private Map<String, ICdmViewer> viewerNameMap;
40
    private Object input;
41

  
42
    public CdmViewerChooser(Shell parentShell) {
43
        this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...", "Clicking will open the selected viewer");
44
    }
45

  
46
    public CdmViewerChooser(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean persistSize,
47
            boolean persistLocation, boolean showDialogMenu, boolean showPersistActions, String titleText,
48
            String infoText) {
49
        super(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation, showDialogMenu, showPersistActions,
50
                titleText, infoText);
51
    }
52

  
53
    public void chooseViewer(Object input){
54
        viewerNameMap = new HashMap<String, ICdmViewer>();
55
        this.input = input;
56
        IExtensionRegistry reg = Platform.getExtensionRegistry();
57
        IConfigurationElement[] extensions = reg
58
                .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
59
        for (IConfigurationElement e : extensions) {
60
            Object o;
61
//            try {
62
//                o = e.createExecutableExtension("class");
63
//                if (o instanceof ICdmViewer) {
64
//                    ICdmViewer cdmViewer = (ICdmViewer) o;
65
//                    Collection<String> viewerNames = cdmViewer.getViewerNames(input);
66
//                    if(viewerNames!=null){
67
//                        for (String string : viewerNames) {
68
//                            viewerNameMap.put(string, cdmViewer);
69
//                        }
70
//                    }
71
//                }
72
//            } catch (CoreException e1) {
73
//                MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e1);
74
//            }
75
            for (IConfigurationElement inputConfigurationElement : e.getChildren("input")) {
76
                System.out.println("input");
77
                for (IConfigurationElement partConfigurationElement : inputConfigurationElement.getChildren("part")) {
78
                    System.out.println("part");
79
                }
80
            }
81
        }
82
        this.open();
83
    }
84

  
85
    /* (non-Javadoc)
86
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
87
     */
88
    @Override
89
    protected Control createDialogArea(Composite parent) {
90
        TableViewer viewer = new TableViewer(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
91
        viewer.setContentProvider(new ArrayContentProvider());
92
        viewer.setLabelProvider(new ColumnLabelProvider());
93
        viewer.addSelectionChangedListener(this);
94
        viewer.setInput(viewerNameMap.keySet());
95
        return parent;
96
    }
97

  
98
    /* (non-Javadoc)
99
     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
100
     */
101
    @Override
102
    public void selectionChanged(SelectionChangedEvent event) {
103
        ISelection selection = event.getSelection();
104
        if(selection instanceof IStructuredSelection){
105
            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
106
            ICdmViewer cdmViewer = viewerNameMap.get(firstElement);
107
            if(cdmViewer!=null){
108
                cdmViewer.show(input, null);
109
                this.close();
110
            }
111
        }
112
    }
113

  
114
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.view;
11

  
12

  
13
/**
14
 * @author pplitzner
15
 * @date Feb 23, 2015
16
 *
17
 */
18
public interface ICdmViewer {
19

  
20
    public void show(Object input, Class<?> viewerName);
21

  
22
}

Also available in: Unified diff