import javax.inject.Named;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.di.annotations.CanExecute;
-import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.AggregateTaxonDescriptionsOperation;
+import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
-public class AggregateTaxonDescriptionsHandler {
- @Execute
- public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection) {
- TaxonNodeDto node = (TaxonNodeDto) selection.getFirstElement();
-
- }
-
- @CanExecute
- public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
- MHandledMenuItem menuItem){
- boolean canExecute = false;
-// canExecute = selection instanceof TreeSelection
-// && ((TreeSelection) selection).size()==1
-// && ((TreeSelection) selection).getFirstElement() instanceof TaxonNodeDto;
- menuItem.setVisible(canExecute);
- return canExecute;
- }
+public class AggregateTaxonDescriptionsHandler extends RemotingCdmHandlerE4 {
+ private TaxonNavigatorE4 navigator;
+
+ public AggregateTaxonDescriptionsHandler() {
+ super("Aggregate taxon descriptions");
+ }
+
+ @Override
+ public IStatus allowOperations(IStructuredSelection selection,
+ Shell shell,
+ MPart activePart,
+ MHandledMenuItem menuItem) {
+ if(selection!=null
+ && !selection.isEmpty()
+ && selection.getFirstElement() instanceof TaxonNodeDto){
+
+ TaxonNodeDto node = (TaxonNodeDto) selection.getFirstElement();
+ boolean confirm = MessagingUtils.confirmDialog("Create aggregated description",
+ String.format("The aggregated description will be stored at the selected taxon %s"
+ , node.getTaxonTitleCache()));
+
+ return confirm?Status.OK_STATUS:Status.CANCEL_STATUS;
+ }
+ return Status.CANCEL_STATUS;
+ }
+
+ @Override
+ public AbstractOperation prepareOperation(IStructuredSelection selection,
+ Shell shell,
+ MPart activePart,
+ MHandledMenuItem menuItem) {
+
+ return new AggregateTaxonDescriptionsOperation(getTrigger(),
+ false,
+ ((TaxonNodeDto) selection.getFirstElement()).getUuid()
+ );
+ }
+
+ @CanExecute
+ private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
+ boolean canExecute = false;
+ canExecute = selection.getFirstElement() instanceof TaxonNodeDto
+ && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null;
+ menuItem.setVisible(canExecute);
+ return canExecute;
+ }
+
+ @Override
+ public void onComplete() {
+ }
+
+ @Override
+ protected Object getTrigger() {
+ return this;
+ }
}
\ No newline at end of file
--- /dev/null
+/**
+* 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.operation;
+
+import java.util.UUID;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
+import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
+import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ *
+ * @author pplitzner
+ * @date 06.08.2018
+ *
+ */
+public class AggregateTaxonDescriptionsOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled {
+
+ private TaxonNavigatorE4 taxonNavigator;
+ private UUID nodeUuid;
+
+ public AggregateTaxonDescriptionsOperation(Object source,
+ boolean async,
+ UUID nodeUuid) {
+ super("Aggregate taxon descriptions", Action.Update, source,async);
+ this.nodeUuid = nodeUuid;
+
+ }
+
+ @Override
+ protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+ runMoniteredOperation();
+ return updateResult;
+ }
+
+ public void runMoniteredOperation() {
+ UUID uuid = CdmStore.getService(IDescriptionService.class).aggregateComputedTaxonDescriptions(nodeUuid);
+
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ AbstractUtility.executeMoniteredOperation("Aggregate taxon descriptions: ",
+ uuid,
+ 500,
+ false,
+ AggregateTaxonDescriptionsOperation.this,
+ null,
+ true);
+ }
+ });
+
+
+ }
+
+ @Override
+ public void postOperation(IRemotingProgressMonitor monitor) {
+ monitor.done();
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, true);
+
+ }
+
+}