75
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.ui.forms.SectionPart;
|
|
14
|
|
15 import dwtx.ui.forms.AbstractFormPart;
|
|
16
|
|
17 import dwt.widgets.Composite;
|
|
18 import dwt.widgets.Control;
|
|
19 import dwtx.ui.forms.events.ExpansionAdapter;
|
|
20 import dwtx.ui.forms.events.ExpansionEvent;
|
|
21 import dwtx.ui.forms.widgets.FormToolkit;
|
|
22 import dwtx.ui.forms.widgets.Section;
|
|
23
|
|
24 import dwt.dwthelper.utils;
|
|
25
|
|
26 /**
|
|
27 * Section part implements IFormPart interface based on the Section widget. It
|
|
28 * can either wrap the widget or create one itself.
|
|
29 * <p>
|
|
30 * Subclasses should extend <code>SectionPart</code> and implement life cycle
|
|
31 * methods like <code>refresh</code>, <code>commit</code>,
|
|
32 * <code>setFocus</code> etc. Note that most of these methods are not empty -
|
|
33 * calling <code>super</code> is required.
|
|
34 *
|
|
35 * @see Section
|
|
36 * @since 3.0
|
|
37 */
|
|
38 public class SectionPart : AbstractFormPart {
|
|
39 private Section section;
|
|
40
|
|
41 /**
|
|
42 * Creates a new section part based on the provided section.
|
|
43 *
|
|
44 * @param section
|
|
45 * the section to use
|
|
46 */
|
|
47 public this(Section section) {
|
|
48 this.section = section;
|
|
49 hookListeners();
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Creates a new section part inside the provided parent and using the
|
|
54 * provided toolkit. The section part will create the section widget.
|
|
55 *
|
|
56 * @param parent
|
|
57 * the parent
|
|
58 * @param toolkit
|
|
59 * the toolkit to use
|
|
60 * @param style
|
|
61 * the section widget style
|
|
62 */
|
|
63 public this(Composite parent, FormToolkit toolkit, int style) {
|
|
64 this(toolkit.createSection(parent, style));
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * Adds listeners to the underlying widget.
|
|
69 */
|
|
70 protected void hookListeners() {
|
|
71 if ((section.getExpansionStyle() & Section.TWISTIE) !is 0
|
|
72 || (section.getExpansionStyle() & Section.TREE_NODE) !is 0) {
|
|
73 section.addExpansionListener(new class ExpansionAdapter {
|
|
74 public void expansionStateChanging(ExpansionEvent e) {
|
|
75 this.outer.expansionStateChanging(e.getState());
|
|
76 }
|
|
77
|
|
78 public void expansionStateChanged(ExpansionEvent e) {
|
|
79 this.outer.expansionStateChanged(e.getState());
|
|
80 }
|
|
81 });
|
|
82 }
|
|
83 }
|
|
84
|
|
85 /**
|
|
86 * Returns the section widget used in this part.
|
|
87 *
|
|
88 * @return the section widget
|
|
89 */
|
|
90 public Section getSection() {
|
|
91 return section;
|
|
92 }
|
|
93
|
|
94 /**
|
|
95 * The section is about to expand or collapse.
|
|
96 *
|
|
97 * @param expanding
|
|
98 * <code>true</code> for expansion, <code>false</code> for
|
|
99 * collapse.
|
|
100 */
|
|
101 protected void expansionStateChanging(bool expanding) {
|
|
102 }
|
|
103
|
|
104 /**
|
|
105 * The section has expanded or collapsed.
|
|
106 *
|
|
107 * @param expanded
|
|
108 * <code>true</code> for expansion, <code>false</code> for
|
|
109 * collapse.
|
|
110 */
|
|
111 protected void expansionStateChanged(bool expanded) {
|
|
112 getManagedForm().getForm().reflow(false);
|
|
113 }
|
|
114
|
|
115 /* (non-Javadoc)
|
|
116 * @see dwtx.ui.forms.AbstractFormPart#setFocus()
|
|
117 */
|
|
118 public void setFocus() {
|
|
119 Control client = section.getClient();
|
|
120 if (client !is null)
|
|
121 client.setFocus();
|
|
122 }
|
|
123 }
|