b737a2212ff20295c47051f1fe3fdcf39d818ce7
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivative / OccurenceView.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 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.view.derivative;
11
12 import org.eclipse.jface.action.MenuManager;
13 import org.eclipse.jface.viewers.AbstractTreeViewer;
14 import org.eclipse.jface.viewers.ISelectionChangedListener;
15 import org.eclipse.jface.viewers.SelectionChangedEvent;
16 import org.eclipse.jface.viewers.TreeViewer;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Menu;
22 import org.eclipse.swt.widgets.Tree;
23 import org.eclipse.ui.part.ViewPart;
24
25 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
26 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
27 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
30 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
31
32 /**
33 * @author pplitzner
34 * @date Oct 7, 2015
35 *
36 */
37 public class OccurenceView extends ViewPart implements IConversationEnabled, ISelectionChangedListener{
38
39 private TreeViewer viewer;
40 private DerivateContentProvider contentProvider;
41 private DerivateLabelProvider labelProvider;
42 private ConversationHolder conversation;
43
44 public OccurenceView() {
45 conversation = CdmStore.createConversation();
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 @Override
52 public void createPartControl(Composite parent) {
53 //---tree viewer---
54 viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
55 GridData gridDataTree = new GridData();
56 gridDataTree.horizontalAlignment = GridData.FILL;
57 gridDataTree.verticalAlignment = GridData.FILL;
58 gridDataTree.grabExcessVerticalSpace = true;
59 gridDataTree.grabExcessHorizontalSpace = true;
60 viewer.getTree().setLayoutData(gridDataTree);
61 contentProvider = new DerivateContentProvider();
62 viewer.setContentProvider(contentProvider);
63 labelProvider = new DerivateLabelProvider();
64 labelProvider.setConversation(conversation);
65 viewer.setLabelProvider(labelProvider);
66 viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
67 // Propagate selection from viewer
68 getSite().setSelectionProvider(viewer);
69 //listen to selection changes
70 viewer.addSelectionChangedListener(this);
71
72 //create context menu
73 MenuManager menuManager = new MenuManager();
74 getSite().registerContextMenu(menuManager, viewer);
75 Control control = viewer.getControl();
76 Menu menu = menuManager.createContextMenu(control);
77 control.setMenu(menu);
78
79 }
80
81 /**
82 * {@inheritDoc}
83 */
84 @Override
85 public void setFocus() {
86 if(!conversation.isClosed()){
87 conversation.bind();
88 }
89 }
90
91 /**
92 * {@inheritDoc}
93 */
94 @Override
95 public void update(CdmDataChangeMap arg0) {
96 }
97
98 /**
99 * {@inheritDoc}
100 */
101 @Override
102 public ConversationHolder getConversationHolder() {
103 return conversation;
104 }
105
106 /**
107 * {@inheritDoc}
108 */
109 @Override
110 public void dispose() {
111 if(conversation.isBound() && !conversation.isClosed()){
112 conversation.close();
113 }
114 }
115
116 /**
117 * {@inheritDoc}
118 */
119 @Override
120 public void selectionChanged(SelectionChangedEvent event) {
121
122 }
123
124 }