Issue #3592 Significantly reworked SampleSetManager and sample set dialogs to better match A1 behavior.

Change-Id: I8aef618a5091ee7acae470f5729add3c44287f30

Former-commit-id: bb859073c6ab56141434b84dc104857759a81d82
This commit is contained in:
Ron Anderson 2014-09-15 16:32:41 -05:00
parent d5c0049ba2
commit 5c7290bf7c
12 changed files with 682 additions and 705 deletions

View file

@ -146,14 +146,16 @@
<command id="com.raytheon.viz.gfe.actions.ShowProcessMonitorDialog"
name="ShowProcessMonitorDialog">
</command>
<command id="com.raytheon.viz.gfe.actions.ShowDeleteSampleSetDialog"
name="ShowDeleteSampleSetDialog">
</command>
<command id="com.raytheon.viz.gfe.actions.ShowLoadSampleSetDialog"
name="ShowLoadSampleSetDialog">
</command>
<command id="com.raytheon.viz.gfe.actions.ShowSaveSampleSetDialog"
name="ShowSaveSampleSetDialog">
<command id="com.raytheon.viz.gfe.actions.ShowSaveDeleteSampleSetDialog"
name="ShowSaveDeleteSampleSetDialog">
<commandParameter
id="Action"
name="Action"
optional="false">
</commandParameter>
</command>
<command id="com.raytheon.viz.gfe.actions.ShowClearSamples"
name="ShowClearSamples">
@ -574,13 +576,6 @@
<activeWhen>
<reference definitionId="com.raytheon.viz.gfe.inGFEActionSet">
</reference>
</activeWhen>
</handler>
<handler class="com.raytheon.viz.gfe.actions.ShowDeleteSampleSetDialog"
commandId="com.raytheon.viz.gfe.actions.ShowDeleteSampleSetDialog">
<activeWhen>
<reference definitionId="com.raytheon.viz.gfe.inGFEActionSet">
</reference>
</activeWhen>
</handler>
<handler class="com.raytheon.viz.gfe.actions.ShowLoadSampleSetDialog"
@ -590,8 +585,8 @@
</reference>
</activeWhen>
</handler>
<handler class="com.raytheon.viz.gfe.actions.ShowSaveSampleSetDialog"
commandId="com.raytheon.viz.gfe.actions.ShowSaveSampleSetDialog">
<handler class="com.raytheon.viz.gfe.actions.ShowSaveDeleteSampleSetDialog"
commandId="com.raytheon.viz.gfe.actions.ShowSaveDeleteSampleSetDialog">
<activeWhen>
<reference definitionId="com.raytheon.viz.gfe.inGFEActionSet">
</reference>
@ -1349,11 +1344,19 @@
<command commandId="com.raytheon.viz.gfe.actions.ShowClearSamples"
label="Clear">
</command>
<command commandId="com.raytheon.viz.gfe.actions.ShowSaveSampleSetDialog"
<command commandId="com.raytheon.viz.gfe.actions.ShowSaveDeleteSampleSetDialog"
label="Save...">
<parameter
name="Action"
value="Save">
</parameter>
</command>
<command commandId="com.raytheon.viz.gfe.actions.ShowDeleteSampleSetDialog"
<command commandId="com.raytheon.viz.gfe.actions.ShowSaveDeleteSampleSetDialog"
label="Delete...">
<parameter
name="Action"
value="Delete">
</parameter>
</command>
<separator name="xxx" visible="true" />
<command

View file

@ -1,136 +0,0 @@
/**
* 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.actions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.dialogs.SampleSetDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
/**
* Action for launching delete samples dialog.
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 7, 2008 Eric Babin Initial Creation
* 22JUL2008 #1275. Eric Babin Remove inadvertent dispose on parent shell.
* Oct 24, 2012 #1287 rferrel Changes for non-blocking SampleSetDialog.
*
* </pre>
*
* @author ebabin
* @version 1.0
*/
public class ShowDeleteSampleSetDialog extends AbstractHandler {
private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ShowDeleteSampleSetDialog.class);
private SampleSetDialog dialog;
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) {
ArrayList<SampleId> sampleIdList = DataManager.getCurrentInstance()
.getSampleSetManager().getInventoryAsList();
Collections.sort(sampleIdList, new Comparator<SampleId>() {
@Override
public int compare(SampleId o1, SampleId o2) {
return o1.getName().compareTo(o2.getName());
}
});
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
dialog = new SampleSetDialog(shell, sampleIdList,
SampleSetDialog.DELETE);
dialog.setBlockOnOpen(false);
dialog.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof Integer) {
int returnCode = (Integer) returnValue;
doDialogClose(returnCode);
}
dialog = null;
}
});
dialog.open();
} else {
dialog.bringToTop();
}
return null;
}
private void doDialogClose(int returnCode) {
if (returnCode != Window.CANCEL
&& dialog.getSelectedSampleIdIndexes() != null) {
List<SampleId> sampleIdList = dialog.getSamples();
SampleId id = sampleIdList
.get(dialog.getSelectedSampleIdIndexes()[0]);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
if (MessageDialog.openConfirm(shell, "Delete sample set",
"Delete selected sample set?")) {
if (DataManager.getCurrentInstance().getSampleSetManager()
.deleteSampleSet(id)) {
statusHandler.handle(Priority.EVENTA, id.getName()
+ ", Sample set deleted successfully");
} else {
statusHandler.handle(Priority.PROBLEM,
"Error deleting sample set, " + id.getName());
}
}
}
}
}

