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
;
13 import java
.util
.Map
.Entry
;
15 import org
.eclipse
.jface
.dialogs
.PopupDialog
;
16 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
17 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
18 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
19 import org
.eclipse
.jface
.viewers
.ISelection
;
20 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
23 import org
.eclipse
.jface
.viewers
.TableViewer
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.graphics
.Image
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Shell
;
29 import org
.eclipse
.swt
.widgets
.Table
;
32 * This class opens a popup dialog and provides the possibility to choose from a
33 * list of possible viewers which can be opened for a given input.
39 public class CdmViewerChooser
extends PopupDialog
implements ISelectionChangedListener
, ILabelProvider
{
42 private Map
<Entry
<Class
<?
>, String
>, ICdmViewer
> nameViewerMap
;
44 public CdmViewerChooser(Shell parentShell
) {
45 this(parentShell
, SWT
.RESIZE
| SWT
.ON_TOP
, true, false, false, false, false, "Open in ...",
46 "Clicking will open the selected viewer");
49 public CdmViewerChooser(Shell parent
, int shellStyle
, boolean takeFocusOnOpen
, boolean persistSize
,
50 boolean persistLocation
, boolean showDialogMenu
, boolean showPersistActions
, String titleText
,
52 super(parent
, shellStyle
, takeFocusOnOpen
, persistSize
, persistLocation
, showDialogMenu
, showPersistActions
,
57 * Opens a popup dialog with all possible viewers for the given input.
58 * @param input the input for which the viewers are listed
60 public void chooseViewer(Object input
){
62 this.nameViewerMap
= CdmViewerUtil
.getNameViewerMap(input
);
64 //if only one editor is available then open it
65 if(nameViewerMap
.size()==1){
66 Entry
<Class
<?
>, String
> next
= nameViewerMap
.keySet().iterator().next();
67 ICdmViewer cdmViewer
= nameViewerMap
.get(next
);
68 cdmViewer
.show(input
, next
.getKey());
71 if(nameViewerMap
.isEmpty()){
72 this.setInfoText("No viewers registered for this input");
79 protected Control
createDialogArea(Composite parent
) {
80 TableViewer viewer
= new TableViewer(new Table(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
81 viewer
.setContentProvider(new ArrayContentProvider());
82 viewer
.setLabelProvider(this);
83 viewer
.addSelectionChangedListener(this);
84 viewer
.setInput(nameViewerMap
.keySet());
89 public void selectionChanged(SelectionChangedEvent event
) {
90 ISelection selection
= event
.getSelection();
91 if(selection
instanceof IStructuredSelection
){
92 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
93 if(nameViewerMap
.containsKey(firstElement
)){
94 Entry
<Class
<?
>, String
> entry
= (Entry
<Class
<?
>, String
>)firstElement
;
95 ICdmViewer cdmViewer
= nameViewerMap
.get(entry
);
96 cdmViewer
.show(input
, entry
.getKey());
103 public String
getText(Object element
) {
105 if(nameViewerMap
.containsKey(element
)){
106 Entry
<Class
<?
>, String
> entry
= (Entry
<Class
<?
>, String
>) element
;
107 text
= entry
.getValue();
113 public void addListener(ILabelProviderListener listener
) {
114 // TODO Auto-generated method stub
119 public void dispose() {
120 // TODO Auto-generated method stub
125 public boolean isLabelProperty(Object element
, String property
) {
126 // TODO Auto-generated method stub
131 public void removeListener(ILabelProviderListener listener
) {
132 // TODO Auto-generated method stub
137 public Image
getImage(Object element
) {
138 // TODO Auto-generated method stub