Project

General

Profile

« Previous | Next » 

Revision ea1b3d44

Added by Patrick Plitzner almost 7 years ago

ref #6596 Add new utility class WorkbenchUtility in workbench plugin

  • move getE4WrappedPart() method to that class

View differences:

eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF
25 25
 org.eclipse.ui.forms,
26 26
 eu.etaxonomy.taxeditor.store,
27 27
 eu.etaxonomy.taxeditor.bulkeditor,
28
 eu.etaxonomy.taxeditor.workbench,
28 29
 org.eclipse.zest.core,
29 30
 org.eclipse.zest.layouts,
30 31
 eu.etaxonomy.taxeditor.cdmlib,
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java
61 61
				IEditorInput input = ((IEditorPart) part).getEditorInput();
62 62
				showViewer(part, new StructuredSelection(input));
63 63
			}
64
			showViewer();
65 64
		}
66 65

  
67 66
	}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveViewPart.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.editor.view.descriptive;
11 11

  
12
import java.util.ArrayList;
13 12
import java.util.HashMap;
14 13
import java.util.Map;
15 14

  
16
import javax.annotation.PostConstruct;
17
import javax.inject.Inject;
18

  
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.e4.ui.di.Persist;
21
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
22
import org.eclipse.e4.ui.workbench.UIEvents.Dirtyable;
23 15
import org.eclipse.jface.action.Action;
24 16
import org.eclipse.jface.action.GroupMarker;
25 17
import org.eclipse.jface.action.IAction;
......
45 37
import org.eclipse.ui.IWorkbenchPart;
46 38
import org.eclipse.ui.internal.E4PartWrapper;
47 39

  
48
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
49
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
50 40
import eu.etaxonomy.cdm.model.common.CdmBase;
51 41
import eu.etaxonomy.cdm.model.description.DescriptionBase;
52 42
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
......
57 47
import eu.etaxonomy.taxeditor.editor.EditorUtil;
58 48
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
59 49
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
60
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
61 50
import eu.etaxonomy.taxeditor.editor.view.media.MediaViewPart;
62
import eu.etaxonomy.taxeditor.model.AbstractUtility;
63 51
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
64 52
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
65 53
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
67 55
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
68 56
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
69 57
import eu.etaxonomy.taxeditor.model.ImageResources;
70
import eu.etaxonomy.taxeditor.store.CdmStore;
71 58
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
72 59
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
73 60
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
61
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
74 62

  
75 63
/**
76 64
 * @author n.hoffmann
......
97 85
	protected int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
98 86

  
99 87
    private DescriptiveContentProvider provider;
100
    
101
    
88

  
89

  
102 90
	/** {@inheritDoc} */
103 91
	@Override
104 92
	public void createViewer(Composite parent) {
......
207 195
		    showEmptyPage();
208 196
		}
209 197
	}
210
 
198

  
211 199
	@Override
212 200
	protected String getViewName(){
213 201
	    return Messages.DescriptiveViewPart_FACTUAL_DATA;
......
286 274
		    ((BulkEditor) part).forceDirty();
287 275
		    IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
288 276
		    ((BulkEditor) part).changed(selection.getFirstElement());
289
		    
277

  
290 278
		}
291
		
279

  
292 280
		if (part instanceof E4PartWrapper){
293
	    	part = AbstractUtility.getE4WrappedPart(part);
281
	    	part = WorkbenchUtility.getE4WrappedPart(part);
294 282
	    	if (part instanceof IDirtyMarkable){
295 283
	    		 StructuredSelection selection = new StructuredSelection(object);
296 284
	    		((IDirtyMarkable)part).changed(selection.getFirstElement());
297 285
	    	}
298 286
	    }
299 287

  
300
		
288

  
301 289
		super.changed(object);
302 290
	}
303 291

  
......
316 304
	    provider.toggleShowOnlyIndividualAssociations();
317 305
	    viewer.refresh();
318 306
	}
319
	
320
	