View file

@ -19,27 +19,17 @@
**/
package com.raytheon.viz.gfe.actions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.viz.gfe.GFEException;
import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.core.ISampleSetManager;
import com.raytheon.viz.gfe.dialogs.SampleSetDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.gfe.core.DataManagerUIFactory;
import com.raytheon.viz.gfe.dialogs.LoadSampleSetDialog;
/**
* Action to launch sampele set dialog.
@ -51,6 +41,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* Mar 7, 2008 Eric Babin Initial Creation
* Apr 9, 2009 1288 rjpeter Removed explicit refresh of SpatialDisplayManager.
* Oct 24, 2012 1287 rferrel Changes for non-blocking SampleSetDialog.
* Sep 15, 2014 3592 randerso Move logic into dialog code.
*
* </pre>
*
@ -60,11 +51,9 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
public class ShowLoadSampleSetDialog extends AbstractHandler {
private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ShowLoadSampleSetDialog.class);
.getHandler(ShowSaveDeleteSampleSetDialog.class);
private SampleSetDialog dialog;
private DataManager dm;
private LoadSampleSetDialog dialog;
/*
* (non-Javadoc)
@ -74,82 +63,26 @@ public class ShowLoadSampleSetDialog extends AbstractHandler {
* .ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) {
dm = DataManager.getCurrentInstance();
if (dm == null) {
return null;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
DataManager dm = DataManagerUIFactory.getCurrentInstance();
if (dm == null) {
return null;
}
if ((dialog == null) || (dialog.getShell() == null)
|| dialog.isDisposed()) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
ArrayList<SampleId> sampleIdList = dm.getSampleSetManager()
.getInventoryAsList();
Collections.sort(sampleIdList, new Comparator<SampleId>() {
@Override
public int compare(SampleId o1, SampleId o2) {
return o1.getName().compareTo(o2.getName());
}
});
dialog = new SampleSetDialog(shell, sampleIdList,
SampleSetDialog.LOAD);
dialog = new LoadSampleSetDialog(dm.getSampleSetManager(), shell);
dialog.setBlockOnOpen(false);
dialog.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof Integer) {
int returnCode = (Integer) returnValue;
doDialogClosed(returnCode);
}
dialog = null;
}
});
dialog.open();
} else {
dialog.bringToTop();
}
return null;
}
private void doDialogClosed(int returnCode) {
if (returnCode != Window.CANCEL
&& dialog.getSelectedSampleIdIndexes() != null) {
List<SampleId> sampleIdList = dialog.getSamples();
ISampleSetManager.SampleSetLoadMode mode = null;
switch (returnCode) {
case SampleSetDialog.OK:
mode = ISampleSetManager.SampleSetLoadMode.ADD;
break;
case SampleSetDialog.REMOVE:
mode = ISampleSetManager.SampleSetLoadMode.REMOVE;
break;
case SampleSetDialog.REPLACE:
mode = ISampleSetManager.SampleSetLoadMode.REPLACE;
break;
default:
statusHandler.handle(Priority.PROBLEM,
"Load unknow return code: " + returnCode);
return;
}
for (int index : dialog.getSelectedSampleIdIndexes()) {
SampleId id = sampleIdList.get(index);
try {
dm.getSampleSetManager().loadSampleSet(id, mode);
} catch (GFEException e) {
statusHandler.handle(Priority.ERROR,
"Load failed for mode: " + mode.toString()
+ ", sample id: " + id.toString(), e);
}
}
}
}
}

View file

@ -0,0 +1,90 @@
/**
* 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.actions;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.core.DataManagerUIFactory;
import com.raytheon.viz.gfe.dialogs.SaveDeleteSampleSetDialog;
/**
* Action for launching delete samples dialog.
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 7, 2008 Eric Babin Initial Creation
* Jul 28, 2008 #1275. Eric Babin Remove inadvertent dispose on parent shell.
* Oct 24, 2012 #1287 rferrel Changes for non-blocking SampleSetDialog.
* Sep 15, 2014 #3592 randerso Renamed class, moved logic to dialog.
*
* </pre>
*
* @author ebabin
* @version 1.0
*/
public class ShowSaveDeleteSampleSetDialog extends AbstractHandler {
private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ShowSaveDeleteSampleSetDialog.class);
private SaveDeleteSampleSetDialog dialog;
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DataManager dm = DataManagerUIFactory.getCurrentInstance();
if (dm == null) {
return null;
}
if ((dialog == null) || (dialog.getShell() == null)
|| dialog.isDisposed()) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
String action = event.getParameter("Action");
dialog = new SaveDeleteSampleSetDialog(dm.getSampleSetManager(),
shell, action);
dialog.setBlockOnOpen(false);
dialog.open();
} else {
dialog.bringToTop();
}
return null;
}
}

