fixes issues with named area selection dialog and custom areas; fixes #2265
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / ui / forms / AbstractCdmEntityWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.forms;
12
13 import org.eclipse.jface.wizard.WizardPage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.forms.widgets.ScrolledForm;
20
21 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23 import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
24 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
26
27 /**
28 * <p>Abstract AbstractCdmEntityWizardPage class.</p>
29 *
30 * @author n.hoffmann
31 * @created Jun 1, 2010
32 * @version 1.0
33 */
34 public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage implements IConversationEnabled {
35
36 protected CdmFormFactory formFactory;
37 protected T entity;
38
39 AbstractCdmDetailElement<T> detailElement;
40 private ConversationHolder conversation;
41
42 /**
43 * <p>Constructor for AbstractCdmEntityWizardPage.</p>
44 *
45 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
46 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
47 * @param entity a T object.
48 * @param <T> a T object.
49 */
50 protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory, ConversationHolder conversation, T entity) {
51 super("page");
52 this.formFactory = formFactory;
53 this.entity = entity;
54 this.conversation = conversation;
55 setDescription(getEntityTitle());
56 }
57
58 /**
59 * @return
60 */
61 private String getEntityTitle() {
62 if(entity instanceof IIdentifiableEntity){
63 ((IIdentifiableEntity) entity).getTitleCache();
64 }
65 return "";
66 }
67
68 /*
69 * (non-Javadoc)
70 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
71 */
72 /** {@inheritDoc} */
73 public void createControl(Composite parent) {
74 ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
75 GridLayout layout = new GridLayout();
76 scrolledForm.getBody().setLayout(layout);
77
78 Composite control = formFactory.createComposite(scrolledForm.getBody());
79 control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
80
81 control.setLayout(CdmFormFactory.LAYOUT(2, false));
82 WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder());
83
84 Color bgColor = getShell().getBackground();
85
86 detailElement = createElement(rootElement);
87
88 rootElement.setBackground(bgColor);
89 control.setBackground(bgColor);
90 scrolledForm.setBackground(bgColor);
91
92 setControl(scrolledForm);
93 }
94
95 /**
96 * <p>Getter for the field <code>entity</code>.</p>
97 *
98 * @return a T object.
99 */
100 public T getEntity() {
101 return entity;
102 }
103
104 /**
105 * Creates the detail element for this wizard page
106 *
107 * @param rootElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
108 * @return a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement} object.
109 */
110 public abstract AbstractCdmDetailElement<T> createElement(ICdmFormElement rootElement);
111
112 private class WizardPageRootElement extends RootElement implements IConversationEnabled{
113
114 private ConversationHolder conversation;
115
116 public WizardPageRootElement(CdmFormFactory formFactory,
117 Composite layoutComposite, ConversationHolder conversation) {
118 super(formFactory, layoutComposite);
119 this.conversation = conversation;
120 }
121
122 @Override
123 public void refresh() {
124 super.refresh();
125 this.removeElements();
126 detailElement = createElement(this);
127 ((Composite) getControl()).layout();
128 }
129
130 public ConversationHolder getConversationHolder() {
131 return conversation;
132 }
133
134 public void update(CdmDataChangeMap changeEvents) {}
135 }
136
137 /**
138 * <p>getConversationHolder</p>
139 *
140 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
141 */
142 public ConversationHolder getConversationHolder() {
143 return conversation;
144 }
145
146 /** {@inheritDoc} */
147 @Override
148 public void dispose() {
149 super.dispose();
150 detailElement.removeElements();
151 }
152
153 /**
154 * <p>Getter for the field <code>detailElement</code>.</p>
155 *
156 * @return a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement} object.
157 */
158 public AbstractCdmDetailElement<T> getDetailElement() {
159 return detailElement;
160 }
161
162 /** {@inheritDoc} */
163 public void update(CdmDataChangeMap changeEvents) {}
164 }