1 11 package org.eclipse.team.internal.ccvs.ui.tags; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.core.runtime.jobs.Job; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.dialogs.TrayDialog; 19 import org.eclipse.jface.operation.IRunnableContext; 20 import org.eclipse.jface.operation.IRunnableWithProgress; 21 import org.eclipse.jface.util.IPropertyChangeListener; 22 import org.eclipse.jface.util.PropertyChangeEvent; 23 import org.eclipse.jface.window.Window; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.events.DisposeEvent; 26 import org.eclipse.swt.events.DisposeListener; 27 import org.eclipse.swt.graphics.Cursor; 28 import org.eclipse.swt.graphics.Point; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.*; 31 import org.eclipse.team.internal.ccvs.core.CVSStatus; 32 import org.eclipse.team.internal.ccvs.core.CVSTag; 33 import org.eclipse.team.internal.ccvs.ui.*; 34 35 38 public class TagSelectionDialog extends TrayDialog implements IPropertyChangeListener { 39 40 private TagSelectionArea tagSelectionArea; 41 private Cursor appBusyCursor; 42 43 public static final int INCLUDE_HEAD_TAG = TagSourceWorkbenchAdapter.INCLUDE_HEAD_TAG; 44 public static final int INCLUDE_BASE_TAG = TagSourceWorkbenchAdapter.INCLUDE_BASE_TAG; 45 public static final int INCLUDE_BRANCHES = TagSourceWorkbenchAdapter.INCLUDE_BRANCHES; 46 public static final int INCLUDE_VERSIONS = TagSourceWorkbenchAdapter.INCLUDE_VERSIONS; 47 public static final int INCLUDE_DATES = TagSourceWorkbenchAdapter.INCLUDE_DATES; 48 public static final int INCLUDE_ALL_TAGS = TagSourceWorkbenchAdapter.INCLUDE_ALL_TAGS; 49 50 private Button okButton; 51 52 private String title; 55 56 private boolean recurse = true; 57 58 private static final int SIZING_DIALOG_WIDTH = 90; 60 private static final int SIZING_DIALOG_HEIGHT = 25; 61 62 private CVSTag selection; 63 64 private TagSource tagSource; 65 66 private String message; 67 68 private int includeFlags; 69 70 private String helpContext; 71 72 private boolean showRecurse; 73 74 public static CVSTag getTagToCompareWith(Shell shell, TagSource tagSource, int includeFlags) { 75 TagSelectionDialog dialog = new TagSelectionDialog(shell, tagSource, 76 CVSUIMessages.CompareWithTagAction_message, 77 CVSUIMessages.TagSelectionDialog_Select_a_Tag_1, 78 includeFlags, 79 false, 80 IHelpContextIds.COMPARE_TAG_SELECTION_DIALOG); 81 dialog.setBlockOnOpen(true); 82 int result = dialog.open(); 83 if (result == Window.CANCEL) { 84 return null; 85 } 86 return dialog.getResult(); 87 } 88 89 93 public TagSelectionDialog(Shell parentShell, TagSource tagSource, String title, String message, int includeFlags, final boolean showRecurse, String helpContext) { 94 super(parentShell); 95 96 this.tagSource = tagSource; 98 this.message = message; 99 this.includeFlags = includeFlags; 100 this.helpContext = helpContext; 101 this.showRecurse = showRecurse; 102 this.title = title; 103 setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); 104 } 105 106 109 protected void configureShell(Shell newShell) { 110 super.configureShell(newShell); 111 newShell.setText(title); 112 } 113 114 117 protected Point getInitialSize() { 118 final Point size= super.getInitialSize(); 119 size.x= convertWidthInCharsToPixels(SIZING_DIALOG_WIDTH); 120 size.y= convertHeightInCharsToPixels(SIZING_DIALOG_HEIGHT); 121 return size; 122 } 123 124 136 public void create() { 137 super.create(); 138 initialize(); 139 } 140 141 146 protected void createButtonsForButtonBar(Composite parent) { 147 okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 149 okButton.setEnabled(false); 150 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 151 } 152 153 166 protected Control createDialogArea(Composite parent) { 167 168 applyDialogFont(parent); 169 initializeDialogUnits(parent); 170 171 final Composite top = (Composite)super.createDialogArea(parent); 172 173 tagSelectionArea = new TagSelectionArea(getShell(), tagSource, includeFlags, helpContext) { 175 protected void createCustomArea(Composite parent) { 176 if(showRecurse) { 177 final Button recurseCheck = new Button(parent, SWT.CHECK); 178 recurseCheck.setText(CVSUIMessages.TagSelectionDialog_recurseOption); 179 recurseCheck.addListener(SWT.Selection, new Listener() { 180 public void handleEvent(Event event) { 181 recurse = recurseCheck.getSelection(); 182 } 183 }); 184 recurseCheck.setSelection(true); 185 } 186 } 187 }; 188 if (message != null) 189 tagSelectionArea.setTagAreaLabel(message); 190 tagSelectionArea.addPropertyChangeListener(this); 191 tagSelectionArea.createArea(top); 192 tagSelectionArea.setRunnableContext(getRunnableContext()); 193 194 final Label seperator = new Label(top, SWT.SEPARATOR | SWT.HORIZONTAL); 196 final GridData data = new GridData (GridData.FILL_HORIZONTAL); 197 data.horizontalSpan = 2; 198 seperator.setLayoutData(data); 199 200 updateEnablement(); 201 applyDialogFont(parent); 202 203 return top; 204 } 205 206 207 215 protected Label createLabel(Composite parent, String text) { 216 Label label = new Label(parent, SWT.LEFT); 217 label.setText(text); 218 GridData data = new GridData(); 219 data.horizontalSpan = 1; 220 data.horizontalAlignment = GridData.FILL; 221 label.setLayoutData(data); 222 return label; 223 } 224 225 228 public CVSTag getResult() { 229 return selection; 230 } 231 232 public boolean getRecursive() { 233 return recurse; 234 } 235 236 239 protected void initialize() { 240 okButton.setEnabled(false); 241 if (CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_AUTO_REFRESH_TAGS_IN_TAG_SELECTION_DIALOG)) 242 tagSelectionArea.refreshTagList(); 243 } 244 245 246 249 protected void updateEnablement() { 250 if(okButton!=null) { 251 okButton.setEnabled(selection != null); 252 } 253 } 254 255 258 public void propertyChange(PropertyChangeEvent event) { 259 String property = event.getProperty(); 260 if (property.equals(TagSelectionArea.SELECTED_TAG)) { 261 selection = (CVSTag)event.getNewValue(); 262 updateEnablement(); 263 } else if (property.equals(TagSelectionArea.OPEN_SELECTED_TAG)) { 264 okPressed(); 265 } 266 } 267 268 273 private IRunnableContext getRunnableContext() { 274 return new IRunnableContext() { 275 public void run(boolean fork, boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException , InterruptedException { 276 final Job refreshJob = new Job(CVSUIMessages.TagSelectionDialog_7) { 277 protected IStatus run(IProgressMonitor monitor) { 278 if (monitor.isCanceled()) 279 return Status.CANCEL_STATUS; 280 try { 281 setBusy(true); 282 runnable.run(monitor); 283 } catch (InvocationTargetException e) { 284 return new CVSStatus(IStatus.ERROR, CVSUIMessages.TagSelectionDialog_8, e); 285 } catch (InterruptedException e) { 286 return new CVSStatus(IStatus.ERROR, CVSUIMessages.TagSelectionDialog_8, e); 287 } finally { 288 setBusy(false); 289 } 290 if (monitor.isCanceled()) 291 return Status.CANCEL_STATUS; 292 else 293 return Status.OK_STATUS; 294 } 295 }; 296 refreshJob.setUser(false); 297 refreshJob.setPriority(Job.DECORATE); 298 getShell().addDisposeListener(new DisposeListener() { 299 public void widgetDisposed(DisposeEvent e) { 300 refreshJob.cancel(); 301 } 302 }); 303 refreshJob.schedule(); 304 } 305 }; 306 } 307 308 private void setBusy(final boolean busy) { 309 final Shell shell = getShell(); 310 if (shell != null && !shell.isDisposed()) { 311 shell.getDisplay().asyncExec(new Runnable () { 312 public void run() { 313 if (!shell.isDisposed()) { 314 Cursor cursor = null; 315 if (busy) { 316 if (appBusyCursor == null) 317 appBusyCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_APPSTARTING); 318 cursor = appBusyCursor; 319 } 320 shell.setCursor(cursor); 321 } 322 } 323 }); 324 } 325 } 326 327 public boolean close() { 328 if(appBusyCursor != null) 329 appBusyCursor.dispose(); 330 return super.close(); 331 } 332 } 333 | Popular Tags |