*/
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
+import java.util.Collection;
+import java.util.Iterator;
+
import javax.inject.Named;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.di.annotations.CanExecute;
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.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.window.Window;
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetPublishForSubtreeOperation;
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetPublishForSubtreeWizard;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
/**
* @author k.luther
public SetPublishFlagForSubtreeHandlerE4() {
//FIXME add missing l10n property
// super(TaxonNavigatorLabels.CHANGE_PUBLISH_FOR_SUBTREE);
- super("");
+ super(""); //$NON-NLS-1$
}
- private ITaxonTreeNode taxonNode;
+ private TaxonNodeDto taxonNode;
private PublishForSubtreeConfigurator configurator;
-
+ private static final String NO = Messages.NO;
+ private static final String CANCEL = Messages.RemotingMoveTaxonNodeHandler_CANCEL;
+ private static final String YES = Messages.YES;
@Override
public IStatus allowOperations(IStructuredSelection selection, Shell shell, MPart activePart,
// check that selected object is a taxon node
Object obj = selection.iterator().next();
- if(obj instanceof ITaxonTreeNode) {
- if (obj instanceof Classification){
- taxonNode = ((Classification)obj).getRootNode();
- }else{
- taxonNode = (ITaxonTreeNode)obj;
- }
- } else{
+ if(obj instanceof TaxonNodeDto) {
+ taxonNode = (TaxonNodeDto)obj;
+ } else if(obj instanceof Classification){
+ taxonNode = new TaxonNodeDto(((Classification)obj).getRootNode());
+ }else{
return new Status(IStatus.ERROR,
"unknown", //$NON-NLS-1$
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
}
- configurator = new PublishForSubtreeConfigurator(taxonNode.getUuid());
+ Collection<IE4SavablePart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
+
+ if (dirtyParts != null && !dirtyParts.isEmpty()){
+ String[] buttonLables = {YES, NO,CANCEL};
+ MessageDialog dialog = new MessageDialog(null, Messages.SetPublishFlagForSubtreeHandlerE4_UnsavedChanges, null, Messages.SetPublishFlagForSubtreeHandlerE4_UnsavedChangesQuestion, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
+ dialog.open();
+ int returnCode = dialog.getReturnCode();
+ boolean proceed = false;
+ if (returnCode == 0){
+ proceed = true;
+ }else if (returnCode == 2){
+ return Status.CANCEL_STATUS;
+ }
+
+ Iterator<IE4SavablePart> partIterator = dirtyParts.iterator();
+ while( partIterator.hasNext() ){
+ IE4SavablePart part = partIterator.next();
+ if (proceed) {
+ if (part != null){
+ part.save(new NullProgressMonitor());
+ }
+ }
+ }
+ }
+
+
+ configurator = new PublishForSubtreeConfigurator(taxonNode.getUuid(), false, null);
SetPublishForSubtreeWizard wizard = new SetPublishForSubtreeWizard(configurator);
WizardDialog dialog = new WizardDialog(shell, wizard);
@CanExecute
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
boolean canExecute = false;
- canExecute = selection.getFirstElement() instanceof ITaxonTreeNode;
+ canExecute = selection.size()==1
+ && selection.getFirstElement() instanceof TaxonNodeDto;
menuItem.setVisible(canExecute);
return canExecute;
}
partService,
activePart,
application,
+ modelService,
configurator);
return operation;