import org.eclipse.ui.IPlaceholderFolderLayout;
import org.eclipse.ui.progress.IProgressConstants;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
-import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView;
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
public static final String ADDITIONAL = "additional";
- /* (non-Javadoc)
- * @see org.eclipse.ui.IPerspectiveFactory#createInitialLayout(org.eclipse.ui.IPageLayout)
- */
@Override
public void createInitialLayout(IPageLayout layout) {
layout.addView(TaxonNavigator.ID, IPageLayout.LEFT, 0.25f, layout.getEditorArea());
layout.addView(DetailsViewPart.ID, IPageLayout.RIGHT, 0.6f, layout.getEditorArea());
- layout.addView(DerivateSearchView.ID, IPageLayout.TOP, 0.5f, layout.getEditorArea());
+ layout.addView(DerivateView.ID, IPageLayout.BOTTOM, 0.5f, layout.getEditorArea());
layout.addView(DescriptiveViewPart.ID, IPageLayout.BOTTOM, 0.6f, TaxonNavigator.ID);
eu.etaxonomy.taxeditor.editor.name.operation,
eu.etaxonomy.taxeditor.editor.view.concept,
eu.etaxonomy.taxeditor.editor.view.dataimport,
+ eu.etaxonomy.taxeditor.editor.view.derivate,
eu.etaxonomy.taxeditor.editor.view.descriptive,
eu.etaxonomy.taxeditor.editor.view.media,
eu.etaxonomy.taxeditor.editor.view.uses
id="eu.etaxonomy.taxeditor.editor.group.authority"
name="%editor.name.4">
</editor>
- <editor
- class="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
- default="false"
- icon="icons/derivate_view-16x16-32.png"
- id="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
- name="%editor.name.5">
- </editor>
<editor
class="eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportEditor"
default="false"
id="eu.etaxonomy.taxeditor.editor.view.validation.problems"
name="%view.name.6">
</view>
+ <view
+ class="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
+ icon="icons/derivate_view-16x16-32.png"
+ id="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
+ name="Derivative Editor"
+ restorable="true">
+ </view>
</extension>
<!-- VALIDATION RELATED STUFF -->
</menuContribution>
<menuContribution
locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?before=eu.etaxonomy.taxeditor.store.showViewMenu.details">
- <separator
- name="eu.etaxonomy.taxeditor.editor.showViewMenu"
- visible="true">
- </separator>
<command
commandId="org.eclipse.ui.views.showView"
label="%command.label.4"
</and>
</visibleWhen>
</command>
+ <separator
+ name="eu.etaxonomy.taxeditor.store.separator_derivative_start"
+ visible="true">
+ </separator>
+ <command
+ commandId="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
+ label="Derivative Editor"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ <reference
+ definitionId="isCdmStoreConnected">
+ </reference>
+ </visibleWhen>
+ </command>
+ <separator
+ name="eu.etaxonomy.taxeditor.editor.separator1"
+ visible="true">
+ </separator>
+ </menuContribution>
+ <menuContribution
+ locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?after=org.eclipse.ui.views.showView.supplemental">
+ <separator
+ name="eu.etaxonomy.taxeditor.store.showViewMenu.validation.separator"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.ui.views.showView"
+ label="%command.name.40"
+ style="push">
+ <parameter
+ name="org.eclipse.ui.views.showView.viewId"
+ value="eu.etaxonomy.taxeditor.editor.view.validation.problems">
+ </parameter>
+ <visibleWhen
+ checkEnabled="true">
+ <reference
+ definitionId="isCdmStoreConnected">
+ </reference>
+ </visibleWhen>
+ </command>
</menuContribution>
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu.navigate">
label="%command.label.52"
style="push">
</command>
- <command
- commandId="eu.etaxonomy.taxeditor.editor.derivate.createFieldUnit"
- label="%command.label.53"
- style="push">
- </command>
<command
commandId="eu.etaxonomy.taxeditor.editor.derivate.deepDelete"
icon="icons/deep-delete-16x16-32.png"
</menuContribution>
<menuContribution
allPopups="false"
- locationURI="popup:eu.etaxonomy.taxeditor.navigation.navigatorpopup?after=taxeditor-navigation.separator2">
+ locationURI="toolbar:eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
<command
- commandId="eu.etaxonomy.taxeditor.editor.handler.openDerivateView"
- label="%command.label.55"
- style="push">
+ commandId="eu.etaxonomy.taxeditor.editor.derivative.listenToSelectionChange"
+ icon="icons/synced.gif"
+ label="Link with Editor"
+ style="toggle">
<visibleWhen
checkEnabled="false">
- <and>
- <reference
- definitionId="isCdmStoreConnected">
- </reference>
- <reference
- definitionId="isTaxonNode">
- </reference>
- </and>
- </visibleWhen>
- </command>
- <separator
- name="eu.etaxonomy.taxeditor.editor.separator1"
- visible="true">
- </separator>
- </menuContribution>
- <menuContribution
- locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?after=org.eclipse.ui.views.showView.supplemental">
- <separator
- name="eu.etaxonomy.taxeditor.store.showViewMenu.validation.separator"
- visible="true">
- </separator>
- <command
- commandId="org.eclipse.ui.views.showView"
- label="%command.name.40"
- style="push">
- <parameter
- name="org.eclipse.ui.views.showView.viewId"
- value="eu.etaxonomy.taxeditor.editor.view.validation.problems">
- </parameter>
- <visibleWhen
- checkEnabled="true">
<reference
definitionId="isCdmStoreConnected">
</reference>
<command
defaultHandler="eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler"
id="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
- name="Open Specimen Editor">
+ name="Open Derivative Editor">
<commandParameter
id="eu.etaxonomy.taxeditor.specimenUuidParameter"
name="Specimen UUID parameter"
typeId="eu.etaxonomy.taxeditor.specimenUuidParameterType">
</commandParameter>
</command>
+ <command
+ defaultHandler="eu.etaxonomy.taxeditor.editor.view.derivate.handler.ListenToSelectionChangeHandler"
+ id="eu.etaxonomy.taxeditor.editor.derivative.listenToSelectionChange"
+ name="Link with editor">
+ </command>
</extension>
<extension
package eu.etaxonomy.taxeditor.editor.handler;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.HandlerUtil;
-import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
public class OpenDerivateViewHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
- Object parameter;
- //check if parameter is set
- try {
- parameter = event.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
- } catch (ExecutionException e) {
- parameter = null;
- }
- if(parameter instanceof UUID){
- selectedElementUUIDs.add((UUID) parameter);
- }
- else{
- //if not, try with current selection
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if(currentSelection instanceof IStructuredSelection){
- Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
- while(selectionIterator.hasNext()){
- Object object = selectionIterator.next();
- if(object instanceof SpecimenOrObservationBase<?>){
- selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
- }
- else if(object instanceof IndividualsAssociation){
- SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
- if(specimen!=null){
- selectedElementUUIDs.add(specimen.getUuid());
- }
- }
- }
- }
- }
- if(!selectedElementUUIDs.isEmpty()){
- DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
- try {
- EditorUtil.open(input);
- } catch (PartInitException e) {
- MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
- } catch (NullPointerException npe){
- MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
- }
- }
- else{
- MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
- }
+ AbstractUtility.showView(DerivateView.ID);
return null;
}
package eu.etaxonomy.taxeditor.editor.view.derivate;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.UUID;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.ISaveablePart2;
+import org.eclipse.ui.IWorkbenchPart;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.molecular.Sequence;
import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.Messages;
-import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
+import eu.etaxonomy.taxeditor.model.IContextListener;
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
* Displays the derivate hierarchy of the specimen specified in the editor input.
*
*/
-public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
- IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
- ISelectionChangedListener, IPostOperationEnabled{
-
+public class DerivateView extends AbstractCdmViewPart implements IPartContentHasFactualData, ISaveablePart2,
+ IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia, IContextListener {
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
public static final String VIEW_HAS_UNSAVED_CHANGES = Messages.DerivateView_UNSAVED_CHANGES;
+ private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
+ "descriptions",
+ "annotations",
+ "markers",
+ "credits",
+ "extensions",
+ "rights",
+ "sources",
+ "derivationEvents.derivatives.annotations",
+ "derivationEvents.derivatives.markers",
+ "derivationEvents.derivatives.credits",
+ "derivationEvents.derivatives.extensions",
+ "derivationEvents.derivatives.rights",
+ "derivationEvents.derivatives.sources"
+ });
+
private ConversationHolder conversation;
private TreeViewer viewer;
private Set<SingleRead> multiLinkSingleReads;
- private ISelection selection = null;
+ private DerivateContentProvider contentProvider;
+ private DerivateSearchCompositeController derivateSearchCompositeController;
- private DerivateContentProvider contentProvider;
+ /**
+ * A map with keys being the derivative entities belonging to the {@link UUID}s passed to the constructor
+ * and values being the root elements of the hierarchy (may be the same objects as the derivative entities)
+ */
+ private Map<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>> derivateToRootEntityMap;
+
+ /**
+ * The set of root elements
+ */
+ private Set<SpecimenOrObservationBase<?>> rootElements;
+
+ private ICdmEntitySession cdmEntitySession;
+
+ /**
+ * <code>true</code> if this view is listening to selection changes
+ */
+ private boolean listenToSelectionChange;
+
+ private Taxon selectedTaxon;
/**
* Default constructor
*/
public DerivateView() {
+ init();
+ }
+
+ /**
+ *
+ */
+ private void init() {
+ this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+ this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
+
+ if (CdmStore.isActive() && conversation == null) {
+ conversation = CdmStore.createConversation();
+ }
+ if (CdmStore.isActive()) {
+ cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+ }
+ //listen to context changes
+ CdmStore.getContextManager().addContextListener(this);
}
@Override
public void createPartControl(Composite parent) {
+
+ parent.setLayout(new GridLayout());
+
+ //---search and filter---
+ derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
+ derivateSearchCompositeController.setEnabled(CdmStore.isActive());
+ GridData gridDataSearchBar = new GridData();
+ gridDataSearchBar.horizontalAlignment = GridData.FILL;
+ gridDataSearchBar.grabExcessHorizontalSpace = true;
+ derivateSearchCompositeController.setLayoutData(gridDataSearchBar);
+
+ //---tree viewer---
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+ GridData gridDataTree = new GridData();
+ gridDataTree.horizontalAlignment = GridData.FILL;
+ gridDataTree.verticalAlignment = GridData.FILL;
+ gridDataTree.grabExcessVerticalSpace = true;
+ gridDataTree.grabExcessHorizontalSpace = true;
+ viewer.getTree().setLayoutData(gridDataTree);
contentProvider = new DerivateContentProvider();
viewer.setContentProvider(contentProvider);
labelProvider = new DerivateLabelProvider();
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
// Propagate selection from viewer
getSite().setSelectionProvider(viewer);
+
//listen to selection changes
- viewer.addSelectionChangedListener(this);
+ selectionService = getSite().getWorkbenchWindow().getSelectionService();
+ selectionService.addSelectionListener(this);
//create context menu
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(control);
control.setMenu(menu);
- generateMultiLinkSingleReads();
- labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
- IEditorInput editorInput = getEditorInput();
- viewer.setInput(((DerivateViewEditorInput) editorInput).getRootEntities());
- //set selection to selected derivate if only one was selected
- if(editorInput instanceof DerivateViewEditorInput){
- Set<SpecimenOrObservationBase<?>> derivateEntities = ((DerivateViewEditorInput) editorInput).getDerivateEntities();
- if(derivateEntities.size()==1){
- SpecimenOrObservationBase<?> specimen = derivateEntities.iterator().next();
- if(specimen != null){
- viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
- }
- }
- }
+ //init tree
+ updateRootEntities();
//add drag'n'drop support
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(),};
viewer.addDropSupport(dndOperations, transfers, new DerivateDropListener(this));
}
+ public void updateRootEntities() {
+ updateRootEntities(null);
+ }
+
+ public void updateRootEntities(Collection<UUID> derivativeUuids) {
+ if(conversation!=null){
+ if (!conversation.isBound()) {
+ conversation.bind();
+ }
+ /*
+ * If the active session is not the session of the Derivate Editor then we will
+ * save it, bind temporarily to our session and rebind to the original session.
+ * This happens e.g. if a selection change happens in the taxon editor and
+ * "Link with editor" is enabled. The selection change event and thus the
+ * loading in updateRootEntities() happens in the session of the taxon
+ * editor.
+ */
+ ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
+ if(cdmEntitySession != null) {
+ cdmEntitySession.bind();
+ }
+
+ if(derivativeUuids!=null){
+ this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+ this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
+ for (UUID uuid : derivativeUuids) {
+ SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
+ if(derivate instanceof FieldUnit){
+ derivateToRootEntityMap.put(derivate, derivate);
+ }
+ else {
+ SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+ if(topMostDerivate!=null){
+ derivateToRootEntityMap.put(derivate, topMostDerivate);
+ }
+ else{
+ derivateToRootEntityMap.put(derivate, derivate);
+ }
+ }
+ }
+ for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
+ rootElements.add(specimen);
+ }
+ }
+ viewer.setInput(rootElements);
+ refreshTree();
+ previousCdmEntitySession.bind();
+ }
+ }
+
@Override
public void doSave(IProgressMonitor monitor) {
String taskName = Messages.DerivateView_SAVING_HIERARCHY;
- if(getEditorInput() instanceof DerivateViewEditorInput){
- DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput();
- taskName += " "+derivateViewEditorInput.getName(); //$NON-NLS-1$
- }
monitor.beginTask(taskName, 3);
if (!conversation.isBound()) {
conversation.bind();
// commit the conversation and start a new transaction immediately
conversation.commit(true);
- ((DerivateViewEditorInput) getEditorInput()).merge();
+
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IOccurrenceService.class).merge(new ArrayList<SpecimenOrObservationBase>(rootElements), true);
+ }
monitor.worked(1);
this.setDirty(false);
@Override
public String getTitleToolTip() {
- if(getEditorInput() instanceof DerivateViewEditorInput){
- DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput();
- return derivateViewEditorInput.getName();
- }
return Messages.DerivateView_DERIVATIVE_EDITOR;
}
- @Override
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {
- setSite(site);
- setInput(input);
- if(input instanceof DerivateViewEditorInput){
- DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) input;
- conversation = derivateViewEditorInput.getConversationHolder();
- setPartName(derivateViewEditorInput.getName());
- }
- }
-
@Override
public boolean isDirty() {
return isDirty;
public void setFocus() {
viewer.getControl().setFocus();
//make sure to bind again if maybe in another view the conversation was unbound
- if(!conversation.isBound()){
+ if(conversation!=null && !conversation.isBound()){
conversation.bind();
}
- ((DerivateViewEditorInput) getEditorInput()).bind();
+ if(cdmEntitySession != null) {
+ cdmEntitySession.bind();
+ }
}
@Override
/**
* @return the viewer
*/
+ @Override
public TreeViewer getViewer() {
return viewer;
}
changed(null);
}
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ List<String> specimenPropertyPaths = Arrays.asList(new String[] {
+ "descriptions",
+ "derivationEvents.derivates",
+ "annotations",
+ "markers",
+ "credits",
+ "extensions",
+ "rights",
+ "sources"
+ });
+ Map<Object, List<String>> specimenPropertyPathMap =
+ new HashMap<Object, List<String>>();
+ specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
+ return specimenPropertyPathMap;
+ }
+
/**
* Refreshes the derivate hierarchy tree and expands the tree
* to show and select the given object.
//FIXME:Remoting hack to make this work for remoting
//This should actually be resolved using remoting post operations
public void remove(Object obj) {
- Set<SpecimenOrObservationBase<?>> rootEntities = ((DerivateViewEditorInput) getEditorInput()).getRootEntities();
- rootEntities.remove(obj);
- viewer.setInput(rootEntities);
+ rootElements.remove(obj);
+ viewer.setInput(rootElements);
}
private void generateMultiLinkSingleReads() {
return this.multiLinkSingleReads;
}
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- this.selection = event.getSelection();
- }
-
- public ISelection getSelection() {
- return selection;
+ public Object getSelectionInput() {
+ return selectedTaxon;
}
public DerivateLabelProvider getLabelProvider() {
return true;
}
+
+ @Override
+ public boolean canAttachMedia() {
+ return true;
+ }
+
+ public void addFieldUnit(FieldUnit fieldUnit) {
+ rootElements.add(fieldUnit);
+ derivateToRootEntityMap.put(fieldUnit, fieldUnit);
+ }
+
+ @Override
+ public ICdmEntitySession getCdmEntitySession() {
+ return cdmEntitySession;
+ }
+
@Override
public void dispose() {
- ((DerivateViewEditorInput) getEditorInput()).dispose();
super.dispose();
+ if(conversation!=null){
+ conversation.close();
+ }
+ if(cdmEntitySession != null) {
+ cdmEntitySession.dispose();
+ }
}
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if(listenToSelectionChange && selection instanceof IStructuredSelection){
+ Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
+ if(selectedElement instanceof CdmBase && ((CdmBase) selectedElement).isInstanceOf(Taxon.class)){
+ selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, Taxon.class);
+ Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon(selectedTaxon, null, null);
+ Collection<UUID> uuids = new HashSet<UUID>();
+ for (SpecimenOrObservationBase specimenOrObservationBase : fieldUnits) {
+ uuids.add(specimenOrObservationBase.getUuid());
+ }
+ updateRootEntities(uuids);
+ }
+ if(part instanceof MultiPageTaxonEditor){
+ Taxon taxon = ((MultiPageTaxonEditor) part).getTaxon();
+ derivateSearchCompositeController.setTaxon(taxon);
+ }
+ }
+ }
+ /**
+ * {@inheritDoc}
+ */
@Override
- public boolean canAttachMedia() {
- return true;
+ public List<SpecimenOrObservationBase<?>> getRootEntities() {
+ return new ArrayList<SpecimenOrObservationBase<?>>(rootElements);
+ }
+
+ @Override
+ public void createViewer(Composite parent) {
+ // TODO Auto-generated method stub
+
}
+
+ @Override
+ public boolean isSaveOnCloseNeeded() {
+ return isDirty();
+ }
+
+ @Override
+ public int promptToSaveOnClose() {
+ return ISaveablePart2.DEFAULT;
+ }
+
+ public void toggleListenToSelectionChange() {
+ listenToSelectionChange = !listenToSelectionChange;
+ derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
+ derivateSearchCompositeController.setTaxon(null);
+ if(!listenToSelectionChange){
+ selectedTaxon = null;
+ }
+ }
+
+ public boolean isListenToSelectionChange(){
+ return listenToSelectionChange;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void contextStop(IMemento memento, IProgressMonitor monitor) {
+ derivateSearchCompositeController.setEnabled(false);
+ viewer.setInput(null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void contextStart(IMemento memento, IProgressMonitor monitor) {
+ init();
+ derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
+ refreshTree();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void contextRefresh(IProgressMonitor monitor) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
+ }
+
}
*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
-import eu.etaxonomy.cdm.api.application.CdmApplicationState;
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.Messages;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
/**
* Editor input for the {@link DerivateView} which holds the currently selected derivate for which
* @date 25.11.2013
*
*/
-public class DerivateViewEditorInput extends CdmEntitySessionInput implements IEditorInput {
+public class DerivateViewEditorInput implements IEditorInput {
/**
- * The selected derivate {@link UUID}s
+ * The {@link UUID}s of the derivative entities
*/
- private final Set<SpecimenOrObservationBase<?>> derivateEntities;
- /**
- * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
- */
- private Set<SpecimenOrObservationBase<?>> rootEntities;
- private Set<UUID> rootUUIDs;
-
- private final ConversationHolder conversationHolder;
-
- private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
- "descriptions",
- "annotations",
- "markers",
- "credits",
- "extensions",
- "rights",
- "sources",
- "derivationEvents.derivatives.annotations",
- "derivationEvents.derivatives.markers",
- "derivationEvents.derivatives.credits",
- "derivationEvents.derivatives.extensions",
- "derivationEvents.derivatives.rights",
- "derivationEvents.derivatives.sources"
- });
+ private Set<UUID> derivativeUUIDs;
/**
* Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
* corresponding {@link FieldUnit}s (both may be the same object).
* @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
- * @param rootUUIDs the root of the hierarchy
+ * @param derivativeUUIDs the root of the hierarchy
*/
public DerivateViewEditorInput(Set<UUID> derivateUuids) {
- super(false);
- rootUUIDs = derivateUuids;
- //FIXME:Remoting temporary hack for making the sessions work
- //This should ideally be changed to initializing the
- //super class with a collection of (id) objects which can
- //then be used for the hashCode, equals methods
- initSession();
- this.conversationHolder = CdmStore.createConversation();
- this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
- this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
- for (UUID uuid : derivateUuids) {
- SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
- derivateEntities.add(derivate);
- if(derivate instanceof FieldUnit){
- rootEntities.add(derivate);
- }
- else if(derivate instanceof DerivedUnit){
- SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
- if(topMostDerivate!=null){
- rootEntities.add(topMostDerivate);
- }
- }
- }
- if(rootEntities.isEmpty()){
- rootEntities = derivateEntities;
- }
- if(rootEntities.isEmpty()){
- MessagingUtils.messageDialog(Messages.DerivateViewEditorInput_FAIL_INIT, DerivateViewEditorInput.class, Messages.DerivateViewEditorInput_NO_ROOT);
- }
-
-
+ this.derivativeUUIDs = derivateUuids;
}
/* (non-Javadoc)
}
private String getEditorName() {
- String name = null;
- for( SpecimenOrObservationBase<?> specimen : rootEntities){
- if(specimen!=null){
- if(name==null){
- name = DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
- }
- else{
- name += " + "+DerivateLabelProvider.getDerivateText(specimen, conversationHolder); //$NON-NLS-1$
- }
- }
- }
- return name;
- }
-
- @Override
- public Set<SpecimenOrObservationBase<?>> getRootEntities() {
- return rootEntities;
- }
-
- public Set<SpecimenOrObservationBase<?>> getDerivateEntities() {
- return derivateEntities;
- }
-
- public void addRootEntity(SpecimenOrObservationBase<?> root){
- rootEntities.add(root);
+ return "Derivative Editor";
}
-
- public ConversationHolder getConversationHolder() {
- return conversationHolder;
+ /**
+ * @return the derivativeUUIDs
+ */
+ public Set<UUID> getDerivativeUUIDs() {
+ return derivativeUUIDs;
}
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((rootUUIDs == null) ? 0 : rootUUIDs.hashCode());
+ result = prime * result + ((derivativeUUIDs == null) ? 0 : derivativeUUIDs.hashCode());
return result;
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {
return false;
}
DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
- if (rootUUIDs == null) {
- if (other.rootUUIDs != null) {
+ if (derivativeUUIDs == null) {
+ if (other.derivativeUUIDs != null) {
return false;
}
- } else if (!rootUUIDs.equals(other.rootUUIDs)) {
+ } else if (!derivativeUUIDs.equals(other.derivativeUUIDs)) {
return false;
}
return true;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
- */
- @Override
- public void merge() {
- if(CdmStore.getCurrentSessionManager().isRemoting()) {
- CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
- }
-
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
- */
- @Override
- public Map<Object, List<String>> getPropertyPathsMap() {
- List<String> specimenPropertyPaths = Arrays.asList(new String[] {
- "descriptions",
- "derivationEvents.derivates",
- "annotations",
- "markers",
- "credits",
- "extensions",
- "rights",
- "sources"
- });
- Map<Object, List<String>> specimenPropertyPathMap =
- new HashMap<Object, List<String>>();
- specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
- return specimenPropertyPathMap;
- }
-
-
}
--- /dev/null
+package eu.etaxonomy.taxeditor.editor.view.derivate.contextMenu;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CompoundContributionItem;
+
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * Context menu for the SingleReads in the derivate hierarchy.
+ *
+ */
+public class CreateFieldUnitContextMenu extends CompoundContributionItem {
+
+ private enum CommandType {
+ COPY_TO_CLIPBOARD, REMOVE_FROM_SEQUENCE, ADD_TO_SEQUENCE
+ }
+
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ IContributionItem[] contributionItems = new IContributionItem[] {
+ new ContributionItem() {
+ @Override
+ public void fill(Menu menu, int index) {
+ final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchPart activePart = window.getActivePage().getActivePart();
+ if(activePart instanceof DerivateView){
+ final DerivateView derivateView = (DerivateView) activePart;
+ if(derivateView.isListenToSelectionChange()){
+ Object selectionInput = derivateView.getSelectionInput();
+ if(selectionInput instanceof CdmBase && ((CdmBase) selectionInput).isInstanceOf(Taxon.class)){
+ final Taxon taxon = HibernateProxyHelper.deproxy(selectionInput, Taxon.class);
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText("Create FieldUnit (attach to "+taxon.getTitleCache()+")");
+ item.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if(derivateView.isDirty()){
+ MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
+ return;
+ }
+ FieldUnit fieldUnit = FieldUnit.NewInstance();
+ fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
+ IndividualsAssociation association = IndividualsAssociation.NewInstance(fieldUnit);
+ association.setFeature(Feature.SPECIMEN());
+ TaxonDescription description;
+ if(!taxon.getDescriptions().isEmpty()){
+ description = taxon.getDescriptions().iterator().next();
+ }
+ else{
+ description = TaxonDescription.NewInstance(taxon);
+ }
+ description.addElement(IndividualsAssociation.NewInstance(fieldUnit));
+
+ derivateView.getConversationHolder().commit();
+ derivateView.addFieldUnit(fieldUnit);
+ derivateView.refreshTree();
+ }
+ });
+ }
+ }
+ else{
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText("Create FieldUnit");
+ item.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if(derivateView.isDirty()){
+ MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
+ return;
+ }
+ FieldUnit fieldUnit = FieldUnit.NewInstance();
+ fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
+ derivateView.getConversationHolder().commit();
+ derivateView.addFieldUnit(fieldUnit);
+ derivateView.refreshTree();
+ }
+ });
+ }
+ }
+ }
+ }
+ };
+ return contributionItems;
+ }
+}
+
@Override
protected IContributionItem[] getContributionItems() {
IContributionItem[] contributionItems = new IContributionItem[] {
+ new CreateFieldUnitContextMenu(),
new CreateDerivateContextMenu(),
new SingleReadSequenceContextMenu()
};
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
FieldUnit fieldUnit = FieldUnit.NewInstance();
fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
derivateView.getConversationHolder().commit();
- DerivateViewEditorInput input = (DerivateViewEditorInput) derivateView.getEditorInput();
- input.addRootEntity(fieldUnit);
+ derivateView.addFieldUnit(fieldUnit);
derivateView.refreshTree();
}
return null;
--- /dev/null
+package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+
+public class ListenToSelectionChangeHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ if(activePart instanceof DerivateView){
+ DerivateView derivativeEditor = (DerivateView)activePart;
+ derivativeEditor.toggleListenToSelectionChange();
+ }
+ return null;
+ }
+
+}
import eu.etaxonomy.cdm.model.molecular.SingleRead;
import eu.etaxonomy.taxeditor.editor.Messages;
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
//update DerivateView
derivateView.getConversationHolder().commit();
IStatus returnStatus = postExecute(null);
- //close if no more items left
- if(derivateView.getViewer().getTree().getItemCount()<1){
- AbstractUtility.close(derivateView);
- }
return returnStatus;
}
}
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-package eu.etaxonomy.taxeditor.view.derivateSearch;
+package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
-import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
*
*/
public class DerivateSearchComposite extends Composite {
+
+ public static final int ALL_SPECIMENS = 0;
+ public static final int ASSIGNED_SPECIMENS = 1;
+ public static final int UNASSIGNED_SPECIMENS = 2;
+
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
private final Text searchField;
- private final Table table;
- private final TableViewer resultViewer;
private final Combo comboDerivateType;
private final Button buttonSearch;
- private final Button btnFilterUndeterminedSpecimen;
private final Text textTaxonName;
private final Button btnBrowseTaxa;
private final Label lblTaxon;
private final Label lblDerivateType;
private final Button btnClearTaxon;
+ private Label lbltaxonAssignment;
+ private Combo comboTaxonAssignment;
+ private Label lblTitleCache;
/**
* Create the composite.
+ *
* @param parent
* @param style
*/
public DerivateSearchComposite(Composite parent, int style) {
super(parent, style);
- setLayout(new GridLayout(4, false));
+ setLayout(new GridLayout(7, false));
lblTaxon = new Label(this, SWT.NONE);
lblTaxon.setText("Taxon");
- textTaxonName = formToolkit.createText(this, "New Text", SWT.NONE);
+ textTaxonName = formToolkit.createText(this, "New Text", SWT.BORDER);
textTaxonName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
textTaxonName.setEnabled(false);
textTaxonName.setText("");
btnBrowseTaxa = formToolkit.createButton(this, "", SWT.NONE);
+ btnBrowseTaxa.setAlignment(SWT.RIGHT);
btnBrowseTaxa.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
btnClearTaxon = formToolkit.createButton(this, "", SWT.NONE);
- btnClearTaxon.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ btnClearTaxon.setAlignment(SWT.RIGHT);
+ btnClearTaxon.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
btnClearTaxon.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
+ lbltaxonAssignment = new Label(this, SWT.NONE);
+ lbltaxonAssignment.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lbltaxonAssignment.setText("Taxon assignment");
+
+ comboTaxonAssignment = new Combo(this, SWT.NONE);
+ comboTaxonAssignment.setItems(new String[] { "All", "Yes", "No" });
+ comboTaxonAssignment.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ formToolkit.adapt(comboTaxonAssignment);
+ formToolkit.paintBordersFor(comboTaxonAssignment);
+ comboTaxonAssignment.select(ALL_SPECIMENS);
+ new Label(this, SWT.NONE);
+
+ lblTitleCache = new Label(this, SWT.NONE);
+ lblTitleCache.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblTitleCache.setText("Title Cache");
+
+ searchField = formToolkit.createText(this, "New Text", SWT.BORDER);
+ searchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
+ searchField.setText("");
+
lblDerivateType = new Label(this, SWT.NULL);
+ lblDerivateType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblDerivateType.setText("Derivative Type");
comboDerivateType = new Combo(this, SWT.READ_ONLY);
comboDerivateType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
formToolkit.paintBordersFor(comboDerivateType);
- btnFilterUndeterminedSpecimen = new Button(this, SWT.CHECK);
- btnFilterUndeterminedSpecimen.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
- btnFilterUndeterminedSpecimen.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- }
- });
- btnFilterUndeterminedSpecimen.setText("Determined");
-
- buttonSearch = new Button(this, SWT.NONE);
- formToolkit.adapt(buttonSearch, true, true);
- buttonSearch.setText("Search");
-
- searchField = formToolkit.createText(this, "New Text", SWT.NONE);
- searchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
- searchField.setText("");
- new Label(this, SWT.NONE);
- new Label(this, SWT.NONE);
-
- resultViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
- table = resultViewer.getTable();
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
+ buttonSearch = new Button(this, SWT.NONE);
+ formToolkit.adapt(buttonSearch, true, true);
+ buttonSearch.setText("Search");
}
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
+
public Text getSearchField() {
return searchField;
}
- public TableViewer getResultViewer() {
- return resultViewer;
- }
+
public Combo getComboDerivateType() {
return comboDerivateType;
}
+
public Button getButtonSearch() {
return buttonSearch;
}
@Override
- public void setEnabled(boolean enabled){
+ public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
searchField.setEnabled(enabled);
- table.setEnabled(enabled);
- // resultViewer.setEnabled(enabled);
comboDerivateType.setEnabled(enabled);
+ comboTaxonAssignment.setEnabled(enabled);
buttonSearch.setEnabled(enabled);
- btnFilterUndeterminedSpecimen.setEnabled(enabled);
btnBrowseTaxa.setEnabled(enabled);
+ btnClearTaxon.setEnabled(enabled);
lblTaxon.setEnabled(enabled);
+ lblTitleCache.setEnabled(enabled);
+ lbltaxonAssignment.setEnabled(enabled);
lblDerivateType.setEnabled(enabled);
}
- public Button getBtnFilterUndeterminedSpecimen() {
- return btnFilterUndeterminedSpecimen;
- }
+
+
public Button getBtnBrowseTaxa() {
return btnBrowseTaxa;
}
+
public Text getTextTaxonName() {
return textTaxonName;
}
+
public Button getBtnClearTaxon() {
return btnClearTaxon;
}
+ public Combo getComboTaxonAssignment() {
+ return comboTaxonAssignment;
+ }
}
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-package eu.etaxonomy.taxeditor.view.derivateSearch;
+package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.UUID;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.handlers.IHandlerService;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.SearchManager;
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermComboController;
+import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
/**
* Controller class for the {@link DerivateSearchComposite}.<br>
private final DerivateSearchComposite derivateSearchComposite;
private EnumTermComboController<SpecimenOrObservationType> comboSpecimenTypeController;
- private final DerivateSearchView derivateSearchView;
private DerivateLabelProvider labelProvider;
private Taxon selectedTaxon;
+ private DerivateView derivativeEditor;
- /**
- * @param parent
- * @param derivateSearchView
- */
- public DerivateSearchCompositeController(Composite parent, DerivateSearchView derivateSearchView) {
+ public DerivateSearchCompositeController(Composite parent, DerivateView derivativeEditor) {
this.derivateSearchComposite = new DerivateSearchComposite(parent, SWT.NONE);
- this.derivateSearchView = derivateSearchView;
+ this.derivativeEditor = derivativeEditor;
init();
}
derivateSearchComposite.getBtnBrowseTaxa().addListener(SWT.Selection, this);
derivateSearchComposite.getBtnClearTaxon().addListener(SWT.Selection, this);
-
- //result table
- TableViewer resultViewer = derivateSearchComposite.getResultViewer();
- resultViewer.setContentProvider(new ArrayContentProvider());
- labelProvider = new DerivateLabelProvider();
- resultViewer.setLabelProvider(labelProvider);
- resultViewer.addDoubleClickListener(new IDoubleClickListener() {
- @Override
- public void doubleClick(DoubleClickEvent event) {
- String commandId = "eu.etaxonomy.taxeditor.editor.handler.openDerivateView";
-
- IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
- try {
- handlerService.executeCommand(commandId, null);
- } catch (ExecutionException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
- } catch (NotDefinedException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
- } catch (NotEnabledException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
- } catch (NotHandledException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
- }
-
- }
- });
-
}
private void searchDerivates(){
- if(!derivateSearchView.getConversationHolder().isBound()){
- derivateSearchView.setFocus(); //rebind the conversation
- }
+// if(!conversation.isBound()){
+// conversation.bind();
+// }
String queryString = derivateSearchComposite.getSearchField().getText();
SpecimenOrObservationType specimenType = comboSpecimenTypeController.getSelection();
config.setSpecimenType(specimenType.equals(SpecimenOrObservationType.Unknown)?null:specimenType);//unknown := all types
config.setTitleSearchString(queryString);
if(selectedTaxon!=null){
- config.setRetrieveIndirectlyAssociatedSpecimens(true);
config.setSpecimenType(null);
}
occurrences = specimensOfCorrectType;
}
- //filter out assigned specimens
- if(derivateSearchComposite.getBtnFilterUndeterminedSpecimen().getSelection()){
- List<SpecimenOrObservationBase> specimensWithNoDetermination = new ArrayList<SpecimenOrObservationBase>();
- for(SpecimenOrObservationBase<?> result:occurrences){
- if(CdmStore.getService(IOccurrenceService.class).countDeterminations(result, null)==0){
- specimensWithNoDetermination.add(result);
+ //filter out (un-)assigned specimens
+ int selectionIndex = derivateSearchComposite.getComboTaxonAssignment().getSelectionIndex();
+ List<SpecimenOrObservationBase<?>> specimenWithAssociations = new ArrayList<SpecimenOrObservationBase<?>>();
+ if(selectionIndex!=DerivateSearchComposite.ALL_SPECIMENS){
+ for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
+ Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(specimenOrObservationBase, null, null, null, null);
+ if(!associatedTaxa.isEmpty()){
+ specimenWithAssociations.add(specimenOrObservationBase);
+ specimenWithAssociations.addAll(CdmStore.getService(IOccurrenceService.class).getFieldUnits(specimenOrObservationBase.getUuid()));
}
}
- occurrences = specimensWithNoDetermination;
}
- derivateSearchComposite.getResultViewer().setInput(occurrences);
+ if(selectionIndex==DerivateSearchComposite.UNASSIGNED_SPECIMENS){
+ occurrences.removeAll(specimenWithAssociations);
+ }
+ else if(selectionIndex==DerivateSearchComposite.ASSIGNED_SPECIMENS){
+ occurrences = new ArrayList<SpecimenOrObservationBase>(specimenWithAssociations);
+ }
+ List<UUID> derivateUuids = new ArrayList<UUID>();
+ for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
+ derivateUuids.add(specimenOrObservationBase.getUuid());
+ }
+ derivativeEditor.updateRootEntities(derivateUuids);
}
@Override
searchDerivates();
}
else if(eventSource==derivateSearchComposite.getBtnBrowseTaxa()){
- selectedTaxon = SelectionDialogFactory.getSelectionFromDialog(Taxon.class, derivateSearchView.getSite().getShell(), derivateSearchView.getConversationHolder(), null);
+ selectedTaxon = SelectionDialogFactory.getSelectionFromDialog(Taxon.class, this.derivateSearchComposite.getShell(), derivativeEditor.getConversationHolder(), null);
if(selectedTaxon!=null){
derivateSearchComposite.getTextTaxonName().setText(selectedTaxon.getTitleCache());
}
}
}
+ public void setLayoutData(Object layoutData){
+ derivateSearchComposite.setLayoutData(layoutData);
+ }
+
/**
* Resets all input fields
*/
public void reset(){
if(!derivateSearchComposite.isDisposed()){
- derivateSearchComposite.getResultViewer().setInput(null);
derivateSearchComposite.getSearchField().setText("");
derivateSearchComposite.getComboDerivateType().deselectAll();
comboSpecimenTypeController.setSelection(SpecimenOrObservationType.Unknown);
selectedTaxon = null;
}
- public TableViewer getResultViewer() {
- return derivateSearchComposite.getResultViewer();
- }
-
- public void setFocus() {
- derivateSearchComposite.getResultViewer().getControl().setFocus();
+ public void setConversation(ConversationHolder conversationHolder) {
+ labelProvider.setConversation(conversationHolder);
}
/**
- * @param conversationHolder
+ * @param taxon
*/
- public void setConversation(ConversationHolder conversationHolder) {
- labelProvider.setConversation(conversationHolder);
+ public void setTaxon(Taxon taxon) {
+ if(taxon==null){
+ derivateSearchComposite.getTextTaxonName().setText("");
+ }
+ else{
+ derivateSearchComposite.getTextTaxonName().setText(taxon.getTitleCache());
+ }
}
}
eu.etaxonomy.taxeditor.ui.dialog.selection,
eu.etaxonomy.taxeditor.ui.element,
eu.etaxonomy.taxeditor.ui.group.grantedauthority,
+ eu.etaxonomy.taxeditor.ui.mvc.combo,
eu.etaxonomy.taxeditor.ui.section,
eu.etaxonomy.taxeditor.ui.section.agent,
eu.etaxonomy.taxeditor.ui.section.classification,
eu.etaxonomy.taxeditor.view.derivateSearch,
eu.etaxonomy.taxeditor.view.detail,
eu.etaxonomy.taxeditor.view.specimenSearch,
- eu.etaxonomy.taxeditor.view.supplementaldata
+ eu.etaxonomy.taxeditor.view.supplementaldata,
+ org.eclipse.wb.swt
Require-Bundle: org.eclipse.osgi,
org.eclipse.ui,
org.eclipse.jface.text,
name="%view.name.5"
restorable="true">
</view>
- <view
- class="eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView"
- icon="icons/derivate_search_view-16x16-32.png"
- id="eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView"
- name="%view.name.6"
- restorable="true">
- </view>
<view
allowMultiple="false"
class="eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"
label="%menu.label">
<command
commandId="org.eclipse.ui.views.showView"
- label="%command.label"
- style="push">
- <parameter
- name="org.eclipse.ui.views.showView.viewId"
- value="eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView">
- </parameter>
- <visibleWhen
- checkEnabled="true">
- <reference
- definitionId="isCdmStoreConnected">
- </reference>
- </visibleWhen>
- </command>
- <separator
- name="eu.etaxonomy.taxeditor.store.showViewMenu.details"
- visible="true">
- </separator>
- <command
- commandId="org.eclipse.ui.views.showView"
+ id="eu.etaxonomy.taxeditor.store.showViewMenu.details"
label="%command.label.0"
style="push">
<parameter
</visibleWhen>
</command>
</menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="popup:eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView">
- <command
- commandId="eu.etaxonomy.taxeditor.editor.handler.openDerivateView"
- label="%command.label.openInSpecimenEditor"
- style="push">
- <visibleWhen
- checkEnabled="true">
- <with
- variable="selection">
- <count
- value="+">
- </count>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralWizardPage;
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
-import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchCompositeController;
/**
* @author n.hoffmann
try {
handlerService.executeCommand(parameterizedCommand, null);
} catch (ExecutionException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ MessagingUtils.error(NewDerivedUnitBaseWizard.class, e);
} catch (NotDefinedException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ MessagingUtils.error(NewDerivedUnitBaseWizard.class, e);
} catch (NotEnabledException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ MessagingUtils.error(NewDerivedUnitBaseWizard.class, e);
} catch (NotHandledException e) {
- MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ MessagingUtils.error(NewDerivedUnitBaseWizard.class, e);
}
}
}
@Override
- public List<CdmBase> getRootEntities() {
+ public List<? extends CdmBase> getRootEntities() {
return Arrays.asList((CdmBase)getViewer().getInput());
}
package eu.etaxonomy.taxeditor.view.derivateSearch;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@Override
public Object[] getElements(Object inputElement) {
rootNodes = new ArrayList<TreeNode>();
- if(inputElement instanceof Set){
- for (Object o: (Set)inputElement) {
+ if(inputElement instanceof Collection){
+ for (Object o: (Collection)inputElement) {
if(o instanceof SpecimenOrObservationBase){
SpecimenOrObservationBase<?> rootElement = (SpecimenOrObservationBase<?>)o;
if(rootElement!=null){
derivate = node.getValue();
}
- conversation.bind();
+ if(conversation!=null){
+ conversation.bind();
+ }
final String emptyString = "";
final String separator = " ";
}
else if(cdmBase.isInstanceOf(SingleRead.class)){
- if(multiLinkSingleReads.contains(element)){
+ if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){
return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
}
else{
+++ /dev/null
-// $Id$
-/**
- * Copyright (C) 2013 EDIT
- * European Distributed Institute of Taxonomy
- * http://www.e-taxonomy.eu
- *
- * The contents of this file are subject to the Mozilla Public License Version 1.1
- * See LICENSE.TXT at the top of this package for the full license terms.
- */
-package eu.etaxonomy.taxeditor.view.derivateSearch;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.part.ViewPart;
-
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.taxeditor.model.IContextListener;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-/**
- * This view allows to search for and filter {@link SpecimenOrObservationBase}s and display
- * the results in a list. The results can be selected and opened in an editor.
- */
-public class DerivateSearchView extends ViewPart implements IContextListener, ICdmEntitySessionEnabled {
-
- public static final String ID = "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView";
- private DerivateSearchCompositeController derivateSearchCompositeController;
- private ConversationHolder conversationHolder;
- private ICdmEntitySession cdmEntitySession;
-
- /**
- * Constructs a new DerivateSearchView and registers it to listen to context changes
- */
- public DerivateSearchView() {
- CdmStore.getContextManager().addContextListener(this);
- }
-
- @Override
- public void createPartControl(Composite parent) {
-
- derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
- getSite().setSelectionProvider(derivateSearchCompositeController.getResultViewer());
- derivateSearchCompositeController.setEnabled(CdmStore.isActive());
-
- //create context menu
- MenuManager menuManager = new MenuManager();
- getSite().registerContextMenu(menuManager, derivateSearchCompositeController.getResultViewer());
- Control control = derivateSearchCompositeController.getResultViewer().getControl();
- Menu menu = menuManager.createContextMenu(control);
- control.setMenu(menu);
- }
-
- @Override
- public void setFocus() {
- derivateSearchCompositeController.setFocus();
- //make sure to bind again if maybe in another view the conversation was unbound
- if(getConversationHolder()!=null && !getConversationHolder().isClosed() && !getConversationHolder().isBound()){
- getConversationHolder().bind();
- }
- if(getCdmEntitySession() != null) {
- getCdmEntitySession().bind();
- }
- }
-
- @Override
- public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
- }
-
- @Override
- public void contextStop(IMemento memento, IProgressMonitor monitor) {
- derivateSearchCompositeController.setEnabled(false);
- derivateSearchCompositeController.reset();
- }
-
- @Override
- public void contextStart(IMemento memento, IProgressMonitor monitor) {
- derivateSearchCompositeController.setEnabled(true);
- }
-
- @Override
- public void contextRefresh(IProgressMonitor monitor) {
- initConversation();
- initSession();
- }
-
- private void initSession() {
- if(CdmStore.isActive()) {
- cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
- }
- }
-
- private void initConversation(){
- if(conversationHolder==null){
- conversationHolder = CdmStore.createConversation();
- derivateSearchCompositeController.setConversation(conversationHolder);
- }
- }
-
- @Override
- public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
- }
-
- public ConversationHolder getConversationHolder() {
- if(CdmStore.isActive() && conversationHolder==null){
- initConversation();
- }
- return conversationHolder;
- }
-
-
- @Override
- public void dispose() {
- if(conversationHolder!=null){
- conversationHolder.close();
- }
-
- if(cdmEntitySession != null) {
- cdmEntitySession.dispose();
- }
- super.dispose();
- }
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
- */
- @Override
- public ICdmEntitySession getCdmEntitySession() {
- initSession();
- return cdmEntitySession;
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
- */
- @Override
- public <T extends CdmBase> Collection<T> getRootEntities() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
- */
- @Override
- public Map<Object, List<String>> getPropertyPathsMap() {
- // TODO Auto-generated method stub
- return null;
- }
-}