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 java.util.Collection;
|
13 |
|
|
14 |
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15 |
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
16 |
|
import org.eclipse.jface.action.MenuManager;
|
17 |
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
18 |
|
import org.eclipse.jface.viewers.ISelection;
|
19 |
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20 |
|
import org.eclipse.jface.viewers.TreeViewer;
|
21 |
|
import org.eclipse.jface.viewers.Viewer;
|
22 |
|
import org.eclipse.swt.SWT;
|
23 |
|
import org.eclipse.swt.layout.GridData;
|
24 |
|
import org.eclipse.swt.widgets.Composite;
|
25 |
|
import org.eclipse.swt.widgets.Control;
|
26 |
|
import org.eclipse.swt.widgets.Menu;
|
27 |
|
import org.eclipse.swt.widgets.Tree;
|
28 |
|
import org.eclipse.ui.ISaveablePart2;
|
29 |
|
import org.eclipse.ui.ISelectionService;
|
30 |
|
import org.eclipse.ui.IWorkbenchPart;
|
31 |
|
|
32 |
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
33 |
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
34 |
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
35 |
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
36 |
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
37 |
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
38 |
|
import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
|
39 |
|
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
|
40 |
|
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
41 |
|
|
42 |
|
/**
|
43 |
|
* @author pplitzner
|
44 |
|
* @date Oct 7, 2015
|
45 |
|
*
|
46 |
|
*/
|
47 |
|
public class OccurrenceView extends AbstractCdmViewPart implements IPartContentHasDetails, ISaveablePart2{
|
48 |
|
|
49 |
|
public static String ID = "eu.etaxonomy.taxeditor.view.derivative.OccurrenceView";
|
50 |
|
|
51 |
|
private TreeViewer viewer;
|
52 |
|
private DerivateContentProvider contentProvider;
|
53 |
|
private DerivateLabelProvider labelProvider;
|
54 |
|
|
55 |
|
private ISelectionService selectionService;
|
56 |
|
|
57 |
|
private ConversationHolder conversation;
|
58 |
|
|
59 |
|
private boolean dirty;
|
60 |
|
|
61 |
|
|
62 |
|
public OccurrenceView() {
|
63 |
|
if(conversation==null && CdmStore.isActive()){
|
64 |
|
conversation = CdmStore.createConversation();
|
65 |
|
}
|
66 |
|
}
|
67 |
|
|
68 |
|
/**
|
69 |
|
* {@inheritDoc}
|
70 |
|
*/
|
71 |
|
@Override
|
72 |
|
public void createPartControl(Composite parent) {
|
73 |
|
|
74 |
|
//listen to selection changes
|
75 |
|
selectionService = getSite().getWorkbenchWindow().getSelectionService();
|
76 |
|
selectionService.addSelectionListener(this);
|
77 |
|
|
78 |
|
//---tree viewer---
|
79 |
|
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
|
80 |
|
GridData gridDataTree = new GridData();
|
81 |
|
gridDataTree.horizontalAlignment = GridData.FILL;
|
82 |
|
gridDataTree.verticalAlignment = GridData.FILL;
|
83 |
|
gridDataTree.grabExcessVerticalSpace = true;
|
84 |
|
gridDataTree.grabExcessHorizontalSpace = true;
|
85 |
|
viewer.getTree().setLayoutData(gridDataTree);
|
86 |
|
contentProvider = new DerivateContentProvider();
|
87 |
|
viewer.setContentProvider(contentProvider);
|
88 |
|
labelProvider = new DerivateLabelProvider();
|
89 |
|
viewer.setLabelProvider(labelProvider);
|
90 |
|
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
|
91 |
|
// Propagate selection from viewer
|
92 |
|
getSite().setSelectionProvider(viewer);
|
93 |
|
|
94 |
|
//create context menu
|
95 |
|
MenuManager menuManager = new MenuManager();
|
96 |
|
getSite().registerContextMenu(menuManager, viewer);
|
97 |
|
Control control = viewer.getControl();
|
98 |
|
Menu menu = menuManager.createContextMenu(control);
|
99 |
|
control.setMenu(menu);
|
100 |
|
|
101 |
|
}
|
102 |
|
|
103 |
|
/**
|
104 |
|
* {@inheritDoc}
|
105 |
|
*/
|
106 |
|
@Override
|
107 |
|
public void setFocus() {
|
108 |
|
if(!conversation.isBound()){
|
109 |
|
conversation.bind();
|
110 |
|
}
|
111 |
|
}
|
112 |
|
|
113 |
|
/**
|
114 |
|
* {@inheritDoc}
|
115 |
|
*/
|
116 |
|
@Override
|
117 |
|
public void dispose() {
|
118 |
|
selectionService.removeSelectionListener(this);
|
119 |
|
if(conversation!=null){
|
120 |
|
conversation.close();
|
121 |
|
}
|
122 |
|
}
|
123 |
|
|
124 |
|
/**
|
125 |
|
* {@inheritDoc}
|
126 |
|
*/
|
127 |
|
@Override
|
128 |
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
129 |
|
if(selection instanceof IStructuredSelection){
|
130 |
|
Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
|
131 |
|
if(selectedElement instanceof Taxon){
|
132 |
|
Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon((Taxon) selectedElement, null, null);
|
133 |
|
viewer.setInput(fieldUnits);
|
134 |
|
}
|
135 |
|
}
|
136 |
|
}
|
137 |
|
|
138 |
|
@Override
|
139 |
|
public boolean onComplete() {
|
140 |
|
return false;
|
141 |
|
}
|
142 |
|
|
143 |
|
@Override
|
144 |
|
public Viewer getViewer() {
|
145 |
|
return viewer;
|
146 |
|
}
|
147 |
|
|
148 |
|
@Override
|
149 |
|
public void createViewer(Composite parent) {
|
150 |
|
}
|
151 |
|
|
152 |
|
@Override
|
153 |
|
public void changed(Object object) {
|
154 |
|
this.dirty = true;
|
155 |
|
firePropertyChange(PROP_DIRTY);
|
156 |
|
}
|
157 |
|
|
158 |
|
@Override
|
159 |
|
public void doSave(IProgressMonitor monitor) {
|
160 |
|
if(conversation.isBound()){
|
161 |
|
// input.merge(); TODO remote merging
|
162 |
|
conversation.commit(true);
|
163 |
|
}
|
164 |
|
this.dirty = false;
|
165 |
|
firePropertyChange(PROP_DIRTY);
|
166 |
|
}
|
167 |
|
|
168 |
|
@Override
|
169 |
|
public void doSaveAs() {
|
170 |
|
doSave(new NullProgressMonitor());
|
171 |
|
}
|
172 |
|
|
173 |
|
@Override
|
174 |
|
public boolean isDirty() {
|
175 |
|
return this.dirty;
|
176 |
|
}
|
177 |
|
|
178 |
|
@Override
|
179 |
|
public boolean isSaveAsAllowed() {
|
180 |
|
return false;
|
181 |
|
}
|
182 |
|
|
183 |
|
@Override
|
184 |
|
public boolean isSaveOnCloseNeeded() {
|
185 |
|
return isDirty();
|
186 |
|
}
|
187 |
|
|
188 |
|
@Override
|
189 |
|
public int promptToSaveOnClose() {
|
190 |
|
return ISaveablePart2.DEFAULT;
|
191 |
|
}
|
192 |
|
}
|
Removed OccurrenceView