Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save in main thread #45

Merged
merged 5 commits into from
Apr 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Revert "Revert "Save operation is now blocking the UI thread, needed …
…for save on close dialog""

This reverts commit 8f9fe07.
  • Loading branch information
Andras Toth committed Apr 25, 2018
commit afdc6015a44ed8c39027a800186c8890726c2f06
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package com.hpe.octane.ideplugins.eclipse.ui.entitydetail;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.MessageDialog;
Expand All @@ -30,6 +31,7 @@
import org.eclipse.ui.part.EditorPart;

import com.hpe.adm.nga.sdk.exception.OctaneException;
import com.hpe.adm.nga.sdk.model.ErrorModel;
import com.hpe.adm.nga.sdk.model.FieldModel;
import com.hpe.adm.octane.ideplugins.services.EntityService;
import com.hpe.octane.ideplugins.eclipse.Activator;
Expand Down Expand Up @@ -148,45 +150,48 @@ private void setIsDirty(boolean isDirty) {
}

@Override
public void setFocus() {
}
public void setFocus() {}

@Override
public void doSave(IProgressMonitor monitor) {
UpdateEntityJob updateEntityJob = new UpdateEntityJob("Saving " + entityModelWrapper.getEntityType(), entityModelWrapper.getEntityModel());

updateEntityJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
OctaneException octaneException = updateEntityJob.getOctaneException();

if (octaneException == null) {
updateEntityJob.schedule();

try {
updateEntityJob.join(1000 * 10, monitor);

OctaneException octaneException = updateEntityJob.getOctaneException();
if (octaneException == null) {
loadEntity();

} else {
EntityDetailErrorDialog errorDialog = new EntityDetailErrorDialog(rootComposite.getShell());
errorDialog.addButton("Back", () -> errorDialog.close());
errorDialog.addButton("Refresh", () -> {
loadEntity();

} else {
Display.getDefault().asyncExec(() -> {

EntityDetailErrorDialog errorDialog = new EntityDetailErrorDialog(rootComposite.getShell());

errorDialog.addButton("Back", () -> errorDialog.close());

errorDialog.addButton("Refresh", () -> {
loadEntity();
errorDialog.close();
});
errorDialog.addButton("Open in browser", () -> {
entityService.openInBrowser(entityModelWrapper.getReadOnlyEntityModel());
errorDialog.close();
});

errorDialog.open(octaneException, "Saving entity failed");

});
}
errorDialog.close();
});
errorDialog.addButton("Open in browser", () -> {
entityService.openInBrowser(entityModelWrapper.getReadOnlyEntityModel());
errorDialog.close();
});

errorDialog.open(octaneException, "Saving entity failed");

//This will stop the window from closing if an error occurs
//when saving from the dialog that appears when you close a dirty tab
monitor.setCanceled(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atothhpe Looking at the code, it seems that doSave is only called twice and with null as a param.
monitor.setCanceled(true); will definitely throw an exception.
What will happen to "updateEntityJob.join(1000 * 10, monitor);" when monitor is null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateEntityJob.join(1000 * 10, monitor); can have a null monitor param

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The monitor for the doSave is provided from the platfrom, sadly I have no idea where to get it from.
monitor.setCancelled is a problem, I need to find another way to keep the tab from closing on error

}
});

updateEntityJob.schedule();

} catch (OperationCanceledException | InterruptedException ignored) {
EntityDetailErrorDialog errorDialog = new EntityDetailErrorDialog(rootComposite.getShell());
errorDialog.addButton("Back", () -> errorDialog.close());
errorDialog.open(new OctaneException(new ErrorModel("Save timeout")), "Saving entity failed");

//This will stop the window from closing if an error occurs
//when saving from the dialog that appears when you close a dirty tab
monitor.setCanceled(true);
}
}

@Override
Expand All @@ -203,4 +208,6 @@ public boolean isDirty() {
public boolean isSaveAsAllowed() {
return entityModelWrapper != null && isDirty;
}


}