001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.examples.views.properties.tabbed.article.views;
011:
012: import org.eclipse.jface.util.Assert;
013: import org.eclipse.jface.viewers.ISelection;
014: import org.eclipse.jface.viewers.IStructuredSelection;
015: import org.eclipse.swt.custom.CLabel;
016: import org.eclipse.swt.events.ModifyEvent;
017: import org.eclipse.swt.events.ModifyListener;
018: import org.eclipse.swt.layout.FormAttachment;
019: import org.eclipse.swt.layout.FormData;
020: import org.eclipse.swt.widgets.Composite;
021: import org.eclipse.swt.widgets.Text;
022: import org.eclipse.ui.IWorkbenchPart;
023: import org.eclipse.ui.views.properties.IPropertySource;
024: import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
025: import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
026: import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
027:
028: /**
029: * The size section on the button tab.
030: *
031: * @author Anthony Hunter
032: */
033: public class SizeSection extends AbstractPropertySection {
034:
035: private Text widthText;
036:
037: private Text heightText;
038:
039: private ButtonElement buttonElement;
040:
041: private ModifyListener listener = new ModifyListener() {
042:
043: public void modifyText(ModifyEvent arg0) {
044: ButtonElementProperties properties = (ButtonElementProperties) buttonElement
045: .getAdapter(IPropertySource.class);
046: SizePropertySource sizePropertySource = (SizePropertySource) properties
047: .getPropertyValue(ButtonElementProperties.PROPERTY_SIZE);
048: sizePropertySource.setPropertyValue(
049: SizePropertySource.ID_HEIGHT, heightText.getText());
050: sizePropertySource.setPropertyValue(
051: SizePropertySource.ID_WIDTH, widthText.getText());
052: }
053: };
054:
055: public void setInput(IWorkbenchPart part, ISelection selection) {
056: super .setInput(part, selection);
057: Assert.isTrue(selection instanceof IStructuredSelection);
058: Object input = ((IStructuredSelection) selection)
059: .getFirstElement();
060: Assert.isTrue(input instanceof ButtonElement);
061: this .buttonElement = (ButtonElement) input;
062: }
063:
064: /**
065: * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite,
066: * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
067: */
068: public void createControls(Composite parent,
069: TabbedPropertySheetPage tabbedPropertySheetPage) {
070: super .createControls(parent, tabbedPropertySheetPage);
071: Composite composite = getWidgetFactory()
072: .createFlatFormComposite(parent);
073: FormData data;
074:
075: CLabel widthLabel = getWidgetFactory().createCLabel(composite,
076: "Width:"); //$NON-NLS-1$
077: widthText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$
078: CLabel heightLabel = getWidgetFactory().createCLabel(composite,
079: "Height:"); //$NON-NLS-1$
080: heightText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$
081:
082: data = new FormData();
083: data.left = new FormAttachment(0, 0);
084: data.right = new FormAttachment(widthText,
085: -ITabbedPropertyConstants.HSPACE);
086: data.top = new FormAttachment(0, 0);
087: widthLabel.setLayoutData(data);
088:
089: data = new FormData();
090: data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
091: data.right = new FormAttachment(heightLabel,
092: -ITabbedPropertyConstants.HSPACE);
093: data.top = new FormAttachment(0, 0);
094: widthText.setLayoutData(data);
095:
096: data = new FormData();
097: data.left = new FormAttachment(50, 0);
098: // data.right = new FormAttachment(heightText,
099: // -ITabbedPropertyConstants.HSPACE);
100: data.top = new FormAttachment(0, 0);
101: heightLabel.setLayoutData(data);
102:
103: data = new FormData();
104: data.left = new FormAttachment(heightLabel,
105: ITabbedPropertyConstants.HSPACE);
106: data.right = new FormAttachment(100, 0);
107: data.top = new FormAttachment(0, 0);
108: heightText.setLayoutData(data);
109:
110: heightText.addModifyListener(listener);
111: widthText.addModifyListener(listener);
112: }
113:
114: /*
115: * @see org.eclipse.ui.views.properties.tabbed.view.ITabbedPropertySection#refresh()
116: */
117: public void refresh() {
118: heightText.removeModifyListener(listener);
119: widthText.removeModifyListener(listener);
120: ButtonElementProperties properties = (ButtonElementProperties) buttonElement
121: .getAdapter(IPropertySource.class);
122: widthText.setText(Integer.toString(properties.ptSize.x));
123: heightText.setText(Integer.toString(properties.ptSize.y));
124: heightText.addModifyListener(listener);
125: widthText.addModifyListener(listener);
126: }
127: }
|