Project

General

Profile

Download (6.84 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.view.detail;
11

    
12
import java.util.Collection;
13

    
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.workbench.modeling.EPartService;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.TreeNode;
20
import org.eclipse.jface.viewers.Viewer;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.ui.IEditorPart;
23
import org.eclipse.ui.IMemento;
24
import org.eclipse.ui.IWorkbenchPart;
25

    
26
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
27
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29
import eu.etaxonomy.cdm.model.description.Feature;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import eu.etaxonomy.taxeditor.l10n.Messages;
32
import eu.etaxonomy.taxeditor.model.AbstractUtility;
33
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
34
import eu.etaxonomy.taxeditor.model.IContextListener;
35
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
36
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
37
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
38
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
39

    
40
/**
41
 * <p>DetailsViewPart class.</p>
42
 *
43
 * @author n.hoffmann
44
 * @created Jun 10, 2010
45
 * @version 1.0
46
 */
47
public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartContentHasSupplementalData, IContextListener{
48

    
49
	/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
50
	public static String ID = "eu.etaxonomy.taxeditor.view.detail"; //$NON-NLS-1$
51

    
52
	private DetailsViewer viewer;
53

    
54
	//FIXME E4: this can be removed when working with E4 event system
55
	private Object selectionProvidingPart;
56

    
57
	/** {@inheritDoc} */
58
	@Override
59
	public void createViewer(Composite parent) {
60

    
61
		viewer = new DetailsViewer(parent, this);
62
		getSite().setSelectionProvider(viewer);
63
	}
64

    
65
	@Override
66
    protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection){
67
	    Object part = workbenchPart;
68
	    Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
69
	    if(wrappedPart!=null){
70
	        part = wrappedPart;
71
	    }
72
	    if(AbstractUtility.getActiveE4Editor() == null && !(AbstractUtility.getActiveE4Part() instanceof IConversationEnabled)){
73
            showEmptyPage();
74
            return;
75
        }
76

    
77
	    //special case where the details view still open with details about the closed object #5495
78
	    try{
79
	        boolean isSelectionProvidingPartStillActive = false;
80
	        if(selectionProvidingPart!=null){
81
	            EPartService partService = TaxeditorStorePlugin.getDefault().getWorkbench().getService(EPartService.class);
82
	            Collection<MPart> parts = partService.getParts();
83
	            for (MPart mPart : parts) {
84
	                if(selectionProvidingPart.equals(mPart.getObject())){
85
	                    isSelectionProvidingPartStillActive = true;
86
	                    break;
87
	                }
88
	            }
89
	            if(!isSelectionProvidingPartStillActive &&
90
	                    selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() !=null){
91
	                showEmptyPage();
92
	                return;
93
	            }
94
	        }
95
	    }catch(IllegalStateException e){
96
	        //nothing
97
	    }
98

    
99
	    if(part == this){
100
	        return;
101
	    }
102

    
103
        if(!(selection instanceof IStructuredSelection)){
104
            return;
105
        }
106

    
107
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
108

    
109
        if((part instanceof IEditorPart) || (part instanceof IPartContentHasDetails)) {
110
            if(structuredSelection.size() != 1){
111
                showEmptyPage();
112
                return;
113
            }
114

    
115
            // do not show details for feature nodes TODO really?
116
            if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
117
                // do show the map for distributions
118
                Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature();
119
                if(!feature.equals(Feature.DISTRIBUTION())){
120
                    showEmptyPage();
121
                    return;
122
                }
123
            }
124
            selectionProvidingPart = part;
125
            showViewer(part, structuredSelection);
126
        }else{
127
            showEmptyPage();
128
        }
129
	}
130

    
131
	@Override
132
	protected String getViewName(){
133
	    return Messages.DetailsViewPart_VIEWER_NAME;
134
	}
135

    
136
	@Override
137
	protected String createPartTitle(Object selectedObject){
138
	    if(selectedObject!=null){
139
	        if(selectedObject instanceof TreeNode){
140
	            selectedObject = ((TreeNode) selectedObject).getValue();
141
	        }
142
	        if(selectedObject instanceof SpecimenOrObservationBase){
143
	            return getViewName()+": "+HibernateProxyHelper.deproxy(selectedObject, SpecimenOrObservationBase.class).getRecordBasis(); //$NON-NLS-1$
144
	        }
145
	        if(selectedObject instanceof CdmBase){
146
	            return getViewName()+": "+HibernateProxyHelper.deproxy(selectedObject, CdmBase.class).getClass().getSimpleName(); //$NON-NLS-1$
147
	        }
148
	        return getViewName()+": "+selectedObject.getClass().getSimpleName(); //$NON-NLS-1$
149
	    }
150
	    return getViewName();
151
	}
152

    
153
	@Override
154
	public void showEmptyPage() {
155
	    selectionProvidingPart = null;
156
	    viewer.setSelection(null);
157
	    super.showEmptyPage();
158
	}
159

    
160
	/** {@inheritDoc} */
161
	@Override
162
	public boolean postOperation(CdmBase objectAffectedByOperation) {
163

    
164
		viewer.setInput(objectAffectedByOperation);
165

    
166
		return super.postOperation(objectAffectedByOperation);
167
	}
168

    
169

    
170
	/** {@inheritDoc} */
171
	@Override
172
	public Viewer getViewer() {
173
		return viewer;
174
	}
175

    
176

    
177
	/** {@inheritDoc} */
178
	@Override
179
	public void dispose() {
180
		selectionService.removePostSelectionListener(this);
181
		super.dispose();
182

    
183
	}
184

    
185
	@Override
186
    public boolean onComplete() {
187
		return true;
188
	}
189

    
190
    /**
191
     * {@inheritDoc}
192
     */
193
    @Override
194
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
195
    }
196

    
197
    /**
198
     * {@inheritDoc}
199
     */
200
    @Override
201
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
202
        showEmptyPage();
203
    }
204

    
205
    /**
206
     * {@inheritDoc}
207
     */
208
    @Override
209
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
210
    }
211

    
212
    /**
213
     * {@inheritDoc}
214
     */
215
    @Override
216
    public void contextRefresh(IProgressMonitor monitor) {
217
    }
218

    
219
    /**
220
     * {@inheritDoc}
221
     */
222
    @Override
223
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
224
    }
225

    
226

    
227

    
228
}
(2-2/3)