Revision 243636c2
Added by Patrick Plitzner almost 9 years ago
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; |
|
17 | 16 |
import org.eclipse.ui.PartInitException; |
18 | 17 |
|
19 | 18 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
... | ... | |
31 | 30 |
|
32 | 31 |
private final Logger logger = Logger.getLogger(EditorCdmViewer.class); |
33 | 32 |
|
34 |
/* (non-Javadoc) |
|
35 |
* @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object) |
|
36 |
*/ |
|
37 | 33 |
@Override |
38 |
public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
|
|
34 |
public void show(Object input, Class<?> viewerClass) { |
|
39 | 35 |
try { |
40 | 36 |
if(viewerClass.equals(MultiPageTaxonEditor.class)){ |
41 | 37 |
if(input instanceof TaxonBase){ |
... | ... | |
54 | 50 |
} |
55 | 51 |
} |
56 | 52 |
|
57 |
/* (non-Javadoc) |
|
58 |
* @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object) |
|
59 |
*/ |
|
60 | 53 |
@Override |
61 | 54 |
public Map<Class<?>, String> getViewerClasses(Object input) { |
62 | 55 |
Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>(); |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java | ||
---|---|---|
4 | 4 |
import java.util.Map; |
5 | 5 |
|
6 | 6 |
import org.apache.log4j.Logger; |
7 |
import org.eclipse.core.commands.ExecutionEvent; |
|
8 | 7 |
import org.eclipse.jface.wizard.WizardDialog; |
9 |
import org.eclipse.ui.handlers.HandlerUtil;
|
|
8 |
import org.eclipse.ui.PlatformUI;
|
|
10 | 9 |
|
11 | 10 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
12 | 11 |
import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard; |
... | ... | |
18 | 17 |
@SuppressWarnings("unused") |
19 | 18 |
private final Logger logger = Logger.getLogger(NavigationCdmViewer.class); |
20 | 19 |
|
21 |
/* (non-Javadoc) |
|
22 |
* @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object) |
|
23 |
*/ |
|
24 | 20 |
@Override |
25 |
public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
|
|
21 |
public void show(Object input, Class<?> viewerClass) { |
|
26 | 22 |
if(viewerClass.equals(NewClassificationWizard.class)){ |
27 | 23 |
if(input instanceof Classification){ |
28 | 24 |
Classification classification = (Classification)input; |
29 | 25 |
NewClassificationWizard classificationWizard = new NewClassificationWizard(); |
30 | 26 |
classificationWizard.init(null, null); |
31 | 27 |
classificationWizard.setEntity(classification); |
32 |
WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
|
|
28 |
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
|
|
33 | 29 |
dialog.open(); |
34 | 30 |
} |
35 | 31 |
} |
36 | 32 |
} |
37 | 33 |
|
38 |
/* (non-Javadoc) |
|
39 |
* @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object) |
|
40 |
*/ |
|
41 | 34 |
@Override |
42 | 35 |
public Map<Class<?>, String> getViewerClasses(Object input) { |
43 | 36 |
Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>(); |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
import eu.etaxonomy.taxeditor.view.CdmViewerChooser; |
11 | 11 |
|
12 |
/** |
|
13 |
* Opens the (first) currently selected element in a viewer. Opens a list of |
|
14 |
* possible viewers if more than one are registered for this element. |
|
15 |
* |
|
16 |
* @author pplitzner |
|
17 |
* @date Jul 6, 2015 |
|
18 |
* |
|
19 |
*/ |
|
12 | 20 |
public class OpenHandler extends AbstractHandler { |
13 | 21 |
|
14 | 22 |
@Override |
... | ... | |
17 | 25 |
if(currentSelection instanceof IStructuredSelection){ |
18 | 26 |
Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement(); |
19 | 27 |
CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event)); |
20 |
viewerChooser.chooseViewer(firstElement, event);
|
|
28 |
viewerChooser.chooseViewer(firstElement); |
|
21 | 29 |
} |
22 | 30 |
return null; |
23 | 31 |
} |
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; |
|
17 | 16 |
import org.eclipse.core.runtime.CoreException; |
18 | 17 |
import org.eclipse.core.runtime.IConfigurationElement; |
19 | 18 |
import org.eclipse.core.runtime.IExtensionRegistry; |
... | ... | |
40 | 39 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
41 | 40 |
|
42 | 41 |
/** |
43 |
* This class provides the possibility to choose from a list of possible viewers
|
|
44 |
* which can be opened for a given input in a popup dialog.
|
|
42 |
* This class opens a popup dialog and provides the possibility to choose from a
|
|
43 |
* list of possible viewers which can be opened for a given input.
|
|
45 | 44 |
* |
46 | 45 |
* @author pplitzner |
47 | 46 |
* @date Feb 23, 2015 |
... | ... | |
51 | 50 |
|
52 | 51 |
private Object input; |
53 | 52 |
private Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap; |
54 |
private ExecutionEvent executionEvent; |
|
55 | 53 |
|
56 | 54 |
public CdmViewerChooser(Shell parentShell) { |
57 | 55 |
this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...", |
... | ... | |
65 | 63 |
titleText, infoText); |
66 | 64 |
} |
67 | 65 |
|
68 |
/** |
|
69 |
* Opens a popup dialog with all possible viewers for the given input. |
|
70 |
* @param input the input for which the viewers are listed |
|
71 |
* @param event the {@link ExecutionEvent} if invoked via command/handler |
|
72 |
*/ |
|
73 |
public void chooseViewer(Object input, ExecutionEvent event){ |
|
74 |
this.input = input; |
|
75 |
this.executionEvent = event; |
|
76 |
this.nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>(); |
|
66 |
public static Map<Entry<Class<?>, String>, ICdmViewer> getNameViewerMap(Object input){ |
|
67 |
Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>(); |
|
77 | 68 |
|
78 | 69 |
IExtensionRegistry reg = Platform.getExtensionRegistry(); |
79 | 70 |
IConfigurationElement[] extensions = reg |
... | ... | |
95 | 86 |
MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e); |
96 | 87 |
} |
97 | 88 |
} |
89 |
return nameViewerMap; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Opens a popup dialog with all possible viewers for the given input. |
|
94 |
* @param input the input for which the viewers are listed |
|
95 |
*/ |
|
96 |
public void chooseViewer(Object input){ |
|
97 |
this.input = input; |
|
98 |
this.nameViewerMap = getNameViewerMap(input); |
|
99 |
|
|
98 | 100 |
//if only one editor is available then open it |
99 | 101 |
if(nameViewerMap.size()==1){ |
100 | 102 |
Entry<Class<?>, String> next = nameViewerMap.keySet().iterator().next(); |
101 | 103 |
ICdmViewer cdmViewer = nameViewerMap.get(next); |
102 |
cdmViewer.show(input, next.getKey(), event);
|
|
104 |
cdmViewer.show(input, next.getKey()); |
|
103 | 105 |
} |
104 | 106 |
else{ |
105 | 107 |
if(nameViewerMap.isEmpty()){ |
... | ... | |
109 | 111 |
} |
110 | 112 |
} |
111 | 113 |
|
112 |
/* (non-Javadoc) |
|
113 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
|
114 |
*/ |
|
115 | 114 |
@Override |
116 | 115 |
protected Control createDialogArea(Composite parent) { |
117 | 116 |
TableViewer viewer = new TableViewer(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION)); |
... | ... | |
122 | 121 |
return parent; |
123 | 122 |
} |
124 | 123 |
|
125 |
/* (non-Javadoc) |
|
126 |
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
|
127 |
*/ |
|
128 | 124 |
@Override |
129 | 125 |
public void selectionChanged(SelectionChangedEvent event) { |
130 | 126 |
ISelection selection = event.getSelection(); |
... | ... | |
133 | 129 |
if(nameViewerMap.containsKey(firstElement)){ |
134 | 130 |
Entry<Class<?>, String> entry = (Entry<Class<?>, String>)firstElement; |
135 | 131 |
ICdmViewer cdmViewer = nameViewerMap.get(entry); |
136 |
cdmViewer.show(input, entry.getKey(), this.executionEvent);
|
|
132 |
cdmViewer.show(input, entry.getKey()); |
|
137 | 133 |
this.close(); |
138 | 134 |
} |
139 | 135 |
} |
140 | 136 |
} |
141 | 137 |
|
142 |
/* (non-Javadoc) |
|
143 |
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) |
|
144 |
*/ |
|
145 | 138 |
@Override |
146 | 139 |
public String getText(Object element) { |
147 | 140 |
String text = null; |
... | ... | |
152 | 145 |
return text; |
153 | 146 |
} |
154 | 147 |
|
155 |
/* (non-Javadoc) |
|
156 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) |
|
157 |
*/ |
|
158 | 148 |
@Override |
159 | 149 |
public void addListener(ILabelProviderListener listener) { |
160 | 150 |
// TODO Auto-generated method stub |
161 | 151 |
|
162 | 152 |
} |
163 | 153 |
|
164 |
/* (non-Javadoc) |
|
165 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() |
|
166 |
*/ |
|
167 | 154 |
@Override |
168 | 155 |
public void dispose() { |
169 | 156 |
// TODO Auto-generated method stub |
170 | 157 |
|
171 | 158 |
} |
172 | 159 |
|
173 |
/* (non-Javadoc) |
|
174 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) |
|
175 |
*/ |
|
176 | 160 |
@Override |
177 | 161 |
public boolean isLabelProperty(Object element, String property) { |
178 | 162 |
// TODO Auto-generated method stub |
179 | 163 |
return false; |
180 | 164 |
} |
181 | 165 |
|
182 |
/* (non-Javadoc) |
|
183 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) |
|
184 |
*/ |
|
185 | 166 |
@Override |
186 | 167 |
public void removeListener(ILabelProviderListener listener) { |
187 | 168 |
// TODO Auto-generated method stub |
188 | 169 |
|
189 | 170 |
} |
190 | 171 |
|
191 |
/* (non-Javadoc) |
|
192 |
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) |
|
193 |
*/ |
|
194 | 172 |
@Override |
195 | 173 |
public Image getImage(Object element) { |
196 | 174 |
// TODO Auto-generated method stub |
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 |
|
|
16 | 14 |
|
17 | 15 |
/** |
18 | 16 |
* Implementors of this interface provide a mapping of input elements to views |
... | ... | |
26 | 24 |
public interface ICdmViewer { |
27 | 25 |
|
28 | 26 |
/** |
29 |
* For the given input a map specifying the available viewers classes as
|
|
30 |
* keys and their string representation as values is returned
|
|
27 |
* For the given input a map is returned specifying the available viewer
|
|
28 |
* classes as keys and their string representation as values
|
|
31 | 29 |
* |
32 | 30 |
* @param input |
33 | 31 |
* the input for which the viewer classes should be returned |
... | ... | |
40 | 38 |
* Opens the viewer defined by the given viewerClass for the given input. |
41 | 39 |
* @param input the input for which a viewer should be opened |
42 | 40 |
* @param viewerClass the qualified class name of the viewer |
43 |
* @param event the {@link ExecutionEvent} if invoked via command/handler |
|
44 | 41 |
*/ |
45 |
public void show(Object input, Class<?> viewerClass, ExecutionEvent event);
|
|
42 |
public void show(Object input, Class<?> viewerClass); |
|
46 | 43 |
|
47 | 44 |
} |
Also available in: Unified diff
Refactor ICdmViewer framework
Removed unnecessary ExecutionEvent