- added section for associated taxa (IndividualsAssocation, TypeDesignation) to...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / association / TaxonAssociationDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.ui.section.occurrence.association;
11
12 import java.util.Collection;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.NotEnabledException;
16 import org.eclipse.core.commands.NotHandledException;
17 import org.eclipse.core.commands.common.NotDefinedException;
18 import org.eclipse.jface.viewers.ArrayContentProvider;
19 import org.eclipse.jface.viewers.DoubleClickEvent;
20 import org.eclipse.jface.viewers.IDoubleClickListener;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.ui.handlers.IHandlerService;
25
26 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
27 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
28 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
29 import eu.etaxonomy.taxeditor.model.AbstractUtility;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
32 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
33 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
34 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
35
36 /**
37 * @author pplitzner
38 * @date Dec 1, 2014
39 *
40 */
41 public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> implements IDoubleClickListener{
42
43
44 public TaxonAssociationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
45 super(formFactory, formElement);
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
51
52 Label associationsLabel = formFactory.createLabel(getLayoutComposite(), "Individuals Associations");
53 associationsLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
54
55 TableViewer associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
56 associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
57 associationsViewer.setContentProvider(new ArrayContentProvider());
58 Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(entity.innerDerivedUnit(), null, null, null, null);
59 associationsViewer.setInput(associatedTaxa);
60 associationsViewer.addDoubleClickListener(this);
61
62 Label typeLabel = formFactory.createLabel(getLayoutComposite(), "Type Designations");
63 typeLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
64
65 TableViewer typeDesignationViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
66 typeDesignationViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
67 typeDesignationViewer.setContentProvider(new ArrayContentProvider());
68 Collection<TaxonBase<?>> typedTaxa = CdmStore.getService(IOccurrenceService.class).listTypedTaxa(entity.innerDerivedUnit(), null, null, null, null);
69 typeDesignationViewer.setInput(typedTaxa);
70 typeDesignationViewer.addDoubleClickListener(this);
71 }
72
73 /** {@inheritDoc} */
74 @Override
75 public void handleEvent(Object eventSource) {
76
77 }
78
79 /* (non-Javadoc)
80 * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
81 */
82 @Override
83 public void doubleClick(DoubleClickEvent event) {
84 String commandId = "eu.etaxonomy.taxeditor.navigation.command.update.editSelection";
85
86 IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
87 try {
88 handlerService.executeCommand(commandId, null);
89 } catch (ExecutionException e) {
90 // TODO Auto-generated catch block
91 e.printStackTrace();
92 } catch (NotDefinedException e) {
93 // TODO Auto-generated catch block
94 e.printStackTrace();
95 } catch (NotEnabledException e) {
96 // TODO Auto-generated catch block
97 e.printStackTrace();
98 } catch (NotHandledException e) {
99 // TODO Auto-generated catch block
100 e.printStackTrace();
101 }
102
103
104 // if(event.getSelection() instanceof StructuredSelection){
105 // StructuredSelection selection = (StructuredSelection)event.getSelection();
106 // if(selection.getFirstElement() instanceof TaxonBase<?>){
107 // UUID taxonBaseUUID = ((TaxonBase<?>) selection.getFirstElement()).getUuid();
108 // }
109 // }
110 }
111
112 }