*/
package eu.etaxonomy.taxeditor.editor;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.log4j.Logger;
import org.eclipse.ui.PartInitException;
* @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
*/
@Override
- public void show(Object input, String viewerClass) {
+ public void show(Object input, Class<?> viewerClass) {
try {
- if(viewerClass.equals(MultiPageTaxonEditor.class.toString())){
+ if(viewerClass.equals(MultiPageTaxonEditor.class)){
if(input instanceof TaxonBase){
TaxonEditorInput editorInput = TaxonEditorInput.NewInstanceFromTaxonBase(((TaxonBase<?>) input).getUuid());
EditorUtil.open(editorInput);
}
}
- else if(viewerClass.equals(DerivateView.class.toString())){
+ else if(viewerClass.equals(DerivateView.class)){
if(input instanceof SpecimenOrObservationBase){
}
}
}
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
+ */
+ @Override
+ public Map<Class<?>, String> getViewerClasses(Object input) {
+ Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>();
+ if(input instanceof TaxonBase){
+ viewerNameMap.put(MultiPageTaxonEditor.class, "Taxon Editor");
+ }
+ return viewerNameMap;
+ }
+
}
*/
package eu.etaxonomy.taxeditor.view;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.widgets.Table;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
/**
* This class provides the possibility to choose from a list of possible viewers
public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener, ILabelProvider{
private Object input;
- private Collection<IConfigurationElement> partConfigurationElements;
+ private Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap;
public CdmViewerChooser(Shell parentShell) {
this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
*/
public void chooseViewer(Object input){
this.input = input;
- partConfigurationElements = new ArrayList<>();
+ this.nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IConfigurationElement[] extensions = reg
.getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
- for (IConfigurationElement e : extensions) {
- for (IConfigurationElement inputConfigurationElement : e.getChildren("input")) {
- String inputClass = inputConfigurationElement.getAttribute("class");
- if(inputClass.equals(input.getClass().toString())){
- System.out.println("input class: " + inputClass);
- for (IConfigurationElement partConfigurationElement : inputConfigurationElement.getChildren("part")) {
- partConfigurationElements.add(partConfigurationElement);
+ for (IConfigurationElement configElement : extensions) {
+ try {
+ Object object = configElement.createExecutableExtension("class");
+ if(object instanceof ICdmViewer){
+ ICdmViewer cdmViewer = (ICdmViewer)object;
+ Map<Class<?>, String> viewerClasses = cdmViewer.getViewerClasses(input);
+ for (Entry<Class<?>, String> entry : viewerClasses.entrySet()) {
+ nameViewerMap.put(entry, cdmViewer);
}
}
+ else{
+ MessagingUtils.error(CdmViewerChooser.class, new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Could not load cdmViewer extension"));
+ }
+ } catch (CoreException e) {
+ MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
+ }
+ }
+ //if only one editor is available then open it
+ if(nameViewerMap.size()==1){
+ Entry<Class<?>, String> next = nameViewerMap.keySet().iterator().next();
+ ICdmViewer cdmViewer = nameViewerMap.get(next);
+ cdmViewer.show(input, next.getKey());
+ }
+ else{
+ if(nameViewerMap.isEmpty()){
+ this.setInfoText("No viewers registered for this input");
}
+ this.open();
}
- this.open();
}
/* (non-Javadoc)
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(this);
viewer.addSelectionChangedListener(this);
- viewer.setInput(partConfigurationElements);
+ viewer.setInput(nameViewerMap.keySet());
return parent;
}
ISelection selection = event.getSelection();
if(selection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
- if(firstElement instanceof IConfigurationElement){
- IConfigurationElement configElement = (IConfigurationElement)firstElement;
- String viewerClass = configElement.getAttribute("class");
- try {
- //get the grand parent (this is the cdmViewer)
- Object o = ((IConfigurationElement)((IConfigurationElement)configElement.getParent()).getParent()).createExecutableExtension("class");
- if(o instanceof ICdmViewer){
- ((ICdmViewer) o).show(input, viewerClass);
- this.close();
- }
- } catch (InvalidRegistryObjectException e) {
- MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
- } catch (CoreException e) {
- MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
- }
+ if(nameViewerMap.containsKey(firstElement)){
+ Entry<Class<?>, String> entry = (Entry<Class<?>, String>)firstElement;
+ ICdmViewer cdmViewer = nameViewerMap.get(entry);
+ cdmViewer.show(input, entry.getKey());
+ this.close();
}
}
}
@Override
public String getText(Object element) {
String text = null;
- if(element instanceof IConfigurationElement){
- IConfigurationElement configElement = (IConfigurationElement)element;
- text = configElement.getAttribute("name");
- if(text==null){
- text = configElement.getAttribute("class");
- }
+ if(nameViewerMap.containsKey(element)){
+ Entry<Class<?>, String> entry = (Entry<Class<?>, String>) element;
+ text = entry.getValue();
}
return text;
}