Project

General

Profile

« Previous | Next » 

Revision c0a29cdd

Added by Patrick Plitzner over 8 years ago

Fix double click on taxa in taxon navigator and search results

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
12 12
import java.util.Set;
13 13
import java.util.UUID;
14 14

  
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.NotEnabledException;
17
import org.eclipse.core.commands.NotHandledException;
18
import org.eclipse.core.commands.common.NotDefinedException;
19 15
import org.eclipse.core.commands.operations.IUndoContext;
20 16
import org.eclipse.core.commands.operations.UndoContext;
21 17
import org.eclipse.jface.viewers.StructuredSelection;
......
25 21
import org.eclipse.ui.IEditorReference;
26 22
import org.eclipse.ui.IWorkbenchWindow;
27 23
import org.eclipse.ui.PartInitException;
28
import org.eclipse.ui.handlers.IHandlerService;
29 24
import org.eclipse.ui.navigator.CommonViewer;
30 25

  
31 26
import eu.etaxonomy.cdm.model.common.ICdmBase;
......
54 49
public class NavigationUtil extends AbstractUtility{
55 50
	private static IUndoContext defaultUndoContext;
56 51

  
57
	/**
58
	 * <p>executeEditHandler</p>
59
	 */
60
	public static void executeEditHandler(){
61

  
62
		String commandId = "eu.etaxonomy.taxeditor.navigation.command.update.editSelection";
63

  
64
		IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
65
		try {
66
			handlerService.executeCommand(commandId, null);
67
		} catch (ExecutionException e) {
68
			MessagingUtils.error(NavigationUtil.class, e);
69
		} catch (NotDefinedException e) {
70
			MessagingUtils.error(NavigationUtil.class, e);
71
		} catch (NotEnabledException e) {
72
			MessagingUtils.error(NavigationUtil.class, e);
73
		} catch (NotHandledException e) {
74
			MessagingUtils.error(NavigationUtil.class, e);
75
		}
76
	}
77

  
78 52
	/**
79 53
	 * <p>openEditor</p>
80 54
	 *
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java
25 25
import org.eclipse.core.runtime.IAdaptable;
26 26
import org.eclipse.core.runtime.IProgressMonitor;
27 27
import org.eclipse.jface.viewers.DoubleClickEvent;
28
import org.eclipse.jface.viewers.IStructuredSelection;
28 29
import org.eclipse.jface.viewers.TreePath;
29 30
import org.eclipse.ui.IMemento;
30 31
import org.eclipse.ui.IViewSite;
......
54 55
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
55 56
import eu.etaxonomy.taxeditor.store.CdmStore;
56 57
import eu.etaxonomy.taxeditor.store.LoginManager;
58
import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
57 59

  
58 60
/**
59 61
 * Taxonomic tree implementation using Common Navigator Framework.
......
449 451

  
450 452
	/** {@inheritDoc} */
451 453
	@Override
452
	protected void handleDoubleClick(DoubleClickEvent anEvent) {
453
		NavigationUtil.executeEditHandler();
454
	protected void handleDoubleClick(DoubleClickEvent event) {
455
        if(event.getSelection() instanceof IStructuredSelection){
456
            Object selectedObject = ((IStructuredSelection) event.getSelection()).getFirstElement();
457
            CdmViewerChooser chooser = new CdmViewerChooser(getSite().getShell());
458
            chooser.chooseViewer(selectedObject);
459
        }
454 460
		// If the double click is passed up to the super-class it will
455 461
		// expand/collapse trees.
456 462
		// We do not want that
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java
21 21
import org.eclipse.jface.viewers.ArrayContentProvider;
22 22
import org.eclipse.jface.viewers.DoubleClickEvent;
23 23
import org.eclipse.jface.viewers.IDoubleClickListener;
24
import org.eclipse.jface.viewers.IStructuredSelection;
24 25
import org.eclipse.jface.viewers.TableViewer;
25 26
import org.eclipse.swt.SWT;
26 27
import org.eclipse.swt.layout.GridData;
......
37 38

  
38 39
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
39 40
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
41
import eu.etaxonomy.cdm.api.service.ITaxonService;
40 42
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
41 43
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
44
import eu.etaxonomy.cdm.model.taxon.Synonym;
45
import eu.etaxonomy.cdm.model.taxon.Taxon;
46
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
42 47
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
43 48
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
44 49
import eu.etaxonomy.cdm.persistence.query.MatchMode;
45 50
import eu.etaxonomy.taxeditor.model.AbstractUtility;
46 51
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
47 52
import eu.etaxonomy.taxeditor.model.IContextListener;
48
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
49 53
import eu.etaxonomy.taxeditor.navigation.search.SearchBar.SearchOption;
50 54
import eu.etaxonomy.taxeditor.store.CdmStore;
55
import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
51 56

  
52 57
/**
53 58
 * <p>SearchResultView class.</p>
......
116 121
		resultViewer.addDoubleClickListener(new IDoubleClickListener() {
117 122
			@Override
118 123
            public void doubleClick(DoubleClickEvent event) {
119
				NavigationUtil.executeEditHandler();
124
			    if(event.getSelection() instanceof IStructuredSelection){
125
			        Object selectedObject = ((IStructuredSelection) event.getSelection()).getFirstElement();
126
			        if (selectedObject instanceof UuidAndTitleCache){
127
			            Class type = ((UuidAndTitleCache) selectedObject).getType();
128
			            if(type == Taxon.class || type == Synonym.class){
129
			                TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(((UuidAndTitleCache) selectedObject).getUuid());
130
			                CdmViewerChooser chooser = new CdmViewerChooser(getSite().getShell());
131
			                chooser.chooseViewer(taxonBase);
132
			            }
133
			        }
134
			    }
120 135
			}
121 136
		});
122 137

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
12 12
import java.util.HashMap;
13 13
import java.util.Map;
14 14

  
15
import org.eclipse.core.commands.Command;
15 16
import org.eclipse.core.runtime.IConfigurationElement;
16 17
import org.eclipse.core.runtime.IExtensionRegistry;
17 18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.commands.ICommandService;
18 21

  
19 22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
20 23

  
......
49 52
                        String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
50 53
                        Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
51 54
                        if(selectionClass.isAssignableFrom(input.getClass())){
52
                            commandViewerNameMap.put(commandId, viewerName);
55
                            ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
56
                            Command command = commandService.getCommand(commandId);
57
                            //TODO: maybe pass the command directly instead of just the command id
58
                            if(command.isEnabled()){
59
                                commandViewerNameMap.put(commandId, viewerName);
60
                            }
53 61
                        }
54 62
                    } catch (ClassNotFoundException e) {
55 63
                        MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$

Also available in: Unified diff