View file

@ -1,113 +0,0 @@
/**
* 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.actions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.core.ISampleSetManager;
import com.raytheon.viz.gfe.dialogs.SampleSetDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
/**
* Action to show save sample set dialog.
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 7, 2008 Eric Babin Initial Creation
* Oct 24, 2012 1287 rferrel Changes for non-blocking SampleSetDialog.
*
* </pre>
*
* @author ebabin
* @version 1.0
*/
public class ShowSaveSampleSetDialog extends AbstractHandler {
private SampleSetDialog dialog;
private ISampleSetManager sampleMgr;
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
sampleMgr = DataManager.getCurrentInstance().getSampleSetManager();
ArrayList<SampleId> sampleIdList = sampleMgr.getInventoryAsList();
Collections.sort(sampleIdList, new Comparator<SampleId>() {
@Override
public int compare(SampleId o1, SampleId o2) {
return o1.getName().compareTo(o2.getName());
}
});
dialog = new SampleSetDialog(shell, sampleIdList,
SampleSetDialog.SAVE);
dialog.setBlockOnOpen(false);
dialog.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof Integer) {
int returnCode = (Integer) returnValue;
doDialogClose(returnCode);
}
dialog = null;
}
});
dialog.open();
} else {
dialog.bringToTop();
}
return null;
}
private void doDialogClose(int returnCode) {
if ((returnCode == SampleSetDialog.OK)
&& (dialog.getSelectedSampleIdIndexes() != null)
&& (dialog.getSampleName() != null)) {
sampleMgr.saveActiveSampleSet(new SampleId(dialog.getSampleName()));
}
}
}

View file

