1 11 package org.eclipse.ui.dialogs; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.dialogs.IDialogSettings; 19 import org.eclipse.jface.dialogs.TrayDialog; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.widgets.Button; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Label; 24 import org.eclipse.swt.widgets.Shell; 25 import org.eclipse.ui.internal.WorkbenchMessages; 26 27 35 public abstract class SelectionDialog extends TrayDialog { 36 private Object [] result; 39 40 private List initialSelections = new ArrayList (); 42 43 private String title; 45 46 private String message = ""; 49 private int dialogBoundsStrategy = Dialog.DIALOG_PERSISTLOCATION | Dialog.DIALOG_PERSISTSIZE; 51 52 private IDialogSettings dialogBoundsSettings = null; 54 55 static String SELECT_ALL_TITLE = WorkbenchMessages.SelectionDialog_selectLabel; 56 57 static String DESELECT_ALL_TITLE = WorkbenchMessages.SelectionDialog_deselectLabel; 58 59 66 protected SelectionDialog(Shell parentShell) { 67 super(parentShell); 68 } 69 70 73 protected void configureShell(Shell shell) { 74 super.configureShell(shell); 75 if (title != null) { 76 shell.setText(title); 77 } 78 } 79 80 83 protected void createButtonsForButtonBar(Composite parent) { 84 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, 85 true); 86 createButton(parent, IDialogConstants.CANCEL_ID, 87 IDialogConstants.CANCEL_LABEL, false); 88 } 89 90 101 protected Label createMessageArea(Composite composite) { 102 Label label = new Label(composite, SWT.NONE); 103 if (message != null) { 104 label.setText(message); 105 } 106 label.setFont(composite.getFont()); 107 return label; 108 } 109 110 116 protected List getInitialSelections() { 117 if (initialSelections.isEmpty()) { 118 return null; 119 } else { 120 return getInitialElementSelections(); 121 } 122 } 123 124 129 protected List getInitialElementSelections() { 130 return initialSelections; 131 } 132 133 138 protected String getMessage() { 139 return message; 140 } 141 142 148 public Button getOkButton() { 149 return getButton(IDialogConstants.OK_ID); 150 } 151 152 159 public Object [] getResult() { 160 return result; 161 } 162 163 170 public void setInitialSelections(Object [] selectedElements) { 171 initialSelections = new ArrayList (selectedElements.length); 172 for (int i = 0; i < selectedElements.length; i++) { 173 initialSelections.add(selectedElements[i]); 174 } 175 } 176 177 184 public void setInitialElementSelections(List selectedElements) { 185 initialSelections = selectedElements; 186 } 187 188 194 public void setMessage(String message) { 195 this.message = message; 196 } 197 198 206 protected void setResult(List newResult) { 207 if (newResult == null) { 208 result = null; 209 } else { 210 result = new Object [newResult.size()]; 211 newResult.toArray(result); 212 } 213 } 214 215 226 protected void setSelectionResult(Object [] newResult) { 227 result = newResult; 228 } 229 230 236 public void setTitle(String title) { 237 this.title = title; 238 } 239 240 260 public void setDialogBoundsSettings(IDialogSettings settings, int strategy) { 261 dialogBoundsStrategy = strategy; 262 dialogBoundsSettings = settings; 263 } 264 265 280 protected IDialogSettings getDialogBoundsSettings() { 281 return dialogBoundsSettings; 282 } 283 284 298 protected int getDialogBoundsStrategy() { 299 return dialogBoundsStrategy; 300 } 301 } 302 | Popular Tags |