* 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.editor.name.e4.handler;
import javax.inject.Named;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
/**
- *
* @author pplitzner
* @since Aug 28, 2017
- *
*/
public class SwapSynonymAndAcceptedHandlerE4 implements IPostOperationEnabled {
- private TaxonNameEditorE4 editor;
- private Taxon taxon;
- private EPartService partService;
- private MPart activePart;
- private MApplication application;
- private EModelService modelService;
+ protected TaxonNameEditorE4 editor;
+ protected Taxon taxon;
+ protected EPartService partService;
+ protected MPart activePart;
+ protected MApplication application;
+ protected EModelService modelService;
+ protected boolean isSetNameInSource = false;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
if (!EditorUtil.forceUserSaveE4Editor(editor, shell)) {
return;
}
+ TaxonNode parentNode = editor.getTaxonNode()!= null? editor.getTaxonNode().getParent(): null;
+ Boolean isParentPublish = null;
+ if (parentNode != null){
+ if (parentNode.getTaxon() != null){
+ isParentPublish = parentNode.getTaxon().isPublish();
+ }
+ }
+ if (synonym.isPublish() != editor.getTaxon().isPublish() || (isParentPublish != null && (isParentPublish.booleanValue() != synonym.isPublish() || isParentPublish.booleanValue() != synonym.isPublish()))){
+ MessagingUtils.warningDialog("Publish flag", this, Messages.SwapSynonymToAcceptedHandler_Different_Publish_Flag);
+ }
SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(menuItem.getLocalizedLabel(),
- editor.getUndoContext(), editor.getTaxon(), synonym, this, editor.getEditorInput());
+ editor.getUndoContext(), editor.getTaxon(), synonym, this, editor.getEditorInput(), isSetNameInSource);
AbstractUtility.executeOperation(operation, sync);
-
}
@CanExecute
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
MHandledMenuItem menuItem){
boolean canExecute = false;
- Object selectedElement = selection.getFirstElement();
- canExecute =
- NameEditorMenuPropertyTester.isSynonym(selectedElement);
+ if(selection.size()==1){
+ Object selectedElement = selection.getFirstElement();
+ canExecute = NameEditorMenuPropertyTester.isSynonym(selectedElement);
+ }
menuItem.setVisible(canExecute);
return canExecute;
}
@Override
- public boolean postOperation(CdmBase objectAffectedByOperation) {
- // Redraw existing editor
- // ((IPostOperationEnabled) editor).postOperation(null);
-
- editor.save(AbstractUtility.getMonitor());
+ public boolean postOperation(Object objectAffectedByOperation) {
partService.hidePart(activePart);
-
if (objectAffectedByOperation instanceof Taxon) {
taxon = (Taxon) objectAffectedByOperation;
}
@Override
public void run() {
try {
- EditorUtil.openTaxonBaseE4(taxon.getUuid(), modelService, partService, application);
+ TaxonNode node;
+
+ if (!taxon.getTaxonNodes().isEmpty()) {
+ node = taxon.getTaxonNodes().iterator().next();
+ } else {
+ node = null;
+ }
+ if (node != null){
+ EditorUtil.openTaxonNodeE4((node).getUuid(), modelService, partService, application);
+ for (TaxonNode nodetoUpdate: taxon.getTaxonNodes()){
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, new TaxonNodeDto(nodetoUpdate.getParent()));
+ }
+ }
} catch (Exception e) {
MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this,
e.getMessage());
}
-
}
});
return true;
}
-}
+}
\ No newline at end of file