@ -20,12 +20,10 @@
package com.raytheon.viz.gfe.core;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.viz.gfe.GFEException;
import com.raytheon.viz.gfe.core.msgs.ISampleSetChangedListener;
import com.raytheon.viz.gfe.edittool.GridID;
import com.vividsolutions.jts.geom.Coordinate;
@ -39,15 +37,33 @@ import com.vividsolutions.jts.geom.Coordinate;
* ------------ ---------- ----------- --------------------------
* Jun 30, 2008 chammack Initial creation
* Apr 09, 2009 1288 rjpeter Added add/remove method for sample set listener
* Sep 09, 2014 3592 randerso Added dispose method, removed networkNotification method
* Sep 09, 2014 3592 randerso Added dispose method,
* removed getInventoryAsList and networkNotification,
* improved JavaDoc
* </pre>
*
* @author chammack
* @version 1.0
*/
public interface ISampleSetManager {
/**
* Sample Set Load Mode
*/
public static enum SampleSetLoadMode {
ADD, REMOVE, REPLACE
/**
* Add sample set to existing sample points
*/
ADD,
/**
* Remove sample set from existing sample points
*/
REMOVE,
/**
* Replase existing sample points with sample set
*/
REPLACE
}
public static final float DEFAULT_THRESHOLD = 0.0f;
@ -64,8 +80,7 @@ public interface ISampleSetManager {
* @param setName
* @return the locations
*/
public List<Coordinate> sampleSetLocations(final String setName)
throws GFEException;
public List<Coordinate> sampleSetLocations(final String setName);
/**
* Loads the named sample set and mixes it with the active sample set in a
@ -81,7 +96,7 @@ public interface ISampleSetManager {
* @param loadMode
*/
public void loadSampleSet(final SampleId sampleId,
SampleSetLoadMode loadMode) throws GFEException;
SampleSetLoadMode loadMode);
/**
* Clears all anchored samples.
@ -211,13 +226,6 @@ public interface ISampleSetManager {
*/
public SampleId[] getInventory();
/**
* Return the inventory as a list
*
* @return the inventory
*/
public ArrayList<SampleId> getInventoryAsList();
/**
* @return the inventory
*/

View file

@ -29,6 +29,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.geotools.referencing.GeodeticCalculator;
@ -55,6 +57,7 @@ import com.raytheon.viz.gfe.GFEException;
import com.raytheon.viz.gfe.core.ISampleSetManager;
import com.raytheon.viz.gfe.core.msgs.ISampleSetChangedListener;
import com.raytheon.viz.gfe.edittool.GridID;
import com.raytheon.viz.gfe.ui.AccessMgr;
import com.vividsolutions.jts.geom.Coordinate;
/**
@ -69,7 +72,9 @@ import com.vividsolutions.jts.geom.Coordinate;
* Apr 9, 2009 1288 rjpeter Added ISampleSetChangedListener handling.
* Aug 6, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles()
* Sep 30, 2013 2361 njensen Use JAXBManager for XML
* Sep 08, 2104 #3592 randerso Changed to use new pm listStaticFiles()
* Sep 08, 2104 #3592 randerso Changed to use new pm listStaticFiles().
* Reworked inventory to use a map to better handle
* files at multiple localization levels
* </pre>
*
* @author rbell
@ -88,7 +93,7 @@ public class SampleSetManager implements ISampleSetManager,
private SampleId loadedSet;
private Set<SampleId> inventory;
private SortedMap<String, SampleId> inventory;
private ArrayList<Coordinate> locations;
@ -110,7 +115,7 @@ public class SampleSetManager implements ISampleSetManager,
public SampleSetManager() {
this.loadedSet = new SampleId();
this.inventory = new HashSet<SampleId>();
this.inventory = new TreeMap<String, SampleId>();
this.locations = new ArrayList<Coordinate>();
@ -129,10 +134,11 @@ public class SampleSetManager implements ISampleSetManager,
LocalizationType.COMMON_STATIC, SAMPLE_SETS_DIR,
new String[] { ".xml" }, true, true);
for (LocalizationFile file : files) {
String fn = LocalizationUtil.extractName(file.getName()).replace(
for (LocalizationFile lf : files) {
String name = LocalizationUtil.extractName(lf.getName()).replace(
".xml", "");
this.inventory.add(new SampleId(fn));
this.inventory.put(name, new SampleId(name, false, lf.getContext()
.getLocalizationLevel()));
}
this.sampleSetDir.addFileUpdatedObserver(this);
@ -140,9 +146,9 @@ public class SampleSetManager implements ISampleSetManager,
String[] sampleSets = Activator.getDefault().getPreferenceStore()
.getStringArray("DefaultSamples");
if (sampleSets != null) {
for (String id : sampleSets) {
SampleId sid = new SampleId(id);
if (this.inventory.contains(sid)) {
for (String name : sampleSets) {
SampleId sid = inventory.get(name);
if (sid != null) {
loadSampleSet(sid, SampleSetLoadMode.ADD);
}
}
@ -171,31 +177,27 @@ public class SampleSetManager implements ISampleSetManager,
@Override
public List<Coordinate> sampleSetLocations(final String setName) {
// verify set in inventory
boolean found = false;
for (SampleId thisId : this.inventory) {
if (setName.equals(thisId.getName())) {
found = true;
break;
}
}
SampleId sampleId = this.inventory.get(setName);
if (!found) {
if (sampleId == null) {
statusHandler
.error("Attempt to get locations for unknown sample set ["
+ setName + "]");
return Collections.emptyList();
}
String fileName = FileUtil.join(SAMPLE_SETS_DIR, setName + ".xml");
String fileName = FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName()
+ ".xml");
LocalizationFile file = PathManagerFactory.getPathManager()
.getStaticLocalizationFile(fileName);
LocalizationFile lf = this.pathManager.getLocalizationFile(
this.pathManager.getContext(LocalizationType.COMMON_STATIC,
sampleId.getAccess()), fileName);
File f = null;
File file = null;
try {
f = file.getFile(true);
file = lf.getFile(true);
} catch (LocalizationException e) {
if (f == null) {
if (file == null) {
statusHandler.error("An error occurred retrieving SampleSet: "
+ fileName, e);
return Collections.emptyList();
@ -205,9 +207,9 @@ public class SampleSetManager implements ISampleSetManager,
SampleData sampleData = null;
try {
sampleData = SampleData.getJAXBManager().unmarshalFromXmlFile(
f.getAbsolutePath());
file.getAbsolutePath());
} catch (Exception e) {
statusHandler.error("Unable to load sampledata: " + f, e);
statusHandler.error("Unable to load sampledata: " + file, e);
return Collections.emptyList();
}
@ -225,8 +227,8 @@ public class SampleSetManager implements ISampleSetManager,
@Override
public void loadSampleSet(final SampleId sampleId,
SampleSetLoadMode loadMode) {
File f = PathManagerFactory.getPathManager().getStaticFile(
FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName() + ".xml"));
File f = this.pathManager.getStaticFile(FileUtil.join(SAMPLE_SETS_DIR,
sampleId.getName() + ".xml"));
SampleData sampleData = null;
try {
@ -414,12 +416,10 @@ public class SampleSetManager implements ISampleSetManager,
SampleData sd = new SampleData(sampleId, sampleLocations);
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = this.pathManager.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.USER);
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.USER);
LocalizationFile file = pm.getLocalizationFile(lc,
LocalizationFile file = this.pathManager.getLocalizationFile(lc,
FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName() + ".xml"));
try {
@ -459,27 +459,25 @@ public class SampleSetManager implements ISampleSetManager,
*/
@Override
public boolean deleteSampleSet(final SampleId sampleId) {
LocalizationFile file = PathManagerFactory.getPathManager()
.getStaticLocalizationFile(
FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName()
+ ".xml"));
LocalizationContext context = file.getContext();
if (context.getLocalizationLevel() != LocalizationLevel.USER) {
statusHandler.handle(Priority.PROBLEM, "Unable to delete "
+ sampleId.getName()
+ ", because it is not a sampleset owned by you.");
return false;
LocalizationContext ctx = this.pathManager.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.USER);
LocalizationFile lf = this.pathManager.getLocalizationFile(ctx,
FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName() + ".xml"));
if ((lf != null)
&& (AccessMgr.verifyDelete(lf.getName(),
LocalizationType.COMMON_STATIC, false))) {
try {
lf.delete();
return true;
} catch (LocalizationException e) {
statusHandler.handle(Priority.PROBLEM, "Unable to sample set "
+ sampleId.getName() + " from server.", e);
}
}
try {
file.delete();
} catch (LocalizationOpFailedException e) {
statusHandler.handle(Priority.PROBLEM,
"Error deleting from localization server", e);
}
return true;
return false;
}
/*
@ -494,19 +492,24 @@ public class SampleSetManager implements ISampleSetManager,
String name = LocalizationUtil.extractName(message.getFileName())
.replace(".xml", "");
SampleId id = new SampleId(name);
SampleId id = new SampleId(name, false, message.getContext()
.getLocalizationLevel());
switch (message.getChangeType()) {
case ADDED:
case UPDATED:
this.inventory.add(id);
SampleId existing = this.inventory.get(id.getName());
if ((existing == null)
|| (existing.getAccess().compareTo(id.getAccess()) <= 0)) {
this.inventory.put(id.getName(), id);
// loaded sample set "added", may simply be a rename
if (id.getName().equals(this.loadedSet.getName())) {
loadSampleSet(id, SampleSetLoadMode.REPLACE);
}
if (id.getName().equals(SampleSetManager.MARKER_NAME)) {
getMarkerPoints();
// loaded sample set "added", may simply be a rename
if (id.getName().equals(this.loadedSet.getName())) {
loadSampleSet(id, SampleSetLoadMode.REPLACE);
}
if (id.getName().equals(SampleSetManager.MARKER_NAME)) {
getMarkerPoints();
}
}
break;
@ -515,13 +518,15 @@ public class SampleSetManager implements ISampleSetManager,
LocalizationType.COMMON_STATIC, message.getFileName(),
new String[] { ".xml" }, false, true);
if (files.length == 0) {
this.inventory.remove(id.getName());
} else {
this.inventory.put(id.getName(), new SampleId(id.getName(),
false, files[0].getContext().getLocalizationLevel()));
}
if (id.getName().equals(this.loadedSet.getName())) {
if (files.length > 0) {
loadSampleSet(id, SampleSetLoadMode.REPLACE);
} else {
this.inventory.remove(id);
this.loadedSet = new SampleId();
}
this.loadedSet = new SampleId();
}
if (id.getName().equals(SampleSetManager.MARKER_NAME)) {
@ -608,11 +613,9 @@ public class SampleSetManager implements ISampleSetManager,
// ensure it is in the inventory
this.markerLocations.clear();
for (Iterator<SampleId> it = this.inventory.iterator(); it.hasNext();) {
SampleId id = it.next();
if (id.getName().startsWith(MARKER_NAME)) {
markerLocations.put(id.getName(),
this.sampleSetLocations(id.getName()));
for (String name : this.inventory.keySet()) {
if (name.startsWith(MARKER_NAME)) {
markerLocations.put(name, this.sampleSetLocations(name));
}
}
}
@ -634,21 +637,8 @@ public class SampleSetManager implements ISampleSetManager,
*/
@Override
public SampleId[] getInventory() {
return this.inventory.toArray(new SampleId[this.inventory.size()]);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getInventoryAsList()
*/
@Override
public ArrayList<SampleId> getInventoryAsList() {
ArrayList<SampleId> ids = new ArrayList<SampleId>();
for (SampleId id : this.inventory) {
ids.add(id);
}
return ids;
return this.inventory.values().toArray(
new SampleId[this.inventory.size()]);
}
/*
@ -660,9 +650,8 @@ public class SampleSetManager implements ISampleSetManager,
public String[] getInventoryAsStrings() {
String[] retVal = new String[this.inventory.size()];
int i = 0;
for (SampleId id : this.inventory) {
retVal[i] = id.getName();
i++;
for (String name : this.inventory.keySet()) {
retVal[i++] = name;
}
return retVal;
@ -721,6 +710,15 @@ public class SampleSetManager implements ISampleSetManager,
}
/**
* Load sample set (for Python use)
*
* @param sampleId
* id of sample set to load
* @param loadMode
* load mode
* @throws GFEException
*/
public void loadSampleSet(final SampleId sampleId, String loadMode)
throws GFEException {
loadSampleSet(sampleId, SampleSetLoadMode.valueOf(loadMode));

View file

@ -0,0 +1,161 @@
/**
* 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.dialogs;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.viz.gfe.core.ISampleSetManager;
import com.raytheon.viz.gfe.core.ISampleSetManager.SampleSetLoadMode;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
/**
* Dialog for selecting sample sets to load
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 15, 2014 #3592 randerso Re-implemented to match A1
*
* </pre>
*
* @author randerso
* @version 1.0
*/
public class LoadSampleSetDialog extends CaveJFACEDialog {
private static final int ADD_ID = IDialogConstants.CLIENT_ID;
private static final int REMOVE_ID = IDialogConstants.CLIENT_ID + 1;
private static final int REPLACE_ID = IDialogConstants.CLIENT_ID + 2;
private ISampleSetManager sampleSetMgr;
private String[] sets;
private List sampleSetList;
public LoadSampleSetDialog(ISampleSetManager sampleSetMgr, Shell parent) {
super(parent);
this.sampleSetMgr = sampleSetMgr;
this.sets = this.sampleSetMgr.getInventoryAsStrings();
}
@Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
Label label = new Label(comp, SWT.NONE);
GridData layoutData = new GridData(SWT.DEFAULT, SWT.DEFAULT, false,
false);
label.setLayoutData(layoutData);
label.setText("Sample Set Name(s)");
sampleSetList = new List(comp, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL
| SWT.MULTI);
layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
sampleSetList.setLayoutData(layoutData);
sampleSetList.setItems(sets);
return comp;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
* .Shell)
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Load Sample Set");
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButton(parent, ADD_ID, "Add", false);
super.createButton(parent, REMOVE_ID, "Remove", false);
super.createButton(parent, REPLACE_ID, "Replace", false);
super.createButton(parent, IDialogConstants.CANCEL_ID, "Cancel", false);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
*/
@Override
protected void buttonPressed(int buttonId) {
SampleSetLoadMode mode;
switch (buttonId) {
case ADD_ID:
mode = SampleSetLoadMode.ADD;
break;
case REPLACE_ID:
mode = SampleSetLoadMode.REPLACE;
break;
case REMOVE_ID:
mode = SampleSetLoadMode.REMOVE;
break;
default:
super.cancelPressed();
return;
}
action(mode);
super.okPressed();
}
private void action(SampleSetLoadMode mode) {
for (int index : sampleSetList.getSelectionIndices()) {
String name = sampleSetList.getItem(index);
SampleId id = new SampleId(name);
if (id.isValid()) {
sampleSetMgr.loadSampleSet(id, mode);
}
/*
* REPLACE with multiple entries needs to ADD after the first one to
* have the effect of replacing the currently loaded Samples with
* the set of selected samples. If actionType is REPLACE, set
* actionType to ADD for second and subsequent entries.
*/
if (mode.equals(SampleSetLoadMode.REPLACE)) {
mode = SampleSetLoadMode.ADD;
}
}
}
}

View file

@ -1,227 +0,0 @@
/**
* 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.dialogs;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
/**
* The sample set dialog.
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 7, 2008 Eric Babin Initial Creation
* Oct 24, 2012 1287 rferrel Code clean up for non-blocking dialog.
*
* </pre>
*
* @author ebabin
* @version 1.0
*/
public class SampleSetDialog extends CaveJFACEDialog {
public final static int LOAD = 1;
public final static int SAVE = 2;
public final static int DELETE = 3;
public final static int OK = 97;
public final static int REMOVE = 98;
public final static int REPLACE = 99;
public final static int CANCEL = Window.CANCEL;
private Composite top;
private java.util.List<SampleId> samples;
private List sampleSetList;
private Text identifierField;
private String sampleName;
private int[] selectedSamples;
private int returnCode = CANCEL;
private int type;
public SampleSetDialog(Shell parent, java.util.List<SampleId> samples,
int type) {
super(parent);
this.setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS);
this.samples = samples;
this.type = type;
}
private void initializeComponents() {
Label lab = new Label(top, SWT.NONE);
lab.setText("Sample Set Name(s)");
if (type == SampleSetDialog.LOAD) {
sampleSetList = new List(top, SWT.BORDER | SWT.V_SCROLL
| SWT.H_SCROLL | SWT.MULTI);
} else {
sampleSetList = new List(top, SWT.BORDER | SWT.V_SCROLL
| SWT.H_SCROLL | SWT.SINGLE);
}
for (SampleId sample : samples) {
sampleSetList.add(sample.getName());
}
sampleSetList.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
selectedSamples = sampleSetList.getSelectionIndices();
if (identifierField != null
&& sampleSetList.getSelectionIndex() != -1) {
identifierField.setText(sampleSetList.getItem(sampleSetList
.getSelectionIndex()));
}
}
});
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
sampleSetList.setLayoutData(data);
if (type != SampleSetDialog.LOAD) {
Label processOn = new Label(top, SWT.NONE);
processOn.setText("Identifier");
if (type == SampleSetDialog.DELETE) {
identifierField = new Text(top, SWT.BORDER | SWT.READ_ONLY);
} else {
identifierField = new Text(top, SWT.BORDER);
}
identifierField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent arg0) {
selectedSamples = sampleSetList.getSelectionIndices();
sampleName = identifierField.getText();
}
});
identifierField
.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
}
@Override
protected void buttonPressed(int buttonId) {
returnCode = buttonId;
super.buttonPressed(Window.OK);
}
@Override
protected Control createDialogArea(Composite parent) {
top = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout(1, true);
top.setLayout(layout);
initializeComponents();
return top;
}
@Override
public int getReturnCode() {
return returnCode;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
* .Shell)
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
if (type == SampleSetDialog.LOAD) {
shell.setText("Load Sample Set");
} else if (type == SampleSetDialog.SAVE) {
shell.setText("Save Sample Set");
} else if (type == SampleSetDialog.DELETE) {
shell.setText("Delete Sample Set");
}
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
if (type == SampleSetDialog.LOAD) {
super.createButton(parent, OK, "Add", false);
super.createButton(parent, REMOVE, "Remove", false);
super.createButton(parent, REPLACE, "Replace", true);
super.createButton(parent, CANCEL, "Cancel", true);
} else if (type == SampleSetDialog.SAVE) {
super.createButton(parent, OK, "Save", false);
super.createButton(parent, CANCEL, "Cancel", false);
} else if (type == SampleSetDialog.DELETE) {
super.createButton(parent, OK, "Delete", false);
super.createButton(parent, CANCEL, "Cancel", false);
}
}
public int[] getSelectedSampleIdIndexes() {
return selectedSamples;
}
public int getType() {
return type;
}
public String getSampleName() {
return sampleName;
}
public void setSampleName(String sampleName) {
this.sampleName = sampleName;
}
public java.util.List<SampleId> getSamples() {
return samples;
}
}

