Project

General

Profile

« Previous | Next » 

Revision ed04d0e4

Added by Patrick Plitzner almost 6 years ago

fix #5348 Add "copy" context menu to taxon association details view

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
13 13
import java.util.Collection;
14 14
import java.util.Set;
15 15

  
16
import org.eclipse.jface.action.MenuManager;
17 16
import org.eclipse.jface.viewers.ArrayContentProvider;
18 17
import org.eclipse.jface.viewers.DoubleClickEvent;
19 18
import org.eclipse.jface.viewers.IDoubleClickListener;
19
import org.eclipse.jface.viewers.ISelection;
20 20
import org.eclipse.jface.viewers.IStructuredSelection;
21 21
import org.eclipse.jface.viewers.LabelProvider;
22 22
import org.eclipse.jface.viewers.ListViewer;
23 23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.dnd.Clipboard;
25
import org.eclipse.swt.dnd.TextTransfer;
26
import org.eclipse.swt.dnd.Transfer;
27
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.events.SelectionListener;
25 29
import org.eclipse.swt.widgets.Label;
26 30
import org.eclipse.swt.widgets.Menu;
27
import org.eclipse.ui.handlers.HandlerUtil;
31
import org.eclipse.swt.widgets.MenuItem;
28 32

  
29 33
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
30 34
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
......
55 59
    /** {@inheritDoc} */
56 60
    @Override
57 61
    protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
58

  
59
        //TODO add context menu for deleting associations
60

  
61 62
        Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listIndividualsAssociationTaxa(entity.innerDerivedUnit(), null, null, null, null);
62 63
        Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null);
63 64
        Collection<DeterminationEvent> determinationEvents = CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(entity.innerDerivedUnit(), null, null, null, null);
......
66 67
        associations.addAll(associatedTaxa);
67 68
        associations.addAll(typeDesignations);
68 69
        associations.addAll(determinationEvents);
69
        
70

  
70 71
        if(associatedTaxa.isEmpty() && typeDesignations.isEmpty() && determinationEvents.isEmpty()){
71 72
            Label label = formFactory.createLabel(getLayoutComposite(), "No associations");
72 73
            label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
73 74
            return;
74 75
        }
75 76
        if(!associations.isEmpty()){
76
        	ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.SINGLE);
77
        	final ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.SINGLE);
77 78
        	viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
78 79
        	viewer.setContentProvider(new ArrayContentProvider());
79 80
        	viewer.setLabelProvider(new LabelProvider(){
......
108 109
        	});
109 110
        	viewer.setInput(associations);
110 111
        	viewer.addDoubleClickListener(this);
112

  
113
            //TODO add context menu for deleting associations
114
        	//context menu
115
        	Menu menu = new Menu(viewer.getControl());
116
        	MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
117
        	copyItem.setText("Copy");
118
        	copyItem.addSelectionListener(new SelectionListener() {
119

  
120
                @Override
121
                public void widgetSelected(SelectionEvent e) {
122
                    ISelection selection = viewer.getSelection();
123
                    if(!selection.isEmpty() && selection instanceof IStructuredSelection){
124
                        Object firstElement = ((IStructuredSelection) selection).getFirstElement();
125
                        Object[] data = new Object[]{firstElement.toString()};
126
                        Clipboard clipboard = new Clipboard(viewer.getControl().getDisplay());
127
                        clipboard.setContents(data, new Transfer[]{TextTransfer.getInstance()});
128
                    }
129
                }
130

  
131
                @Override
132
                public void widgetDefaultSelected(SelectionEvent e) {
133
                }
134
            });
135
        	viewer.getControl().setMenu(menu);
111 136
        }
112 137
    }
113 138

  

Also available in: Unified diff