From: Patrick Plitzner
Date: Tue, 7 Jul 2015 14:36:18 +0000 (+0200)
Subject: Refactor ICdmViewer framework
X-Git-Tag: 3.7.0~1^2~17
X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/243636c263a5c0779c58c6ebb435a025767ad362
Refactor ICdmViewer framework
Removed unnecessary ExecutionEvent
---
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
index 4d92e047d..796d19aa3 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
@@ -13,7 +13,6 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.PartInitException;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
@@ -31,11 +30,8 @@ public class EditorCdmViewer implements ICdmViewer {
private final Logger logger = Logger.getLogger(EditorCdmViewer.class);
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
- */
@Override
- public void show(Object input, Class> viewerClass, ExecutionEvent event) {
+ public void show(Object input, Class> viewerClass) {
try {
if(viewerClass.equals(MultiPageTaxonEditor.class)){
if(input instanceof TaxonBase){
@@ -54,9 +50,6 @@ public class EditorCdmViewer implements ICdmViewer {
}
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
- */
@Override
public Map, String> getViewerClasses(Object input) {
Map, String> viewerNameMap = new HashMap, String>();
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java
index 9784c9a76..8ba357df8 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java
@@ -4,9 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.PlatformUI;
import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
@@ -18,26 +17,20 @@ public class NavigationCdmViewer implements ICdmViewer {
@SuppressWarnings("unused")
private final Logger logger = Logger.getLogger(NavigationCdmViewer.class);
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
- */
@Override
- public void show(Object input, Class> viewerClass, ExecutionEvent event) {
+ public void show(Object input, Class> viewerClass) {
if(viewerClass.equals(NewClassificationWizard.class)){
if(input instanceof Classification){
Classification classification = (Classification)input;
NewClassificationWizard classificationWizard = new NewClassificationWizard();
classificationWizard.init(null, null);
classificationWizard.setEntity(classification);
- WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
+ WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
dialog.open();
}
}
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
- */
@Override
public Map, String> getViewerClasses(Object input) {
Map, String> viewerNameMap = new HashMap, String>();
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java
index eecb24ba9..e6e8dc6d8 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java
@@ -9,6 +9,14 @@ import org.eclipse.ui.handlers.HandlerUtil;
import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
+/**
+ * Opens the (first) currently selected element in a viewer. Opens a list of
+ * possible viewers if more than one are registered for this element.
+ *
+ * @author pplitzner
+ * @date Jul 6, 2015
+ *
+ */
public class OpenHandler extends AbstractHandler {
@Override
@@ -17,7 +25,7 @@ public class OpenHandler extends AbstractHandler {
if(currentSelection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement();
CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event));
- viewerChooser.chooseViewer(firstElement, event);
+ viewerChooser.chooseViewer(firstElement);
}
return null;
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
index 3b3909385..2aa1f6766 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
@@ -13,7 +13,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
@@ -40,8 +39,8 @@ 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
- * which can be opened for a given input in a popup dialog.
+ * This class opens a popup dialog and provides the possibility to choose from a
+ * list of possible viewers which can be opened for a given input.
*
* @author pplitzner
* @date Feb 23, 2015
@@ -51,7 +50,6 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
private Object input;
private Map, String>, ICdmViewer> nameViewerMap;
- private ExecutionEvent executionEvent;
public CdmViewerChooser(Shell parentShell) {
this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
@@ -65,15 +63,8 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
titleText, infoText);
}
- /**
- * Opens a popup dialog with all possible viewers for the given input.
- * @param input the input for which the viewers are listed
- * @param event the {@link ExecutionEvent} if invoked via command/handler
- */
- public void chooseViewer(Object input, ExecutionEvent event){
- this.input = input;
- this.executionEvent = event;
- this.nameViewerMap = new HashMap, String>, ICdmViewer>();
+ public static Map, String>, ICdmViewer> getNameViewerMap(Object input){
+ Map, String>, ICdmViewer> nameViewerMap = new HashMap, String>, ICdmViewer>();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IConfigurationElement[] extensions = reg
@@ -95,11 +86,22 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
}
}
+ return nameViewerMap;
+ }
+
+ /**
+ * Opens a popup dialog with all possible viewers for the given input.
+ * @param input the input for which the viewers are listed
+ */
+ public void chooseViewer(Object input){
+ this.input = input;
+ this.nameViewerMap = getNameViewerMap(input);
+
//if only one editor is available then open it
if(nameViewerMap.size()==1){
Entry, String> next = nameViewerMap.keySet().iterator().next();
ICdmViewer cdmViewer = nameViewerMap.get(next);
- cdmViewer.show(input, next.getKey(), event);
+ cdmViewer.show(input, next.getKey());
}
else{
if(nameViewerMap.isEmpty()){
@@ -109,9 +111,6 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
}
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
- */
@Override
protected Control createDialogArea(Composite parent) {
TableViewer viewer = new TableViewer(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
@@ -122,9 +121,6 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
return parent;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
- */
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
@@ -133,15 +129,12 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
if(nameViewerMap.containsKey(firstElement)){
Entry, String> entry = (Entry, String>)firstElement;
ICdmViewer cdmViewer = nameViewerMap.get(entry);
- cdmViewer.show(input, entry.getKey(), this.executionEvent);
+ cdmViewer.show(input, entry.getKey());
this.close();
}
}
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- */
@Override
public String getText(Object element) {
String text = null;
@@ -152,45 +145,30 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
return text;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
- */
@Override
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
- */
@Override
public void dispose() {
// TODO Auto-generated method stub
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
- */
@Override
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
- */
@Override
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
- */
@Override
public Image getImage(Object element) {
// TODO Auto-generated method stub
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
index 877daa81a..92063cfb2 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
@@ -11,8 +11,6 @@ package eu.etaxonomy.taxeditor.view;
import java.util.Map;
-import org.eclipse.core.commands.ExecutionEvent;
-
/**
* Implementors of this interface provide a mapping of input elements to views
@@ -26,8 +24,8 @@ import org.eclipse.core.commands.ExecutionEvent;
public interface ICdmViewer {
/**
- * For the given input a map specifying the available viewers classes as
- * keys and their string representation as values is returned
+ * For the given input a map is returned specifying the available viewer
+ * classes as keys and their string representation as values
*
* @param input
* the input for which the viewer classes should be returned
@@ -40,8 +38,7 @@ public interface ICdmViewer {
* Opens the viewer defined by the given viewerClass for the given input.
* @param input the input for which a viewer should be opened
* @param viewerClass the qualified class name of the viewer
- * @param event the {@link ExecutionEvent} if invoked via command/handler
*/
- public void show(Object input, Class> viewerClass, ExecutionEvent event);
+ public void show(Object input, Class> viewerClass);
}