1 11 package org.eclipse.jdt.internal.ui.wizards.dialogfields; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.GC; 15 import org.eclipse.swt.graphics.Image; 16 import org.eclipse.swt.widgets.Button; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.swt.widgets.Label; 20 import org.eclipse.swt.widgets.Text; 21 22 import org.eclipse.swt.layout.GridData; 23 24 import org.eclipse.jface.resource.JFaceResources; 25 26 31 public class StringButtonStatusDialogField extends StringButtonDialogField { 32 33 private Label fStatusLabelControl; 34 private Object fStatus; 36 private String fWidthHintString; 37 private int fWidthHint; 38 39 public StringButtonStatusDialogField(IStringButtonAdapter adapter) { 40 super(adapter); 41 fStatus= null; 42 fWidthHintString= null; 43 fWidthHint= -1; 44 } 45 46 48 51 public void setStatus(String status) { 52 if (isOkToUse(fStatusLabelControl)) { 53 fStatusLabelControl.setText(status); 54 } 55 fStatus= status; 56 } 57 58 62 public void setStatus(Image image) { 63 if (isOkToUse(fStatusLabelControl)) { 64 if (image == null) { 65 fStatusLabelControl.setImage(null); 66 } else { 67 fStatusLabelControl.setImage(image); 68 } 69 } 70 fStatus= image; 71 } 72 73 77 public void setStatusWidthHint(String widthHintString) { 78 fWidthHintString= widthHintString; 79 fWidthHint= -1; 80 } 81 82 85 public void setStatusWidthHint(int widthHint) { 86 fWidthHint= widthHint; 87 fWidthHintString= null; 88 } 89 90 92 95 public Control[] doFillIntoGrid(Composite parent, int nColumns) { 96 assertEnoughColumns(nColumns); 97 98 Label label= getLabelControl(parent); 99 label.setLayoutData(gridDataForLabel(1)); 100 Text text= getTextControl(parent); 101 text.setLayoutData(gridDataForText(nColumns - 3)); 102 Label status= getStatusLabelControl(parent); 103 status.setLayoutData(gridDataForStatusLabel(parent, 1)); 104 Button button= getChangeControl(parent); 105 button.setLayoutData(gridDataForButton(button, 1)); 106 107 return new Control[] { label, text, status, button }; 108 } 109 110 113 public int getNumberOfControls() { 114 return 4; 115 } 116 117 protected GridData gridDataForStatusLabel(Control aControl, int span) { 118 GridData gd= new GridData(); 119 gd.horizontalAlignment= GridData.BEGINNING; 120 gd.grabExcessHorizontalSpace= false; 121 gd.horizontalIndent= 0; 122 if (fWidthHintString != null) { 123 GC gc= new GC(aControl); 124 gc.setFont(JFaceResources.getDialogFont()); 125 gd.widthHint= gc.textExtent(fWidthHintString).x; 126 gc.dispose(); 127 } else if (fWidthHint != -1) { 128 gd.widthHint= fWidthHint; 129 } else { 130 gd.widthHint= SWT.DEFAULT; 131 } 132 return gd; 133 } 134 135 137 142 public Label getStatusLabelControl(Composite parent) { 143 if (fStatusLabelControl == null) { 144 assertCompositeNotNull(parent); 145 fStatusLabelControl= new Label(parent, SWT.LEFT); 146 fStatusLabelControl.setFont(parent.getFont()); 147 fStatusLabelControl.setEnabled(isEnabled()); 148 if (fStatus instanceof Image) { 149 fStatusLabelControl.setImage((Image)fStatus); 150 } else if (fStatus instanceof String ) { 151 fStatusLabelControl.setText((String )fStatus); 152 } else { 153 } 155 } 156 return fStatusLabelControl; 157 } 158 159 161 164 protected void updateEnableState() { 165 super.updateEnableState(); 166 if (isOkToUse(fStatusLabelControl)) { 167 fStatusLabelControl.setEnabled(isEnabled()); 168 } 169 } 170 171 174 public void refresh() { 175 super.refresh(); 176 if (fStatus instanceof String ) { 177 setStatus((String ) fStatus); 178 } else { 179 setStatus((Image) fStatus); 180 } 181 } 182 } 183 | Popular Tags |