Project

General

Profile

« Previous | Next » 

Revision 20fa89e3

Added by Patrick Plitzner over 6 years ago

fix #6809 add selection delay to parts

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/e4/ReferencingObjectsViewE4.java
19 19
import javax.annotation.PostConstruct;
20 20
import javax.annotation.PreDestroy;
21 21
import javax.inject.Inject;
22
import javax.inject.Named;
23 22

  
24 23
import org.apache.log4j.Logger;
25 24
import org.eclipse.core.runtime.IProgressMonitor;
26 25
import org.eclipse.core.runtime.IStatus;
27 26
import org.eclipse.core.runtime.Status;
28 27
import org.eclipse.core.runtime.jobs.Job;
29
import org.eclipse.e4.core.di.annotations.Optional;
30 28
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
31 29
import org.eclipse.e4.ui.services.EMenuService;
32
import org.eclipse.e4.ui.services.IServiceConstants;
33 30
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
34 31
import org.eclipse.jface.viewers.CellEditor;
35 32
import org.eclipse.jface.viewers.ICellModifier;
......
399 396
         });
400 397
	 }
401 398

  
402
    @Inject
403
    @Optional
404
    public void selectionChanged(
405
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
406
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
407
            MPart thisPart){
399
    @Override
400
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
408 401
        if(activePart==thisPart){
409 402
            return;
410 403
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/ConceptViewPartE4.java
13 13

  
14 14
import javax.annotation.PostConstruct;
15 15
import javax.inject.Inject;
16
import javax.inject.Named;
17 16

  
18
import org.eclipse.e4.core.di.annotations.Optional;
19 17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20 18
import org.eclipse.e4.ui.services.EMenuService;
21
import org.eclipse.e4.ui.services.IServiceConstants;
22 19
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
23 20
import org.eclipse.jface.viewers.ISelection;
24 21
import org.eclipse.jface.viewers.ISelectionChangedListener;
......
60 57
    @Inject
61 58
    private ESelectionService selService;
62 59

  
63
    @Inject
64
    @Optional
65
    public void selectionChanged(
66
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
67
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
68
            MPart thisPart){
60
    @Override
61
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
69 62
        if(activePart==thisPart){
70 63
            return;
71 64
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/FactualDataPartE4.java
16 16

  
17 17
import javax.annotation.PostConstruct;
18 18
import javax.inject.Inject;
19
import javax.inject.Named;
20 19

  
21
import org.eclipse.e4.core.di.annotations.Optional;
22 20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23 21
import org.eclipse.e4.ui.services.EMenuService;
24
import org.eclipse.e4.ui.services.IServiceConstants;
25 22
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
26 23
import org.eclipse.jface.action.Action;
27 24
import org.eclipse.jface.action.IAction;
......
136 133
//    }
137 134

  
138 135

  
139
    @Inject
140
    @Optional
141
    public void selectionChanged(
142
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
143
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
144
            MPart thisPart){
136
    @Override
137
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
145 138
        if(activePart==thisPart){
146 139
            return;
147 140
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java
11 11

  
12 12
import javax.annotation.PostConstruct;
13 13
import javax.inject.Inject;
14
import javax.inject.Named;
15 14

  
16
import org.eclipse.e4.core.di.annotations.Optional;
17 15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18 16
import org.eclipse.e4.ui.services.EMenuService;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20 17
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
21 18
import org.eclipse.jface.viewers.AbstractTreeViewer;
22 19
import org.eclipse.jface.viewers.ISelectionChangedListener;
......
76 73

  
77 74
	}
78 75

  
79
	@Inject
80
	@Optional
81
	public void selectionChanged(
82
	        @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
83
	        @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
84
	        MPart thisPart){
76
    @Override
77
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
85 78
	    if(activePart==thisPart){
86 79
	        return;
87 80
	    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
11 11
import java.util.Set;
12 12

  
13 13
import javax.annotation.PreDestroy;
14
import javax.inject.Inject;
15
import javax.inject.Named;
14 16

  
17
import org.eclipse.e4.core.di.annotations.Optional;
15 18
import org.eclipse.e4.ui.di.PersistState;
16 19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.IServiceConstants;
17 21
import org.eclipse.jface.viewers.IStructuredSelection;
18 22
import org.eclipse.jface.viewers.StructuredSelection;
19 23
import org.eclipse.jface.viewers.Viewer;
24
import org.eclipse.swt.widgets.Display;
20 25
import org.eclipse.ui.IEditorPart;
21 26

  
22 27
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
42 47
public abstract class AbstractCdmEditorPartE4
43 48
        implements IConversationEnabled, IDirtyMarkable, ISelectionElementEditingPart, IPostOperationEnabled{
44 49

  
50
    private DelaySelection delaySelection = null;
51
    /**
52
     * This is the monitor for the DelaySelection runnable.
53
     * If it is <code>true</code> then it is currently delaying a selection.
54
     */
55
    private boolean isInDelay;
56

  
57

  
58
    /**
59
     * This class invokes internal_selectionChanged() in a separate thread.
60
     * This allows an asynchronous and/or delayed handling of selection changes
61
     */
62
    private class DelaySelection implements Runnable{
63
        private Object selection;
64
        private MPart activePart;
65
        private MPart thisPart;
66

  
67
        public DelaySelection(Object selection, MPart activePart, MPart thisPart) {
68
            super();
69
            this.selection = selection;
70
            this.activePart= activePart;
71
            this.thisPart = thisPart;
72
        }
73

  
74
        @Override
75
        public void run() {
76
            try{
77
                selectionChanged_internal(selection, activePart, thisPart);
78
            }
79
            finally{
80
                isInDelay = false;
81
            }
82
        }
83

  
84
        public synchronized void setSelection(Object selection) {
85
            this.selection = selection;
86
        }
87

  
88
        public synchronized void setActivePart(MPart activePart) {
89
            this.activePart = activePart;
90
        }
91

  
92
        public synchronized void setThisPart(MPart thisPart) {
93
            this.thisPart = thisPart;
94
        }
95

  
96
    }
97

  
98
    protected abstract void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart);
99

  
100
    @Inject
101
    @Optional
102
    public void selectionChanged(
103
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
104
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
105
            MPart thisPart){
106
        if(delaySelection==null){
107
            delaySelection = new DelaySelection(selection, activePart, thisPart);
108
        }
109
        delaySelection.setSelection(selection);
110
        delaySelection.setActivePart(activePart);
111
        delaySelection.setThisPart(thisPart);
112
        if(!isInDelay){
113
            isInDelay = true;
114
            Display.getCurrent().asyncExec(delaySelection);
115
        }
116
    }
117

  
45 118
    protected Viewer viewer;
46 119

  
47 120
    protected MPart selectionProvidingPart;
......
68 141
    }
69 142

  
70 143
    protected void showViewer(IStructuredSelection selection, MPart activePart, Viewer viewer){
144
        long start = System.currentTimeMillis();
71 145
        if(viewer!=null){
72 146
            Object element = selection.getFirstElement();
73 147
            if(selection.getFirstElement()!=null){
......
100 174
            }
101 175
            selectionProvidingPart = activePart;
102 176
        }
177
        long stop = System.currentTimeMillis();
178
        System.out.println(thisPart.getObject().getClass().getSimpleName()+": "+(stop-start));
103 179
    }
104 180

  
105 181
    protected Object createPartObject(MPart activePart) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
11 11

  
12 12
import javax.annotation.PostConstruct;
13 13
import javax.inject.Inject;
14
import javax.inject.Named;
15 14

  
16
import org.eclipse.e4.core.di.annotations.Optional;
17 15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.services.IServiceConstants;
19 16
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
20 17
import org.eclipse.jface.viewers.ISelectionChangedListener;
21 18
import org.eclipse.jface.viewers.IStructuredSelection;
......
55 52
        viewer.addSelectionChangedListener(selectionChangedListener);
56 53
    }
57 54

  
58
    @Inject
59
    @Optional
60
    public void selectionChanged(
61
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
62
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
63
            MPart thisPart){
64
        if(activePart==thisPart){
55
    @Override
56
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
57
        if (activePart==thisPart){
65 58
            return;
66 59
        }
67 60

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/supplementaldata/SupplementalDataPartE4.java
13 13

  
14 14
import javax.annotation.PostConstruct;
15 15
import javax.inject.Inject;
16
import javax.inject.Named;
17 16

  
18
import org.eclipse.e4.core.di.annotations.Optional;
19 17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21 18
import org.eclipse.jface.viewers.IStructuredSelection;
22 19
import org.eclipse.jface.viewers.StructuredSelection;
23 20
import org.eclipse.jface.viewers.TreeNode;
......
52 49
		viewer = new SupplementalDataViewerE4(parent, this);
53 50
	}
54 51

  
55
	@Inject
56
	@Optional
57
	protected void selectionChanged_internal(
58
	        @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
59
	        @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
60
	        MPart thisPart) {
52
    @Override
53
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
61 54
	    if(activePart==thisPart){
62 55
	        return;
63 56
	    }

Also available in: Unified diff