Merged refactoring from development branch.
[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.graphics.Color;
15 import org.eclipse.swt.widgets.Composite;
16
17 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19 import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
20 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
21 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
22
23 /**
24 * <p>Abstract AbstractCdmEntityWizardPage class.</p>
25 *
26 * @author n.hoffmann
27 * @created Jun 1, 2010
28 * @version 1.0
29 */
30 public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage implements IConversationEnabled {
31
32 protected CdmFormFactory formFactory;
33 protected T entity;
34
35 AbstractCdmDetailElement<T> detailElement;
36 private ConversationHolder conversation;
37
38 /**
39 * <p>Constructor for AbstractCdmEntityWizardPage.</p>
40 *
41 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
42 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
43 * @param entity a T object.
44 * @param <T> a T object.
45 */
46 protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory, ConversationHolder conversation, T entity) {
47 super("page");
48 this.formFactory = formFactory;
49 this.entity = entity;
50 this.conversation = conversation;
51 setDescription(getEntityTitle());
52 }
53
54 /**
55 * @return
56 */
57 private String getEntityTitle() {
58 if(entity instanceof IIdentifiableEntity){
59 ((IIdentifiableEntity) entity).getTitleCache();
60 }
61 return "";
62 }
63
64 /*
65 * (non-Javadoc)
66 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
67 */
68 /** {@inheritDoc} */
69 public void createControl(Composite parent) {
70 Composite control = formFactory.createComposite(parent);
71
72 control.setLayout(CdmFormFactory.LAYOUT(2, false));
73 WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder());
74
75 Color bgColor = getShell().getBackground();
76
77 detailElement = createElement(rootElement);
78
79 rootElement.setBackground(bgColor);
80 control.setBackground(bgColor);
81
82 setControl(control);
83 }
84
85 /**
86 * <p>Getter for the field <code>entity</code>.</p>
87 *
88 * @return a T object.
89 */
90 public T getEntity() {
91 return entity;
92 }
93
94 /**
95 * Creates the detail element for this wizard page
96 *
97 * @param rootElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
98 * @return a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement} object.
99 */
100 public abstract AbstractCdmDetailElement createElement(ICdmFormElement rootElement);
101
102 private class WizardPageRootElement extends RootElement implements IConversationEnabled{
103
104 private ConversationHolder conversation;
105
106 public WizardPageRootElement(CdmFormFactory formFactory,
107 Composite layoutComposite, ConversationHolder conversation) {
108 super(formFactory, layoutComposite);
109 this.conversation = conversation;
110 }
111
112 @Override
113 public void refresh() {
114 super.refresh();
115 this.removeElements();
116 detailElement = createElement(this);
117 ((Composite) getControl()).layout();
118 }
119
120 public ConversationHolder getConversationHolder() {
121 return conversation;
122 }
123
124 public void update(CdmDataChangeMap changeEvents) {}
125 }
126
127 /**
128 * <p>getConversationHolder</p>
129 *
130 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
131 */
132 public ConversationHolder getConversationHolder() {
133 return conversation;
134 }
135
136 /** {@inheritDoc} */
137 @Override
138 public void dispose() {
139 super.dispose();
140 detailElement.removeElements();
141 }
142
143 /**
144 * <p>Getter for the field <code>detailElement</code>.</p>
145 *
146 * @return a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement} object.
147 */
148 public AbstractCdmDetailElement<T> getDetailElement() {
149 return detailElement;
150 }
151
152 /** {@inheritDoc} */
153 public void update(CdmDataChangeMap changeEvents) {}
154 }