| /******************************************************************************* |
| * Copyright (c) 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.dtd.ui.internal.properties.section; |
| |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.CCombo; |
| import org.eclipse.swt.custom.CLabel; |
| import org.eclipse.swt.events.SelectionEvent; |
| 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.wst.common.ui.properties.internal.provisional.ITabbedPropertyConstants; |
| import org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory; |
| import org.eclipse.wst.dtd.core.internal.Attribute; |
| import org.eclipse.wst.dtd.ui.internal.DTDPropertiesMessages; |
| |
| public class AttributeDefaultSection extends AbstractSection { |
| |
| private final String IMPLIED = Attribute.IMPLIED; |
| private final String REQUIRED = Attribute.REQUIRED; |
| private final String FIXED = Attribute.FIXED; |
| |
| private CCombo usageCombo; |
| private String[] usageComboValues = {IMPLIED, REQUIRED, FIXED, DTDPropertiesMessages._UI_DEFAULT}; |
| private Text defaultValueText; |
| private CLabel defaultValueLabel; |
| |
| /** |
| * @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 composite = getWidgetFactory().createFlatFormComposite(parent); |
| |
| usageCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); |
| FormData data = new FormData(); |
| data.left = new FormAttachment(0, 100); |
| data.right = new FormAttachment(100, 0); |
| data.top = new FormAttachment(0, 0); |
| usageCombo.setLayoutData(data); |
| usageCombo.addSelectionListener(this); |
| usageCombo.setItems(usageComboValues); |
| |
| CLabel usageLabel = getWidgetFactory().createCLabel(composite, DTDPropertiesMessages._UI_LABEL_USAGE); |
| data = new FormData(); |
| data.left = new FormAttachment(0, 0); |
| data.right = new FormAttachment(usageCombo, -ITabbedPropertyConstants.HSPACE); |
| data.top = new FormAttachment(usageCombo, 0, SWT.CENTER); |
| usageLabel.setLayoutData(data); |
| |
| defaultValueText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ |
| data = new FormData(); |
| data.left = new FormAttachment(0, 100); |
| data.right = new FormAttachment(100, 0); |
| data.top = new FormAttachment(usageCombo, +ITabbedPropertyConstants.VSPACE); |
| defaultValueText.setLayoutData(data); |
| defaultValueText.addListener(SWT.Modify, this); |
| |
| defaultValueLabel = getWidgetFactory().createCLabel(composite, DTDPropertiesMessages._UI_LABEL_DEFAULT_VALUE); |
| data = new FormData(); |
| data.left = new FormAttachment(0, 0); |
| data.right = new FormAttachment(defaultValueText, -ITabbedPropertyConstants.HSPACE); |
| data.top = new FormAttachment(defaultValueText, 0, SWT.CENTER); |
| defaultValueLabel.setLayoutData(data); |
| } |
| |
| /* |
| * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() |
| */ |
| public void refresh() { |
| setListenerEnabled(false); |
| Object input = getInput(); |
| if (input != null) { |
| if (input instanceof Attribute) { |
| String kind = ((Attribute) input).getDefaultKind(); |
| if ("".equals(kind)) |
| usageCombo.setText(DTDPropertiesMessages._UI_DEFAULT); |
| else |
| usageCombo.setText(kind); |
| |
| if ("".equals(kind) || FIXED.equals(kind)) { |
| defaultValueLabel.setVisible(true); |
| defaultValueText.setEnabled(true); |
| defaultValueText.setText(((Attribute) input).getDefaultValue()); |
| } |
| else { |
| defaultValueText.setText(""); |
| defaultValueLabel.setVisible(false); |
| defaultValueText.setEnabled(false); |
| } |
| } |
| } |
| setListenerEnabled(true); |
| } |
| |
| public void widgetSelected(SelectionEvent e) { |
| if (e.widget == usageCombo) { |
| Object input = getInput(); |
| if (input instanceof Attribute) { |
| String usage = usageCombo.getText(); |
| Attribute attribute = (Attribute) input; |
| if (usage.equals(DTDPropertiesMessages._UI_DEFAULT)) |
| attribute.setDefaultKind(""); |
| else |
| attribute.setDefaultKind(usage); |
| |
| if (DTDPropertiesMessages._UI_DEFAULT.equals(usage) || FIXED.equals(usage)) { |
| defaultValueLabel.setVisible(true); |
| defaultValueText.setEnabled(true); |
| } |
| else { |
| defaultValueLabel.setVisible(false); |
| defaultValueText.setEnabled(false); |
| } |
| } |
| } |
| } |
| |
| public void doHandleEvent(Event event) { |
| Object input = getInput(); |
| if (input instanceof Attribute) { |
| if (event.widget == defaultValueText) { |
| String newValue = defaultValueText.getText(); |
| ((Attribute) input).setDefaultValue(newValue, usageCombo.getText().equals(FIXED)); |
| } |
| } |
| } |
| |
| } |