1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.wizards.dialogfields;
13 import org.eclipse.jface.resource.JFaceResources;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.GC;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
25 * Dialog field containing a label, text control, status label and a button
26 * control. The status label can be either a image or text label, and can be usd
27 * to give additional information about the current element chosen.
29 public class StringButtonStatusDialogField extends StringButtonDialogField {
31 private Label fStatusLabelControl;
33 private Object fStatus; // String or ImageDescriptor
35 private String fWidthHintString;
37 private int fWidthHint;
39 public StringButtonStatusDialogField(IStringButtonAdapter adapter) {
42 fWidthHintString = null;
49 * Sets the status string.
51 public void setStatus(String status) {
52 if (isOkToUse(fStatusLabelControl)) {
53 fStatusLabelControl.setText(status);
59 * Sets the status image. Caller is responsible to dispose image
61 public void setStatus(Image image) {
62 if (isOkToUse(fStatusLabelControl)) {
64 fStatusLabelControl.setImage(null);
66 fStatusLabelControl.setImage(image);
73 * Sets the staus string hint of the status label. The string is used to
74 * calculate the size of the status label.
76 public void setStatusWidthHint(String widthHintString) {
77 fWidthHintString = widthHintString;
82 * Sets the width hint of the status label.
84 public void setStatusWidthHint(int widthHint) {
85 fWidthHint = widthHint;
86 fWidthHintString = null;
89 // ------- layout helpers
92 * @see DialogField#doFillIntoGrid
94 public Control[] doFillIntoGrid(Composite parent, int nColumns) {
95 assertEnoughColumns(nColumns);
97 Label label = getLabelControl(parent);
98 label.setLayoutData(gridDataForLabel(1));
99 Text text = getTextControl(parent);
100 text.setLayoutData(gridDataForText(nColumns - 3));
101 Label status = getStatusLabelControl(parent);
102 status.setLayoutData(gridDataForStatusLabel(parent, 1));
103 Button button = getChangeControl(parent);
104 button.setLayoutData(gridDataForButton(button, 1));
106 return new Control[] { label, text, status, button };
110 * @see DialogField#getNumberOfControls
112 public int getNumberOfControls() {
116 protected GridData gridDataForStatusLabel(Control aControl, int span) {
117 GridData gd = new GridData();
118 gd.horizontalAlignment = GridData.BEGINNING;
119 gd.grabExcessHorizontalSpace = false;
120 gd.horizontalIndent = 0;
121 if (fWidthHintString != null) {
122 GC gc = new GC(aControl);
123 gc.setFont(JFaceResources.getDialogFont());
124 gd.widthHint = gc.textExtent(fWidthHintString).x;
126 } else if (fWidthHint != -1) {
127 gd.widthHint = fWidthHint;
129 gd.widthHint = SWT.DEFAULT;
134 // ------- ui creation
137 * Creates or returns the created status label widget.
140 * The parent composite or <code>null</code> when the widget
141 * has already been created.
143 public Label getStatusLabelControl(Composite parent) {
144 if (fStatusLabelControl == null) {
145 assertCompositeNotNull(parent);
146 fStatusLabelControl = new Label(parent, SWT.LEFT);
147 fStatusLabelControl.setFont(parent.getFont());
148 fStatusLabelControl.setEnabled(isEnabled());
149 if (fStatus instanceof Image) {
150 fStatusLabelControl.setImage((Image) fStatus);
151 } else if (fStatus instanceof String) {
152 fStatusLabelControl.setText((String) fStatus);
157 return fStatusLabelControl;
160 // ------ enable / disable management
163 * @see DialogField#updateEnableState
165 protected void updateEnableState() {
166 super.updateEnableState();
167 if (isOkToUse(fStatusLabelControl)) {
168 fStatusLabelControl.setEnabled(isEnabled());