1 13 package org.eclipse.ui.dialogs; 14 15 import java.util.Arrays ; 16 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.jface.dialogs.IDialogConstants; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.graphics.Font; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.Button; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.ui.internal.MessageLine; 29 30 38 public abstract class SelectionStatusDialog extends SelectionDialog { 39 40 private MessageLine fStatusLine; 41 42 private IStatus fLastStatus; 43 44 private Image fImage; 45 46 private boolean fStatusLineAboveButtons = false; 47 48 52 public SelectionStatusDialog(Shell parent) { 53 super(parent); 54 } 55 56 63 public void setStatusLineAboveButtons(boolean aboveButtons) { 64 fStatusLineAboveButtons = aboveButtons; 65 } 66 67 71 public void setImage(Image image) { 72 fImage = image; 73 } 74 75 82 public Object getFirstResult() { 83 Object [] result = getResult(); 84 if (result == null || result.length == 0) { 85 return null; 86 } 87 return result[0]; 88 } 89 90 95 protected void setResult(int position, Object element) { 96 Object [] result = getResult(); 97 result[position] = element; 98 setResult(Arrays.asList(result)); 99 } 100 101 104 protected abstract void computeResult(); 105 106 109 protected void configureShell(Shell shell) { 110 super.configureShell(shell); 111 if (fImage != null) { 112 shell.setImage(fImage); 113 } 114 } 115 116 121 protected void updateStatus(IStatus status) { 122 fLastStatus = status; 123 if (fStatusLine != null && !fStatusLine.isDisposed()) { 124 updateButtonsEnableState(status); 125 fStatusLine.setErrorStatus(status); 126 } 127 } 128 129 134 protected void updateButtonsEnableState(IStatus status) { 135 Button okButton = getOkButton(); 136 if (okButton != null && !okButton.isDisposed()) { 137 okButton.setEnabled(!status.matches(IStatus.ERROR)); 138 } 139 } 140 141 144 protected void okPressed() { 145 computeResult(); 146 super.okPressed(); 147 } 148 149 152 public void create() { 153 super.create(); 154 if (fLastStatus != null) { 155 updateStatus(fLastStatus); 156 } 157 } 158 159 162 protected Control createButtonBar(Composite parent) { 163 Font font = parent.getFont(); 164 Composite composite = new Composite(parent, SWT.NULL); 165 GridLayout layout = new GridLayout(); 166 if (!fStatusLineAboveButtons) { 167 layout.numColumns = 2; 168 } 169 layout.marginHeight = 0; 170 layout.marginLeft = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 171 layout.marginWidth = 0; 172 composite.setLayout(layout); 173 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 174 composite.setFont(font); 175 176 if (!fStatusLineAboveButtons && isHelpAvailable()) { 177 createHelpControl(composite); 178 } 179 fStatusLine = new MessageLine(composite); 180 fStatusLine.setAlignment(SWT.LEFT); 181 GridData statusData = new GridData(GridData.FILL_HORIZONTAL); 182 fStatusLine.setErrorStatus(null); 183 fStatusLine.setFont(font); 184 if (fStatusLineAboveButtons && isHelpAvailable()) { 185 statusData.horizontalSpan = 2; 186 createHelpControl(composite); 187 } 188 fStatusLine.setLayoutData(statusData); 189 190 194 boolean helpAvailable = isHelpAvailable(); 195 setHelpAvailable(false); 196 super.createButtonBar(composite); 197 setHelpAvailable(helpAvailable); 198 return composite; 199 } 200 201 } 202 | Popular Tags |