Project

General

Profile

« Previous | Next » 

Revision bda49ed8

Added by Katja Luther over 5 years ago

adapt media delete handler to e4 migration

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java
25 25
import eu.etaxonomy.cdm.model.description.TaxonDescription;
26 26
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
27 27
import eu.etaxonomy.cdm.model.media.Media;
28
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
28 29
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29 30
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
30 31
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
32
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
31 33
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
32 34
import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation;
33 35
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
51 53

  
52 54
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
53 55

  
54
        IEditorPart editor = null;
56
       
55 57
        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart());
56 58
        if (e4WrappedPart instanceof FormEditor) {
59
        	IEditorPart editor = null;
57 60
            editor = (FormEditor) e4WrappedPart;
58 61
            IEditorInput input = editor.getEditorInput();
59
            if (input instanceof TaxonEditorInput) {
62
            if (input instanceof CdmEntitySessionInput) {
60 63
                ISelection selection = mediaView.getViewer().getSelection();
61 64
                if (selection instanceof TreeSelection) {
62 65
                    TreePath[] paths = ((TreeSelection) selection).getPaths();
......
91 94
                    }
92 95
                    AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView);
93 96
                    AbstractUtility.executeOperation(operation);
97
                    
94 98
                }
95 99
            }
100
        } else if (e4WrappedPart instanceof DerivateView){
101
        	 DerivateView view = (DerivateView) e4WrappedPart;
102
          
103
                 ISelection selection = mediaView.getViewer().getSelection();
104
                 if (selection instanceof TreeSelection) {
105
                     TreePath[] paths = ((TreeSelection) selection).getPaths();
106
                     int count = paths[0].getSegmentCount();
107
                     DescriptionBase description = null;
108
                     for (int i = 0; i < count; i++ ) {
109
                         if (paths[0].getSegment(i) instanceof DescriptionBase) {
110
                             description = (DescriptionBase) paths[0].getSegment(i);
111
                             break;
112
                         }
113
                     }
114
                     // TODO use undo context specific to editor
115
                     MediaDeletionConfigurator config = new MediaDeletionConfigurator();
116
                    
117
                     config.setDeleteFromDescription(true);
118
                     config.setOnlyRemoveFromGallery(false);
119
                     
120
                     if (description instanceof SpecimenDescription){
121
                     	config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation());
122
                     } else if (description instanceof TaxonDescription){
123
                     	config.setDeleteFrom(((TaxonDescription)description).getTaxon());
124
                     }else if (description instanceof TaxonNameDescription){
125
                     	config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName());
126
                     }
127
                     	
128

  
129
                     DeleteConfiguratorDialog dialog;
130
                     dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM,  null,  Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
131
                     int result_dialog= dialog.open();
132
                     if (result_dialog != IStatus.OK){
133
                         return;
134
                     }
135
                     AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView);
136
                     AbstractUtility.executeOperation(operation);
137
                     
138
                 }
139
             }
96 140
        }
97 141

  
98
    }
142
    
99 143
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/operation/DeleteMediaOperation.java
74 74
	   // ImagesUtility.removeMediaFromGallery(description, media);
75 75

  
76 76
		monitor.worked(20);
77
		DeleteResult result = CdmStore.getService(IMediaService.class).delete(media.getUuid(), config);
78
		String errorMessage = "The media ";
79
		ImagesUtility.removeMediaFromGallery(description, media);
80
		if (!result.isOk()){
81
			List<String> messages = new ArrayList<String>();
82
			int i = result.getExceptions().size();
83
			for (Exception e:result.getExceptions()){
84
				messages.add(e.getMessage());
77
		if (!config.isOnlyRemoveFromGallery()){
78
			DeleteResult result = CdmStore.getService(IMediaService.class).delete(media.getUuid(), config);
79
			String errorMessage = "The media ";
80
			
81
			if (!result.isOk()){
82
				List<String> messages = new ArrayList<String>();
83
				int i = result.getExceptions().size();
84
				for (Exception e:result.getExceptions()){
85
					messages.add(e.getMessage());
86
				}
87
				errorMessage += "could not be deleted from database. ";
88
				//MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
89
				DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
90
				if (config.isDeleteFromDescription()){
91
					ImagesUtility.removeMediaFromGallery(description, media);
92
				}
93
			}else{
94
				ImagesUtility.removeMediaFromGallery(description, media);
85 95
			}
86
			errorMessage += "could not be deleted from database. ";
87
			//MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
88
			DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
96
		} else{
97
			ImagesUtility.removeMediaFromGallery(description, media);
89 98
		}
99
		
90 100
		monitor.worked(40);
91 101

  
92 102
		return postExecute(null);

Also available in: Unified diff