Merge "Issue #2302 Fixed simultaneous save issue. Cleaned up AutoSave." into omaha_13.5.2

Former-commit-id: 89c1f24ff8 [formerly 475d289ae5a3a024d5f52f7a2c8263533ada6e3f]
Former-commit-id: a78ebffdb5
This commit is contained in:
Ron Anderson 2013-08-28 11:18:34 -05:00 committed by Gerrit Code Review
commit a7a4f9d60e
6 changed files with 350 additions and 222 deletions

View file

@ -20,10 +20,12 @@
package com.raytheon.viz.gfe.actions; package com.raytheon.viz.gfe.actions;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
@ -42,8 +44,9 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jan 23, 2008 Eric Babin Initial Creation * Jan 23, 2008 Eric Babin Initial Creation
* Jul 8, 2008 randerso reworked * Jul 8, 2008 randerso reworked
* Oct 23, 2012 1287 rferrel Changes for non-blocking AutoSaveIntervalDialog. * Oct 23, 2012 1287 rferrel Changes for non-blocking AutoSaveIntervalDialog.
* Aug 27, 2013 2302 randerso Code clean up for AutoSaveJob changes
* *
* </pre> * </pre>
* *
@ -51,7 +54,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* @version 1.0 * @version 1.0
*/ */
public class ShowAutoSaveIntervalDialog extends AbstractHandler { public class ShowAutoSaveIntervalDialog extends AbstractHandler {
private AutoSaveIntervalDialog dialog; final private Map<IWorkbenchWindow, AutoSaveIntervalDialog> dialogMap = new HashMap<IWorkbenchWindow, AutoSaveIntervalDialog>();
/** /**
* *
@ -69,47 +72,28 @@ public class ShowAutoSaveIntervalDialog extends AbstractHandler {
*/ */
@Override @Override
public Object execute(ExecutionEvent arg0) throws ExecutionException { public Object execute(ExecutionEvent arg0) throws ExecutionException {
final IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
DataManager dm = DataManagerUIFactory.findInstance(window);
if (dm == null) {
return null;
}
AutoSaveIntervalDialog dialog = dialogMap.get(window);
if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) { if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) {
final IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
Shell shell = window.getShell();
int interval = AutoSaveJob.getInterval(); AutoSaveJob autoSaveJob = dm.getAutoSaveJob();
boolean autoSaveEnabled = interval > 0;
if (!autoSaveEnabled) { Shell shell = window.getShell();
interval = AutoSaveJob.MAX_INTERVAL; dialog = new AutoSaveIntervalDialog(shell, autoSaveJob);
} dialogMap.put(window, dialog);
dialog = new AutoSaveIntervalDialog(shell, interval,
autoSaveEnabled);
dialog.setBlockOnOpen(false); dialog.setBlockOnOpen(false);
dialog.setCloseCallback(new ICloseCallback() { dialog.setCloseCallback(new ICloseCallback() {
@Override @Override
public void dialogClosed(Object returnValue) { public void dialogClosed(Object returnValue) {
if (returnValue instanceof Integer) { dialogMap.remove(window);
int returnCode = (Integer) returnValue;
if (returnCode == Window.OK) {
DataManager dm = DataManagerUIFactory
.findInstance(window);
// update
if (dialog.isAutoSaveEnabled()) {
int interval = dialog.getCurrentInterval();
AutoSaveJob.setInterval(interval);
if (dm != null) {
dm.enableAutoSave();
}
DataManagerUIFactory.findInstance(window)
.enableAutoSave();
} else {
AutoSaveJob.setInterval(0);
if (dm != null) {
dm.disableAutoSave();
}
}
}
}
} }
}); });
dialog.open(); dialog.open();

View file

@ -96,6 +96,7 @@ import com.raytheon.viz.gfe.textformatter.TextProductManager;
* initialized by constructor. * initialized by constructor.
* 04/24/2013 1936 dgilling Move initialization of TextProductMgr * 04/24/2013 1936 dgilling Move initialization of TextProductMgr
* to GFE startup. * to GFE startup.
* 08/27/2013 2302 randerso Code cleanup for AutoSaveJob
* *
* </pre> * </pre>
* *
@ -271,18 +272,10 @@ public class DataManager {
} }
/** /**
* Start auto save jobs * @return the autoSaveJob
*/ */
public void enableAutoSave() { public AutoSaveJob getAutoSaveJob() {
autoSaveJob.cancel(); return autoSaveJob;
autoSaveJob.reSchedule();
}
/**
* Stop auto save jobs
*/
public void disableAutoSave() {
autoSaveJob.cancel();
} }
/** /**

View file

@ -84,6 +84,7 @@ import com.raytheon.viz.gfe.GFEServerException;
import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.core.griddata.AbstractGridData; import com.raytheon.viz.gfe.core.griddata.AbstractGridData;
import com.raytheon.viz.gfe.core.griddata.IGridData; import com.raytheon.viz.gfe.core.griddata.IGridData;
import com.raytheon.viz.gfe.core.parm.ParmSaveJob.ParmSaveStatus;
import com.raytheon.viz.gfe.core.parm.ParmState.InterpMode; import com.raytheon.viz.gfe.core.parm.ParmState.InterpMode;
import com.raytheon.viz.gfe.core.wxvalue.DiscreteWxValue; import com.raytheon.viz.gfe.core.wxvalue.DiscreteWxValue;
import com.raytheon.viz.gfe.core.wxvalue.ScalarWxValue; import com.raytheon.viz.gfe.core.wxvalue.ScalarWxValue;
@ -182,6 +183,8 @@ import com.vividsolutions.jts.geom.Coordinate;
* Mar 13, 2013 1792 bsteffen Improve performance of gfe parm average * Mar 13, 2013 1792 bsteffen Improve performance of gfe parm average
* ant time weighted average. * ant time weighted average.
* Apr 02, 2013 #1774 randerso Fixed a possible deadlock issue. * Apr 02, 2013 #1774 randerso Fixed a possible deadlock issue.
* Aug 27, 2013 #2302 randerso Fix simultaneous save issue
*
* </pre> * </pre>
* *
* @author chammack * @author chammack
@ -229,6 +232,8 @@ public abstract class Parm implements Comparable<Parm> {
protected boolean disposed; protected boolean disposed;
private ParmSaveJob saveJob;
/** /**
* The create from scratch mode * The create from scratch mode
*/ */
@ -360,6 +365,7 @@ public abstract class Parm implements Comparable<Parm> {
} }
this.disposed = false; this.disposed = false;
this.saveJob = new ParmSaveJob(this);
} }
public void dispose() { public void dispose() {
@ -708,7 +714,7 @@ public abstract class Parm implements Comparable<Parm> {
* Save a parameter * Save a parameter
* *
* @param all * @param all
* @return * @return true if save successful
*/ */
public boolean saveParameter(boolean all) { public boolean saveParameter(boolean all) {
if (inParmEdit) { if (inParmEdit) {
@ -729,14 +735,16 @@ public abstract class Parm implements Comparable<Parm> {
/** /**
* Save a parameter * Save a parameter
* *
* @param tr * @param times
* @return * TimeRanges to be saved
* @return true if save successful
*/ */
public boolean saveParameter(List<TimeRange> tr) { public boolean saveParameter(List<TimeRange> times) {
if (inParmEdit) { if (inParmEdit) {
return false; return false;
} else { } else {
return saveParameterSubClass(tr); ParmSaveStatus status = this.saveJob.requestSave(times);
return status.isSuccessful();
} }
} }
@ -744,7 +752,7 @@ public abstract class Parm implements Comparable<Parm> {
* Save a parameter * Save a parameter
* *
* @param tr * @param tr
* @return * @return true if save successful
*/ */
public boolean saveParameter(TimeRange tr) { public boolean saveParameter(TimeRange tr) {
ArrayList<TimeRange> trs = new ArrayList<TimeRange>(); ArrayList<TimeRange> trs = new ArrayList<TimeRange>();
@ -756,7 +764,8 @@ public abstract class Parm implements Comparable<Parm> {
* Subclass specific save implementation * Subclass specific save implementation
* *
* @param tr * @param tr
* @return * TimeRanges to be saved
* @return true if save successful
*/ */
protected abstract boolean saveParameterSubClass(List<TimeRange> tr); protected abstract boolean saveParameterSubClass(List<TimeRange> tr);

View file

@ -0,0 +1,135 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.gfe.core.parm;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Semaphore;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import com.raytheon.uf.common.time.TimeRange;
/**
* Job to queue up and work of parm save requests
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 27, 2013 #2302 randerso Initial creation
*
* </pre>
*
* @author randerso
* @version 1.0
*/
public class ParmSaveJob extends Job {
public static class ParmSaveStatus {
boolean successful = false;
Semaphore complete = new Semaphore(0);
/**
* @return the successful
*/
public boolean isSuccessful() {
try {
complete.acquire();
return successful;
} catch (InterruptedException e) {
return false;
}
}
/**
* @param successful
* the successful to set
*/
private void setSuccessful(boolean successful) {
this.successful = successful;
complete.release();
}
}
private class ParmSaveRequest {
private List<TimeRange> times;
private ParmSaveStatus status;
public ParmSaveRequest(List<TimeRange> times) {
this.times = times;
this.status = new ParmSaveStatus();
}
}
private Parm parm;
private ConcurrentLinkedQueue<ParmSaveRequest> saveQueue;
/**
* @param parm
*/
public ParmSaveJob(Parm parm) {
super("ParmSaveJob");
this.setSystem(true);
this.parm = parm;
this.saveQueue = new ConcurrentLinkedQueue<ParmSaveJob.ParmSaveRequest>();
}
/**
* Request save.
*
* Caller should call isSuccessful on the returned ParmSaveStatus object to
* await completion and to determine success
*
* @param times
* @return ParmSaveStatus object
*/
public ParmSaveStatus requestSave(List<TimeRange> times) {
ParmSaveRequest request = new ParmSaveRequest(times);
this.saveQueue.add(request);
this.schedule();
return request.status;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
* IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
ParmSaveRequest req = null;
while ((req = this.saveQueue.poll()) != null) {
boolean successful = parm.saveParameterSubClass(req.times);
req.status.setSuccessful(successful);
}
return Status.OK_STATUS;
}
}

View file

@ -29,20 +29,21 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import com.raytheon.viz.gfe.jobs.AutoSaveJob; import com.raytheon.viz.gfe.jobs.AutoSaveJob;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog; import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
import com.raytheon.viz.ui.widgets.SpinScale;
/** /**
* The auto save iterval dialog. * The auto save interval dialog.
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jan 30, 2008 Eric Babin Initial Creation * Jan 30, 2008 Eric Babin Initial Creation
* Aug 27, 2013 #2302 randerso Code cleanup
* *
* </pre> * </pre>
* *
@ -52,98 +53,26 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
public class AutoSaveIntervalDialog extends CaveJFACEDialog { public class AutoSaveIntervalDialog extends CaveJFACEDialog {
private Composite top = null; private AutoSaveJob autoSaveJob;
private Label intervalMinutes;
private Scale intervalScale;
private int currentInterval = 1;
private boolean autoSaveEnabled = false;
private Button offButton; private Button offButton;
private Button onButton; private Button onButton;
public AutoSaveIntervalDialog(Shell parent, int currentInterval, private Label intervalLabel;
boolean isEnabled) {
private SpinScale intervalScale;
/**
* Constructor
*
* @param parent
* @param currentInterval
* @param isEnabled
*/
public AutoSaveIntervalDialog(Shell parent, AutoSaveJob autoSaveJob) {
super(parent); super(parent);
this.setShellStyle(SWT.TITLE | SWT.MODELESS | SWT.CLOSE); this.autoSaveJob = autoSaveJob;
this.currentInterval = currentInterval;
this.autoSaveEnabled = isEnabled;
}
@Override
protected Control createDialogArea(Composite parent) {
top = (Composite) super.createDialogArea(parent);
top.setLayout(new GridLayout(2, false));
loadConfigData();
initializeComponents();
return top;
}
private void initializeComponents() {
Group g = new Group(top, SWT.NONE);
g.setLayout(new GridLayout(2, true));
offButton = new Button(g, SWT.RADIO);
offButton.setText("Off");
offButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
autoSaveEnabled = false;
}
});
offButton.setSelection(!autoSaveEnabled);
onButton = new Button(g, SWT.RADIO);
onButton.setText("On");
onButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
autoSaveEnabled = true;
}
});
onButton.setSelection(autoSaveEnabled);
Composite c = new Composite(top, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginBottom = 10;
c.setLayout(layout);
c.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
Label label = new Label(c, SWT.NONE);
label.setText("Save Interval in Minutes");
GridData data = new GridData();
data.horizontalSpan = 2;
label.setLayoutData(data);
intervalScale = new Scale(c, SWT.HORIZONTAL);
intervalScale.setLayoutData(new GridData(120, SWT.DEFAULT));
intervalScale.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
autoSaveEnabled = true;
currentInterval = intervalScale.getSelection();
String s = Integer.toString(currentInterval);
intervalMinutes.setText(s);
intervalMinutes.setToolTipText(s);
onButton.setSelection(autoSaveEnabled);
offButton.setSelection(!autoSaveEnabled);
}
});
intervalScale.setMinimum(AutoSaveJob.MIN_INTERVAL);
intervalScale.setMaximum(AutoSaveJob.MAX_INTERVAL);
intervalScale.setSelection(this.currentInterval);
intervalMinutes = new Label(c, SWT.NONE);
intervalMinutes.setLayoutData(new GridData(20, SWT.DEFAULT));
intervalMinutes.setText(String.valueOf(intervalScale.getSelection()));
} }
/* /*
@ -154,23 +83,92 @@ public class AutoSaveIntervalDialog extends CaveJFACEDialog {
* .Shell) * .Shell)
*/ */
@Override @Override
protected void configureShell(Shell shell) { protected void configureShell(Shell newShell) {
super.configureShell(shell); super.configureShell(newShell);
shell.setText("Auto Save Interval Dialog"); newShell.setText("Auto Save Interval Dialog");
} }
/** @Override
* Method for loading the various config data for the dialog. protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) comp.getLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
Group group = new Group(comp, SWT.NONE);
layout = new GridLayout(2, false);
group.setLayout(layout);
GridData layoutData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
group.setLayoutData(layoutData);
group.setText("Auto Save");
int interval = autoSaveJob.getInterval();
offButton = new Button(group, SWT.RADIO);
layoutData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
offButton.setLayoutData(layoutData);
offButton.setText("Off");
offButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (offButton.getSelection()) {
intervalLabel.setEnabled(false);
intervalScale.setEnabled(false);
}
}
});
offButton.setSelection(interval == 0);
onButton = new Button(group, SWT.RADIO);
layoutData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
onButton.setLayoutData(layoutData);
onButton.setText("On");
onButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (onButton.getSelection()) {
intervalLabel.setEnabled(true);
intervalScale.setEnabled(true);
}
}
});
onButton.setSelection(interval > 0);
intervalLabel = new Label(group, SWT.CENTER);
intervalLabel.setText("Save Interval in Minutes");
layoutData = new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1);
intervalLabel.setLayoutData(layoutData);
intervalScale = new SpinScale(group, SWT.HORIZONTAL);
layoutData = new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1);
layoutData.minimumWidth = 240;
intervalScale.setLayoutData(layoutData);
intervalScale.setMinimum(AutoSaveJob.MIN_INTERVAL);
intervalScale.setMaximum(AutoSaveJob.MAX_INTERVAL);
if (interval > 0) {
intervalScale.setSelection(interval);
} else {
intervalLabel.setEnabled(false);
intervalScale.setEnabled(false);
intervalScale.setSelection(AutoSaveJob.MAX_INTERVAL);
}
return comp;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/ */
private void loadConfigData() { @Override
protected void okPressed() {
if (offButton.getSelection()) {
autoSaveJob.setInterval(0);
} else {
autoSaveJob.setInterval(intervalScale.getSelection());
}
super.okPressed();
} }
public int getCurrentInterval() {
return currentInterval;
}
public boolean isAutoSaveEnabled() {
return autoSaveEnabled;
}
} }

View file

@ -24,11 +24,14 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import com.raytheon.viz.gfe.Activator; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.viz.gfe.GFEPreference; import com.raytheon.viz.gfe.GFEPreference;
import com.raytheon.viz.gfe.PreferenceConstants; import com.raytheon.viz.gfe.PreferenceConstants;
import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.core.parm.Parm; import com.raytheon.viz.gfe.core.parm.Parm;
import com.raytheon.viz.gfe.ui.HazardUIUtils;
/** /**
* Job implementing the auto save functionality. Uses user preferences to * Job implementing the auto save functionality. Uses user preferences to
@ -38,7 +41,8 @@ import com.raytheon.viz.gfe.core.parm.Parm;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jun 25, 2008 Eric Babin Initial Creation * Jun 25, 2008 Eric Babin Initial Creation
* Aug 27, 2013 #2302 randerso Fixed to behave more like A1, code cleanup
* *
* </pre> * </pre>
* *
@ -47,38 +51,34 @@ import com.raytheon.viz.gfe.core.parm.Parm;
*/ */
public class AutoSaveJob extends Job { public class AutoSaveJob extends Job {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(AutoSaveJob.class);
private static final int MILLISECONDS_PER_MINUTE = 60 * 1000; /**
* Max auto save interval in minutes
*/
public static final int MAX_INTERVAL = 60; public static final int MAX_INTERVAL = 60;
/**
* Min auto save interval in minutes
*/
public static final int MIN_INTERVAL = 1; public static final int MIN_INTERVAL = 1;
/** /**
* auto save interval in minutes, 0 = disabled * auto save interval in milliseconds, 0 = disabled
*/ */
private static int interval; private long interval;
static {
int i = 0;
if (GFEPreference.storeAvailable()) {
i = GFEPreference
.getIntPreference(PreferenceConstants.GFE_AUTO_SAVE_INTERVAL);
}
interval = i;
}
/** /**
* Set the auto save interval * Set the auto save interval
* *
* @param i * @param interval
* desired interval in minutes * desired interval in minutes
*/ */
public static void setInterval(int i) { public void setInterval(int interval) {
interval = i; this.interval = interval * TimeUtil.MILLIS_PER_MINUTE;
this.cancel();
GFEPreference.setPreference(PreferenceConstants.GFE_AUTO_SAVE_INTERVAL, this.reSchedule(this.interval);
Integer.toString(i));
} }
/** /**
@ -86,8 +86,8 @@ public class AutoSaveJob extends Job {
* *
* @return interval in minutes * @return interval in minutes
*/ */
public static int getInterval() { public int getInterval() {
return interval; return (int) (interval / TimeUtil.MILLIS_PER_MINUTE);
} }
private DataManager dataManager; private DataManager dataManager;
@ -104,17 +104,28 @@ public class AutoSaveJob extends Job {
this.dataManager = dataManager; this.dataManager = dataManager;
this.disposed = false; this.disposed = false;
this.setSystem(true); this.setSystem(true);
int pref = GFEPreference
.getIntPreference(PreferenceConstants.GFE_AUTO_SAVE_INTERVAL);
if (pref > MAX_INTERVAL) {
pref = MAX_INTERVAL;
} else if (pref < 0) {
pref = 0;
}
reSchedule(); this.interval = pref * TimeUtil.MILLIS_PER_MINUTE;
reSchedule(this.interval);
} }
/** /**
* Schedule this job to run after the desired interval * Schedule this job to run after the desired
*
* @param delay
* interval in milliseconds
*/ */
public void reSchedule() { public void reSchedule(long delay) {
if (!disposed) { if (!disposed) {
if (interval > 0) { if (delay > 0) {
this.schedule(interval * MILLISECONDS_PER_MINUTE); this.schedule(delay);
} }
} else { } else {
dataManager = null; dataManager = null;
@ -138,53 +149,51 @@ public class AutoSaveJob extends Job {
*/ */
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS; long delay = this.interval;
try { if (delay > 0) {
Parm[] parms = this.dataManager.getParmManager().getModifiedParms(); String msg = "GFE Auto Save called. ";
if (parms != null && parms.length != 0) { boolean success = false;
String autoSaveResult = "GFE Auto Save called. Save of Parms["; try {
for (int i = 0; i < parms.length; i++) { Parm modifiedParm = getModifiedParm();
String name = parms[i].getParmID().getParmName(); if (modifiedParm != null) {
if (name.indexOf("Hazards") == -1) { msg += "Save of Parm "
autoSaveResult += saveParm(parms[i]); + modifiedParm.getParmID().getParmName() + " = ";
} else {
if (!tempHazardsExist()) {
saveParm(parms[i]);
autoSaveResult += saveParm(parms[i]);
}
}
}
autoSaveResult += "]";
Activator.getDefault().getLog().log( // save the data
new Status(IStatus.INFO, Activator.PLUGIN_ID, success = modifiedParm.saveParameter(false);
autoSaveResult)); msg += (success ? "success" : "failure");
delay = 1500;
} else {
msg += "Nothing to save.";
}
statusHandler.info(msg);
} catch (Exception e) {
msg += "failure";
statusHandler.error(msg, e);
} }
} catch (Exception e) { reSchedule(delay);
status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"GFE auto save failed.", e);
} }
reSchedule(); return Status.OK_STATUS;
return status;
} }
/** /**
* If tempHazards exist, then autosave kicked off in the middle of merge * Find the first available modified parm. Skip Hazards if temp hazards
* hazard. (which creates a "temp" hazard with "haz" in the name. * exist
* *
* So we will ignore the "Hazard" WE parm save... * @return the first available modified parm or null if none
*
* @return if temp haz exists.
*/ */
private boolean tempHazardsExist() { private Parm getModifiedParm() {
Parm[] parms = this.dataManager.getParmManager().getDisplayedParms(); boolean tempHazDisplayed = HazardUIUtils
for (int i = 0; i < parms.length; i++) { .tempHazardsExist(this.dataManager);
if (parms[i].getParmID().getParmName().indexOf("haz") != -1) { for (Parm p : this.dataManager.getParmManager().getModifiedParms()) {
return true; if (p.getParmID().getParmName().contains("Hazards")
&& tempHazDisplayed) {
continue;
} else {
return p;
} }
} }
return null;
return false;
} }
/** /**