View file

@ -0,0 +1,238 @@
/**
* 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.dialogs;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.viz.gfe.core.ISampleSetManager;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
/**
* Dialog for selecting sample sets to save or delete
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 07, 2008 Eric Babin Initial Creation
* Oct 24, 2012 1287 rferrel Code clean up for non-blocking dialog.
* Sep 15, 2014 3592 randerso Re-implemented to match A1
*
* </pre>
*
* @author ebabin
* @version 1.0
*/
public class SaveDeleteSampleSetDialog extends CaveJFACEDialog {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(SaveDeleteSampleSetDialog.class);
private ISampleSetManager sampleSetMgr;
private String optionStr;
private SortedSet<String> sets;
private Set<String> protectedSets;
private List sampleSetList;
private Text identifierField;
/**
* Constructor
*
* @param sampleSetMgr
* SampleSetManager to use
* @param parent
* parent shell for dialog
* @param optionStr
* "Save" or "Delete"
*/
public SaveDeleteSampleSetDialog(ISampleSetManager sampleSetMgr,
Shell parent, String optionStr) {
super(parent);
this.sampleSetMgr = sampleSetMgr;
this.optionStr = optionStr;
this.sets = new TreeSet<String>();
this.protectedSets = new HashSet<String>();
SampleId[] sampleIDs = this.sampleSetMgr.getInventory();
if (this.optionStr.equals("Save")) {
for (SampleId id : sampleIDs) {
if (!id.isProtected()) {
this.sets.add(id.getName());
} else {
this.protectedSets.add(id.getName());
}
}
}
// delete mode
else {
for (SampleId id : sampleIDs) {
if (!id.isProtected()
&& id.getAccess().equals(LocalizationLevel.USER)) {
this.sets.add(id.getName());
} else {
this.protectedSets.add(id.getName());
}
}
}
}
@Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
Group group = new Group(comp, SWT.NONE);
group.setLayout(new GridLayout());
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
group.setLayoutData(layoutData);
group.setLayout(new GridLayout(1, false));
group.setText("Sample Set Name");
sampleSetList = new List(group, SWT.BORDER | SWT.V_SCROLL
| SWT.H_SCROLL | SWT.SINGLE);
layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
sampleSetList.setLayoutData(layoutData);
if (!sets.isEmpty()) {
sampleSetList.setItems(sets.toArray(new String[sets.size()]));
sampleSetList.select(0);
sampleSetList.deselectAll();
}
sampleSetList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
identifierField.setText(sampleSetList.getItem(sampleSetList
.getSelectionIndex()));
}
});
Label label = new Label(group, SWT.NONE);
layoutData = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
label.setLayoutData(layoutData);
label.setText("Identifier");
if (this.optionStr.equals("Save")) {
identifierField = new Text(group, SWT.BORDER);
} else {
identifierField = new Text(group, SWT.BORDER | SWT.READ_ONLY);
}
layoutData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
identifierField.setLayoutData(layoutData);
return group;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
* .Shell)
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
if (this.optionStr.equals("Save")) {
shell.setText("Save Sample Set");
} else {
shell.setText("Delete Sample Set");
}
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButton(parent, IDialogConstants.OK_ID, this.optionStr,
false);
super.createButton(parent, IDialogConstants.CANCEL_ID, "Cancel", false);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
String name = this.identifierField.getText();
if (this.optionStr.equals("Save")) {
saveSample(name);
} else {
deleteSample(name);
}
super.okPressed();
}
private void saveSample(String name) {
SampleId id = new SampleId(name);
if (id.isValid() && !this.protectedSets.contains(name)) {
// LogStream.logUse("Save", name);
this.sampleSetMgr.saveActiveSampleSet(id);
} else {
String message = "Sample Set " + name + " is protected "
+ "or an invalid name. ";
statusHandler.handle(Priority.SIGNIFICANT, message);
}
}
private void deleteSample(String name) {
SampleId id = new SampleId(name);
if (id.isValid() && !this.protectedSets.contains(name)
&& this.sets.contains(name)) {
// LogStream.logUse("Delete", name);
this.sampleSetMgr.deleteSampleSet(id);
} else {
String message = "Sample Set " + name + " is protected "
+ "or an invalid name. ";
statusHandler.handle(Priority.SIGNIFICANT, message);
}
}
}

