Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ead102c38fa85bccd4f68dc47bcc3741f18eec9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.ui.forms.parts;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.te.ui.forms.FormLayoutFactory;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;

/**
 * Abstract form text section implementation.
 */
public abstract class AbstractFormTextSection extends AbstractSection implements IHyperlinkListener {

	/**
	 * Constructor.
	 *
	 * @param form The parent managed form. Must not be <code>null</code>.
	 * @param parent The parent composite. Must not be <code>null</code>.
	 * @param style The section style.
	 */
	public AbstractFormTextSection(IManagedForm form, Composite parent, int style) {
		this(form, parent, style, true);
	}

	/**
	 * Constructor.
	 *
	 * @param form The parent managed form. Must not be <code>null</code>.
	 * @param parent The parent composite. Must not be <code>null</code>.
	 * @param style The section style.
	 * @param titleBar If <code>true</code>, the title bar style bit is added to <code>style</code>.
	 */
	public AbstractFormTextSection(IManagedForm form, Composite parent, int style, boolean titleBar) {
		super(form, parent, style, titleBar);
		getSection().setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.forms.parts.AbstractSection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
	 */
	@Override
	protected void createClient(Section section, FormToolkit toolkit) {
		Assert.isNotNull(section);
		Assert.isNotNull(toolkit);

		// Configure the section
		section.setText(getSectionTitle());

		section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		// Create the section client
		Composite client = toolkit.createComposite(section, SWT.NONE);
		Assert.isNotNull(client);
		client.setLayout(FormLayoutFactory.createSectionClientTableWrapLayout(false, 1));
		client.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));

		FormText text = createFormText(client, toolkit);
		configureFormText(text);

		section.setClient(client);

		// Mark the control update as completed now
		setIsUpdating(false);
	}

	/**
	 * Returns the section title.
	 *
	 * @return The section title.
	 */
	protected abstract String getSectionTitle();

	/**
	 * Returns the form text content.
	 *
	 * @return The form text content.
	 */
	protected abstract String getFormTextContent();

	/**
	 * Creates a form text control in the given parent composite with the given
	 * content and form toolkit.
	 *
	 * @param parent The parent composite. Must not be <code>null</code>.
	 * @param toolkit The toolkit. Must not be <code>null</code>.
	 *
	 * @return The form text control.
	 */
	protected final FormText createFormText(Composite parent, FormToolkit toolkit) {
		Assert.isNotNull(parent);
		Assert.isNotNull(toolkit);

		// Create the form text control
		return toolkit.createFormText(parent, true);
	}

	/**
	 * Configure the form text.
	 * <p>
	 * The default implementation is setting the form text content
	 * and adding ourself as hyper link listener. The form text
	 * content is queried through {@link #getFormTextContent()}.
	 *
	 * @param text The form text. Must not be <code>null</code>.
	 */
	protected void configureFormText(FormText text) {
		Assert.isNotNull(text);

		// Set the content. If it fails, set the failure message
		try {
			text.setText(getFormTextContent(), true, false);
		} catch (SWTException e) {
			text.setText(e.getMessage(), false, false);
		}

		// Add ourself as hyper link listener
		text.addHyperlinkListener(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.forms.events.IHyperlinkListener#linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent)
	 */
	@Override
	public void linkEntered(HyperlinkEvent e) {
		Object container = getManagedForm().getContainer();
		if (container instanceof IEditorPart) {
			IStatusLineManager manager = ((IEditorPart)container).getEditorSite().getActionBars().getStatusLineManager();
			manager.setMessage(e.getLabel());
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.forms.events.IHyperlinkListener#linkExited(org.eclipse.ui.forms.events.HyperlinkEvent)
	 */
	@Override
	public void linkExited(HyperlinkEvent e) {
		Object container = getManagedForm().getContainer();
		if (container instanceof IEditorPart) {
			IStatusLineManager manager = ((IEditorPart)container).getEditorSite().getActionBars().getStatusLineManager();
			manager.setMessage(null);
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.forms.events.IHyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
	 */
	@Override
	public void linkActivated(HyperlinkEvent e) {
	}
}

Back to the top