nitind | 35747e3 | 2006-02-20 18:52:34 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
| 12 | package org.eclipse.wst.dtd.ui.internal.properties.section; |
| 13 | |
| 14 | import org.eclipse.swt.SWT; |
| 15 | import org.eclipse.swt.layout.FormAttachment; |
| 16 | import org.eclipse.swt.layout.FormData; |
| 17 | import org.eclipse.swt.widgets.Composite; |
| 18 | import org.eclipse.swt.widgets.Event; |
| 19 | import org.eclipse.swt.widgets.Text; |
nitind | 003afb7 | 2006-04-18 09:03:42 +0000 | [diff] [blame] | 20 | import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; |
nitind | 35747e3 | 2006-02-20 18:52:34 +0000 | [diff] [blame] | 21 | import org.eclipse.wst.dtd.core.internal.Comment; |
| 22 | |
| 23 | public 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); |
amywu | 93ab096 | 2006-04-06 04:38:55 +0000 | [diff] [blame] | 34 | commentText = getWidgetFactory().createText(composite, "", SWT.MULTI | SWT.NONE); //$NON-NLS-1$ |
nitind | 35747e3 | 2006-02-20 18:52:34 +0000 | [diff] [blame] | 35 | 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(); |
amywu | 93ab096 | 2006-04-06 04:38:55 +0000 | [diff] [blame] | 52 | commentText.setText(""); //$NON-NLS-1$ |
nitind | 35747e3 | 2006-02-20 18:52:34 +0000 | [diff] [blame] | 53 | 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 | } |