View file

@ -20,6 +20,10 @@
package com.raytheon.viz.gfe.ui;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.dialogs.MessageDialog;
@ -40,7 +44,9 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 10, 2010 #4727 randerso Initial creation
* Jun 10, 2010 #4727 randerso Initial creation
* Sep 15, 2014 #3592 randerso Fix logic to not include USER level.
* Code cleanup.
*
* </pre>
*
@ -66,33 +72,24 @@ public class AccessMgr {
IPathManager pm = PathManagerFactory.getPathManager();
Map<LocalizationLevel, LocalizationFile> tieredData = pm
.getTieredLocalizationFile(type, itemName);
tieredData.remove(LocalizationLevel.USER);
StringBuilder kind = new StringBuilder();
int i = 1;
for (LocalizationLevel level : tieredData.keySet()) {
if (i == 1) {
kind.append(level.toString());
} else if (i == tieredData.size()) {
kind.append(" and ").append(level.toString());
} else {
kind.append(", ").append(level.toString());
}
i++;
}
List<LocalizationLevel> availableLevels = new ArrayList<LocalizationLevel>(
Arrays.asList(pm.getAvailableLevels()));
availableLevels.remove(LocalizationLevel.USER);
boolean continueFlag = false;
boolean answer = false;
String message;
if (kind.length() == 0) {
message = "There is no version of " + altName
+ " at the BASE, CONFIGURED, or SITE levels.";
if (tieredData.isEmpty()) {
message = "There is no version of " + altName + " at the "
+ levelString(availableLevels) + " levels.";
} else {
message = "Note that " + altName
+ " will continue to appear in your "
+ "GFESuite since a version of it exists " + "at the "
+ kind + " level.";
+ levelString(tieredData.keySet()) + " level.";
continueFlag = true;
}
message = altName + " will be deleted. \n\n" + message;
@ -104,4 +101,25 @@ public class AccessMgr {
}
return answer;
}
private static String levelString(Collection<LocalizationLevel> levels) {
StringBuilder kind = new StringBuilder();
int i = 1;
for (LocalizationLevel level : levels) {
if (level.equals(LocalizationLevel.USER)) {
continue;
}
if (i == 1) {
kind.append(level.toString());
} else if (i == levels.size()) {
kind.append(" and ").append(level.toString());
} else {
kind.append(", ").append(level.toString());
}
i++;
}
return kind.toString();
}
}

