Revision df5fb45a
ref #6913 Remove abstract cdm editor/data view
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractAccountViewPart.java | ||
---|---|---|
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; |
|
11 |
|
|
12 |
import java.util.Collection; |
|
13 |
|
|
14 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
15 |
import org.eclipse.jface.action.GroupMarker; |
|
16 |
import org.eclipse.jface.action.MenuManager; |
|
17 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
18 |
import org.eclipse.jface.viewers.IBaseLabelProvider; |
|
19 |
import org.eclipse.jface.viewers.ISelection; |
|
20 |
import org.eclipse.jface.viewers.TableViewer; |
|
21 |
import org.eclipse.jface.viewers.Viewer; |
|
22 |
import org.eclipse.swt.SWT; |
|
23 |
import org.eclipse.swt.events.FocusAdapter; |
|
24 |
import org.eclipse.swt.events.FocusEvent; |
|
25 |
import org.eclipse.swt.layout.FillLayout; |
|
26 |
import org.eclipse.swt.widgets.Composite; |
|
27 |
import org.eclipse.swt.widgets.Control; |
|
28 |
import org.eclipse.swt.widgets.Menu; |
|
29 |
import org.eclipse.ui.IMemento; |
|
30 |
import org.eclipse.ui.IWorkbenchActionConstants; |
|
31 |
import org.eclipse.ui.IWorkbenchPart; |
|
32 |
|
|
33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
34 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
35 |
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter; |
|
36 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
|
37 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author n.hoffmann |
|
41 |
* @created Feb 16, 2011 |
|
42 |
* @version 1.0 |
|
43 |
*/ |
|
44 |
public abstract class AbstractAccountViewPart<T> extends AbstractCdmViewPart { |
|
45 |
|
|
46 |
private class ContextListener extends ContextListenerAdapter{ |
|
47 |
|
|
48 |
/* (non-Javadoc) |
|
49 |
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
|
50 |
*/ |
|
51 |
@Override |
|
52 |
public void contextStop(IMemento memento, IProgressMonitor monitor) { |
|
53 |
monitor.subTask("Shutting down User View"); |
|
54 |
viewer.setInput(null); |
|
55 |
} |
|
56 |
|
|
57 |
/* (non-Javadoc) |
|
58 |
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public void contextStart(IMemento memento, IProgressMonitor monitor) { |
|
62 |
monitor.subTask("Initiating User View"); |
|
63 |
viewer.setInput(getInput()); |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
protected TableViewer viewer; |
|
68 |
|
|
69 |
private IContextListener contextListener; |
|
70 |
|
|
71 |
/* (non-Javadoc) |
|
72 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
73 |
*/ |
|
74 |
/** {@inheritDoc} */ |
|
75 |
@Override |
|
76 |
public void createPartControl(Composite parent) { |
|
77 |
contextListener = new ContextListener(); |
|
78 |
CdmStore.getContextManager().addContextListener(contextListener); |
|
79 |
|
|
80 |
FillLayout fillLayout = new FillLayout(); |
|
81 |
fillLayout.marginWidth = 0; |
|
82 |
fillLayout.marginHeight = 0; |
|
83 |
fillLayout.type = SWT.VERTICAL; |
|
84 |
parent.setLayout(fillLayout); |
|
85 |
|
|
86 |
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
|
87 |
| SWT.V_SCROLL | SWT.FULL_SELECTION); |
|
88 |
|
|
89 |
getSite().setSelectionProvider(viewer); |
|
90 |
|
|
91 |
createColumns(viewer); |
|
92 |
|
|
93 |
MenuManager menuMgr = new MenuManager(); |
|
94 |
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
95 |
getSite().registerContextMenu(menuMgr, viewer); |
|
96 |
|
|
97 |
Control control = viewer.getControl(); |
|
98 |
Menu menu = menuMgr.createContextMenu(control); |
|
99 |
control.setMenu(menu); |
|
100 |
|
|
101 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
102 |
viewer.setLabelProvider(getLabelProvider()); |
|
103 |
|
|
104 |
if(CdmStore.isActive()){ |
|
105 |
viewer.setInput(getInput()); |
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
this.addListenerObject(new FocusAdapter() { |
|
110 |
/* (non-Javadoc) |
|
111 |
* @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent) |
|
112 |
*/ |
|
113 |
@Override |
|
114 |
public void focusGained(FocusEvent e) { |
|
115 |
super.focusGained(e); |
|
116 |
getConversationHolder().bind(); |
|
117 |
if (!viewer.getControl().isDisposed()){ |
|
118 |
viewer.getControl().setFocus(); |
|
119 |
} |
|
120 |
} |
|
121 |
}); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* @return |
|
126 |
*/ |
|
127 |
protected abstract IBaseLabelProvider getLabelProvider(); |
|
128 |
|
|
129 |
/** |
|
130 |
* @param viewer2 |
|
131 |
*/ |
|
132 |
protected abstract void createColumns(TableViewer viewer); |
|
133 |
|
|
134 |
/** |
|
135 |
* @return the contextListener |
|
136 |
*/ |
|
137 |
public IContextListener getContextListener() { |
|
138 |
if(contextListener == null){ |
|
139 |
throw new IllegalStateException("Context listener was not initialized"); |
|
140 |
} |
|
141 |
return contextListener; |
|
142 |
} |
|
143 |
|
|
144 |
/* (non-Javadoc) |
|
145 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
146 |
*/ |
|
147 |
@Override |
|
148 |
public void update(CdmDataChangeMap changeEvents) { |
|
149 |
// data changes can only be generate here at the moment |
|
150 |
} |
|
151 |
|
|
152 |
/* (non-Javadoc) |
|
153 |
* @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) |
|
154 |
*/ |
|
155 |
@Override |
|
156 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
157 |
if(CdmStore.isActive()){ |
|
158 |
viewer.setInput(getInput()); |
|
159 |
viewer.refresh(); |
|
160 |
} |
|
161 |
|
|
162 |
return true; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* @return |
|
167 |
*/ |
|
168 |
public abstract Collection getInput(); |
|
169 |
|
|
170 |
/* (non-Javadoc) |
|
171 |
* @see org.eclipse.ui.part.WorkbenchPart#dispose() |
|
172 |
*/ |
|
173 |
@Override |
|
174 |
public void dispose() { |
|
175 |
CdmStore.getContextManager().removeContextListener(getContextListener()); |
|
176 |
super.dispose(); |
|
177 |
} |
|
178 |
|
|
179 |
|
|
180 |
@Override |
|
181 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
182 |
// TODO Auto-generated method stub |
|
183 |
|
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public Viewer getViewer() { |
|
188 |
return viewer; |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public void createViewer(Composite parent) { |
|
193 |
// TODO Auto-generated method stub |
|
194 |
|
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public void changed(Object object) { |
|
199 |
// do nothing |
|
200 |
} |
|
201 |
|
|
202 |
|
|
203 |
@Override |
|
204 |
public boolean onComplete() { |
|
205 |
return true; |
|
206 |
} |
|
207 |
|
|
208 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmDataViewer.java | ||
---|---|---|
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; |
|
11 |
|
|
12 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
13 |
import org.eclipse.jface.viewers.Viewer; |
|
14 |
import org.eclipse.swt.widgets.Composite; |
|
15 |
import org.eclipse.swt.widgets.Control; |
|
16 |
import org.eclipse.ui.forms.IFormPart; |
|
17 |
import org.eclipse.ui.forms.ManagedForm; |
|
18 |
import org.eclipse.ui.forms.widgets.ScrolledForm; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
21 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
22 |
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection; |
|
23 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
|
24 |
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants; |
|
25 |
import eu.etaxonomy.taxeditor.ui.element.RootElement; |
|
26 |
import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author n.hoffmann |
|
30 |
* @created Feb 9, 2010 |
|
31 |
* @version 1.0 |
|
32 |
*/ |
|
33 |
public abstract class AbstractCdmDataViewer extends Viewer implements IConversationEnabled{ |
|
34 |
|
|
35 |
protected ManagedForm managedForm; |
|
36 |
|
|
37 |
protected CdmFormFactory formFactory; |
|
38 |
|
|
39 |
protected ScrolledForm scrolledForm; |
|
40 |
|
|
41 |
private final Composite body; |
|
42 |
|
|
43 |
protected RootElement rootElement; |
|
44 |
|
|
45 |
//TODO: create a super class for this? |
|
46 |
private Object input; |
|
47 |
|
|
48 |
private final AbstractCdmViewPart viewPart; |
|
49 |
|
|
50 |
|
|
51 |
public AbstractCdmDataViewer(Composite parent, AbstractCdmViewPart viewPart) { |
|
52 |
this.viewPart = viewPart; |
|
53 |
|
|
54 |
managedForm = new ManagedForm(parent){ |
|
55 |
|
|
56 |
@Override |
|
57 |
public void dirtyStateChanged() { |
|
58 |
markViewPartDirty(); |
|
59 |
} |
|
60 |
}; |
|
61 |
|
|
62 |
createFormFactory(); |
|
63 |
|
|
64 |
scrolledForm = managedForm.getForm(); |
|
65 |
|
|
66 |
body = scrolledForm.getBody(); |
|
67 |
|
|
68 |
body.setLayout(LayoutConstants.LAYOUT()); |
|
69 |
|
|
70 |
rootElement = new RootElement(formFactory, body); |
|
71 |
} |
|
72 |
|
|
73 |
protected void createFormFactory() { |
|
74 |
if(formFactory != null){ |
|
75 |
formFactory.dispose(); |
|
76 |
formFactory = null; |
|
77 |
} |
|
78 |
// formFactory = new CdmFormFactory(Display.getCurrent(), this); |
|
79 |
} |
|
80 |
|
|
81 |
protected void markViewPartDirty(){ |
|
82 |
viewPart.changed(input); |
|
83 |
} |
|
84 |
|
|
85 |
protected AbstractCdmViewPart getViewPart() { |
|
86 |
return viewPart; |
|
87 |
} |
|
88 |
|
|
89 |
/** {@inheritDoc} */ |
|
90 |
@Override |
|
91 |
public Control getControl() { |
|
92 |
if(body.isDisposed()){ |
|
93 |
return null; |
|
94 |
} |
|
95 |
for(Control child : body.getChildren()){ |
|
96 |
return child; |
|
97 |
} |
|
98 |
|
|
99 |
return body; |
|
100 |
} |
|
101 |
|
|
102 |
/** {@inheritDoc} */ |
|
103 |
@Override |
|
104 |
public void setInput(Object input) { |
|
105 |
this.input = input; |
|
106 |
// reset selection |
|
107 |
setSelection(new StructuredSelection(input)); |
|
108 |
refresh(); |
|
109 |
} |
|
110 |
|
|
111 |
/** {@inheritDoc} */ |
|
112 |
@Override |
|
113 |
public Object getInput() { |
|
114 |
return input; |
|
115 |
} |
|
116 |
|
|
117 |
/** {@inheritDoc} */ |
|
118 |
@Override |
|
119 |
public void refresh() { |
|
120 |
showParts(); |
|
121 |
|
|
122 |
managedForm.setInput(input); |
|
123 |
|
|
124 |
managedForm.refresh(); |
|
125 |
|
|
126 |
managedForm.reflow(true); |
|
127 |
} |
|
128 |
|
|
129 |
public void layout(){ |
|
130 |
body.layout(); |
|
131 |
} |
|
132 |
|
|
133 |
protected abstract void showParts(); |
|
134 |
|
|
135 |
protected void destroySections() { |
|
136 |
for (IFormPart formPart : managedForm.getParts()){ |
|
137 |
removePart((CdmSectionPart<?>) formPart); |
|
138 |
} |
|
139 |
|
|
140 |
managedForm.setInput(null); |
|
141 |
|
|
142 |
formFactory.destroyElement(rootElement); |
|
143 |
|
|
144 |
createFormFactory(); |
|
145 |
|
|
146 |
rootElement = new RootElement(formFactory, body); |
|
147 |
|
|
148 |
for(Control control : body.getChildren()){ |
|
149 |
control.dispose(); |
|
150 |
control = null; |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
public void setFocus(){ |
|
155 |
// we have to set focus to a control of this viewer |
|
156 |
// otherwise, after opening a dialog from the details, the focus will not be |
|
157 |
// given back to the details view but to the editor |
|
158 |
for(Control child : body.getChildren()){ |
|
159 |
child.setFocus(); |
|
160 |
break; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
public void reflow(){ |
|
165 |
managedForm.reflow(true); |
|
166 |
} |
|
167 |
|
|
168 |
protected void removePart(CdmSectionPart<?> sectionPart){ |
|
169 |
managedForm.removePart(sectionPart); |
|
170 |
formFactory.removePropertyChangeListener(sectionPart); |
|
171 |
} |
|
172 |
|
|
173 |
protected void addPart(AbstractFormSection<?> section){ |
|
174 |
CdmSectionPart<?> sectionPart = new CdmSectionPart<>(section); |
|
175 |
managedForm.addPart(sectionPart); |
|
176 |
formFactory.addPropertyChangeListener(sectionPart); |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public ConversationHolder getConversationHolder() { |
|
181 |
return viewPart.getConversationHolder(); |
|
182 |
} |
|
183 |
|
|
184 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.view; |
|
5 |
|
|
6 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
7 |
import org.eclipse.jface.viewers.ISelection; |
|
8 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
9 |
import org.eclipse.swt.widgets.Composite; |
|
10 |
import org.eclipse.swt.widgets.Display; |
|
11 |
import org.eclipse.ui.IWorkbenchPart; |
|
12 |
|
|
13 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
|
14 |
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart; |
|
15 |
|
|
16 |
/** |
|
17 |
* <p> |
|
18 |
* Abstract AbstractCdmEditorViewPart class. |
|
19 |
* </p> |
|
20 |
* |
|
21 |
* @author n.hoffmann |
|
22 |
* @created Sep 21, 2010 |
|
23 |
* @version 1.0 |
|
24 |
*/ |
|
25 |
public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart implements ISelectionElementEditingPart { |
|
26 |
|
|
27 |
private DelaySelection delaySelection = null; |
|
28 |
/** |
|
29 |
* This is the monitor for the DelaySelection runnable. |
|
30 |
* If it is <code>true</code> then it is currently delaying a selection. |
|
31 |
*/ |
|
32 |
private boolean isInDelay; |
|
33 |
|
|
34 |
protected Object selectionProvidingPart; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* This class invokes internal_selectionChanged() in a separate thread. |
|
39 |
* This allows an asynchronous and/or delayed handling of selection changes |
|
40 |
*/ |
|
41 |
private class DelaySelection implements Runnable{ |
|
42 |
private IWorkbenchPart part; |
|
43 |
private ISelection selection; |
|
44 |
|
|
45 |
public DelaySelection(IWorkbenchPart part, ISelection selection) { |
|
46 |
super(); |
|
47 |
this.part = part; |
|
48 |
this.selection = selection; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public void run() { |
|
53 |
try{ |
|
54 |
selectionChanged_internal(part, selection); |
|
55 |
} |
|
56 |
finally{ |
|
57 |
isInDelay = false; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
public synchronized void setSelection(ISelection selection) { |
|
62 |
this.selection = selection; |
|
63 |
} |
|
64 |
|
|
65 |
public synchronized void setPart(IWorkbenchPart part) { |
|
66 |
this.part = part; |
|
67 |
} |
|
68 |
|
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Handle selection change events here and <b>not</b> in |
|
73 |
* {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)} |
|
74 |
* if you want asynchronous selection handling. |
|
75 |
* @param part The workbench part that has issued the selection change |
|
76 |
* @param selection the new selection |
|
77 |
*/ |
|
78 |
protected abstract void selectionChanged_internal(IWorkbenchPart part, ISelection selection); |
|
79 |
|
|
80 |
/** {@inheritDoc} */ |
|
81 |
@Override |
|
82 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
83 |
/*to avoid widget is disposed exceptions |
|
84 |
if(getViewer().getControl().isDisposed()){ |
|
85 |
return; |
|
86 |
}*/ |
|
87 |
if(delaySelection==null){ |
|
88 |
delaySelection = new DelaySelection(part, selection); |
|
89 |
} |
|
90 |
delaySelection.setPart(part); |
|
91 |
delaySelection.setSelection(selection); |
|
92 |
if(!isInDelay){ |
|
93 |
isInDelay = true; |
|
94 |
Display.getCurrent().asyncExec(delaySelection); |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* {@inheritDoc} |
|
100 |
*/ |
|
101 |
@Override |
|
102 |
public void showViewer(Object part, IStructuredSelection selection) { |
|
103 |
super.showViewer(part, selection); |
|
104 |
selectionProvidingPart = part; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public MPart getSelectionProvidingPart() { |
|
109 |
return (MPart) selectionProvidingPart; |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
/** {@inheritDoc} */ |
|
115 |
@Override |
|
116 |
public void createPartControl(Composite parent) { |
|
117 |
super.createPartControl(parent); |
|
118 |
isInDelay = false; |
|
119 |
} |
|
120 |
|
|
121 |
// /** |
|
122 |
// * <p> |
|
123 |
// * getEditor |
|
124 |
// * </p> |
|
125 |
// * |
|
126 |
// * @return the currently active editor |
|
127 |
// */ |
|
128 |
// public IEditorPart getEditor() { |
|
129 |
//// return AbstractUtility.getActiveEditor(); |
|
130 |
// } |
|
131 |
|
|
132 |
/** |
|
133 |
* {@inheritDoc} |
|
134 |
*/ |
|
135 |
@Override |
|
136 |
public void showEmptyPage() { |
|
137 |
selectionProvidingPart = null; |
|
138 |
super.showEmptyPage(); |
|
139 |
} |
|
140 |
|
|
141 |
/** {@inheritDoc} */ |
|
142 |
@Override |
|
143 |
public void setFocus() { |
|
144 |
super.setFocus(); |
|
145 |
|
|
146 |
// if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){ |
|
147 |
// boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied(); |
|
148 |
// setEnabled(doEnable); |
|
149 |
// } |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* {@inheritDoc} |
|
154 |
*/ |
|
155 |
@Override |
|
156 |
public void dispose() { |
|
157 |
selectionProvidingPart = null; |
|
158 |
super.dispose(); |
|
159 |
} |
|
160 |
|
|
161 |
/** {@inheritDoc} */ |
|
162 |
@Override |
|
163 |
public void changed(Object object) { |
|
164 |
if(part instanceof IDirtyMarkable){ |
|
165 |
((IDirtyMarkable) part).changed(object); |
|
166 |
} |
|
167 |
else { |
|
168 |
// IEditorPart editor = getEditor(); |
|
169 |
// if (editor != null && editor instanceof IDirtyMarkable) { |
|
170 |
// ((IDirtyMarkable) editor).changed(object); |
|
171 |
// } |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java | ||
---|---|---|
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; |
|
11 |
|
|
12 |
import java.util.Arrays; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Map; |
|
15 |
|
|
16 |
import org.eclipse.jface.viewers.ISelection; |
|
17 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
18 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
19 |
import org.eclipse.jface.viewers.Viewer; |
|
20 |
import org.eclipse.swt.SWT; |
|
21 |
import org.eclipse.swt.custom.SashForm; |
|
22 |
import org.eclipse.swt.widgets.Composite; |
|
23 |
import org.eclipse.swt.widgets.Label; |
|
24 |
import org.eclipse.ui.ISelectionListener; |
|
25 |
import org.eclipse.ui.ISelectionService; |
|
26 |
import org.eclipse.ui.part.PageBook; |
|
27 |
import org.eclipse.ui.part.ViewPart; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
30 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
32 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
33 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
|
34 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
35 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
|
36 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
37 |
|
|
38 |
/** |
|
39 |
* <p>Abstract AbstractCdmViewPart class.</p> |
|
40 |
* |
|
41 |
* @author n.hoffmann |
|
42 |
* @created Jun 15, 2010 |
|
43 |
* @version 1.0 |
|
44 |
*/ |
|
45 |
public abstract class AbstractCdmViewPart extends ViewPart implements ISelectionListener, IPostOperationEnabled, IConversationEnabled, ICdmEntitySessionEnabled, IDirtyMarkable{ |
|
46 |
|
|
47 |
protected ISelectionService selectionService; |
|
48 |
|
|
49 |
public static IStructuredSelection EMPTY_SELECTION = new StructuredSelection(); |
|
50 |
|
|
51 |
protected Object part; |
|
52 |
|
|
53 |
private PageBook pageBook; |
|
54 |
|
|
55 |
private Label emptySelectionLabel; |
|
56 |
|
|
57 |
private Composite viewerComposite; |
|
58 |
|
|
59 |
/** {@inheritDoc} */ |
|
60 |
@Override |
|
61 |
public void createPartControl(Composite parent) { |
|
62 |
selectionService = getSite().getWorkbenchWindow().getSelectionService(); |
|
63 |
selectionService.addSelectionListener(this); |
|
64 |
|
|
65 |
pageBook = new PageBook(parent, SWT.NULL); |
|
66 |
//create viewerComposite |
|
67 |
viewerComposite = new SashForm(pageBook, SWT.HORIZONTAL); |
|
68 |
createViewer(viewerComposite); |
|
69 |
|
|
70 |
// Page 2: Nothing selected |
|
71 |
emptySelectionLabel = new Label(pageBook, SWT.TOP + SWT.LEFT + SWT.WRAP); |
|
72 |
|
|
73 |
setInitialSelection(); |
|
74 |
} |
|
75 |
|
|
76 |
private void setInitialSelection() { |
|
77 |
// selectionChanged(AbstractUtility.getActiveWorkbenchPart(), getInitialSelection()); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* <p>getInitialSelection</p> |
|
82 |
* |
|
83 |
* @return a {@link org.eclipse.jface.viewers.ISelection} object. |
|
84 |
*/ |
|
85 |
protected ISelection getInitialSelection() { |
|
86 |
return selectionService.getSelection(); |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* <p>showEmptyPage</p> |
|
91 |
*/ |
|
92 |
public void showEmptyPage(){ |
|
93 |
setPartName(createPartTitle(null)); |
|
94 |
pageBook.showPage(emptySelectionLabel); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* <p>showViewer</p> |
|
99 |
* |
|
100 |
* @param part a {@link org.eclipse.ui.IWorkbenchPart} object. |
|
101 |
* @param selection a {@link org.eclipse.jface.viewers.ISelection} object. |
|
102 |
*/ |
|
103 |
public void showViewer(Object part, IStructuredSelection selection){ |
|
104 |
this.part = part; |
|
105 |
|
|
106 |
Object element = selection.getFirstElement(); |
|
107 |
//avoid widget is disposed exceptions |
|
108 |
if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){ |
|
109 |
return; |
|
110 |
} |
|
111 |
|
|
112 |
setPartName(createPartTitle(element)); |
|
113 |
getViewer().setInput(element); |
|
114 |
showViewer(); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* <p>getViewer</p> |
|
119 |
* |
|
120 |
* @return a {@link org.eclipse.jface.viewers.Viewer} object. |
|
121 |
*/ |
|
122 |
public abstract Viewer getViewer(); |
|
123 |
|
|
124 |
/** |
|
125 |
* <p>showViewer</p> |
|
126 |
*/ |
|
127 |
public void showViewer(){ |
|
128 |
pageBook.showPage(viewerComposite); |
|
129 |
} |
|
130 |
|
|
131 |
public void setEnabled(boolean enabled){ |
|
132 |
pageBook.setEnabled(enabled); |
|
133 |
} |
|
134 |
|
|
135 |
/** {@inheritDoc} */ |
|
136 |
@Override |
|
137 |
public void setFocus() { |
|
138 |
if(getConversationHolder() != null){ |
|
139 |
getConversationHolder().bind(); |
|
140 |
} |
|
141 |
if(getCdmEntitySession() != null){ |
|
142 |
getCdmEntitySession().bind(); |
|
143 |
} |
|
144 |
getViewer().getControl().setFocus(); |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* <p>createViewer</p> |
|
149 |
* |
|
150 |
* @param parent a {@link org.eclipse.swt.widgets.Composite} object. |
|
151 |
*/ |
|
152 |
public abstract void createViewer(Composite parent); |
|
153 |
|
|
154 |
/** {@inheritDoc} */ |
|
155 |
@Override |
|
156 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
157 |
changed(objectAffectedByOperation); |
|
158 |
return true; |
|
159 |
} |
|
160 |
|
|
161 |
/** {@inheritDoc} */ |
|
162 |
@Override |
|
163 |
public abstract void changed(Object object); |
|
164 |
|
|
165 |
/** |
|
166 |
* <p>getConversationHolder</p> |
|
167 |
* |
|
168 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
169 |
*/ |
|
170 |
@Override |
|
171 |
public ConversationHolder getConversationHolder() { |
|
172 |
if(part != null && part instanceof IConversationEnabled) { |
|
173 |
return ((IConversationEnabled) part).getConversationHolder(); |
|
174 |
} |
|
175 |
|
|
176 |
return null; |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public ICdmEntitySession getCdmEntitySession() { |
|
181 |
if(part != null && part instanceof ICdmEntitySessionEnabled) { |
|
182 |
return ((ICdmEntitySessionEnabled) part).getCdmEntitySession(); |
|
183 |
} |
|
184 |
return null; |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public List<? extends CdmBase> getRootEntities() { |
|
189 |
return Arrays.asList((CdmBase)getViewer().getInput()); |
|
190 |
} |
|
191 |
|
|
192 |
/** {@inheritDoc} */ |
|
193 |
@Override |
|
194 |
public void update(CdmDataChangeMap changeEvents) { |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
/** {@inheritDoc} */ |
|
199 |
@Override |
|
200 |
public void dispose() { |
|
201 |
selectionService.removeSelectionListener(this); |
|
202 |
super.dispose(); |
|
203 |
} |
|
204 |
|
|
205 |
/* (non-Javadoc) |
|
206 |
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty() |
|
207 |
*/ |
|
208 |
@Override |
|
209 |
public void forceDirty() { |
|
210 |
changed(null); |
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
/* (non-Javadoc) |
|
215 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap() |
|
216 |
*/ |
|
217 |
@Override |
|
218 |
public Map<Object, List<String>> getPropertyPathsMap() { |
|
219 |
// TODO Auto-generated method stub |
|
220 |
return null; |
|
221 |
} |
|
222 |
|
|
223 |
protected String createPartTitle(Object selectedObject){ |
|
224 |
if(selectedObject!=null){ |
|
225 |
return getViewName()+": "+selectedObject; //$NON-NLS-1$ |
|
226 |
} |
|
227 |
return getViewName(); |
|
228 |
} |
|
229 |
|
|
230 |
protected abstract String getViewName(); |
|
231 |
} |
Also available in: Unified diff