package eu.etaxonomy.taxeditor.view.e4;
-import org.eclipse.jface.viewers.StructuredSelection;
+import javax.inject.Inject;
+
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.ManagedForm;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.remoting.CdmEagerLoadingException;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
*
*/
public abstract class AbstractCdmDataViewerE4 extends Viewer implements IConversationEnabled{
+ @Inject
+ private Logger logger;
protected ManagedForm managedForm;
protected ScrolledForm scrolledForm;
- private final Composite body;
+ private Composite body;
protected RootElement rootElement;
+ @Inject
+ protected IEclipseContext context;
+
//TODO: create a super class for this?
private Object input;
- private final IDirtyMarkable part;
+ protected IDirtyMarkable part;
+ @Inject
+ public AbstractCdmDataViewerE4() {
+
+ }
- public AbstractCdmDataViewerE4(Composite parent, IDirtyMarkable part) {
+ public void init(Composite parent, IDirtyMarkable part) {
this.part = part;
managedForm = new ManagedForm(parent){
}
- protected void createEmptySection(RootElement parent) {
+ protected void createEmptySection(String message, RootElement parent) {
destroySections();
- EmptySection emptySection = formFactory.createEmptySection(formFactory, parent, SWT.NONE);
+ EmptySection emptySection = formFactory.createEmptySection(message, formFactory, parent, SWT.NONE);
addPart(emptySection);
}
- public void showEmptyPage(){
- destroySections();
- createEmptySection(rootElement);
+ public void showEmptyPage(String message){
+ destroySections();
+ createEmptySection(message, rootElement);
}
protected void markViewPartDirty(){
formFactory.dispose();
formFactory = null;
}
- formFactory = new CdmFormFactory(Display.getCurrent(), this);
+ formFactory = new CdmFormFactory(Display.getCurrent(), this);
+ ContextInjectionFactory.inject(formFactory, context);
}
/** {@inheritDoc} */
@Override
public Control getControl() {
- if(body.isDisposed()){
- return null;
- }
- for(Control child : body.getChildren()){
- return child;
- }
+ if(body!=null){
+ if(body.isDisposed()){
+ return null;
+ }
+ for(Control child : body.getChildren()){
+ return child;
+ }
+ }
return body;
}
public void setInput(Object input) {
this.input = input;
if(input!=null){
- // reset selection
- setSelection(new StructuredSelection(input));
- refresh();
+ try{
+ refresh();
+ }catch(CdmEagerLoadingException e){
+ logger.error(e);
+ }
}
}
public void refresh() {
showParts();
- managedForm.setInput(input);
+ if(input!=null){
+ managedForm.setInput(input);
+ }
managedForm.refresh();
- managedForm.reflow(true);
+// managedForm.reflow(true);
}
public void layout(){
body.layout();
}
+ protected int getSectionStyle(Class<? extends AbstractFormSection> clazz){
+ return getSectionStyle(clazz, false);
+ }
+
+ protected int getSectionStyle(Class<? extends AbstractFormSection> clazz, boolean initiallyExpanded){
+ int style = ExpandableComposite.TWISTIE;
+ String prefKey = StoreUtil.getPrefKey(clazz, getInput());
+ if(PreferencesUtil.contains(prefKey)){
+ style = PreferencesUtil.getStringValue(prefKey)==CdmSectionPart.EXPANDED?style |= ExpandableComposite.EXPANDED:style;
+ }
+ else{
+ style = initiallyExpanded?style |= ExpandableComposite.EXPANDED:style;
+ }
+ return style;
+ }
+
protected abstract void showParts();
- protected void destroySections() {
+ public void destroySections() {
for (IFormPart formPart : managedForm.getParts()){
removePart((CdmSectionPart<?>) formPart);
}
rootElement = new RootElement(formFactory, body);
for(Control control : body.getChildren()){
- control.dispose();
+ try{
+ if (control != null && !control.isDisposed()){
+ control.dispose();
+ }
+ }catch(SWTException e){
+ if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
+ MessagingUtils.errorDialog("Widget is disposed",
+ null,
+ MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
+ null,
+ e,
+ true);
+
+ }
+ }
control = null;
}
}