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 control.
26 * The status label can be either a image or text label, and can be usd to give
27 * additional information about the current element chosen.
29 public class StringButtonStatusDialogField extends StringButtonDialogField {
31 private Label fStatusLabelControl;
32 private Object fStatus; // String or ImageDescriptor
34 private String fWidthHintString;
35 private int fWidthHint;
37 public StringButtonStatusDialogField(IStringButtonAdapter adapter) {
40 fWidthHintString= null;
47 * Sets the status string.
49 public void setStatus(String status) {
50 if (isOkToUse(fStatusLabelControl)) {
51 fStatusLabelControl.setText(status);
57 * Sets the status image.
58 * Caller is responsible to dispose image
60 public void setStatus(Image image) {
61 if (isOkToUse(fStatusLabelControl)) {
63 fStatusLabelControl.setImage(null);
65 fStatusLabelControl.setImage(image);
72 * Sets the staus string hint of the status label.
73 * The string is used to calculate the size of the status label.
75 public void setStatusWidthHint(String widthHintString) {
76 fWidthHintString= widthHintString;
81 * Sets the width hint of the status label.
83 public void setStatusWidthHint(int widthHint) {
84 fWidthHint= widthHint;
85 fWidthHintString= null;
88 // ------- layout helpers
91 * @see DialogField#doFillIntoGrid
93 public Control[] doFillIntoGrid(Composite parent, int nColumns) {
94 assertEnoughColumns(nColumns);
96 Label label= getLabelControl(parent);
97 label.setLayoutData(gridDataForLabel(1));
98 Text text= getTextControl(parent);
99 text.setLayoutData(gridDataForText(nColumns - 3));
100 Label status= getStatusLabelControl(parent);
101 status.setLayoutData(gridDataForStatusLabel(parent, 1));
102 Button button= getChangeControl(parent);
103 button.setLayoutData(gridDataForButton(button, 1));
105 return new Control[] { label, text, status, button };
109 * @see DialogField#getNumberOfControls
111 public int getNumberOfControls() {
115 protected GridData gridDataForStatusLabel(Control aControl, int span) {
116 GridData gd= new GridData();
117 gd.horizontalAlignment= GridData.BEGINNING;
118 gd.grabExcessHorizontalSpace= false;
119 gd.horizontalIndent= 0;
120 if (fWidthHintString != null) {
121 GC gc= new GC(aControl);
122 gc.setFont(JFaceResources.getDialogFont());
123 gd.widthHint= gc.textExtent(fWidthHintString).x;
125 } else if (fWidthHint != -1) {
126 gd.widthHint= fWidthHint;
128 gd.widthHint= SWT.DEFAULT;
133 // ------- ui creation
136 * Creates or returns the created status label widget.
137 * @param parent The parent composite or <code>null</code> when the widget has
138 * already been created.
140 public Label getStatusLabelControl(Composite parent) {
141 if (fStatusLabelControl == null) {
142 assertCompositeNotNull(parent);
143 fStatusLabelControl= new Label(parent, SWT.LEFT);
144 fStatusLabelControl.setFont(parent.getFont());
145 fStatusLabelControl.setEnabled(isEnabled());
146 if (fStatus instanceof Image) {
147 fStatusLabelControl.setImage((Image)fStatus);
148 } else if (fStatus instanceof String) {
149 fStatusLabelControl.setText((String)fStatus);
154 return fStatusLabelControl;
157 // ------ enable / disable management
160 * @see DialogField#updateEnableState
162 protected void updateEnableState() {
163 super.updateEnableState();
164 if (isOkToUse(fStatusLabelControl)) {
165 fStatusLabelControl.setEnabled(isEnabled());