KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > forms > SectionPart


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  *******************************************************************************/

11 package org.eclipse.ui.forms;
12
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.ui.forms.events.ExpansionAdapter;
16 import org.eclipse.ui.forms.events.ExpansionEvent;
17 import org.eclipse.ui.forms.widgets.FormToolkit;
18 import org.eclipse.ui.forms.widgets.Section;
19
20 /**
21  * Section part implements IFormPart interface based on the Section widget. It
22  * can either wrap the widget or create one itself.
23  * <p>
24  * Subclasses should extend <code>SectionPart</code> and implement life cycle
25  * methods like <code>refresh</code>, <code>commit</code>,
26  * <code>setFocus</code> etc. Note that most of these methods are not empty -
27  * calling <code>super</code> is required.
28  *
29  * @see Section
30  * @since 3.0
31  */

32 public class SectionPart extends AbstractFormPart {
33     private Section section;
34
35     /**
36      * Creates a new section part based on the provided section.
37      *
38      * @param section
39      * the section to use
40      */

41     public SectionPart(Section section) {
42         this.section = section;
43         hookListeners();
44     }
45
46     /**
47      * Creates a new section part inside the provided parent and using the
48      * provided toolkit. The section part will create the section widget.
49      *
50      * @param parent
51      * the parent
52      * @param toolkit
53      * the toolkit to use
54      * @param style
55      * the section widget style
56      */

57     public SectionPart(Composite parent, FormToolkit toolkit, int style) {
58         this(toolkit.createSection(parent, style));
59     }
60
61     /**
62      * Adds listeners to the underlying widget.
63      */

64     protected void hookListeners() {
65         if ((section.getExpansionStyle() & Section.TWISTIE) != 0
66                 || (section.getExpansionStyle() & Section.TREE_NODE) != 0) {
67             section.addExpansionListener(new ExpansionAdapter() {
68                 public void expansionStateChanging(ExpansionEvent e) {
69                     SectionPart.this.expansionStateChanging(e.getState());
70                 }
71
72                 public void expansionStateChanged(ExpansionEvent e) {
73                     SectionPart.this.expansionStateChanged(e.getState());
74                 }
75             });
76         }
77     }
78
79     /**
80      * Returns the section widget used in this part.
81      *
82      * @return the section widget
83      */

84     public Section getSection() {
85         return section;
86     }
87
88     /**
89      * The section is about to expand or collapse.
90      *
91      * @param expanding
92      * <code>true</code> for expansion, <code>false</code> for
93      * collapse.
94      */

95     protected void expansionStateChanging(boolean expanding) {
96     }
97
98     /**
99      * The section has expanded or collapsed.
100      *
101      * @param expanded
102      * <code>true</code> for expansion, <code>false</code> for
103      * collapse.
104      */

105     protected void expansionStateChanged(boolean expanded) {
106         getManagedForm().getForm().reflow(false);
107     }
108
109     /* (non-Javadoc)
110      * @see org.eclipse.ui.forms.AbstractFormPart#setFocus()
111      */

112     public void setFocus() {
113         Control client = section.getClient();
114         if (client != null)
115             client.setFocus();
116     }
117 }
118
Popular Tags