From: Patrick Plitzner Date: Tue, 18 Aug 2015 12:56:14 +0000 (+0200) Subject: Merge branch 'develop' into LibrAlign X-Git-Tag: 3.8.0^2~40^2~5 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/b7c9ffeeff71a7b3348efee12f91924b697ba995?hp=3141e8b037b34f599ad53bdc96178ad938e17ce3 Merge branch 'develop' into LibrAlign --- diff --git a/eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF index 81bdf0a83..6a5c28686 100644 --- a/eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF @@ -21,6 +21,7 @@ Require-Bundle: org.eclipse.ui, eu.etaxonomy.taxeditor.bulkeditor, eu.etaxonomy.taxeditor.editor, eu.etaxonomy.taxeditor.printpublisher, + eu.etaxonomy.taxeditor.molecular, eu.etaxonomy.taxeditor.help, org.eclipse.equinox.ds, org.eclipse.equinox.util, diff --git a/eu.etaxonomy.taxeditor.application/plugin.xml b/eu.etaxonomy.taxeditor.application/plugin.xml index b74e209ce..f6e4ab946 100644 --- a/eu.etaxonomy.taxeditor.application/plugin.xml +++ b/eu.etaxonomy.taxeditor.application/plugin.xml @@ -414,7 +414,7 @@ id="eu_etaxonomy_taxeditor_product" point="org.eclipse.core.runtime.products"> MergeGroupHandler class.

