blob: 1c9f2dff2adfcbef5ffbc5abb05245f5c0a4e00e [file] [log] [blame]
nitind35747e32006-02-20 18:52:34 +00001/*******************************************************************************
2 * Copyright (c) 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 *******************************************************************************/
12package org.eclipse.wst.dtd.ui.internal.properties.section;
13
14import org.eclipse.swt.SWT;
15import org.eclipse.swt.layout.FormAttachment;
16import org.eclipse.swt.layout.FormData;
17import org.eclipse.swt.widgets.Composite;
18import org.eclipse.swt.widgets.Event;
19import org.eclipse.swt.widgets.Text;
nitind003afb72006-04-18 09:03:42 +000020import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
nitind35747e32006-02-20 18:52:34 +000021import org.eclipse.wst.dtd.core.internal.Comment;
22
23public class CommentSection extends AbstractSection {
24 private Text commentText;
25
26 /**
27 * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite,
28 * org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory)
29 */
30 public void createControls(Composite parent, TabbedPropertySheetWidgetFactory factory) {
31 super.createControls(parent, factory);
32
33 Composite composite = getWidgetFactory().createFlatFormComposite(parent);
amywu93ab0962006-04-06 04:38:55 +000034 commentText = getWidgetFactory().createText(composite, "", SWT.MULTI | SWT.NONE); //$NON-NLS-1$
nitind35747e32006-02-20 18:52:34 +000035 commentText.addListener(SWT.Modify, CommentSection.this);
36
37 FormData data = new FormData();
38 data.left = new FormAttachment(0, 0);
39 data.right = new FormAttachment(100, 0);
40 data.top = new FormAttachment(0, 0);
41 data.bottom = new FormAttachment(100, 0);
42 commentText.setLayoutData(data);
43 }
44
45 /*
46 * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh()
47 */
48 public void refresh() {
49 setListenerEnabled(false);
50 commentText.setEnabled(true);
51 Object input = getInput();
amywu93ab0962006-04-06 04:38:55 +000052 commentText.setText(""); //$NON-NLS-1$
nitind35747e32006-02-20 18:52:34 +000053 if (input != null) {
54 if (input instanceof Comment)
55 commentText.setText(((Comment) input).getText());
56 }
57 setListenerEnabled(true);
58 }
59
60
61 public void doHandleEvent(Event event) {
62 Object input = getInput();
63 if (input != null) {
64 String newValue = commentText.getText();
65 if (newValue.length() > 0 && input instanceof Comment) {
66 Comment comment = (Comment) input;
67 comment.setText(newValue);
68 }
69 }
70
71 }
72
73 public boolean shouldUseExtraSpace() {
74 return true;
75 }
76}