import org.eclipse.swt.widgets.TypedListener;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.IExpansionListener;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.forms.widgets.ToggleHyperlink;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
/**
* <p>
TableWrapLayout layout = LayoutConstants.LAYOUT();
layout.bottomMargin = 10;
layout.rightMargin = 5;
+ layout.horizontalSpacing = 5;
client.setLayout(layout);
*/
public void setEntity(ENTITY entity) {
this.entity = entity;
+ addExpandListener();
}
/*
*/
@Override
public ConversationHolder getConversationHolder() {
- if(getParentElement() instanceof RootElement || getParentElement() == null){
-
- IEditorPart activeEditor = AbstractUtility.getActiveEditor();
- if(activeEditor instanceof IConversationEnabled){
- ConversationHolder conversation = ((IConversationEnabled) AbstractUtility.getActiveEditor()).getConversationHolder();
- return conversation;
- }
- }else if(getParentElement() instanceof IConversationEnabled){
- return ((IConversationEnabled) getParentElement()).getConversationHolder();
- }
+ if(AbstractUtility.getActivePart() instanceof IConversationEnabled){
+ return ((IConversationEnabled) AbstractUtility.getActivePart()).getConversationHolder();
+ }
+ if(getParentElement() instanceof RootElement || getParentElement() == null){
+
+ IEditorPart activeEditor = AbstractUtility.getActiveEditor();
+ if(activeEditor instanceof IConversationEnabled){
+ ConversationHolder conversation = ((IConversationEnabled) AbstractUtility.getActiveEditor()).getConversationHolder();
+ return conversation;
+ }
+ }else if(getParentElement() instanceof IConversationEnabled){
+ return ((IConversationEnabled) getParentElement()).getConversationHolder();
+ }
MessagingUtils.messageDialog("Could not get conversation for AbstractFormSection",
getClass(), "There is an error in the implementation. There should have been an active editor but it wasn't",
new IllegalArgumentException());
}
/** {@inheritDoc} */
-
@Override
public void update(CdmDataChangeMap changeEvents) {
}
+
+ private class ExpandListener implements IExpansionListener{
+ @Override
+ public void expansionStateChanging(ExpansionEvent e) {
+ }
+ @Override
+ public void expansionStateChanged(ExpansionEvent e) {
+ PreferencesUtil.getPreferenceStore().setValue(getPrefKey(), e.getState());
+ }
+ }
+
+ /**
+ * Adds a custom implementation of IExpansionListener to this section
+ * which stores the expansion state in the preferences
+ */
+ private void addExpandListener() {
+ PreferencesUtil.getPreferenceStore().setDefault(getPrefKey(), isExpanded());
+ setExpanded(PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey()));
+ addExpansionListener(new ExpandListener());
+ }
+
+ private String getPrefKey() {
+ return this.getClass().getCanonicalName()+";"+entity.getClass().getCanonicalName();
+ }
}