@@ -71,10 +76,41 @@ public class MergeGroupHandler extends AbstractHandler { } Object targetEntity = ((IEntityContainer) targetAnnotation).getEntity(); + TeamOrPersonBase teamOrPerson = null; + Reference ref = null; + if (targetEntity instanceof TeamOrPersonBase){ + teamOrPerson = HibernateProxyHelper.deproxy(targetEntity, TeamOrPersonBase.class); + } else if(targetEntity instanceof Reference){ + ref = HibernateProxyHelper.deproxy(targetEntity, Reference.class); + } logger.info("Merging group"); // model.printAnnotations(); for (LineAnnotation annotation : candidateAnnotations) { + //first check whether entities are mergeable + + try{ + if (ref != null){ + Reference ref2 = HibernateProxyHelper.deproxy(annotation.getEntity(), Reference.class); + + if (!CdmStore.getCommonService().isMergeable(ref, ref2, null)){ + MessageDialog.openWarning(HandlerUtil.getActiveShell(event), + "No merge possible", "A merge of " + ref.getTitleCache() + " and " + ref2.getTitleCache() + " is not possible."); + return null; + } + } + if (teamOrPerson != null){ + TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(annotation.getEntity(), TeamOrPersonBase.class); + + if (!CdmStore.getCommonService().isMergeable(teamOrPerson, teamOrPerson2, null)){ + MessageDialog.openWarning(HandlerUtil.getActiveShell(event), + "No merge possible", "A merge of " + teamOrPerson.getTitleCache() + " and " + teamOrPerson2.getTitleCache() + " is not possible."); + return null; + } + } + }catch(MergeException e){ + + } ((BulkEditor) editor).removeAnnotatedLine(annotation); // Mark entity container for merging with target entity diff --git a/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin.properties b/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin.properties index 1c03030fc..8281fca55 100644 --- a/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin.properties +++ b/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin.properties @@ -9,7 +9,7 @@ editor.name.1 = Key editor.name.2 = Polytomous Key Graph Editor editor.name.3 = Polytomous Key List Editor editor.name.4 = Cdm Authority Editor -editor.name.5 = Derivative View +editor.name.5 = Derivative Editor view.name = Factual Data view.name.0 = Uses view.name.1 = Media @@ -112,7 +112,7 @@ command.name.32 = Create Concept Relation command.name.33 = Open Related Concept category.name.7 = -- Group command.name.34 = Edit CDM Authorities -command.name.35 = Open Derivative View +command.name.35 = Open Derivative Editor scheme.description = The default key binding scheme for the Taxonomic Editor scheme.name = Taxonomic Editor Default Key Bindings editor.name.6 = Specimen Import Editor diff --git a/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_de.properties b/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_de.properties index 803b460b9..a4d096a11 100644 --- a/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_de.properties +++ b/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_de.properties @@ -112,7 +112,7 @@ command.name.32 = Erstelle Konzeptrelationen command.name.33 = \u00d6ffne verbundenes Konzept category.name.7 = -- Gruppe command.name.34 = Bearbeite CDM Rechte -command.name.35 = \u00d6ffne Derivate Ansicht +command.name.35 = \u00d6ffne Derivat-Editor scheme.description = Die Standard Tastenkombinationsschema f\u00fcr den Taxonomischen Editor scheme.name = Taxonomic Editor Standard Tastenkombinationen editor.name.6 = Specimen Import Editor diff --git a/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_en.properties b/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_en.properties index 65d48bae5..17a5b0490 100644 --- a/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_en.properties +++ b/eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_en.properties @@ -111,7 +111,6 @@ command.name.32 = Create Concept Relation command.name.33 = Open Related Concept category.name.7 = -- Group command.name.34 = Edit CDM Authorities -command.name.35 = Open Derivate View scheme.description = The default key binding scheme for the Taxonomic Editor scheme.name = Taxonomic Editor Default Key Bindingseditor.name.6 = Specimen Import Editor editor.name.7 = Gbif Import Editor diff --git a/eu.etaxonomy.taxeditor.editor/plugin.xml b/eu.etaxonomy.taxeditor.editor/plugin.xml index b3c364a17..b9a3d50db 100644 --- a/eu.etaxonomy.taxeditor.editor/plugin.xml +++ b/eu.etaxonomy.taxeditor.editor/plugin.xml @@ -242,45 +242,21 @@ commandId="eu.etaxonomy.taxeditor.editor.command.new.name" label="%command.label.46" style="push"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + checkEnabled="false"> + + @@ -391,12 +332,6 @@ commandId="eu.etaxonomy.taxeditor.editor.command.openParent" label="%command.label.8" style="push"> - - - - - - @@ -1061,12 +993,6 @@ name="org.eclipse.ui.views.showView.viewId" value="eu.etaxonomy.taxeditor.editor.view.validation.problems"> - - - - @@ -1371,6 +1297,7 @@ id="eu.etaxonomy.taxeditor.editor.media.command.delete" name="%command.name.49"> + @@ -1513,13 +1440,14 @@ + @@ -1733,4 +1661,10 @@ + + + + diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java index 5fc0b2b9a..7b9a605cf 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java @@ -83,6 +83,7 @@ public class KeyEditor extends FormEditor implements IConversationEnabled, @Override public void setFocus() { + getConversationHolder().commit(true); getConversationHolder().bind(); super.setFocus(); } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java index ceae45d69..dc81964bc 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java @@ -345,7 +345,8 @@ public class PolytomousKeyListEditor extends EditorPart implements @Override public boolean postOperation(CdmBase objectAffectedByOperation) { viewer.refresh(); - + getConversationHolder().bind(); + getConversationHolder().commit(true); editor.changed(objectAffectedByOperation); if (objectAffectedByOperation != null) { diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java index 3b4ae0d7a..f31a83125 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java @@ -12,9 +12,12 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.handlers.HandlerUtil; import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; +import eu.etaxonomy.cdm.api.service.DeleteResult; import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService; import eu.etaxonomy.cdm.api.service.ITaxonService; import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; +import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin; +import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -52,15 +55,27 @@ public class DeleteNodeOperation extends AbstractPostTaxonOperation { controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration(); IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService(); - + DeleteResult result; if (node.getChildren().size()>0){ if(! MessageDialog.openQuestion(null, "Confirm deletion of children", "The selected node has children, do you want to delete them, too?")) { - service.delete(node.getUuid(), false); + result = service.delete(node.getUuid(), false); } else{ - service.delete(node.getUuid(), true); + result = service.delete(node.getUuid(), true); } } else{ - service.delete(node.getUuid(), true); + result = service.delete(node.getUuid(), true); + } + + if (!result.isOk() || result.getExceptions().size() > 0){ + Exception t = new Exception(); + if (result.getExceptions().size() >1){ + for (Exception e:result.getExceptions()){ + t.addSuppressed(e); + } + }else { + t = result.getExceptions().iterator().next(); + } + MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(),null, TaxeditorBulkeditorPlugin.PLUGIN_ID, t, true); } return postExecute(null); } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/DataImportEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/DataImportEditorInput.java index a74d15d44..5be66c8bc 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/DataImportEditorInput.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/DataImportEditorInput.java @@ -21,6 +21,9 @@ import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery; import eu.etaxonomy.taxeditor.store.CdmStore; /** + * Input for {@link DataImportEditor}. This class queries a data source for + * occurrences and passes them to the editor. + * * @author pplitzner * @date 25.02.2014 * @@ -35,65 +38,40 @@ public abstract class DataImportEditorInput implements IEditorInput { protected OccurenceQuery query; - /** - * @param results - */ public DataImportEditorInput() { this.conversationHolder = CdmStore.createConversation(); } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ @Override public Object getAdapter(Class adapter) { // TODO Auto-generated method stub return null; } - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#exists() - */ @Override public boolean exists() { return false; } - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getImageDescriptor() - */ @Override public ImageDescriptor getImageDescriptor() { // TODO Auto-generated method stub return null; } - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getPersistable() - */ @Override public IPersistableElement getPersistable() { return null; } - /** - * @return the results - */ public Collection getResults() { return results; } - /** - * @param results the results to set - */ public void setResults(Collection results) { this.results = results; } - /** - * @return the conversationHolder - */ public ConversationHolder getConversationHolder() { return conversationHolder; } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/GbifImportEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/GbifImportEditorInput.java index ed7c89cc0..3aaf22c52 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/GbifImportEditorInput.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/GbifImportEditorInput.java @@ -26,9 +26,6 @@ import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse; */ public class GbifImportEditorInput extends DataImportEditorInput { - /** - * @param query - */ public GbifImportEditorInput(OccurenceQuery query) { super(); this.query = query; @@ -50,25 +47,16 @@ public class GbifImportEditorInput extends DataImportEditorInput { } - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getName() - */ @Override public String getName() { return "[GBIF] " + query.toString(); } - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getToolTipText() - */ @Override public String getToolTipText() { return "[GBIF] " + query.toString(); } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -77,9 +65,6 @@ public class GbifImportEditorInput extends DataImportEditorInput { return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTaxonService.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTaxonService.java index 407234ba7..d1daa7b1f 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTaxonService.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTaxonService.java @@ -1344,7 +1344,7 @@ public class TransientTaxonService implements ITaxonService { public List> getSynonymsByHomotypicGroup(Taxon taxon, List propertyPaths) { return defaultService.getSynonymsByHomotypicGroup(taxon, propertyPaths); } - + @Override public Synonym changeRelatedTaxonToSynonym(Taxon fromTaxon, Taxon toTaxon, TaxonRelationshipType oldRelationshipType, diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java index 7548960d9..a7845395e 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java @@ -166,7 +166,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput(); return derivateViewEditorInput.getName(); } - return "Derivative View"; + return "Derivative Editor"; } /* (non-Javadoc) diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/operation/MoveDerivateOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/operation/MoveDerivateOperation.java index b863dcbe2..9931904ff 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/operation/MoveDerivateOperation.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/operation/MoveDerivateOperation.java @@ -63,7 +63,7 @@ public class MoveDerivateOperation extends AbstractPostOperation { derivateView = (DerivateView) getPostOperationEnabled(); } if(derivateView==null){ - MessagingUtils.operationDialog(this, new NullPointerException("DerivativeView was null"), TaxeditorEditorPlugin.PLUGIN_ID, this.getLabel(), getLabel()); + MessagingUtils.operationDialog(this, new NullPointerException("Derivative Editor was null"), TaxeditorEditorPlugin.PLUGIN_ID, this.getLabel(), getLabel()); return Status.CANCEL_STATUS; } if(derivateView.isDirty()){ diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java index 0c2306ba6..9a801a4d4 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java @@ -20,25 +20,36 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PartInitException; import org.eclipse.ui.handlers.HandlerUtil; import eu.etaxonomy.cdm.api.service.IDescriptionService; import eu.etaxonomy.cdm.api.service.ITaxonService; +import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; import eu.etaxonomy.cdm.model.common.Annotation; import eu.etaxonomy.cdm.model.common.AnnotationType; +import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.common.Language; +import eu.etaxonomy.cdm.model.description.DescriptionBase; import eu.etaxonomy.cdm.model.description.DescriptionElementBase; import eu.etaxonomy.cdm.model.description.TaxonDescription; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.EditorUtil; +import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; +import eu.etaxonomy.taxeditor.editor.Page; +import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart; import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation; +import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog; +import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; /** @@ -46,8 +57,9 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog; * @created Feb 8, 2011 * @version 1.0 */ -public class MoveDescriptionElementsHandler extends AbstractHandler { - +public class MoveDescriptionElementsHandler extends AbstractHandler implements IPostOperationEnabled{ + private UUID newAcceptedTaxonNodeUuid; + private TaxonNameEditor editor; /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @@ -55,7 +67,7 @@ public class MoveDescriptionElementsHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { // ConversationHolder conversation = CdmStore.createConversation(); - + editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME); ISelection selection = HandlerUtil.getCurrentSelection(event); if(selection instanceof IStructuredSelection){ @@ -81,14 +93,28 @@ public class MoveDescriptionElementsHandler extends AbstractHandler { if(elements.size() == 0){ return null; } + DescriptionBase description = elements.get(0).getInDescription(); + List excludeTaxa = new ArrayList(); + if (description.isInstanceOf(TaxonDescription.class)){ + TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class); + Taxon actualTaxon = taxonDescription.getTaxon(); + excludeTaxa.add(actualTaxon.getUuid()); + } - Taxon targetTaxon = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), EditorUtil.getActiveMultiPageTaxonEditor().getConversationHolder(), null); + + TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), + editor.getConversationHolder(), + "Choose the accepted taxon", + excludeTaxa, + null, + null); + Taxon targetTaxon = newAcceptedTaxonNode.getTaxon(); if(targetTaxon == null){ // canceled return null; } - + newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid(); TaxonDescription targetDescription = TaxonDescription.NewInstance(targetTaxon); String moveMessage = String.format("Elements moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon()); targetDescription.setTitleCache(moveMessage, true); @@ -99,10 +125,11 @@ public class MoveDescriptionElementsHandler extends AbstractHandler { try { AbstractPostOperation operation = new MoveDescriptionElementsOperation( event.getCommand().getName(), EditorUtil.getUndoContext(), - targetDescription, elements, false, (IPostOperationEnabled) EditorUtil.getView(DescriptiveViewPart.ID, true)); + targetDescription, elements, false, this); + EditorUtil.executeOperation(operation); -// conversation.commit(true); - CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon); + + //CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon); } catch (NotDefinedException e) { MessagingUtils.error(getClass(), e); @@ -112,4 +139,44 @@ public class MoveDescriptionElementsHandler extends AbstractHandler { return null; } + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) + */ + /** {@inheritDoc} */ + @Override + public boolean postOperation(CdmBase objectAffectedByOperation) { + + editor.getConversationHolder().bind(); + editor.getConversationHolder().commit(true); + Display.getDefault().asyncExec(new Runnable(){ + + public void run() { + //AbstractUtility.close(editor.getMultiPageTaxonEditor()); + + try { + MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid); + if(possibleOpenEditor != null){ + AbstractUtility.close(possibleOpenEditor); + } + EditorUtil.openTaxonNode(newAcceptedTaxonNodeUuid); + } catch (PartInitException e) { + MessagingUtils.error(this.getClass(), e); + throw new RuntimeException(e); + } catch (Exception e) { + MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage()); + } + } + + }); + + + return true; + } + + @Override + public boolean onComplete() { + // TODO Auto-generated method stub + return false; + } + } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionToOtherTaxonHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionToOtherTaxonHandler.java index ab67cf8c6..c4b57e9cb 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionToOtherTaxonHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionToOtherTaxonHandler.java @@ -20,6 +20,7 @@ import org.eclipse.ui.handlers.HandlerUtil; import eu.etaxonomy.cdm.api.service.IDescriptionService; import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.description.DescriptionBase; import eu.etaxonomy.cdm.model.description.TaxonDescription; import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.EditorUtil; @@ -28,6 +29,7 @@ import eu.etaxonomy.taxeditor.editor.Page; import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionToOtherTaxonOperation; import eu.etaxonomy.taxeditor.model.AbstractUtility; +import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -66,8 +68,14 @@ public class MoveDescriptionToOtherTaxonHandler extends AbstractHandler IStructuredSelection structuredSelection = (IStructuredSelection) selection; for(Object element : structuredSelection.toArray()){ - if (element instanceof TaxonDescription){ - UUID uuid = ((TaxonDescription)element).getUuid(); + UUID uuid = null; + if (element instanceof FeatureNodeContainer){ + uuid = ((FeatureNodeContainer)element).getDescription().getUuid(); + } else if (element instanceof DescriptionBase){ + uuid = ((DescriptionBase)element).getUuid(); + } + + if (uuid != null){ descriptions.add((TaxonDescription) CdmStore.getService(IDescriptionService.class).load(uuid, null)); } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java index 5b4b0053e..fd74d7274 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java @@ -17,10 +17,17 @@ import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PartInitException; import eu.etaxonomy.cdm.api.service.IDescriptionService; +import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.description.DescriptionBase; import eu.etaxonomy.cdm.model.description.DescriptionElementBase; +import eu.etaxonomy.taxeditor.editor.EditorUtil; +import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; +import eu.etaxonomy.taxeditor.model.AbstractUtility; +import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -30,7 +37,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @created Feb 8, 2011 * @version 1.0 */ -public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation { +public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation{ private Collection descriptionElements; private DescriptionBase targetDescription; @@ -68,6 +75,7 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation service.moveDescriptionElementsToDescription(descriptionElements, targetDescription, isCopy); + return postExecute(targetDescription); } @@ -90,5 +98,7 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation // TODO Auto-generated method stub return null; } + + } diff --git a/eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF index 38ab0a72c..05dba64f1 100644 --- a/eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF @@ -16,3 +16,7 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Bundle-Vendor: EDIT +Export-Package: eu.etaxonomy.taxeditor.molecular, + eu.etaxonomy.taxeditor.molecular.editor, + eu.etaxonomy.taxeditor.molecular.handler +Bundle-ClassPath: . diff --git a/eu.etaxonomy.taxeditor.molecular/build.properties b/eu.etaxonomy.taxeditor.molecular/build.properties index e4bf8ac38..bdd1c23c4 100644 --- a/eu.etaxonomy.taxeditor.molecular/build.properties +++ b/eu.etaxonomy.taxeditor.molecular/build.properties @@ -1,4 +1,6 @@ -bin.includes = META-INF/,\ +bin.includes = .,\ + META-INF/,\ plugin.xml,\ icons/,\ OSGI-INF/ +source.. = src/main/java/ diff --git a/eu.etaxonomy.taxeditor.navigation/plugin.xml b/eu.etaxonomy.taxeditor.navigation/plugin.xml index 2ace44ef5..86609245a 100644 --- a/eu.etaxonomy.taxeditor.navigation/plugin.xml +++ b/eu.etaxonomy.taxeditor.navigation/plugin.xml @@ -47,12 +47,6 @@ - - - - - - - - - - - - - - - - @@ -348,12 +324,6 @@ commandId="eu.etaxonomy.taxeditor.navigation.command.create.taxonNode" label="%command.label.13" style="push"> - - - - - - - - + + + + diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java index 6075a5062..09861da31 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java @@ -247,6 +247,8 @@ public class PolytomousKeyViewPart extends ViewPart implements */ @Override public boolean postOperation(CdmBase objectAffectedByOperation) { + getConversationHolder().bind(); + getConversationHolder().commit(true); viewer.refresh(); return true; } diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorContentService.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorContentService.java new file mode 100644 index 000000000..46c659bfc --- /dev/null +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorContentService.java @@ -0,0 +1,30 @@ +package eu.etaxonomy.taxeditor.navigation.navigator; + +import org.eclipse.ui.internal.navigator.NavigatorContentService; +import org.eclipse.ui.navigator.INavigatorDnDService; + +public class TaxonNavigatorContentService extends NavigatorContentService { + + private TaxonNavigatorDnDService navigatorDnDService; + + public TaxonNavigatorContentService(String viewerID) { + super(viewerID); + + + } + + public TaxonNavigatorContentService(String aViewerId, + TaxonNavigatorViewer taxonNavigatorViewer) { + super(aViewerId, taxonNavigatorViewer); + getDnDService(); + } + + @Override + public TaxonNavigatorDnDService getDnDService() { + if (navigatorDnDService == null) { + navigatorDnDService = new TaxonNavigatorDnDService(this); + } + return navigatorDnDService; + } + +} diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDnDService.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDnDService.java new file mode 100644 index 000000000..5de170c81 --- /dev/null +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDnDService.java @@ -0,0 +1,170 @@ +package eu.etaxonomy.taxeditor.navigation.navigator; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.ui.internal.navigator.dnd.CommonDropAdapterDescriptor; +import org.eclipse.ui.internal.navigator.dnd.CommonDropDescriptorManager; +import org.eclipse.ui.internal.navigator.extensions.CommonDragAssistantDescriptor; +import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptor; +import org.eclipse.ui.navigator.CommonDragAdapterAssistant; +import org.eclipse.ui.navigator.CommonDropAdapter; +import org.eclipse.ui.navigator.CommonDropAdapterAssistant; +import org.eclipse.ui.navigator.INavigatorContentService; +import org.eclipse.ui.navigator.INavigatorDnDService; + +import eu.etaxonomy.taxeditor.navigation.navigator.dnd.TaxonNavigatorDragAdapterAssistant; + +public class TaxonNavigatorDnDService implements INavigatorDnDService { + private static final CommonDropAdapterAssistant[] NO_ASSISTANTS = new CommonDropAdapterAssistant[0]; + + private INavigatorContentService contentService; + + private TaxonNavigatorDragAdapterAssistant[] dragAssistants; + + private TreeNodeDropAdapter dropAdapter; + + private final Map dropAssistants = new HashMap(); + + public TaxonNavigatorDnDService(INavigatorContentService contentService){ + this.contentService = contentService; + } + + + @Override + public CommonDragAdapterAssistant[] getCommonDragAssistants() { + + return dragAssistants; + } + + @Override + public void bindDragAssistant(CommonDragAdapterAssistant anAssistant) { + if(dragAssistants == null) + initializeDragAssistants(); + TaxonNavigatorDragAdapterAssistant[] newDragAssistants = new TaxonNavigatorDragAdapterAssistant[dragAssistants.length + 1]; + System.arraycopy(dragAssistants, 0, newDragAssistants, 0, dragAssistants.length); + newDragAssistants[dragAssistants.length] = (TaxonNavigatorDragAdapterAssistant) anAssistant; + dragAssistants = newDragAssistants; + + } + + private void initializeDragAssistants() { + int i = 0; + Set dragDescriptors = ((NavigatorViewerDescriptor) contentService + .getViewerDescriptor()).getDragAssistants(); + dragAssistants = new TaxonNavigatorDragAdapterAssistant[dragDescriptors + .size()]; + for (Iterator iter = dragDescriptors.iterator(); iter.hasNext();) { + CommonDragAssistantDescriptor descriptor = (CommonDragAssistantDescriptor) iter + .next(); + dragAssistants[i++] = (TaxonNavigatorDragAdapterAssistant) descriptor.createDragAssistant(); + } + } + + @Override + public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants( + Object aDropTarget, TransferData aTransferType) { + CommonDropAdapterDescriptor[] descriptors = CommonDropDescriptorManager + .getInstance().findCommonDropAdapterAssistants(aDropTarget, + contentService); + + if (descriptors.length == 0) { + return NO_ASSISTANTS; + } + + if (LocalSelectionTransfer.getTransfer().isSupportedType(aTransferType) + && LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) { + return getAssistantsBySelection(descriptors, (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection()); + } + return getAssistantsByTransferData(descriptors, aTransferType); + } + + private CommonDropAdapterAssistant[] getAssistantsByTransferData( + CommonDropAdapterDescriptor[] descriptors, + TransferData aTransferType) { + + Set assistants = new LinkedHashSet(); + for (int i = 0; i < descriptors.length; i++) { + CommonDropAdapterAssistant asst = getAssistant(descriptors[i]); + if (asst.isSupportedType(aTransferType)) { + assistants.add(asst); + } + } + return sortAssistants((CommonDropAdapterAssistant[]) assistants + .toArray(new CommonDropAdapterAssistant[assistants.size()])); + + } + + private CommonDropAdapterAssistant[] getAssistantsBySelection( + CommonDropAdapterDescriptor[] descriptors, IStructuredSelection aSelection) { + + Set assistants = new LinkedHashSet(); + + for (int i = 0; i < descriptors.length; i++) { + if(descriptors[i].areDragElementsSupported(aSelection)) { + assistants.add(getAssistant(descriptors[i])); + } + } + + return sortAssistants((CommonDropAdapterAssistant[]) assistants + .toArray(new CommonDropAdapterAssistant[assistants.size()])); + } + + private CommonDropAdapterAssistant getAssistant( + CommonDropAdapterDescriptor descriptor) { + TreeNodeDropAdapterAssistant asst = (TreeNodeDropAdapterAssistant) dropAssistants + .get(descriptor); + if (asst != null) { + return asst; + } + synchronized (dropAssistants) { + asst = (TreeNodeDropAdapterAssistant) dropAssistants.get(descriptor); + if (asst == null) { + dropAssistants.put(descriptor, (asst = (TreeNodeDropAdapterAssistant) descriptor + .createDropAssistant())); + asst.init(contentService); + //asst.setCommonDropAdapter(dropAdapter); + } + } + return asst; + } + + + private CommonDropAdapterAssistant[] sortAssistants(CommonDropAdapterAssistant[] array) { + Arrays.sort(array, new Comparator() { + public int compare(Object arg0, Object arg1) { + CommonDropAdapterAssistant a = (CommonDropAdapterAssistant) arg0; + CommonDropAdapterAssistant b = (CommonDropAdapterAssistant) arg1; + // This is to ensure that the navigator resources drop assistant will + // always be first on the list of drop assistant, if a conflict ever + // occurs. + String id = "org.eclipse.ui.navigator.resources."; //$NON-NLS-1$ + if (a.getClass().getName().startsWith(id)) + return -1; + if (b.getClass().getName().startsWith(id)) + return 1; + return a.getClass().getName().compareTo(b.getClass().getName()); + } + }); + return array; + } + + @Override + public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants( + Object aDropTarget, IStructuredSelection theDragSelection) { + // TODO Auto-generated method stub + return null; + } + + public void setDropAdaptor(TreeNodeDropAdapter da) { + dropAdapter = da; + } +} diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorViewer.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorViewer.java new file mode 100644 index 000000000..8fdabb831 --- /dev/null +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorViewer.java @@ -0,0 +1,54 @@ +package eu.etaxonomy.taxeditor.navigation.navigator; + +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.internal.navigator.NavigatorContentService; +import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService; +import org.eclipse.ui.navigator.CommonDragAdapter; +import org.eclipse.ui.navigator.CommonDropAdapter; +import org.eclipse.ui.navigator.CommonViewer; +import org.eclipse.ui.navigator.INavigatorContentService; + +import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer; + +public class TaxonNavigatorViewer extends CommonViewer { + + private NavigatorContentService contentService; + String viewerId; + + public TaxonNavigatorViewer(String aViewerId, Composite aParent, int aStyle) { + super(aViewerId, aParent, aStyle); + contentService = new TaxonNavigatorContentService(aViewerId, this); + viewerId = aViewerId; + } + + @Override + protected void initDragAndDrop() { + + int operations = DND.DROP_MOVE ; + + CommonDragAdapter dragAdapter = createDragAdapter(); + addDragSupport(operations, dragAdapter.getSupportedDragTransfers(), + dragAdapter); + Transfer[] transfers = new Transfer[] { TaxonNodeTransfer.getInstance() }; + TreeNodeDropAdapter dropAdapter = createTreeNodeDropAdapter(); + addDropSupport(operations, transfers, dropAdapter); + + TaxonNavigatorDnDService dnd = (TaxonNavigatorDnDService)getNavigatorContentService().getDnDService(); + dnd.setDropAdaptor(dropAdapter); + } + + + protected TreeNodeDropAdapter createTreeNodeDropAdapter() { + return new TreeNodeDropAdapter(this); + } + + public NavigatorContentService getNavigatorContentService(){ + if (contentService == null){ + contentService = new TaxonNavigatorContentService(viewerId); + } + return contentService; + } + +} diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDragListener.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDragListener.java new file mode 100644 index 000000000..9cd02f9eb --- /dev/null +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDragListener.java @@ -0,0 +1,83 @@ +// $Id$ +/** +* Copyright (C) 2015 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.navigation.navigator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.ui.navigator.CommonViewer; + + +import eu.etaxonomy.cdm.model.common.DefinedTermBase; +import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer; +import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer; + +/** + * @author k.luther + * @date 02.06.2015 + * + */ +public class TreeNodeDragListener extends DragSourceAdapter { + private CommonViewer viewer; + + /** + * + */ + public TreeNodeDragListener(CommonViewer viewer) { + this.viewer = viewer; + } + + + public void setViewer(CommonViewer viewer){ + this.viewer = viewer; + } + /* (non-Javadoc) + * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent) + */ + @Override + public void dragStart(DragSourceEvent event) { + + event.doit = true;// set to false if needed - default is true + } + + /* (non-Javadoc) + * @see org.eclipse.swt.dnd.DragSourceAdapter#dragFinished(org.eclipse.swt.dnd.DragSourceEvent) + */ + @Override + public void dragFinished(DragSourceEvent event) { + // TODO Auto-generated method stub + super.dragFinished(event); + } + + /* (non-Javadoc) + * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent) + */ + @Override + public void dragSetData(DragSourceEvent event) { + + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + List taxonNodes = new ArrayList(); + + for (Object object : selection.toList()){ + taxonNodes.add((ITaxonTreeNode)object); + } + + if (TaxonNodeTransfer.getInstance().isSupportedType( + event.dataType)) { + event.data = taxonNodes.toArray(new TaxonNode[taxonNodes.size()]); + } + } +} diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java new file mode 100644 index 000000000..448da0521 --- /dev/null +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java @@ -0,0 +1,284 @@ +// $Id$ +/** +* Copyright (C) 2015 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.navigation.navigator; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.IconAndMessageDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerDropAdapter; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.navigator.CommonDropAdapter; +import org.eclipse.ui.navigator.CommonDropAdapterAssistant; +import org.eclipse.ui.navigator.CommonViewer; + +import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; +import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.common.OrderedTermBase; +import eu.etaxonomy.cdm.model.common.TermBase; +import eu.etaxonomy.cdm.model.taxon.Classification; +import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; +import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; +import eu.etaxonomy.taxeditor.navigation.NavigationUtil; +import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation; +import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; +import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; +import eu.etaxonomy.taxeditor.preference.PreferencesUtil; +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + *

