eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientReferenceService.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTaxonService.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTermService.java -text
-eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/CreateDerivateContextMenu.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateDragListener.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateDropListener.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java -text
-eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewContextMenu.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewPropertyTester.java -text
-eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/SingleReadSequenceContextMenu.java -text
-eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/command/CopySingleReadCommand.java -text
-eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/command/PasteSingleReadCommand.java -text
-eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/command/UnlinkSingleReadCommand.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/CreateDerivateContextMenu.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/DerivateViewContextMenu.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/SingleReadSequenceContextMenu.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDragListener.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDropAdapter.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementTransfer.java -text
<menuContribution
locationURI="popup:eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
<dynamic
- class="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewContextMenu"
+ class="eu.etaxonomy.taxeditor.editor.view.derivate.contextMenu.DerivateViewContextMenu"
id="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateContextMenu">
</dynamic>
- <command
- commandId="eu.etaxonomy.taxeditor.editor.view.derivate.copySingleRead"
- label="Reuse for other Sequence"
- style="push">
- <visibleWhen
- checkEnabled="true">
- <reference
- definitionId="isSingleRead">
- </reference>
- </visibleWhen>
- </command>
- <command
- commandId="eu.etaxonomy.taxeditor.editor.view.derivate.pasteSingleRead"
- label="Reuse Single Read here"
- style="push">
- <visibleWhen
- checkEnabled="true">
- <reference
- definitionId="isSequence">
- </reference>
- </visibleWhen>
- </command>
- <command
- commandId="eu.etaxonomy.taxeditor.editor.view.derivate.unlinkSingleRead"
- label="Remove SingleRead from Sequence"
- style="push">
- <visibleWhen
- checkEnabled="true">
- <reference
- definitionId="isMultiLinkedSingleRead">
- </reference>
- </visibleWhen>
- </command>
</menuContribution>
<menuContribution
locationURI="popup:eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportEditor">
id="eu.etaxonomy.taxeditor.editor.view.dataimport.SaveSpecimenCommand"
name="Save Specimen">
</command>
- <command
- defaultHandler="eu.etaxonomy.taxeditor.editor.view.derivate.command.CopySingleReadCommand"
- id="eu.etaxonomy.taxeditor.editor.view.derivate.copySingleRead"
- name="Copy SingleRead">
- </command>
- <command
- defaultHandler="eu.etaxonomy.taxeditor.editor.view.derivate.command.PasteSingleReadCommand"
- id="eu.etaxonomy.taxeditor.editor.view.derivate.pasteSingleRead"
- name="Paste SingleRead">
- </command>
- <command
- defaultHandler="eu.etaxonomy.taxeditor.editor.view.derivate.command.UnlinkSingleReadCommand"
- id="eu.etaxonomy.taxeditor.editor.view.derivate.unlinkSingleRead"
- name="Unlink SingleRead">
- </command>
</extension>
<extension
</test>
</with>
</definition>
- <definition
- id="isSingleRead">
- <with
- variable="selection">
- <test
- property="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewPropertyTester.isSingleRead">
- </test>
- </with>
- </definition>
- <definition
- id="isSequence">
- <with
- variable="selection">
- <test
- property="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewPropertyTester.isSequence">
- </test>
- </with>
- </definition>
- <definition
- id="isMultiLinkedSingleRead">
- <with
- variable="selection">
- <test
- property="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewPropertyTester.isMultiLinkedSingleRead">
- </test>
- </with>
- </definition>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
TreeNode draggednode = EditorUtil.getTreeNodeValueOfSelection((IStructuredSelection) data);
if(draggednode!=null){
if(moveTreeNode(draggednode, targetNode)){
- derivateView.update();
+ derivateView.refreshTree();
LocalSelectionTransfer.getTransfer().setSelection(null);
return true;
}
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.StructuredSelection;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.jface.viewers.TreeViewer;
viewer.setContentProvider(new DerivateContentProvider());
labelProvider = new DerivateLabelProvider();
viewer.setLabelProvider(labelProvider);
- viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
+ viewer.setAutoExpandLevel(2);
// Propagate selection from viewer
getSite().setSelectionProvider(viewer);
monitor.worked(1);
monitor.done();
firePropertyChange(PROP_DIRTY);
- update();
+ refreshTree();
}
/* (non-Javadoc)
}
/**
- * Updates the derivate hierarchy tree
+ * Refreshes the derivate hierarchy tree
*/
- public void update(){
+ public void refreshTree(){
generateMultiLinkSingleReads();
labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
- viewer.setInput(getEditorInput());
+ viewer.refresh();
}
private void generateMultiLinkSingleReads() {
+++ /dev/null
-package eu.etaxonomy.taxeditor.editor.view.derivate;
-
-import org.eclipse.jface.action.ContributionItem;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeNode;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.ui.IEditorPart;
-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.facade.DerivedUnitFacadeCacheStrategy;
-import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.molecular.DnaSample;
-import eu.etaxonomy.cdm.model.molecular.Sequence;
-import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-
-/**
- * Context menu for the creation of derivates in the derivate hierarchy.
- *
- */
-public class SingleReadSequenceContextMenu extends CompoundContributionItem {
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
- */
- @Override
- protected IContributionItem[] getContributionItems() {
- IContributionItem[] contributionItems = new IContributionItem[] {
- new ContributionItem() {
- @Override
- public void fill(Menu menu, int index) {
- final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- final IEditorPart activeEditor = window.getActivePage().getActiveEditor();
- final ISelection selection = window.getActivePage().getSelection();
- TreeNode selectedTreeNode = EditorUtil.getTreeNodeValueOfSelection(selection);
- TreeNode clipboardNode = EditorUtil.getTreeNodeValueOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
- if(selectedTreeNode!=null){
- //context menu for Sequence
- if(selectedTreeNode.getValue() instanceof Sequence
- && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead){
- MenuItem item = new MenuItem(menu, SWT.NONE);
- item.setText("Reuse SingleRead here");
- }
- else if(selectedTreeNode.getValue() instanceof SingleRead){
- MenuItem item = new MenuItem(menu, SWT.NONE);
- item.setText("Reuse for other Sequence");
- if(activeEditor instanceof DerivateView
- && ((DerivateView) activeEditor).getMultiLinkSingleReads().contains(selectedTreeNode.getValue())){
- MenuItem unlinkItem = new MenuItem(menu, SWT.NONE);
- unlinkItem.setText("Remove from this Sequence");
- }
- }
- }
- }
- }
- };
- return contributionItems;
- }
-
- private class WidgetSelectionListener implements SelectionListener{
-
- private final TreeNode selectedNode;
- //TODO: we need a common interface for the generic like e.g. "IDerivateHierarchyNode"
- private final Class<?> childClass;
- private final SpecimenOrObservationType specimenType;
-
- /**
- * @param selectedNode
- * @param specimenType
- */
- public WidgetSelectionListener(TreeNode selectedNode, Class<?> childClass, SpecimenOrObservationType specimenType) {
- this.selectedNode = selectedNode;
- this.childClass = childClass;
- this.specimenType = specimenType;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent e) {
- Object selectedDerivate = selectedNode.getValue();
- if(selectedDerivate instanceof DnaSample){
- DnaSample dnaSample = (DnaSample)selectedDerivate;
- if(childClass.equals(Sequence.class)){
- dnaSample.addSequence(Sequence.NewInstance(""));//why does this not have DnaSample as constructor parameter?
- }
- }
- else if(selectedDerivate instanceof Sequence){
- ((Sequence) selectedDerivate).addSingleRead(SingleRead.NewInstance());
- }
- else if(selectedDerivate instanceof SpecimenOrObservationBase && DerivedUnit.class.isAssignableFrom(childClass)){
- SpecimenOrObservationBase<?> specimenOrObservationBase = (SpecimenOrObservationBase<?>)selectedDerivate;
- DerivedUnit derivedUnit;
- if(childClass.equals(DnaSample.class)){
- derivedUnit = DnaSample.NewInstance();
- }
- else if(childClass.equals(MediaSpecimen.class)){
- derivedUnit = MediaSpecimen.NewInstance(specimenType);
- //a MediaSpecimen with no media attached does not make sense. Hence we add one
- ((MediaSpecimen)derivedUnit).setMediaSpecimen(Media.NewInstance());
- }
- else{
- derivedUnit = DerivedUnit.NewInstance(specimenType);
- }
- specimenOrObservationBase.addDerivationEvent(DerivationEvent.NewSimpleInstance(specimenOrObservationBase, derivedUnit, DerivationEventType.GATHERING_IN_SITU()));
- derivedUnit.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
- derivedUnit.getTitleCache(); //update title cache
- }
-
- //refresh view
- IWorkbenchPart activePart = AbstractUtility.getActivePart();
- if(activePart instanceof DerivateView){
- DerivateView derivateView = (DerivateView)activePart;
- derivateView.changed(null);
- derivateView.getViewer().refresh();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // TODO Auto-generated method stub
-
- }
- }
-
-}
+++ /dev/null
-package eu.etaxonomy.taxeditor.editor.view.derivate.command;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.PlatformUI;
-
-public class CopySingleReadCommand extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
- LocalSelectionTransfer.getTransfer().setSelection(selection);
- return null;
- }
-
-}
+++ /dev/null
-package eu.etaxonomy.taxeditor.editor.view.derivate.command;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeNode;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-
-import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
-import eu.etaxonomy.cdm.model.molecular.Sequence;
-import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-public class PasteSingleReadCommand extends AbstractHandler {
-
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if(activeEditor.isDirty()){
- AbstractUtility.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
- return null;
- }
- ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
- final ISelection pasteSelection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
-
- TreeNode clipBoardTreeNode = EditorUtil.getTreeNodeValueOfSelection(clipBoardSelection);
- TreeNode pasteTreeNode = EditorUtil.getTreeNodeValueOfSelection(pasteSelection);
- if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead
- && pasteTreeNode!=null && pasteTreeNode.getValue() instanceof Sequence){
- SingleRead singleRead = (SingleRead)clipBoardTreeNode.getValue();
- Sequence sequence = (Sequence)pasteTreeNode.getValue();
- sequence.addSingleRead(singleRead);
- CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
- if(activeEditor instanceof DerivateView) {
- DerivateView derivateView = (DerivateView)activeEditor;
- derivateView.update();
- LocalSelectionTransfer.getTransfer().setSelection(null);
- }
- }
- return null;
- }
-
-}
+++ /dev/null
-package eu.etaxonomy.taxeditor.editor.view.derivate.command;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeNode;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-
-import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
-import eu.etaxonomy.cdm.model.molecular.Sequence;
-import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-public class UnlinkSingleReadCommand extends AbstractHandler {
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if(activeEditor.isDirty()){
- AbstractUtility.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
- return null;
- }
- ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
- final ISelection pasteSelection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
-
- TreeNode clipBoardTreeNode = EditorUtil.getTreeNodeValueOfSelection(clipBoardSelection);
- TreeNode pasteTreeNode = EditorUtil.getTreeNodeValueOfSelection(pasteSelection);
- if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead
- && pasteTreeNode!=null && pasteTreeNode.getValue() instanceof Sequence){
- SingleRead singleRead = (SingleRead)clipBoardTreeNode.getValue();
- Sequence sequence = (Sequence)pasteTreeNode.getValue();
- sequence.addSingleRead(singleRead);
- CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
- if(activeEditor instanceof DerivateView) {
- DerivateView derivateView = (DerivateView)activeEditor;
- derivateView.update();
- LocalSelectionTransfer.getTransfer().setSelection(null);
- }
- }
- return null;
- }
-
-}
-package eu.etaxonomy.taxeditor.editor.view.derivate;
+package eu.etaxonomy.taxeditor.editor.view.derivate.contextMenu;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IWorkbenchPart;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
/**
menuItem.addSelectionListener(new WidgetSelectionListener(selectedNode, childClass, specimenType));
}
- private class WidgetSelectionListener implements SelectionListener{
+ private class WidgetSelectionListener extends SelectionAdapter{
private final TreeNode selectedNode;
//TODO: we need a common interface for the generic like e.g. "IDerivateHierarchyNode"
if(activePart instanceof DerivateView){
DerivateView derivateView = (DerivateView)activePart;
derivateView.changed(null);
- derivateView.getViewer().refresh();
+ derivateView.refreshTree();
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // TODO Auto-generated method stub
-
- }
}
}
-package eu.etaxonomy.taxeditor.editor.view.derivate;
+package eu.etaxonomy.taxeditor.editor.view.derivate.contextMenu;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.ui.actions.CompoundContributionItem;
--- /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.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeNode;
+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.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CompoundContributionItem;
+
+import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.model.molecular.Sequence;
+import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * Context menu for the creation of derivates in the derivate hierarchy.
+ *
+ */
+public class SingleReadSequenceContextMenu extends CompoundContributionItem {
+
+ private enum CommandType{
+ COPY_TO_CLIPBOARD,
+ REMOVE_FROM_SEQUENCE,
+ ADD_TO_SEQUENCE
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ IContributionItem[] contributionItems = new IContributionItem[] {
+ new ContributionItem() {
+ @Override
+ public void fill(Menu menu, int index) {
+ final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ final IEditorPart activeEditor = window.getActivePage().getActiveEditor();
+ final ISelection selection = window.getActivePage().getSelection();
+ TreeNode selectedTreeNode = EditorUtil.getTreeNodeValueOfSelection(selection);
+ TreeNode clipboardNode = EditorUtil.getTreeNodeValueOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
+ if(selectedTreeNode!=null){
+ //context menu for Sequence
+ if(selectedTreeNode.getValue() instanceof Sequence
+ && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead){
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText("Reuse SingleRead here");
+ item.addSelectionListener(new WidgetSelectionListener(CommandType.ADD_TO_SEQUENCE));
+ }
+ else if(selectedTreeNode.getValue() instanceof SingleRead){
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText("Reuse for other Sequence");
+ item.addSelectionListener(new WidgetSelectionListener(CommandType.COPY_TO_CLIPBOARD));
+ if(activeEditor instanceof DerivateView
+ && ((DerivateView) activeEditor).getMultiLinkSingleReads().contains(selectedTreeNode.getValue())){
+ MenuItem unlinkItem = new MenuItem(menu, SWT.NONE);
+ unlinkItem.setText("Remove from this Sequence");
+ unlinkItem.addSelectionListener(new WidgetSelectionListener(CommandType.REMOVE_FROM_SEQUENCE));
+ }
+ }
+ }
+ }
+ }
+ };
+ return contributionItems;
+ }
+
+ private class WidgetSelectionListener extends SelectionAdapter{
+ private final CommandType commandType;
+
+ /**
+ * @param selectedTreeNode
+ * @param clipboardNode
+ * @param commandType
+ */
+ public WidgetSelectionListener(CommandType commandType) {
+ this.commandType = commandType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
+ final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
+ TreeNode clipBoardTreeNode = EditorUtil.getTreeNodeValueOfSelection(clipBoardSelection);
+ TreeNode selectedTreeNode = EditorUtil.getTreeNodeValueOfSelection(selection);
+ switch (commandType) {
+ case REMOVE_FROM_SEQUENCE:
+ if(activeEditor.isDirty()){
+ AbstractUtility.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
+ return;
+ }
+ if(selectedTreeNode!=null && selectedTreeNode.getParent()!=null &&
+ selectedTreeNode.getValue() instanceof SingleRead && selectedTreeNode.getParent().getValue() instanceof Sequence) {
+ Sequence sequence = (Sequence) selectedTreeNode.getParent().getValue();
+ sequence.removeSingleRead((SingleRead) selectedTreeNode.getValue());
+ CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
+ if(activeEditor instanceof DerivateView) {
+ DerivateView derivateView = (DerivateView)activeEditor;
+ derivateView.getConversationHolder().commit();
+ derivateView.refreshTree();
+ }
+ }
+
+ break;
+ case ADD_TO_SEQUENCE:
+ if(activeEditor.isDirty()){
+ AbstractUtility.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
+ return;
+ }
+ if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead
+ && selectedTreeNode!=null && selectedTreeNode.getValue() instanceof Sequence){
+ SingleRead singleRead = (SingleRead)clipBoardTreeNode.getValue();
+ Sequence sequence = (Sequence)selectedTreeNode.getValue();
+ sequence.addSingleRead(singleRead);
+ CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
+ if(activeEditor instanceof DerivateView) {
+ DerivateView derivateView = (DerivateView)activeEditor;
+ derivateView.getConversationHolder().commit();
+ derivateView.refreshTree();
+ LocalSelectionTransfer.getTransfer().setSelection(null);
+ }
+ }
+ break;
+ case COPY_TO_CLIPBOARD:
+ LocalSelectionTransfer.getTransfer().setSelection(selection);
+ break;
+ }
+ }
+ }
+}