Skip to content

Commit

Permalink
Provide user feedback when updating versions
Browse files Browse the repository at this point in the history
One current issue is that users are confused about the meaning of
buttons, especially as pressing them gives no immediate feedback.

This now do the following:
- disable the update button while update is running (or user selects
another location)
- after completion gives a message to the user what was the outcome of
the most recent operation
  • Loading branch information
laeubi committed Dec 14, 2024
1 parent 9a772d2 commit 849c1fa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public class Messages extends NLS {
public static String TargetLocationsGroup_1;

public static String TargetLocationsGroup_TargetUpdateErrorDialog;
public static String TargetLocationsGroup_TargetUpdateNoChange;
public static String TargetStatus_NoActiveTargetPlatformStatus;
public static String TargetStatus_TargetStatusDefaultString;
public static String TargetStatus_UnresolvedTarget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public IStatus update(ITargetDefinition target, TreePath[] treePath, IProgressMo
for (Entry<ITargetLocationHandler, List<TreePath>> entry : handlerMap.entrySet()) {
status.add(entry.getKey().update(target, entry.getValue().toArray(TreePath[]::new), subMonitor.split(100)));
}
IStatus[] children = status.getChildren();
if (children.length == 1) {
return children[0];
}
return status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
Expand Down Expand Up @@ -82,6 +83,7 @@
*/
public class TargetLocationsGroup {

private static final String LOCATION_ID_KEY = "target.location.id"; //$NON-NLS-1$
private static final String BUTTON_STATE = "ButtonState"; //$NON-NLS-1$

private enum DeleteButtonState {
Expand Down Expand Up @@ -121,6 +123,7 @@ static DeleteButtonState computeState(boolean canRemove, boolean canEnable, bool
private final ListenerList<ITargetChangedListener> fChangeListeners = new ListenerList<>();
private final ListenerList<ITargetChangedListener> fReloadListeners = new ListenerList<>();
private static final TargetLocationHandlerAdapter ADAPTER = new TargetLocationHandlerAdapter();
private int counter;

/**
* Creates this part using the form toolkit and adds it to the given
Expand Down Expand Up @@ -478,24 +481,41 @@ private void handleRemove() {
}

private void handleUpdate() {
fUpdateButton.setEnabled(false);
ITreeSelection selection = fTreeViewer.getStructuredSelection();
if (selection.isEmpty()) {
fUpdateButton.setEnabled(false);
return;
}
Integer id = counter++;
fUpdateButton.setCursor(fUpdateButton.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
fUpdateButton.setData(LOCATION_ID_KEY, id);
List<IJobFunction> updateActions = Collections
.singletonList(monitor -> log(ADAPTER.update(fTarget, selection.getPaths(), monitor)));
JobChangeAdapter listener = new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
UIJob job = UIJob.create(Messages.UpdateTargetJob_UpdateJobName, monitor -> {
boolean showMessage = !fUpdateButton.isDisposed() && id == fUpdateButton.getData(LOCATION_ID_KEY);
if (showMessage) {
// we are the current owner so need to reset
// state...
fUpdateButton.setEnabled(!fTreeViewer.getStructuredSelection().isEmpty());
fUpdateButton.setCursor(null);
showMessage = true;
}
IStatus result = event.getJob().getResult();
if (!result.isOK()) {
if (!fTreeViewer.getControl().isDisposed()) {
ErrorDialog.openError(fTreeViewer.getTree().getShell(),
if (showMessage) {
ErrorDialog.openError(fUpdateButton.getShell(),
Messages.TargetLocationsGroup_TargetUpdateErrorDialog, result.getMessage(), result);
}
} else if (result.getCode() != ITargetLocationHandler.STATUS_CODE_NO_CHANGE) {
} else if (result.getCode() == ITargetLocationHandler.STATUS_CODE_NO_CHANGE) {
if (showMessage) {
MessageDialog.openInformation(fUpdateButton.getShell(),
Messages.UpdateTargetJob_UpdateJobName,
Messages.TargetLocationsGroup_TargetUpdateNoChange);
}
} else {
// Update was successful and changed the target, if
// dialog/editor still open, update it
if (!fTreeViewer.getControl().isDisposed()) {
Expand All @@ -518,6 +538,11 @@ public void done(final IJobChangeEvent event) {
// do nothing if we could not set the current
// target.
}
if (showMessage) {
MessageDialog.openInformation(fUpdateButton.getShell(),
Messages.UpdateTargetJob_UpdateJobName,
result.getMessage());
}
}
});
job.schedule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ TargetLocationsGroup_update=Looks for newer versions of the target contents and
TargetLocationsGroup_refresh=Clears the cached target data and resolves the target, looking for newer versions of any artifacts
TargetLocationsGroup_1=&Show location content
TargetLocationsGroup_TargetUpdateErrorDialog=Problems Updating Target Definition
TargetLocationsGroup_TargetUpdateNoChange=All versions are up-to-date
TargetStatus_NoActiveTargetPlatformStatus=No active target platform
TargetStatus_TargetStatusDefaultString=Target Platform
TargetStatus_UnresolvedTarget=Unresolved ''{0}''
Expand Down

0 comments on commit 849c1fa

Please sign in to comment.