Project

General

Profile

« Previous | Next » 

Revision 12257a98

Added by Patrick Plitzner almost 7 years ago

ref #6596 Keep track of active "editor"

  • Add IE4SavablePart to E4 parts that can be saved
  • SaveHandler will recurse through selection providing parts to find savable parts that can be saved

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
73 73
import eu.etaxonomy.taxeditor.store.CdmStore;
74 74
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
75 75
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
76
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
76 77

  
77 78
/**
78 79
 * Displays the derivate hierarchy of the specimen specified in the editor input.
......
80 81
 */
81 82
public class DerivateView implements IPartContentHasFactualData, IConversationEnabled,
82 83
        ICdmEntitySessionEnabled, IDirtyMarkable, IPostOperationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
83
        IContextListener {
84
        IContextListener, IE4SavablePart {
84 85

  
85 86
    private static final String SPECIMEN_EDITOR = Messages.DerivateView_SPECIMEN_EDITOR;
86 87

  
......
316 317
    }
317 318

  
318 319
    @Persist
319
    public void doSave(IProgressMonitor monitor) {
320
    @Override
321
    public void save(IProgressMonitor monitor) {
320 322
        String taskName = Messages.DerivateView_SAVING_HIERARCHY;
321 323
        monitor.beginTask(taskName, 3);
322 324
        if (!conversation.isBound()) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java
4 4
package eu.etaxonomy.taxeditor.view;
5 5

  
6 6
import org.eclipse.jface.viewers.ISelection;
7
import org.eclipse.jface.viewers.IStructuredSelection;
7 8
import org.eclipse.swt.widgets.Composite;
8 9
import org.eclipse.swt.widgets.Display;
9 10
import org.eclipse.ui.IEditorPart;
......
31 32
     * If it is <code>true</code> then it is currently delaying a selection.
32 33
     */
33 34
    private boolean isInDelay;
34
    
35

  
35 36
    protected Object selectionProvidingPart;
36 37

  
37 38

  
......
94 95
            isInDelay = true;
95 96
            Display.getCurrent().asyncExec(delaySelection);
96 97
        }
98
    }
99

  
100
    /**
101
     * {@inheritDoc}
102
     */
103
    @Override
104
    public void showViewer(Object part, IStructuredSelection selection) {
105
        super.showViewer(part, selection);
97 106
        selectionProvidingPart = part;
98 107
    }
99 108

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
251 251
        				 TaxonRelationship rel = rels.iterator().next();
252 252
        				 if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
253 253
	        				 getViewer().setInput(rel);
254
	        				 showViewer();
255
//	        				  super.showViewer(part, selection);
254
	        				  super.showViewer(part, selection);
256 255
	        				  return;
257 256
        				 }
258 257
        			 }
......
262 261
        	}
263 262
        }
264 263
        getViewer().setInput(element);
265
        showViewer();
266
//        super.showViewer(part, selection);
264
        super.showViewer(part, selection);
267 265
    }
268 266
}
269 267

  
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java
3 3

  
4 4
import java.util.Collections;
5 5

  
6
import javax.inject.Named;
7

  
6 8
import org.eclipse.core.commands.Command;
7 9
import org.eclipse.core.commands.ParameterizedCommand;
10
import org.eclipse.core.runtime.NullProgressMonitor;
8 11
import org.eclipse.e4.core.commands.ECommandService;
9 12
import org.eclipse.e4.core.commands.EHandlerService;
10 13
import org.eclipse.e4.core.di.annotations.CanExecute;
11 14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.services.IServiceConstants;
12 17
import org.eclipse.e4.ui.workbench.modeling.EPartService;
18
import org.eclipse.ui.ISaveablePart;
13 19
import org.eclipse.ui.internal.e4.compatibility.CompatibilityPart;
14 20

  
21
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
22
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
23

  
15 24
public class SaveHandler {
16 25

  
17 26
	@Execute
18
	public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService) {
19
	    partService.getDirtyParts().forEach(mPart ->
20
	    {
21
	        if(mPart.getObject() instanceof CompatibilityPart){
22
	            //FIXME E4 remove when fully migrated
23
	            Command command = commandService.getCommand("org.eclipse.ui.file.save");
24
                ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP);
25
	            handlerService.executeHandler(parameterizedCommand);
26
	        }
27
	        else{
28
	            partService.savePart(mPart, false);
29
	        }
30
	    });
27
	public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService
28
	        , @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
29
	    if(activePart.isDirty()){
30
	        savePart(partService, commandService, handlerService, activePart);
31
	    } else {
32
            Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart.getObject());
33
            if(e4WrappedPart instanceof ISelectionElementEditingPart){
34
                ISelectionElementEditingPart editingPart = (ISelectionElementEditingPart)e4WrappedPart;
35
                Object savablePart = findSavablePart(editingPart);
36
                if(savablePart instanceof ISaveablePart){
37
                    ((ISaveablePart) savablePart).doSave(new NullProgressMonitor());
38
                }
39
                else if(savablePart instanceof IE4SavablePart){
40
                    ((IE4SavablePart) savablePart).save(new NullProgressMonitor());
41
                }
42
            }
43
        }
44
	}
45

  
46
	private Object findSavablePart(ISelectionElementEditingPart part){
47
	    Object selectionProvidingPart = part.getSelectionProvidingPart();
48
	    if(selectionProvidingPart instanceof ISaveablePart || selectionProvidingPart instanceof IE4SavablePart){
49
	        return selectionProvidingPart;
50
	    }
51
	    else if(selectionProvidingPart instanceof ISelectionElementEditingPart){
52
	        return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
53
	    }
54
	    return null;
31 55
	}
32 56

  
33 57

  
58
    private void savePart(EPartService partService, ECommandService commandService, EHandlerService handlerService,
59
            MPart mPart) {
60
        if(mPart.getObject() instanceof CompatibilityPart){
61
            //FIXME E4 remove when fully migrated
62
            Command command = commandService.getCommand("org.eclipse.ui.file.save");
63
            ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP);
64
            handlerService.executeHandler(parameterizedCommand);
65
        }
66
        else{
67
            partService.savePart(mPart, false);
68
        }
69
    }
70

  
71

  
34 72
	@CanExecute
35 73
	public boolean canExecute(EPartService partService) {
36 74
	    return !partService.getDirtyParts().isEmpty();
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/IE4SavablePart.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.workbench.part;
10

  
11
import org.eclipse.core.runtime.IProgressMonitor;
12

  
13
/**
14
 * This interface is used to be able to save a part when it is providing
15
 * an element which is edited in another part.
16
 *
17
 * <br>
18
 * This interface is used as a temporary workaround during e4 migration
19
 * for simulating the IEditorPart behavior of editors VS views
20
 *
21
 * @see ISelectionElementEditingPart
22
 * @author pplitzner
23
 * @since Jun 28, 2017
24
 *
25
 */
26
public interface IE4SavablePart {
27
    //FIXME E4
28

  
29
    /**
30
     * Save this part
31
     * @param monitor the progress monitor for long running save actions
32
     */
33
    public void save(IProgressMonitor monitor);
34
}
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/ISelectionElementEditingPart.java
15 15
 * This interface is used as a temporary workaround during e4 migration
16 16
 * for simulating the IEditorPart behavior of editors VS views
17 17
 *
18
 *@see IE4SavablePart
18 19
 * @author pplitzner
19 20
 * @since Jun 27, 2017
20 21
 *

Also available in: Unified diff