TreeNodeDropAdapter class.

+ * + * @author k.luther + * @date 02.06.2015 + * @version 1.0 + */ +public class TreeNodeDropAdapter extends ViewerDropAdapter implements IPostOperationEnabled { + + /** + * @param viewer + */ + protected TreeNodeDropAdapter(TaxonNavigatorViewer navigatorViewer) { + super(navigatorViewer); + this.navigatorViewer = navigatorViewer; + + } + + private final TaxonNavigatorViewer navigatorViewer; + private static final Logger logger = Logger.getLogger(TreeNodeDropAdapter.class); + + /** Constant ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked} */ + public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ + + private static final EnumSet UPDATE = EnumSet.of(CRUD.UPDATE); + + + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) + */ + /** {@inheritDoc} */ + @Override + public boolean performDrop(Object target) { + + + if (target instanceof ITaxonTreeNode) { + Set taxonNodes = getSelectedTaxa(); + ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target; + if (targetTreeNode instanceof Classification){ + targetTreeNode = ((Classification)targetTreeNode).getRootNode(); + targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class); + } + if(taxonNodes != null) { + if (taxonNodes.size() == 1){ + return moveTaxon(taxonNodes.iterator().next(), targetTreeNode); + } else{ + if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ + return true; + } + } + } + } + + return false; + } + + private Set getSelectedTaxa(){ + HashSet taxonNodes = new HashSet(); + + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + if (selection instanceof TreeSelection) { + + Iterator selectionIterator = ((TreeSelection) selection).iterator(); + + while (selectionIterator.hasNext()){ + Object object = selectionIterator.next(); + if(object instanceof TaxonNode){ + TaxonNode taxonNode = (TaxonNode) object; + taxonNodes.add(taxonNode); + } + } + } + return taxonNodes.size() > 0 ? taxonNodes : null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) + */ + /** {@inheritDoc} */ + @Override + public boolean validateDrop(Object target, int operation, + TransferData transferType) { + + if (target instanceof ITaxonTreeNode) { + + // check users permissions with target taxonnode and taxon + if (target instanceof TaxonNode) { + TaxonNode targetNode = (TaxonNode)target; + Boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE); + Boolean hasTargetTaxonPermission = CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE); + + if(logger.isDebugEnabled()){ + logger.debug("target: " + targetNode.getTaxon().getTitleCache()); + } + + if(!hasTargetNodePermission || ! hasTargetNodePermission){ + if(logger.isDebugEnabled()){ + logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission.toString() + " " + hasTargetTaxonPermission.toString() + " "); + } + return false; + } + } + + // do not allow to drop onto itself and + // check users permissions with all selected taxon nodes and taxa + for(TaxonNode taxonNode : getSelectedTaxa()){ + logger.debug("selectedTaxa: " + taxonNode.getTaxon().getTitleCache()); + Boolean isSameTaxonNode = taxonNode.equals(target); + Boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE); + Boolean hasTaxonPermission = CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE); + if ( + isSameTaxonNode + || !hasTaxonNodePermission + || !hasTaxonPermission + ) { + if(logger.isDebugEnabled()){ + logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode.toString() + " " + hasTaxonNodePermission.toString() + " " + hasTaxonPermission.toString() + " "); + } + return false; + } + } + logger.debug("OK_STATUS"); + return true; + } + logger.debug("CANCEL_STATUS"); + return false; + } + + + /** + * @param childTaxonNode + * @param parentTaxon + * @return + */ + private boolean moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) { + + TaxonNavigator taxonNavigator; + taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); + + if(targetITaxonTreeNode instanceof TaxonNode){ + + TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode; + // Make sure parent taxon does not have unsaved changes + if (NavigationUtil.isDirty(targetTaxonNode)){ + MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + + "changes in the parent taxon. Pleas save first."); + return false; + } + + } + if (!PreferencesUtil.getSortNodesNaturally()){ + IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); + if (workspaceUndoContext == null) { + logger.error("Workspace undo context is null. DND operation cancelled"); + return false; + } + + AbstractPostOperation operation = new MoveTaxonOperation + ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true); + NavigationUtil.executeOperation(operation); + + logger.info("Moved taxa to new parent " + targetITaxonTreeNode); + return true; + }else{ + String[] buttonLables = {"Parent", "Predecessor", "Cancel"}; + MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0); + dialog.open(); + int returnCode = dialog.getReturnCode(); + if (returnCode == 0){ + IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); + if (workspaceUndoContext == null) { + logger.error("Workspace undo context is null. DND operation cancelled"); + return false; + } + + AbstractPostOperation operation = new MoveTaxonOperation + ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true); + NavigationUtil.executeOperation(operation); + + logger.info("Moved taxa to new parent " + targetITaxonTreeNode); + return true; + }else if (returnCode == 1){ + IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); + if (workspaceUndoContext == null) { + logger.error("Workspace undo context is null. DND operation cancelled"); + return false; + } + + AbstractPostOperation operation = new MoveTaxonOperation + ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false); + NavigationUtil.executeOperation(operation); + + logger.info("Moved taxa to new parent " + targetITaxonTreeNode); + return true; + } else{ + return false; + } + + + } + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) + */ + /** {@inheritDoc} */ + @Override + public boolean postOperation(CdmBase objectAffectedByOperation) { + return true; + } + + /** + *

onComplete

+ * + * @return a boolean. + */ + @Override + public boolean onComplete() { + // TODO Auto-generated method stub + return false; + } + @Override + public void dragOver(DropTargetEvent event) { + super.dragOver(event); + event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_INSERT_AFTER; + + } + +} diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java index 55df02ba2..5a8650098 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java @@ -87,6 +87,7 @@ public class DeleteHandler extends AbstractHandler{ ITaxonTreeNode treeNode = treeNodes.iterator().next(); ITaxonTreeNode taxonNode =treeNode; TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator(); + //configNodes.setDeleteTaxon(false); if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){ if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){ return null; @@ -122,9 +123,10 @@ public class DeleteHandler extends AbstractHandler{ } }else{ - if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){ + if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){ return null; - } + } + config.setTaxonNodeConfig(configNodes); } } diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index 3b026cdf1..41a4ad279 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -296,12 +296,6 @@ name="org.eclipse.ui.views.showView.viewId" value="eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView"> - - - - - - - - - - - - 0.22.0 3.8.0-SNAPSHOT snapshot @@ -31,11 +32,11 @@ eu.etaxonomy.taxeditor.bulkeditor eu.etaxonomy.taxeditor.printpublisher eu.etaxonomy.taxeditor.help + eu.etaxonomy.taxeditor.molecular + eu.etaxonomy.taxeditor.molecular.lib eu.etaxonomy.taxeditor.application eu.etaxonomy.taxeditor.feature.platform eu.etaxonomy.taxeditor.feature - eu.etaxonomy.taxeditor.molecular - eu.etaxonomy.taxeditor.molecular.lib eu.etaxonomy.taxeditor