Skip to main content
summaryrefslogtreecommitdiffstats
blob: a762c92fc327344bf509663b9c0c6d90b7ebd22c (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
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.asd.properties.sections;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.eclipse.wst.wsdl.WSDLElement;
import org.eclipse.wst.wsdl.ui.internal.actions.AddElementAction;
import org.eclipse.wst.wsdl.ui.internal.adapters.WSDLBaseAdapter;
import org.eclipse.wst.wsdl.ui.internal.asd.ASDEditorCSHelpIds;
import org.eclipse.wst.wsdl.ui.internal.asd.design.editparts.model.AbstractModelCollection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class DocumentationSection extends ASDAbstractSection {
	Text docText;

	/**
	 * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory)
	 */
	public void createControls(Composite parent, TabbedPropertySheetWidgetFactory factory)
	{
		super.createControls(parent, factory);
		composite =	getWidgetFactory().createFlatFormComposite(parent);

		docText = getWidgetFactory().createText(composite, "", SWT.MULTI | SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); //$NON-NLS-1$
		docText.addListener(SWT.KeyDown, this);
		FormData data = new FormData();
		data.left = new FormAttachment(0, 0);
		data.right = new FormAttachment(100, 0);
		data.top = new FormAttachment(0, 0);
		data.bottom = new FormAttachment(100, 0);
		docText.setLayoutData(data);
		PlatformUI.getWorkbench().getHelpSystem().setHelp(docText, ASDEditorCSHelpIds.PROPERTIES_DOCUMENTATION_TAB);
	}

	/*
	 * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh()
	 */
	/*
	 * TODO: the doHandleEvent() and refresh() methods both use WSDL11 specific
	 * knowledge.  This class (DocumentationSection) should be generic.  In Post 1.5,
	 * we need to add documentation support methods to our facade so we don't need
	 * to know WSDL specific implementation....... 
	 */
	public void refresh()
	{
		super.refresh();
		if (docText.isFocusControl())
		{
			return;
		}
		setListenerEnabled(false);
		docText.setText(""); //$NON-NLS-1$
		if (getModel() != null && getElement() != null)
		{
			Element docNode = getElement().getDocumentationElement();
			if (docNode != null)
			{
				Node textNode = docNode.getFirstChild();
				if (textNode != null)
				{
					String docValue = textNode.getNodeValue();
					if (docValue != null)
					{
						docText.setText(docValue);
					}
				}
			}
		}
		setListenerEnabled(true);
	}

	/*
	 * TODO: the doHandleEvent() and refresh() methods both use WSDL11 specific
	 * knowledge.  This class (DocumentationSection) should be generic.  In Post 1.5,
	 * we need to add documentation support methods to our facade so we don't need
	 * to know WSDL specific implementation....... 
	 */
	public void doHandleEvent(Event event)
	{
		if (event.widget == docText)
		{
			String value = docText.getText();
			if (getModel() != null && getElement() != null)
			{
				Element docNode = getElement().getDocumentationElement();
				if (docNode != null)
				{
					Node textNode = docNode.getFirstChild();
					if (textNode != null)
					{
						textNode.setNodeValue(value);
					}
					else
					{
						if (value.length() > 0)
						{
							Document document = docNode.getOwnerDocument();
							org.w3c.dom.Text newTextNode = document.createTextNode(value);
							docNode.appendChild(newTextNode);
						}
					}
				}
				else
				{
					Element element = getElement().getElement();
					AddElementAction action = new AddElementAction(element, element.getPrefix(), "documentation", element.getFirstChild()); //$NON-NLS-1$
					action.run();
					Element newDocumentation = action.getNewElement();

					Document document = newDocumentation.getOwnerDocument();
					org.w3c.dom.Text newTextNode = document.createTextNode(value);
					newDocumentation.appendChild(newTextNode);
					getElement().setDocumentationElement(newDocumentation);
				}
			}
		}
	}

	private WSDLElement getElement() {
		WSDLElement element = null;
		Object model = getModel();

		if (model instanceof AbstractModelCollection) {
			model = ((AbstractModelCollection) model).getModel();
		}
		
		// TODO: Should we be handling the XML Schema case here as well?
		if (model instanceof WSDLBaseAdapter) {
			Object target = ((WSDLBaseAdapter) model).getTarget();
			if (target instanceof WSDLElement) {
				element = (WSDLElement) target;
			}
		}

		return element;
	}
}

Back to the top