3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
;
12 import java
.util
.HashMap
;
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
;
37 public class CdmViewerChooser
extends PopupDialog
implements ISelectionChangedListener
{
39 private Map
<String
, ICdmViewer
> viewerNameMap
;
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");
46 public CdmViewerChooser(Shell parent
, int shellStyle
, boolean takeFocusOnOpen
, boolean persistSize
,
47 boolean persistLocation
, boolean showDialogMenu
, boolean showPersistActions
, String titleText
,
49 super(parent
, shellStyle
, takeFocusOnOpen
, persistSize
, persistLocation
, showDialogMenu
, showPersistActions
,
53 public void chooseViewer(Object input
){
54 viewerNameMap
= new HashMap
<String
, ICdmViewer
>();
56 IExtensionRegistry reg
= Platform
.getExtensionRegistry();
57 IConfigurationElement
[] extensions
= reg
58 .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
59 for (IConfigurationElement e
: extensions
) {
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);
72 // } catch (CoreException e1) {
73 // MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e1);
75 for (IConfigurationElement inputConfigurationElement
: e
.getChildren("input")) {
76 System
.out
.println("input");
77 for (IConfigurationElement partConfigurationElement
: inputConfigurationElement
.getChildren("part")) {
78 System
.out
.println("part");
86 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
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());
99 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
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
);
108 cdmViewer
.show(input
, null);