3333import org .eclipse .jface .action .Action ;
3434import org .eclipse .jface .action .MenuManager ;
3535import org .eclipse .jface .dialogs .ErrorDialog ;
36+ import org .eclipse .jface .dialogs .MessageDialog ;
3637import org .eclipse .jface .viewers .AbstractTreeViewer ;
3738import org .eclipse .jface .viewers .ITreeSelection ;
3839import org .eclipse .jface .viewers .TreePath ;
8283 */
8384public class TargetLocationsGroup {
8485
86+ private static final String LOCATION_ID_KEY = "target.location.id" ; //$NON-NLS-1$
8587 private static final String BUTTON_STATE = "ButtonState" ; //$NON-NLS-1$
8688
8789 private enum DeleteButtonState {
@@ -121,6 +123,7 @@ static DeleteButtonState computeState(boolean canRemove, boolean canEnable, bool
121123 private final ListenerList <ITargetChangedListener > fChangeListeners = new ListenerList <>();
122124 private final ListenerList <ITargetChangedListener > fReloadListeners = new ListenerList <>();
123125 private static final TargetLocationHandlerAdapter ADAPTER = new TargetLocationHandlerAdapter ();
126+ private int counter ;
124127
125128 /**
126129 * Creates this part using the form toolkit and adds it to the given
@@ -478,24 +481,41 @@ private void handleRemove() {
478481 }
479482
480483 private void handleUpdate () {
484+ fUpdateButton .setEnabled (false );
481485 ITreeSelection selection = fTreeViewer .getStructuredSelection ();
482486 if (selection .isEmpty ()) {
483- fUpdateButton .setEnabled (false );
484487 return ;
485488 }
489+ Integer id = counter ++;
490+ fUpdateButton .setCursor (fUpdateButton .getDisplay ().getSystemCursor (SWT .CURSOR_WAIT ));
491+ fUpdateButton .setData (LOCATION_ID_KEY , id );
486492 List <IJobFunction > updateActions = Collections
487493 .singletonList (monitor -> log (ADAPTER .update (fTarget , selection .getPaths (), monitor )));
488494 JobChangeAdapter listener = new JobChangeAdapter () {
489495 @ Override
490496 public void done (final IJobChangeEvent event ) {
491497 UIJob job = UIJob .create (Messages .UpdateTargetJob_UpdateJobName , monitor -> {
498+ boolean showMessage = !fUpdateButton .isDisposed () && id == fUpdateButton .getData (LOCATION_ID_KEY );
499+ if (showMessage ) {
500+ // we are the current owner so need to reset
501+ // state...
502+ fUpdateButton .setEnabled (!fTreeViewer .getStructuredSelection ().isEmpty ());
503+ fUpdateButton .setCursor (null );
504+ showMessage = true ;
505+ }
492506 IStatus result = event .getJob ().getResult ();
493507 if (!result .isOK ()) {
494- if (! fTreeViewer . getControl (). isDisposed () ) {
495- ErrorDialog .openError (fTreeViewer . getTree () .getShell (),
508+ if (showMessage ) {
509+ ErrorDialog .openError (fUpdateButton .getShell (),
496510 Messages .TargetLocationsGroup_TargetUpdateErrorDialog , result .getMessage (), result );
497511 }
498- } else if (result .getCode () != ITargetLocationHandler .STATUS_CODE_NO_CHANGE ) {
512+ } else if (result .getCode () == ITargetLocationHandler .STATUS_CODE_NO_CHANGE ) {
513+ if (showMessage ) {
514+ MessageDialog .openInformation (fUpdateButton .getShell (),
515+ Messages .UpdateTargetJob_UpdateJobName ,
516+ Messages .TargetLocationsGroup_TargetUpdateNoChange );
517+ }
518+ } else {
499519 // Update was successful and changed the target, if
500520 // dialog/editor still open, update it
501521 if (!fTreeViewer .getControl ().isDisposed ()) {
@@ -518,6 +538,11 @@ public void done(final IJobChangeEvent event) {
518538 // do nothing if we could not set the current
519539 // target.
520540 }
541+ if (showMessage ) {
542+ MessageDialog .openInformation (fUpdateButton .getShell (),
543+ Messages .UpdateTargetJob_UpdateJobName ,
544+ result .getMessage ());
545+ }
521546 }
522547 });
523548 job .schedule ();
0 commit comments