import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
import eu.etaxonomy.cdm.api.service.DeleteResult;
-import eu.etaxonomy.cdm.api.service.IAgentService;
-import eu.etaxonomy.cdm.api.service.IGroupService;
import eu.etaxonomy.cdm.api.service.IMediaService;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.IReferenceService;
-import eu.etaxonomy.cdm.api.service.IUserService;
-import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
-import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
-import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
-
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-
-import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
*/
public class DeleteHandler extends AbstractHandler {
-
-
+
+
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
-
+
TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;
-
+
for(Object object : structuredSelection.toList()){
LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(null);
}
-
+
}
}
}
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(null);
}
-
+
}
}
}
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(null);
}
-
+
}
}
}
-
+
// IGroupService service = controller.getGroupService();
// if (object != null){
// result = service.delete(((Group) object).getUuid());
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(null);
}
-
+
}
}
}
-
+
// IUserService service = controller.getUserService();
// if (object != null){
// result = service.delete(((User) object).getUuid());
// }
} else if (object instanceof TaxonNameBase){
TaxonNameBase name = HibernateProxyHelper.deproxy(object, TaxonNameBase.class);
-
-
+
+
if (object != null){
NameDeletionConfigurator config = new NameDeletionConfigurator();
if (result_dialog != Status.OK){
return null;
}
-
+
//operation = new DeleteTaxonNameOperation(commandName,((BulkEditor) editor).getUndoContext() , name, config, (BulkEditor)editor);
errorMessage = "The name ";
-
+
if (model != null) {
Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
while (iter.hasNext()) {
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(config);
}
-
+
}
}
}
}
} else if (object instanceof TaxonBase){
-
+
// synonym
if(object instanceof Synonym){
Synonym synonym = HibernateProxyHelper.deproxy(object, Synonym.class);
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(config);
}
-
+
}
}
}
}
-
+
else if(object instanceof Taxon ){
Taxon taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
if (((Taxon)object).getTaxonNodes().isEmpty()){
-
+
errorMessage = "The taxon ";
} else{
MessagingUtils.messageDialog("Delete not possible", getClass(), "The taxon can not be deleted in bulk editor. It is used in a classification.", null);
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(config);
}
-
+
}
}
}
}
-
-
+
+
// ITaxonService service = controller.getTaxonService();
// if (object != null){
// if (object instanceof Taxon){
// }
// }
} else if (object instanceof TeamOrPersonBase){
-
+
if (model != null) {
Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
while (iter.hasNext()) {
Object next = iter.next();
if (next instanceof LineAnnotation) {
-
+
result = controller.getAgentService().isDeletable((TeamOrPersonBase) object, null);
if (result.isOk()){
((LineAnnotation)next).markAsDeleted(null);
}
-
+
}
}
}
errorMessage = "The team or person ";
} else if (object instanceof Media){
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
-
+
DeleteConfiguratorDialog dialog;
dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", null, "Do you really want to delete the media?", MessageDialog.WARNING, new String[] { "Delete", "Skip" }, 0);
int result_dialog= dialog.open();
}
IMediaService service = controller.getMediaService();
//TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
-
+
errorMessage = "The media ";
-
+
if (model != null) {
Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
while (iter.hasNext()) {
if (next instanceof LineAnnotation) {
result = service.isDeletable(((Media)object), config);
if (result.isOk()){
- ((LineAnnotation)next).markAsDeleted(null);
+ ((LineAnnotation)next).markAsDeleted(config);
}
-
+
}
}
}
MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
}
}
-
-
+
+
if (result.isOk() ){
-
+
((BulkEditor) editor).removeAnnotatedLine(annotation);
-
+
if(result.getUpdatedObjects().size() != 0 || !result.getExceptions().isEmpty()){
List<String> messages = new ArrayList<String>();
int i = result.getExceptions().size();
return null;
}
-
+
}