307

  
308

  
321 309

  
322 310
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java
22 22
import org.eclipse.swt.widgets.Control;
23 23
import org.eclipse.swt.widgets.Menu;
24 24
import org.eclipse.swt.widgets.Tree;
25
import org.eclipse.ui.IEditorPart;
26
import org.eclipse.ui.ISaveablePart;
27 25
import org.eclipse.ui.IWorkbenchActionConstants;
28 26
import org.eclipse.ui.IWorkbenchPart;
29 27
import org.eclipse.ui.internal.E4PartWrapper;
30 28

  
31
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
32 29
import eu.etaxonomy.cdm.model.description.IDescribable;
33
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
34 30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
35 31
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
36 32
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
37 33
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
38
import eu.etaxonomy.taxeditor.model.AbstractUtility;
39 34
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
40 35
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
41 36
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
......
43 38
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
44 39
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
45 40
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
41
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
46 42

  
47 43
/**
48 44
 * @author n.hoffmann
......
102 98
//			showEmptyPage();
103 99
//			return;
104 100
//		}
105
		
101

  
106 102

  
107 103
        if (part instanceof DetailsViewPart || part instanceof SupplementalDataViewPart
108 104
                || part instanceof DescriptiveViewPart) {
......
135 131
				}
136 132
			}
137 133
		}
138
		
134

  
139 135
		showEmptyPage();
140 136
	}
141 137

  
......
158 154

  
159 155
	    }
160 156
	    if (part instanceof E4PartWrapper){
161
	    	part = AbstractUtility.getE4WrappedPart(part);
157
	    	part = WorkbenchUtility.getE4WrappedPart(part);
162 158
	    	if (part instanceof IDirtyMarkable){
163 159
	    		 StructuredSelection selection = new StructuredSelection(object);
164 160
	    		((IDirtyMarkable)part).changed(selection.getFirstElement());
165 161
	    	}
166 162
	    }
167
	        
168
	    
163

  
164

  
169 165
	    super.changed(object);
170 166
	}
171 167

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.model;
11 11

  
12
import java.lang.reflect.Field;
13 12
import java.lang.reflect.InvocationTargetException;
14 13
import java.util.ArrayList;
15 14
import java.util.Collection;
......
35 34
import org.eclipse.core.runtime.SubProgressMonitor;
36 35
import org.eclipse.core.runtime.jobs.ISchedulingRule;
37 36
import org.eclipse.core.runtime.jobs.Job;
38
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
39 37
import org.eclipse.jface.action.IStatusLineManager;
40 38
import org.eclipse.jface.operation.IRunnableWithProgress;
41 39
import org.eclipse.jface.resource.ColorRegistry;
......
57 55
import org.eclipse.ui.PlatformUI;
58 56
import org.eclipse.ui.handlers.IHandlerService;
59 57
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
60
import org.eclipse.ui.internal.E4PartWrapper;
61 58
import org.eclipse.ui.part.EditorPart;
62 59
import org.eclipse.ui.progress.IProgressConstants;
63 60
import org.eclipse.ui.progress.IProgressService;
......
80 77
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
81 78
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
82 79
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
80
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
83 81

  
84 82
/**
85 83
 *
......
143 141
        IWorkbenchPage activePage = getActivePage();
144 142
        if(activePage!=null){
145 143
            IWorkbenchPart activePart = activePage.getActivePart();
146
            Object e4WrappedPart = getE4WrappedPart(activePart);
144
            Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
147 145
            return e4WrappedPart!=null?e4WrappedPart:activePart;
148 146
        }
149 147
        return null;
150 148
    }
151 149

  
152
    public static Object getE4WrappedPart(Object activePart){
153
        if(activePart instanceof E4PartWrapper){
154
            //FIXME can be removed when E4 migration is complete
155
            try {
156
                Field field = activePart.getClass().getDeclaredField("wrappedPart");
157
                field.setAccessible(true);
158
                Object object = field.get(activePart);
159
                if(object instanceof MPart){
160
                    return ((MPart) object).getObject();
161
                }
162
            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
163
                e.printStackTrace();
164
            }
165
        }
166
        return null;
167
    }
168

  
169 150
    public static IWorkbench getWorkbench() {
170 151
        return TaxeditorStorePlugin.getDefault().getWorkbench();
171 152
    }
......
573 554
    public static Object getActiveE4Editor() {
574 555
        if(getActivePage()!=null){
575 556
            IEditorPart activeEditor = getActivePage().getActiveEditor();
576
            Object wrappedPart = getE4WrappedPart(getActivePage().getActivePart());
557
            Object wrappedPart = WorkbenchUtility.getE4WrappedPart(getActivePage().getActivePart());
577 558
            return wrappedPart!=null?wrappedPart:activeEditor;
578 559
        }
579 560
        return null;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
42 42
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
43 43
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
44 44
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
45
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
45 46

  
46 47
/**
47 48
 * <p>DetailsViewPart class.</p>
......
68 69
	@Override
69 70
    protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection){
70 71
	    Object part = workbenchPart;
71
	    Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
72
	    Object wrappedPart = WorkbenchUtility.getE4WrappedPart(part);
72 73
	    if(wrappedPart!=null){
73 74
	        part = wrappedPart;
74 75
	    }
......
250 251
        				 TaxonRelationship rel = rels.iterator().next();
251 252
        				 if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
252 253
	        				 getViewer().setInput(rel);
253
	        				  showViewer();
254
	        				 showViewer();
255
//	        				  super.showViewer(part, selection);
254 256
	        				  return;
255 257
        				 }
256 258
        			 }
......
261 263
        }
262 264
        getViewer().setInput(element);
263 265
        showViewer();
266
//        super.showViewer(part, selection);
264 267
    }
265 268
}
266 269

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java
26 26
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
27 27
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
28 28
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
29
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
29 30

  
30 31

  
31 32
/**
......
56 57
	@Override
57 58
	protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection) {
58 59
	    Object part = workbenchPart;
59
        Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
60
        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(part);
60 61
        if(wrappedPart!=null){
61 62
            part = wrappedPart;
62 63
        }
eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF
20 20
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
21 21
Import-Package: javax.inject;version="1.0.0"
22 22
Bundle-ActivationPolicy: lazy
23
Export-Package: eu.etaxonomy.taxeditor.workbench.part
23
Export-Package: eu.etaxonomy.taxeditor.workbench,
24
 eu.etaxonomy.taxeditor.workbench.part
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.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;
10

  
11
import java.lang.reflect.Field;
12

  
13
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
14
import org.eclipse.ui.internal.E4PartWrapper;
15
import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
16

  
17
/**
18
 * Utility class for e4 workbench related operations
19
 * @author pplitzner
20
 * @since Jun 27, 2017
21
 *
22
 */
23
public class WorkbenchUtility {
24

  
25
    /**
26
     * Checks if the activePart is an E4 wrapper for a legacy part and returns
27
     * that part
28
     *
29
     * @param activePart the e4 wrapper
30
     * @return the wrapped legacy part or <code>null</code>
31
     */
32
    public static Object getE4WrappedPart(Object activePart){
33
        //FIXME can be removed when E4 migration is complete
34

  
35
        Object object = null;
36
        try {
37
            if(activePart instanceof E4PartWrapper){
38
                Field field = activePart.getClass().getDeclaredField("wrappedPart");
39
                field.setAccessible(true);
40
                object = field.get(activePart);
41
            }
42
            else if(activePart instanceof CompatibilityView){
43
                Field field = activePart.getClass().getSuperclass().getDeclaredField("wrapped");
44
                field.setAccessible(true);
45
                object = field.get(activePart);
46
            }
47
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
48
            e.printStackTrace();
49
        }
50
        if(object instanceof MPart){
51
            object =((MPart) object).getObject();
52
        }
53
        return object;
54
    }
55
}

Also available in: Unified diff