View file

@ -20,7 +20,6 @@
package com.raytheon.uf.common.dataplugin.gfe.sample;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* Contains the identifier to uniquely identify a SampleData set.
@ -29,7 +28,8 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 14, 2008 879 rbell Initial creation
* Apr 14, 2008 879 rbell Initial creation
* Sep 15, 2014 #3592 randerso Code cleanup, JavaDoc improvement
*
* </pre>
*
@ -37,7 +37,7 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
* @version 1.0
*/
public class SampleId implements Cloneable, ISerializableObject {
public class SampleId implements Cloneable {
private String name;
@ -52,8 +52,13 @@ public class SampleId implements Cloneable, ISerializableObject {
this((String) null);
}
public SampleId(String aName) {
this(aName, false, LocalizationLevel.UNKNOWN);
/**
* Constructor taking the name to uniquely identify this sample data.
*
* @param name
*/
public SampleId(String name) {
this(name, false, LocalizationLevel.UNKNOWN);
}
/**
@ -64,11 +69,10 @@ public class SampleId implements Cloneable, ISerializableObject {
* @param protect
* @param access
*/
public SampleId(final String aName, boolean aProtect,
LocalizationLevel anAccess) {
this.name = aName;
this.protect = aProtect;
this.access = anAccess;
public SampleId(final String name, boolean protect, LocalizationLevel access) {
this.name = name;
this.protect = protect;
this.access = access;
}
/**
@ -118,11 +122,11 @@ public class SampleId implements Cloneable, ISerializableObject {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
result = (prime * result)
+ ((this.access == null) ? 0 : this.access.hashCode());
result = prime * result
result = (prime * result)
+ ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + (this.protect ? 1231 : 1237);
result = (prime * result) + (this.protect ? 1231 : 1237);
return result;
}