Issue #2000 Subscription overlap configuration GUI

Amend:
  Peer review comments.

Change-Id: Ie951ca4ce61099d0e25ed4938fc71981f34833d6

Former-commit-id: 095acb5ac3 [formerly 554347f17c] [formerly 5b62669f8e] [formerly 38249cd7b9 [formerly 5b62669f8e [formerly c7ad25ab90220a2aa25e704b10c9a7a96af2a8a8]]]
Former-commit-id: 38249cd7b9
Former-commit-id: 97b3d509a5df6b5067753a00490a5ec5d5462760 [formerly 7858a3b57f]
Former-commit-id: 3a504d1e7b
This commit is contained in:
Dustin Johnson 2013-05-16 13:04:36 -05:00
parent f186912fe1
commit 4d30dc16c6
19 changed files with 1499 additions and 1058 deletions

View file

@ -26,13 +26,13 @@
</bean>
<bean name="dataDeliveryServices"
class="com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices"
factory-method="getInstance">
<property name="subscriptionService" ref="subscriptionService" />
<property name="subscriptionNotificationService" ref="subscriptionNotificationService" />
<property name="bandwidthService" ref="bandwidthService" />
<property name="permissionsService" ref="permissionsService" />
<property name="groupDefinitionService" ref="groupDefinitionService" />
class="com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices">
<constructor-arg ref="subscriptionService" />
<constructor-arg ref="subscriptionNotificationService" />
<constructor-arg ref="bandwidthService" />
<constructor-arg ref="permissionsService" />
<constructor-arg ref="groupDefinitionService" />
<constructor-arg ref="subscriptionOverlapService" />
</bean>
<bean id="systemRuleManager"

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.viz.datadelivery.services;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthService;
import com.raytheon.uf.common.datadelivery.service.IGroupDefinitionService;
import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService;
import com.raytheon.uf.common.datadelivery.service.subscription.ISubscriptionOverlapService;
import com.raytheon.uf.viz.datadelivery.subscription.IPermissionsService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
@ -36,7 +37,8 @@ import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 9, 2012 1286 djohnson Initial creation
* Nov 09, 2012 1286 djohnson Initial creation
* May 20, 2013 2000 djohnson Add subscription overlap service.
*
* </pre>
*
@ -46,32 +48,33 @@ import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
public final class DataDeliveryServices {
private static final DataDeliveryServices INSTANCE = new DataDeliveryServices();
private static IBandwidthService bandwidthService;
private IBandwidthService bandwidthService;
private static ISubscriptionService subscriptionService;
private ISubscriptionService subscriptionService;
private static ISubscriptionNotificationService subscriptionNotificationService;
private ISubscriptionNotificationService subscriptionNotificationService;
private static IPermissionsService permissionsService;
private IPermissionsService permissionsService;
private static IGroupDefinitionService groupDefinitionService;
private IGroupDefinitionService groupDefinitionService;
private static ISubscriptionOverlapService subscriptionOverlapService;
/**
* Disabled constructor.
* Spring only constructor. All access should be through static methods.
*/
private DataDeliveryServices() {
}
/**
* Used by Spring to populate the various services. Non Spring code should
* use the static getter methods to retrieve services.
*
* @return the instance
*/
public static DataDeliveryServices getInstance() {
return INSTANCE;
private DataDeliveryServices(IBandwidthService bandwidthService,
ISubscriptionService subscriptionService,
ISubscriptionNotificationService subscriptionNotificationService,
IPermissionsService permissionsService,
IGroupDefinitionService groupDefinitionService,
ISubscriptionOverlapService subscriptionOverlapService) {
DataDeliveryServices.bandwidthService = bandwidthService;
DataDeliveryServices.subscriptionService = subscriptionService;
DataDeliveryServices.subscriptionNotificationService = subscriptionNotificationService;
DataDeliveryServices.permissionsService = permissionsService;
DataDeliveryServices.groupDefinitionService = groupDefinitionService;
DataDeliveryServices.subscriptionOverlapService = subscriptionOverlapService;
}
/**
@ -80,17 +83,7 @@ public final class DataDeliveryServices {
* @return the subscriptionService the subscription service
*/
public static ISubscriptionService getSubscriptionService() {
return INSTANCE.subscriptionService;
}
/**
* Set the subscription service.
*
* @param subscriptionService
* the subscriptionService to set
*/
public void setSubscriptionService(ISubscriptionService subscriptionService) {
this.subscriptionService = subscriptionService;
return DataDeliveryServices.subscriptionService;
}
/**
@ -99,17 +92,7 @@ public final class DataDeliveryServices {
* @return the bandwidthService
*/
public static IBandwidthService getBandwidthService() {
return INSTANCE.bandwidthService;
}
/**
* Set the bandwidth service.
*
* @param bandwidthService
* the bandwidthService to set
*/
public void setBandwidthService(IBandwidthService bandwidthService) {
this.bandwidthService = bandwidthService;
return DataDeliveryServices.bandwidthService;
}
/**
@ -118,18 +101,7 @@ public final class DataDeliveryServices {
* @return the subscription notification service
*/
public static ISubscriptionNotificationService getSubscriptionNotificationService() {
return INSTANCE.subscriptionNotificationService;
}
/**
* Set the subscription notification service.
*
* @param subscriptionNotificationService
* the subscription notification service to set
*/
public void setSubscriptionNotificationService(
ISubscriptionNotificationService subscriptionNotificationService) {
this.subscriptionNotificationService = subscriptionNotificationService;
return DataDeliveryServices.subscriptionNotificationService;
}
/**
@ -138,17 +110,7 @@ public final class DataDeliveryServices {
* @return the permissions service
*/
public static IPermissionsService getPermissionsService() {
return INSTANCE.permissionsService;
}
/**
* Set the permissions service.
*
* @param permissionsService
* the permissionsService to set
*/
public void setPermissionsService(IPermissionsService permissionsService) {
this.permissionsService = permissionsService;
return DataDeliveryServices.permissionsService;
}
/**
@ -157,17 +119,15 @@ public final class DataDeliveryServices {
* @return the groupDefinitionService
*/
public static IGroupDefinitionService getGroupDefinitionService() {
return INSTANCE.groupDefinitionService;
return DataDeliveryServices.groupDefinitionService;
}
/**
* Set the group definition service.
* Get the subscription overlap service.
*
* @param groupDefinitionService
* the groupDefinitionService to set
* @return the subscriptionOverlapService
*/
public void setGroupDefinitionService(
IGroupDefinitionService groupDefinitionService) {
this.groupDefinitionService = groupDefinitionService;
public static ISubscriptionOverlapService getSubscriptionOverlapService() {
return DataDeliveryServices.subscriptionOverlapService;
}
}

View file

@ -0,0 +1,187 @@
/**
* 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.uf.viz.datadelivery.system;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
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.uf.common.util.StringUtil;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Subscription overlap configuration.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 14, 2013 2000 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class BandwidthTab extends SystemApplyCancelTab {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(BandwidthTab.class);
/** Available bandwidth spinner widget */
private Spinner availBandwidthSpinner;
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
*/
public BandwidthTab(Composite parentComp) {
super(parentComp);
}
/**
* Get the tab text.
*
* @return the tab text
*/
@Override
public String getTabText() {
return "Bandwidth";
}
/**
* {@inheritDoc}
*/
@Override
protected void initializeTabComponents(Composite mainComp) {
GridLayout gl = new GridLayout(1, false);
GridData gd = new GridData(SWT.VERTICAL, SWT.DEFAULT, true, false);
Composite configurationComposite = new Composite(mainComp,
SWT.NONE);
configurationComposite.setLayout(gl);
configurationComposite.setLayoutData(gd);
// Label for directions
gd = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
Label directionsLabel = new Label(configurationComposite, SWT.NONE);
directionsLabel.setLayoutData(gd);
directionsLabel
.setText("Please enter the available bandwidth for the OPSNET network.");
gl = new GridLayout(2, false);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite outerComp = new Composite(configurationComposite, SWT.NONE);
outerComp.setLayoutData(gd);
outerComp.setLayout(gl);
// Bandwidth spinner
gd = new GridData(165, SWT.DEFAULT);
Label availBandwith = new Label(outerComp, SWT.NONE);
availBandwith.setLayoutData(gd);
availBandwith.setText("OPSNET Bandwidth (KB):");
final Spinner availBandwidthSpinner = new Spinner(outerComp, SWT.BORDER);
availBandwidthSpinner.setMinimum(0);
availBandwidthSpinner.setMaximum(10000);
availBandwidthSpinner.setToolTipText("Select bandwidth in Kilobytes");
this.availBandwidthSpinner = availBandwidthSpinner;
}
/**
* {@inheritDoc}
*/
@Override
protected void loadConfiguration() {
DataDeliveryGUIUtils.removeListeners(availBandwidthSpinner,
SWT.Selection, SWT.DefaultSelection);
final int availableBandwidth = SystemRuleManager
.getAvailableBandwidth(Network.OPSNET);
availBandwidthSpinner.setSelection(availableBandwidth);
availBandwidthSpinner.addSelectionListener(DataDeliveryGUIUtils
.addValueChangedSelectionListener(availableBandwidth,
availBandwidthSpinner, changesWereMade));
}
/**
* {@inheritDoc}
*/
@Override
protected boolean saveConfiguration() {
boolean changesApplied = false;
final int bandwidth = availBandwidthSpinner.getSelection();
Set<Subscription> unscheduledSubscriptions = SystemRuleManager
.setAvailableBandwidth(Network.OPSNET, bandwidth);
if (unscheduledSubscriptions.isEmpty()) {
changesApplied = true;
} else {
Set<String> subscriptionNames = new TreeSet<String>();
for (Subscription subscription : unscheduledSubscriptions) {
subscriptionNames.add(subscription.getName());
}
StringBuilder sb = new StringBuilder(StringUtil.createMessage(
"Changing the default bandwidth for " + Network.OPSNET
+ " will unschedule the following subscriptions:",
subscriptionNames));
sb.append(StringUtil.NEWLINE).append(StringUtil.NEWLINE);
sb.append("Would you like to change the bandwidth anyway?");
int response = DataDeliveryUtils.showMessage(parentComp.getShell(),
SWT.YES | SWT.NO, "Bandwidth Amount", sb.toString());
if (response == SWT.YES) {
changesApplied = SystemRuleManager.forceSetAvailableBandwidth(
Network.OPSNET, bandwidth);
if (!changesApplied) {
statusHandler
.handle(Priority.ERROR,
"Bandwidth Change",
"Unable to change the bandwidth for network "
+ Network.OPSNET
+ ". Please check the server for details.");
}
}
}
return changesApplied;
}
}

View file

@ -0,0 +1,294 @@
/**
* 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.uf.viz.datadelivery.system;
import java.util.EnumMap;
import java.util.Map.Entry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import com.raytheon.uf.common.datadelivery.service.subscription.ISubscriptionOverlapService;
import com.raytheon.uf.common.datadelivery.service.subscription.SubscriptionOverlapConfig;
import com.raytheon.uf.common.datadelivery.service.subscription.SubscriptionOverlapMatchStrategy;
import com.raytheon.uf.common.localization.exception.LocalizationException;
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.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
/**
* Subscription overlap configuration.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 14, 2013 2000 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class SubscriptionTab extends SystemApplyCancelTab {
private static enum OverlapSpinners {
PARAMETERS("Parameters:") {
@Override
public int getValue(SubscriptionOverlapConfig config) {
return config.getMaxAllowedParameterDuplication();
}
@Override
public void setValue(SubscriptionOverlapConfig config, int value) {
config.setMaxAllowedParameterDuplication(value);
}
},
FORECAST_HOURS("Forecast Hours:") {
@Override
public int getValue(SubscriptionOverlapConfig config) {
return config.getMaxAllowedForecastHourDuplication();
}
@Override
public void setValue(SubscriptionOverlapConfig config, int value) {
config.setMaxAllowedForecastHourDuplication(value);
}
},
CYCLES("Cycles:") {
@Override
public int getValue(SubscriptionOverlapConfig config) {
return config.getMaxAllowedCycleDuplication();
}
@Override
public void setValue(SubscriptionOverlapConfig config, int value) {
config.setMaxAllowedCycleDuplication(value);
}
},
SPATIAL("Spatial:") {
@Override
public int getValue(SubscriptionOverlapConfig config) {
return config.getMaxAllowedSpatialDuplication();
}
@Override
public void setValue(SubscriptionOverlapConfig config, int value) {
config.setMaxAllowedSpatialDuplication(value);
}
};
private String labelText;
private OverlapSpinners(String labelText) {
this.labelText = labelText;
}
/**
* Get the value from the configuration for this spinner.
*
* @param config
* the config
* @return the value
*/
public abstract int getValue(SubscriptionOverlapConfig config);
/**
* Set the configuration value from the spinner.
*
* @param config
* the configuration
* @param value
* the value
*/
public abstract void setValue(SubscriptionOverlapConfig config,
int value);
}
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SubscriptionTab.class);
private final ISubscriptionOverlapService overlapService = DataDeliveryServices
.getSubscriptionOverlapService();
/** Match strategy combo. */
private Combo matchStrategyCombo;
/** Associates the enum spinner configuration to its spinner */
private final EnumMap<OverlapSpinners, Spinner> spinnerMap = new EnumMap<SubscriptionTab.OverlapSpinners, Spinner>(
OverlapSpinners.class);
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
*/
public SubscriptionTab(Composite parentComp) {
super(parentComp);
}
/**
* {@inheritDoc}
*/
@Override
protected void loadConfiguration() {
SubscriptionOverlapConfig config;
try {
config = overlapService.readConfig();
} catch (LocalizationException e) {
statusHandler
.handle(Priority.ERROR,
"Unable to load the subscription overlap rules. "
+ "Defaulting to configuration that will never overlap.",
e);
config = SubscriptionOverlapConfig.NEVER_OVERLAPS;
}
for (Entry<OverlapSpinners, Spinner> entry : spinnerMap.entrySet()) {
final Spinner spinner = entry.getValue();
final int initialValue = entry.getKey().getValue(config);
DataDeliveryGUIUtils.removeListeners(spinner, SWT.Selection,
SWT.DefaultSelection);
spinner.setSelection(initialValue);
spinner.addSelectionListener(DataDeliveryGUIUtils
.addValueChangedSelectionListener(initialValue, spinner,
changesWereMade));
}
DataDeliveryGUIUtils.removeListeners(matchStrategyCombo, SWT.Selection,
SWT.DefaultSelection);
final int indexOfConfigValue = matchStrategyCombo.indexOf(config
.getMatchStrategy().getDisplayString());
matchStrategyCombo.select(indexOfConfigValue);
matchStrategyCombo.addSelectionListener(DataDeliveryGUIUtils
.addValueChangedSelectionListener(indexOfConfigValue,
matchStrategyCombo, changesWereMade));
}
/**
* {@inheritDoc}
*/
@Override
protected void initializeTabComponents(Composite mainComp) {
GridLayout gl = new GridLayout(1, false);
Composite configurationComposite = new Composite(mainComp, SWT.NONE);
configurationComposite.setLayout(gl);
// Label for directions
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
Label directionsLabel = new Label(configurationComposite, SWT.NONE);
directionsLabel.setLayoutData(gd);
directionsLabel
.setText("Please select a percentage of common items between two "
+ "\nsubscriptions that would cause the subscriptions to be "
+ "\nconsidered overlapping.\n");
gl = new GridLayout(2, false);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite outerComp = new Composite(configurationComposite, SWT.NONE);
outerComp.setLayoutData(gd);
outerComp.setLayout(gl);
for (final OverlapSpinners overlapSpinner : OverlapSpinners.values()) {
gl = new GridLayout(2, false);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite spinnerComp = new Composite(outerComp, SWT.NONE);
spinnerComp.setLayoutData(gd);
spinnerComp.setLayout(gl);
gd = new GridData(100, SWT.DEFAULT);
Label label = new Label(spinnerComp, SWT.NONE);
label.setLayoutData(gd);
label.setText(overlapSpinner.labelText);
gd = new GridData(100, SWT.DEFAULT);
final Spinner spinner = new Spinner(spinnerComp, SWT.BORDER);
spinner.setMinimum(0);
spinner.setMaximum(100);
spinnerMap.put(overlapSpinner, spinner);
}
Composite matchStrategyComposite = new Composite(outerComp, SWT.NONE);
gl = new GridLayout(2, false);
matchStrategyComposite.setLayout(gl);
gd = new GridData(100, SWT.DEFAULT);
Label label = new Label(matchStrategyComposite, SWT.NONE);
label.setLayoutData(gd);
label.setText("Match:");
// Match Strategy
matchStrategyCombo = new Combo(matchStrategyComposite, SWT.READ_ONLY);
matchStrategyCombo
.setToolTipText("Select the manner in which the rules should consider two subscriptions to overlap");
for (SubscriptionOverlapMatchStrategy matchStrategy : SubscriptionOverlapMatchStrategy
.values()) {
matchStrategyCombo.add(matchStrategy.getDisplayString());
}
}
/**
* {@inheritDoc}
*/
@Override
protected boolean saveConfiguration() throws LocalizationException {
SubscriptionOverlapConfig config = new SubscriptionOverlapConfig();
for (Entry<OverlapSpinners, Spinner> entry : spinnerMap.entrySet()) {
final OverlapSpinners key = entry.getKey();
key.setValue(config, entry.getValue().getSelection());
}
config.setMatchStrategy(SubscriptionOverlapMatchStrategy.values()[matchStrategyCombo
.getSelectionIndex()]);
overlapService.writeConfig(config);
return true;
}
/**
* Get the tab text.
*
* @return the tab text
*/
@Override
public String getTabText() {
return "Subscription Rules";
}
}

View file

@ -0,0 +1,220 @@
/**
* 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.uf.viz.datadelivery.system;
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.Button;
import org.eclipse.swt.widgets.Composite;
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.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Base class for a System Management tab that has an apply/cancel button
* combination.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 17, 2013 2000 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public abstract class SystemApplyCancelTab extends SystemTab {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SubscriptionTab.class);
/** Priority Composite */
private Composite mainComp;
/** Apply changes button. */
protected Button applyButton;
/** Cancel changes button. */
protected Button cancelButton;
/** Button Height. */
private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */
private final int buttonWidth = 70;
/** The listener that should be used to signify changes were made **/
protected final Runnable changesWereMade = new Runnable() {
@Override
public void run() {
enableButtons();
}
};
/**
* Constructor.
*
* @param parentComp
*/
protected SystemApplyCancelTab(Composite parentComp) {
super(parentComp);
}
/**
* Initialize the tab.
*/
@Override
public void init() {
createBaseTab();
createSideButtons();
loadConfiguration();
}
/**
* Create the base tab.
*/
private void createBaseTab() {
GridLayout gl = new GridLayout(2, false);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
mainComp = new Composite(parentComp, SWT.NONE);
mainComp.setLayout(gl);
mainComp.setLayoutData(gd);
initializeTabComponents(mainComp);
}
/**
* Create the move up/down controls
*/
private void createSideButtons() {
GridData actionData = new GridData(SWT.DEFAULT, SWT.CENTER, false, true);
GridLayout actionLayout = new GridLayout(1, false);
Composite actionComp = new Composite(mainComp, SWT.NONE);
actionComp.setLayout(actionLayout);
actionComp.setLayoutData(actionData);
GridData btnData = new GridData(buttonWidth, buttonHeight);
btnData.horizontalAlignment = SWT.RIGHT;
applyButton = new Button(actionComp, SWT.PUSH);
applyButton.setText("Apply");
applyButton.setLayoutData(btnData);
applyButton.setToolTipText("Apply changes");
applyButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (saveConfigurationChanges()) {
disableButtons();
}
}
});
btnData = new GridData(buttonWidth, buttonHeight);
btnData.horizontalAlignment = SWT.RIGHT;
cancelButton = new Button(actionComp, SWT.PUSH);
cancelButton.setText("Cancel");
cancelButton.setLayoutData(btnData);
cancelButton.setToolTipText("Cancel any changes");
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
loadConfiguration();
disableButtons();
}
});
btnData = new GridData(buttonWidth, buttonHeight);
btnData.horizontalAlignment = SWT.RIGHT;
Button invisibleButtonToAlignWithThreeButtonTabs = new Button(actionComp, SWT.PUSH);
invisibleButtonToAlignWithThreeButtonTabs.setText("");
invisibleButtonToAlignWithThreeButtonTabs.setLayoutData(btnData);
invisibleButtonToAlignWithThreeButtonTabs.setVisible(false);
disableButtons();
}
/**
* Save the configuration changes.
*
* @return true if the configuration changes were saved
*/
private boolean saveConfigurationChanges() {
boolean configurationSaved = false;
try {
configurationSaved = saveConfiguration();
if (configurationSaved) {
DataDeliveryUtils.showChangesWereAppliedMessage(parentComp
.getShell());
}
} catch (Exception e) {
statusHandler.handle(Priority.ERROR,
"Unable to save configuration changes.", e);
}
return configurationSaved;
}
private void enableButtons() {
applyButton.setEnabled(true);
cancelButton.setEnabled(true);
}
private void disableButtons() {
applyButton.setEnabled(false);
cancelButton.setEnabled(false);
}
/**
* Create the main tab components
*
* @param mainComp
* the main tab composite
*/
protected abstract void initializeTabComponents(Composite mainComp);
/**
* Load the configuration.
*/
protected abstract void loadConfiguration();
/**
* Save the user's configuration changes.
*
* @return true if the configuration was actually saved
*
* @throws Exception
* if the configuration cannot be saved
*/
protected abstract boolean saveConfiguration() throws Exception;
}

View file

@ -19,26 +19,11 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
import java.util.Collections;
import java.util.List;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* System Management Main Dialog.
@ -53,279 +38,51 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
* Jan 04, 2012 1420 mpduff Add delete rule function.
* Jan 14, 2013 1286 djohnson Rule list is single item selectable.
* May 17, 2013 2000 djohnson Consolidate duplicate code into {@link SystemRulesTab}.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public class SystemLatencyTab {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemLatencyTab.class);
private final String notAuthorizedMsg = " is not authorized to create, edit, or delete rules using the Data Delivery System Management\nPermission: ";
/** Parent Composite */
private final Composite parentComp;
/** Priority Composite */
private Composite latencyComp;
/** Create and edit rule dialog */
private CreateEditRuleDlg ruleDlg;
public class SystemLatencyTab extends SystemRulesTab {
/** Rule type constant */
private final String LATENCY_TYPE = "latency";
/** Available List widget */
private List latencyList;
/** Flag for create and edit. */
private boolean create;
/** Edit rule button. */
private Button editBtn;
/** New rule button. */
private Button newBtn;
/** Delete rule button. */
private Button deleteBtn;
/** Button Height. */
private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */
private final int buttonWidth = 70;
private static final String LATENCY_TYPE = "latency";
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
* the parent comp
*/
public SystemLatencyTab(Composite parentComp) {
this.parentComp = parentComp;
init();
super(parentComp, LATENCY_TYPE);
}
/**
* Initialize the tab.
*/
private void init() {
createLatencyRulesTab();
createSideButtons();
}
/**
* Create the bar that may be expanded depending on item count.
*/
private void createLatencyRulesTab() {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
GridLayout gl = new GridLayout(2, false);
latencyComp = new Composite(parentComp, SWT.NONE);
latencyComp.setLayout(gl);
gd.widthHint = 375;
gd.heightHint = 200;
latencyList = new List(latencyComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
latencyList.setLayoutData(gd);
latencyList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
enableButtons(latencyList.getSelectionCount() > 0);
}
});
loadList();
}
/**
* Create the move up/down controls
*/
private void createSideButtons() {
GridData actionData = new GridData(SWT.DEFAULT, SWT.CENTER, false, true);
GridLayout actionLayout = new GridLayout(1, false);
Composite actionComp = new Composite(latencyComp, SWT.NONE);
actionComp.setLayout(actionLayout);
actionComp.setLayoutData(actionData);
GridData btnData = new GridData(buttonWidth, buttonHeight);
newBtn = new Button(actionComp, SWT.PUSH);
newBtn.setText("New...");
newBtn.setLayoutData(btnData);
newBtn.setEnabled(true);
newBtn.setToolTipText("Create a new rule");
newBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = true;
handleLatencyRule();
if (latencyList.getItemCount() > 0) {
latencyList.select(0);
enableButtons(true);
} else {
enableButtons(false);
}
}
});
btnData = new GridData(buttonWidth, buttonHeight);
editBtn = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.setLayoutData(btnData);
editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = false;
int idx = latencyList.getSelectionIndex();
handleLatencyRule();
if (!latencyList.isDisposed()) {
latencyList.select(idx);
}
}
});
btnData = new GridData(buttonWidth, buttonHeight);
deleteBtn = new Button(actionComp, SWT.PUSH);
deleteBtn.setText("Delete...");
deleteBtn.setLayoutData(btnData);
deleteBtn.setEnabled(false);
deleteBtn.setToolTipText("Delete item selected in the list");
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
handleDeleteRule();
if (latencyList.getItemCount() > 0) {
latencyList.select(0);
}
}
});
}
/**
* Enable the buttons?
* Get the tab text.
*
* @param enable
* setting for the buttons
* @return the tab text
*/
private void enableButtons(boolean enable) {
deleteBtn.setEnabled(enable);
editBtn.setEnabled(enable);
@Override
public String getTabText() {
return "Latency Rules";
}
/**
* New/Edit latency rule action handler.
* {@inheritDoc}
*/
private void handleLatencyRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + notAuthorizedMsg + permission;
try {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (ruleDlg == null || ruleDlg.isDisposed()) {
// New
if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, LATENCY_TYPE);
} else {
// Edit
String ruleName = null;
int selectedIdx = latencyList.getSelectionIndex();
if (selectedIdx > -1) {
ruleName = latencyList.getItem(selectedIdx);
} else if (latencyList.getItemCount() <= 0) {
DataDeliveryUtils.showMessage(
parentComp.getShell(), SWT.ERROR,
"Create Rule", "Please create a rule.");
return;
} else {
DataDeliveryUtils.showMessage(
parentComp.getShell(), SWT.ERROR,
"Select Rule",
"Please select a rule for edit.");
return;
}
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleName, LATENCY_TYPE);
}
ruleDlg.open();
} else {
ruleDlg.bringToTop();
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
@Override
protected List<String> getRuleNames() {
return SystemRuleManager.getInstance().getLatencyRuleNames();
}
/**
* Delete rule action handler.
* {@inheritDoc}
*/
private void handleDeleteRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + notAuthorizedMsg + permission;
try {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
String ruleName = null;
int selectedIdx = latencyList.getSelectionIndex();
if (selectedIdx > -1) {
int answer = DataDeliveryUtils.showYesNoMessage(
parentComp.getShell(), "Delete?",
"Are you sure you want to delete this rule?");
if (answer == SWT.YES) {
ruleName = latencyList.getItem(selectedIdx);
SystemRuleManager.getInstance().deleteLatencyRule(
ruleName);
loadList();
if (latencyList.getItemCount() == 0) {
enableButtons(false);
}
}
} else {
DataDeliveryUtils.showMessage(parentComp.getShell(),
SWT.ERROR, "Select Rule",
"Please select a rule for delete.");
return;
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
}
/**
* Load the rule list.
*/
public void loadList() {
latencyList.removeAll();
// Get the list of latency rule names
java.util.List<String> rules = null;
rules = SystemRuleManager.getInstance().getLatencyRuleNames();
Collections.sort(rules, String.CASE_INSENSITIVE_ORDER);
latencyList.setItems(rules.toArray(new String[rules.size()]));
@Override
protected void deleteRule(String ruleName) {
SystemRuleManager.getInstance().deleteLatencyRule(ruleName);
}
}

View file

@ -19,10 +19,7 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@ -30,21 +27,13 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
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.uf.common.util.StringUtil;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.ForceApplyPromptResponse;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText;
@ -67,6 +56,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* Jan 04, 2013 1420 mpduff Remove applying of rules.
* Jan 17, 2013 1501 djohnson Close the dialog when force apply occurs,
* and check whether changes have already been applied when OK is pressed.
* May 17, 2013 2000 djohnson Move bandwidth configuration into its own tab, add subscription overlap rules.
*
* </pre>
*
@ -76,66 +66,11 @@ import com.raytheon.viz.ui.presenter.IDisplay;
public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
IForceApplyPromptDisplayText, IRulesUpdateListener {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemManagementDlg.class);
/** Enumeration to use for List of Data Routes */
public static enum DataRoutes {
/** Operations Network */
OPSNET("OpsNet");
/** Data Route */
private final String dataRoute;
private DataRoutes(String dataRoute) {
this.dataRoute = dataRoute;
}
/**
* Get data route.
*
* @return operation
*/
public String getRoute() {
return dataRoute;
}
@Override
public String toString() {
return dataRoute;
}
}
/** Data Route combination box */
private Combo dataRouteCombo;
/** TabFolder object */
private TabFolder tabFolder;
/** Priority Tab constant */
private final String PRIORITY_TAB = "priorityTab";
/** Latency Tab constant */
private final String LATENCY_TAB = "latencyTab";
/** Routing Tab constant */
private final String ROUTING_TAB = "routingTab";
/** Tab text map */
private final Map<String, String> tabTextMap = new HashMap<String, String>();
/** Apply button */
private Button applyBtn;
/** OK button */
private Button okBtn;
/** Available bandwidth modified flag */
private boolean availableBandwidthModified;
/** Available bandwidth spinner widget */
private Spinner availBandwidthSpinner;
private Button closeBtn;
/** The system latency tab */
private SystemLatencyTab lTab;
@ -143,6 +78,12 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
/** The system priority tab */
private SystemPriorityTab pTab;
/** The subscription tab */
private SubscriptionTab sTab;
/** The bandwidth tab */
private BandwidthTab bTab;
/**
* Constructor.
*
@ -181,14 +122,9 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
@Override
protected void initializeComponents(Shell shell) {
createRouteInfo();
createSeparator(true);
getTabText();
createTabFolder();
createSystemTabs(tabFolder);
createSeparator(false);
createBottomButtons();
}
@ -204,139 +140,69 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
SystemRuleManager.getInstance().deregisterAsListener(this);
}
/**
* Create top bar route information.
*/
private void createRouteInfo() {
GridData gd = new GridData(400, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(2, true);
gl.horizontalSpacing = 2;
Composite topComp = new Composite(shell, SWT.NONE);
topComp.setLayoutData(gd);
topComp.setLayout(gl);
Composite dataRouteComp = new Composite(topComp, SWT.NONE);
gl = new GridLayout(2, false);
gd = new GridData(200, SWT.DEFAULT);
dataRouteComp.setLayoutData(gd);
dataRouteComp.setLayout(gl);
// Data Route
Label dataRoute = new Label(dataRouteComp, SWT.NONE);
dataRoute.setText("Data Route:");
gd = new GridData(100, SWT.DEFAULT);
dataRouteCombo = new Combo(dataRouteComp, SWT.READ_ONLY);
dataRouteCombo.setLayoutData(gd);
dataRouteCombo.setToolTipText("Select a data route");
dataRouteCombo.removeAll();
DataRoutes[] dataRoutes = DataRoutes.values();
for (DataRoutes dr : dataRoutes) {
dataRouteCombo.add(dr.getRoute());
}
dataRouteCombo.select(0);
Composite bandwithComp = new Composite(topComp, SWT.NONE);
gl = new GridLayout(2, false);
gd = new GridData(250, SWT.DEFAULT);
bandwithComp.setLayoutData(gd);
bandwithComp.setLayout(gl);
// Bandwidth spinner
gd = new GridData(165, SWT.DEFAULT);
Label availBandwith = new Label(bandwithComp, SWT.NONE);
availBandwith.setLayoutData(gd);
availBandwith.setText("Available Bandwidth (KB):");
gd = new GridData(100, SWT.DEFAULT);
final Spinner availBandwidthSpinner = new Spinner(bandwithComp,
SWT.BORDER);
availBandwidthSpinner.setMinimum(0);
availBandwidthSpinner.setMaximum(10000);
availBandwidthSpinner.setToolTipText("Select bandwidth in Kilobytes");
final int availableBandwidth = SystemRuleManager
.getAvailableBandwidth(Network.OPSNET);
availBandwidthSpinner.setSelection(availableBandwidth);
availBandwidthSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selection = availBandwidthSpinner.getSelection();
availableBandwidthModified = selection != availableBandwidth;
}
});
this.availBandwidthSpinner = availBandwidthSpinner;
}
/**
* Create dialog separator.
*/
private void createSeparator(boolean labelCreate) {
Label separatorBar = new Label(shell, SWT.SEPARATOR | SWT.SHADOW_OUT
| SWT.HORIZONTAL);
separatorBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (labelCreate) {
Label opsLabel = new Label(shell, SWT.NONE);
opsLabel.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_CENTER));
String route = dataRouteCombo.getItem(dataRouteCombo
.getSelectionIndex());
opsLabel.setText(route);
}
}
/**
* Create tabs.
*/
private void createSystemTabs(TabFolder tabFolder) {
GridData gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, false);
// Priority Tab
TabItem priorityTab = new TabItem(tabFolder, SWT.NONE);
priorityTab.setText(tabTextMap.get(PRIORITY_TAB));
priorityTab.setData("valid", false);
Composite priorityComp = new Composite(tabFolder, SWT.NONE);
priorityComp.setLayout(gl);
priorityComp.setLayoutData(gd);
priorityTab.setControl(priorityComp);
pTab = new SystemPriorityTab(priorityComp);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(1, false);
pTab = new SystemPriorityTab(getTabComposite(tabFolder));
createTabItem(tabFolder, pTab);
pTab.init();
// Latency Tab
TabItem latencyTab = new TabItem(tabFolder, SWT.NONE);
latencyTab.setText(tabTextMap.get(LATENCY_TAB));
latencyTab.setData("valid", false);
Composite latencyComp = new Composite(tabFolder, SWT.NONE);
latencyComp.setLayout(gl);
latencyComp.setLayoutData(gd);
latencyTab.setControl(latencyComp);
lTab = new SystemLatencyTab(latencyComp);
lTab = new SystemLatencyTab(getTabComposite(tabFolder));
createTabItem(tabFolder, lTab);
lTab.init();
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
gl = new GridLayout(1, false);
// Subscription Tab
sTab = new SubscriptionTab(getTabComposite(tabFolder));
createTabItem(tabFolder, sTab);
sTab.init();
// Routing Tab
TabItem routingTab = new TabItem(tabFolder, SWT.NONE);
routingTab.setText(tabTextMap.get(ROUTING_TAB));
Composite routingComp = new Composite(tabFolder, SWT.NONE);
routingComp.setLayout(gl);
routingComp.setLayoutData(gd);
routingTab.setControl(routingComp);
SystemRoutingTab rTab = new SystemRoutingTab(routingComp);
// Bandwidth Tab
bTab = new BandwidthTab(getTabComposite(tabFolder));
createTabItem(tabFolder, bTab);
bTab.init();
lTab.loadList();
pTab.loadList();
}
/**
* Create the tab composite.
*
* @param tabFolder
* the
* @return
*/
private Composite getTabComposite(TabFolder tabFolder) {
GridData gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, false);
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(gl);
composite.setLayoutData(gd);
return composite;
}
/**
* Create a {@link TabItem} for the given tab.
*
* @param tabFolder
* the tab folder
* @param tab
* the tab
* @return the tab item
*/
private TabItem createTabItem(TabFolder tabFolder, SystemTab tab) {
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setControl(tab.getParentComp());
tabItem.setText(tab.getTabText());
return tabItem;
}
/**
* Create the bottom buttons.
*/
@ -348,43 +214,15 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
bottomComp.setLayout(gl);
bottomComp.setLayoutData(gd);
// OK Button
// Close Button
int btnWidth = 100;
GridData btnData = new GridData(btnWidth, SWT.DEFAULT);
okBtn = new Button(bottomComp, SWT.PUSH);
okBtn.setText("OK");
okBtn.setLayoutData(btnData);
okBtn.addSelectionListener(new SelectionAdapter() {
closeBtn = new Button(bottomComp, SWT.PUSH);
closeBtn.setText("Close");
closeBtn.setLayoutData(btnData);
closeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (handleOK()) {
close();
}
}
});
// Apply button
btnData = new GridData(btnWidth, SWT.DEFAULT);
applyBtn = new Button(bottomComp, SWT.PUSH);
applyBtn.setText("Apply");
applyBtn.setLayoutData(btnData);
applyBtn.setToolTipText("Apply system changes");
applyBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleOK();
}
});
// Cancel Button
btnData = new GridData(btnWidth, SWT.DEFAULT);
Button cancelBtn = new Button(bottomComp, SWT.PUSH);
cancelBtn.setText("Cancel");
cancelBtn.setLayoutData(btnData);
cancelBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
close();
}
});
@ -403,68 +241,6 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
}
/**
* Discover tab.
*/
private void getTabText() {
this.tabTextMap.put(PRIORITY_TAB, "Priority Rules");
tabTextMap.put(LATENCY_TAB, "Latency Rules");
tabTextMap.put(ROUTING_TAB, "Routing Rules");
}
/**
* Apply all rules to all subscriptions.
*/
private boolean handleOK() {
if (availableBandwidthModified) {
final int bandwidth = availBandwidthSpinner.getSelection();
// TODO: Currently only OPSNET is available, change to be inspecific
// when others are added
Set<Subscription> unscheduledSubscriptions = SystemRuleManager
.setAvailableBandwidth(Network.OPSNET, bandwidth);
if (!unscheduledSubscriptions.isEmpty()) {
Set<String> subscriptionNames = new TreeSet<String>();
for (Subscription subscription : unscheduledSubscriptions) {
subscriptionNames.add(subscription.getName());
}
StringBuilder sb = new StringBuilder(
StringUtil
.createMessage(
"Changing the default bandwidth for route "
+ DataRoutes.OPSNET
+ " will unschedule the following subscriptions:",
subscriptionNames));
sb.append(StringUtil.NEWLINE).append(StringUtil.NEWLINE);
sb.append("Would you like to change the bandwidth anyways?.");
int response = DataDeliveryUtils.showMessage(getShell(),
SWT.YES | SWT.NO, "Bandwidth Amount", sb.toString());
boolean forceApplied = false;
if (response == SWT.YES) {
forceApplied = SystemRuleManager
.forceSetAvailableBandwidth(Network.OPSNET,
bandwidth);
if (forceApplied) {
availableBandwidthModified = false;
} else {
statusHandler
.handle(Priority.ERROR,
"Bandwidth Change",
"Unable to change the bandwidth for network "
+ Network.OPSNET
+ ". Please check the server for details.");
}
}
return forceApplied;
} else {
availableBandwidthModified = false;
}
}
return true;
}
/**
* {@inheritDoc}
*/

View file

@ -19,26 +19,11 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
import java.util.Collections;
import java.util.List;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* System Management Priority tab.
@ -52,286 +37,51 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Sep 17, 2012 730 jpiatt Initial creation.
* Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
* Jan 04, 2013 1420 mpduff Add delete function.
* May 17, 2013 2000 djohnson Consolidate duplicate code into {@link SystemRulesTab}.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public class SystemPriorityTab {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemPriorityTab.class);
/** Parent Composite */
private final Composite parentComp;
/** Priority Composite */
private Composite priorityComp;
/** Create and edit rule dialog */
private CreateEditRuleDlg ruleDlg;
public class SystemPriorityTab extends SystemRulesTab {
/** Rule type constant */
private final String PRIORITY_TYPE = "priority";
/** Available List widget */
private List priorityList;
/** Edit rule button. */
private Button editBtn;
/** New rule button. */
private Button newBtn;
/** Delete rule button */
private Button deleteBtn;
/** Button Height. */
private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */
private final int buttonWidth = 70;
/** Flag for create and edit. */
private boolean create;
private final String notAuthorizedMsg = " is not authorized to create, edit, or delete rules using the Data Delivery System Management\nPermission: ";
private static final String PRIORITY_TYPE = "priority";
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
* @param systemManagementDlg
*
* @param dataSet
* The DataSet object
*/
public SystemPriorityTab(Composite parentComp) {
this.parentComp = parentComp;
init();
super(parentComp, PRIORITY_TYPE);
}
/**
* Initialize the tab.
*/
private void init() {
createPriorityRulesTab();
createSideButtons();
}
/**
* Create the bar that may be expanded depending on item count.
*/
private void createPriorityRulesTab() {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
GridLayout gl = new GridLayout(2, false);
priorityComp = new Composite(parentComp, SWT.NONE);
priorityComp.setLayout(gl);
gd.widthHint = 375;
gd.heightHint = 200;
priorityList = new List(priorityComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL);
priorityList.setLayoutData(gd);
priorityList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (priorityList.getSelectionCount() > 0) {
enableButtons(true);
} else {
enableButtons(false);
}
}
});
loadList();
}
/**
* Create the button controls.
*/
private void createSideButtons() {
GridData actionData = new GridData(SWT.DEFAULT, SWT.CENTER, false, true);
GridLayout actionLayout = new GridLayout(1, false);
Composite actionComp = new Composite(priorityComp, SWT.NONE);
actionComp.setLayout(actionLayout);
actionComp.setLayoutData(actionData);
GridData btnData = new GridData(buttonWidth, buttonHeight);
newBtn = new Button(actionComp, SWT.PUSH);
newBtn.setText("New...");
newBtn.setLayoutData(btnData);
newBtn.setEnabled(true);
newBtn.setToolTipText("Create a new rule");
newBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = true;
handlePriorityRule();
if (priorityList.getItemCount() > 0) {
priorityList.select(0);
} else {
enableButtons(false);
}
}
});
btnData = new GridData(buttonWidth, buttonHeight);
editBtn = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.setLayoutData(btnData);
editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = false;
int idx = priorityList.getSelectionIndex();
handlePriorityRule();
priorityList.select(idx);
}
});
btnData = new GridData(buttonWidth, buttonHeight);
deleteBtn = new Button(actionComp, SWT.PUSH);
deleteBtn.setText("Delete...");
deleteBtn.setLayoutData(btnData);
deleteBtn.setEnabled(false);
deleteBtn.setToolTipText("Edit item selected in the list");
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
handleDeleteRule();
if (priorityList.getItemCount() > 0) {
priorityList.select(0);
}
}
});
}
/**
* enable/disable the delete and edit buttons
* Get the tab text.
*
* @param enable
* setting for buttons
* @return the tab text
*/
private void enableButtons(boolean enable) {
deleteBtn.setEnabled(enable);
editBtn.setEnabled(enable);
@Override
public String getTabText() {
return "Priority Rules";
}
/**
* Handle create and edit rules.
* {@inheritDoc}
*/
private void handlePriorityRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + notAuthorizedMsg + permission;
try {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (ruleDlg == null || ruleDlg.isDisposed()) {
// New
if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, PRIORITY_TYPE);
} else {
// Edit
String ruleName = null;
int selectedIdx = priorityList.getSelectionIndex();
if (selectedIdx > -1) {
ruleName = priorityList.getItem(selectedIdx);
} else if (priorityList.getItemCount() <= 0) {
DataDeliveryUtils.showMessage(
parentComp.getShell(), SWT.ERROR,
"Create Rule", "Please create a rule.");
return;
} else {
DataDeliveryUtils.showMessage(
parentComp.getShell(), SWT.ERROR,
"Select Rule",
"Please select a rule for edit.");
return;
}
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleName, PRIORITY_TYPE);
}
ruleDlg.open();
} else {
ruleDlg.bringToTop();
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
@Override
protected List<String> getRuleNames() {
return SystemRuleManager.getInstance().getPriorityRuleNames();
}
/**
* Delete action handler.
* {@inheritDoc}
*/
private void handleDeleteRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + notAuthorizedMsg + permission;
try {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
String ruleName = null;
int selectedIdx = priorityList.getSelectionIndex();
if (selectedIdx > -1) {
int answer = DataDeliveryUtils.showYesNoMessage(
parentComp.getShell(), "Delete?",
"Are you sure you want to delete this rule?");
if (answer == SWT.YES) {
ruleName = priorityList.getItem(selectedIdx);
SystemRuleManager.getInstance().deletePriorityRule(
ruleName);
loadList();
if (priorityList.getItemCount() == 0) {
enableButtons(false);
}
}
} else {
DataDeliveryUtils.showMessage(parentComp.getShell(),
SWT.ERROR, "Select Rule",
"Please select a rule for delete.");
return;
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
}
/**
* Load the rule list.
*/
public void loadList() {
priorityList.removeAll();
// Get the list of priority rule names
java.util.List<String> rules = SystemRuleManager.getInstance()
.getPriorityRuleNames();
Collections.sort(rules);
priorityList.setItems(rules.toArray(new String[rules.size()]));
@Override
protected void deleteRule(String ruleName) {
SystemRuleManager.getInstance().deletePriorityRule(ruleName);
}
}

View file

@ -1,90 +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.uf.viz.datadelivery.system;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
/**
* System Management Routing Tab.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation.
* Jan 04, 2013 1420 mpduff Remove autoApply of rules.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public class SystemRoutingTab {
/** Parent Composite */
private final Composite parentComp;
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
*/
public SystemRoutingTab(Composite parentComp) {
this.parentComp = parentComp;
init();
}
/**
* Initialize the tab.
*/
private void init() {
createRoutingRulesTab();
}
/**
* Create the bar that may be expanded depending on item count.
*/
private void createRoutingRulesTab() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(2, false);
Composite priorityTabComp = new Composite(parentComp, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(2, false);
priorityTabComp.setLayoutData(gd);
priorityTabComp.setLayout(gl);
// Data Route Combo Box
Label routeHelp = new Label(priorityTabComp, SWT.NONE);
routeHelp
.setText("This tab allows rules to default\nproducts to a specific route.");
}
}

View file

@ -0,0 +1,354 @@
/**
* 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.uf.viz.datadelivery.system;
import java.util.Collections;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Abstract System Management Rules Dialog.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 17, 2013 2000 djohnson Consolidate duplicate code from latency and priority versions.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public abstract class SystemRulesTab extends SystemTab {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemRulesTab.class);
private final String notAuthorizedMsg = " is not authorized to create, edit, or delete rules using the Data Delivery System Management\nPermission: ";
/** Priority Composite */
private Composite listComp;
/** Create and edit rule dialog */
private CreateEditRuleDlg ruleDlg;
/** Available List widget */
private List rulesList;
/** Flag for create and edit. */
private boolean create;
/** Edit rule button. */
private Button editBtn;
/** New rule button. */
private Button newBtn;
/** Delete rule button. */
private Button deleteBtn;
/** Button Height. */
private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */
private final int buttonWidth = 70;
private final String ruleType;
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
*/
public SystemRulesTab(Composite parentComp, String ruleType) {
super(parentComp);
this.ruleType = ruleType;
}
/**
* Initialize the tab.
*/
@Override
public void init() {
createRulesTab();
createSideButtons();
}
/**
* Create the bar that may be expanded depending on item count.
*/
private void createRulesTab() {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
GridLayout gl = new GridLayout(2, false);
listComp = new Composite(parentComp, SWT.NONE);
listComp.setLayout(gl);
listComp.setLayoutData(gd);
gd = new GridData(SWT.DEFAULT, SWT.CENTER, true, true);
gd.widthHint = 375;
gd.heightHint = 200;
rulesList = new List(listComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
rulesList.setLayoutData(gd);
rulesList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
enableButtons(rulesList.getSelectionCount() > 0);
}
});
loadList();
}
/**
* Create the move up/down controls
*/
private void createSideButtons() {
GridData actionData = new GridData(SWT.RIGHT, SWT.CENTER, true, true);
GridLayout actionLayout = new GridLayout(1, false);
Composite actionComp = new Composite(listComp, SWT.NONE);
actionComp.setLayout(actionLayout);
actionComp.setLayoutData(actionData);
final int horizAlign = SWT.LEFT;
final int verticalAlign = SWT.DEFAULT;
boolean horizExcess = true;
boolean verticalExcess = false;
GridData btnData = new GridData(horizAlign, verticalAlign, horizExcess,
verticalExcess);
btnData.widthHint = buttonWidth;
btnData.heightHint = buttonHeight;
newBtn = new Button(actionComp, SWT.PUSH);
newBtn.setText("New...");
newBtn.setLayoutData(btnData);
newBtn.setEnabled(true);
newBtn.setToolTipText("Create a new rule");
newBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = true;
handleRule();
if (rulesList.getItemCount() > 0) {
rulesList.select(0);
enableButtons(true);
} else {
enableButtons(false);
}
}
});
btnData = new GridData(horizAlign, verticalAlign, horizExcess,
verticalExcess);
btnData.widthHint = buttonWidth;
btnData.heightHint = buttonHeight;
editBtn = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.setLayoutData(btnData);
editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = false;
int idx = rulesList.getSelectionIndex();
handleRule();
if (!rulesList.isDisposed()) {
rulesList.select(idx);
}
}
});
btnData = new GridData(horizAlign, verticalAlign, horizExcess,
verticalExcess);
btnData.widthHint = buttonWidth;
btnData.heightHint = buttonHeight;
deleteBtn = new Button(actionComp, SWT.PUSH);
deleteBtn.setText("Delete");
deleteBtn.setLayoutData(btnData);
deleteBtn.setEnabled(false);
deleteBtn.setToolTipText("Delete item selected in the list");
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
handleDeleteRule();
if (rulesList.getItemCount() > 0) {
rulesList.select(0);
}
}
});
}
/**
* Enable the buttons?
*
* @param enable
* setting for the buttons
*/
private void enableButtons(boolean enable) {
deleteBtn.setEnabled(enable);
editBtn.setEnabled(enable);
}
/**
* New/Edit rule action handler.
*/
private void handleRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + notAuthorizedMsg + permission;
try {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (ruleDlg == null || ruleDlg.isDisposed()) {
// New
if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleType);
} else {
// Edit
String ruleName = null;
int selectedIdx = rulesList.getSelectionIndex();
if (selectedIdx > -1) {
ruleName = rulesList.getItem(selectedIdx);
} else if (rulesList.getItemCount() <= 0) {
DataDeliveryUtils.showMessage(
parentComp.getShell(), SWT.ERROR,
"Create Rule", "Please create a rule.");
return;
} else {
DataDeliveryUtils.showMessage(
parentComp.getShell(), SWT.ERROR,
"Select Rule",
"Please select a rule to edit.");
return;
}
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleName, ruleType);
}
ruleDlg.open();
} else {
ruleDlg.bringToTop();
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
}
/**
* Delete rule action handler.
*/
private void handleDeleteRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + notAuthorizedMsg + permission;
try {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
String ruleName = null;
int selectedIdx = rulesList.getSelectionIndex();
if (selectedIdx > -1) {
int answer = DataDeliveryUtils.showYesNoMessage(
parentComp.getShell(), "Delete?",
"Are you sure you want to delete this rule?");
if (answer == SWT.YES) {
ruleName = rulesList.getItem(selectedIdx);
deleteRule(ruleName);
loadList();
if (rulesList.getItemCount() == 0) {
enableButtons(false);
}
}
} else {
DataDeliveryUtils.showMessage(parentComp.getShell(),
SWT.ERROR, "Select Rule",
"Please select a rule for delete.");
return;
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
}
/**
* Load the rule list.
*/
public void loadList() {
rulesList.removeAll();
// Get the list of latency rule names
java.util.List<String> rules = null;
rules = getRuleNames();
Collections.sort(rules, String.CASE_INSENSITIVE_ORDER);
rulesList.setItems(rules.toArray(new String[rules.size()]));
}
/**
* Get the rule names.
*
* @return the rule names
*/
protected abstract java.util.List<String> getRuleNames();
/**
* Delete the rule by name.
*
* @param ruleName
* the rule name
*/
protected abstract void deleteRule(String ruleName);
}

View file

@ -0,0 +1,73 @@
/**
* 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.uf.viz.datadelivery.system;
import org.eclipse.swt.widgets.Composite;
/**
* Base class for system management tabs.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 17, 2013 2000 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public abstract class SystemTab {
/** Parent Composite */
protected final Composite parentComp;
/**
* @return the parentComp
*/
public Composite getParentComp() {
return parentComp;
}
/**
* Constructor.
*
* @param parentComp
*/
protected SystemTab(Composite parentComp) {
this.parentComp = parentComp;
}
/**
* Initialize the tab.
*/
public abstract void init();
/**
* Get the tab's title text.
*
* @return the title text
*/
public abstract String getTabText();
}

View file

@ -26,8 +26,15 @@ import java.util.TimeZone;
import java.util.regex.Pattern;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -53,6 +60,7 @@ import com.raytheon.uf.viz.core.VizApp;
* Dec 18, 2012 1439 mpduff Change Regex to match invalid chars.
* Jan 04, 2013 1420 mpduff Change default priority to normal priority.
* Jan 25, 2013 1528 djohnson Subscription priority has moved up in the world to the Subscription class.
* May 20, 2013 2000 djohnson Add methods for managing widget listeners.
*
* </pre>
*
@ -321,4 +329,72 @@ public class DataDeliveryGUIUtils {
return false;
}
/**
* Remove all listeners of the specified types from the widget.
*
* @param widget
* the widget
* @param listenerTypes
* the listener types
*/
public static void removeListeners(Widget widget, int... listenerTypes) {
// Remove any current listeners
for (int listenerType : listenerTypes) {
Listener[] listeners = widget.getListeners(listenerType);
for (Listener listener : listeners) {
widget.removeListener(listenerType, listener);
}
}
}
/**
* Creates a selection listener that will run the specified runnable if the
* current value does not equal the initial value.
*
* @param initialValue
* the initial value
* @param spinner
* the spinner
* @param runnable
* the runnable to run
* @return the selection listener
*/
public static SelectionListener addValueChangedSelectionListener(
final int initialValue, final Spinner spinner,
final Runnable runnable) {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (spinner.getSelection() != initialValue) {
runnable.run();
}
}
};
}
/**
* Creates a selection listener that will run the specified runnable if the
* current value does not equal the initial value.
*
* @param initialSelectionIndex
* the initial selection index
* @param combo
* the combo
* @param runnable
* the runnable to run
* @return
*/
public static SelectionListener addValueChangedSelectionListener(
final int initialSelectionIndex, final Combo combo,
final Runnable runnable) {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (combo.getSelectionIndex() != initialSelectionIndex) {
runnable.run();
}
}
};
}
}

View file

@ -71,6 +71,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Jan 30, 2013 1543 djohnson Use List instead of ArrayList.
* Apr 08, 2013 1826 djohnson Add getDisplayData() method to subscription columns.
* Apr 10, 2013 1891 djohnson Add getDisplayData() method to pending subscription columns.
* May 20, 2013 2000 djohnson Add message to inform the user changes were applied.
* </pre>
*
* @author mpduff
@ -586,6 +587,17 @@ public class DataDeliveryUtils {
return showMessage(shell, SWT.YES | SWT.NO, title, message);
}
/**
* Inform the user their changes were applied.
*
* @param shell
* the shell reference
*/
public static void showChangesWereAppliedMessage(Shell shell) {
showMessage(shell, SWT.OK, "Changes Applied",
"The changes were successfully applied.");
}
/**
* Provides the text for the subscription details dialog
*

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.common.datadelivery.service.subscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.localization.exception.LocalizationException;
/**
* Checks subscriptions to see if they would be considered duplicates.
@ -76,4 +77,24 @@ public interface ISubscriptionOverlapService {
*/
ISubscriptionOverlapResponse isOverlapping(Subscription sub1,
Subscription sub2);
/**
* Writes the new configuration.
*
* @param config
* the configuration
* @throws LocalizationException
* on error saving the configuration
*/
void writeConfig(SubscriptionOverlapConfig config)
throws LocalizationException;
/**
* Read the configuration.
*
* @return the configuration
* @throws LocalizationException
* on error reading the configuration
*/
SubscriptionOverlapConfig readConfig() throws LocalizationException;
}

View file

@ -40,50 +40,6 @@ import javax.xml.bind.annotation.XmlEnum;
*/
@XmlEnum
public enum SubscriptionOverlapMatchStrategy {
MATCH_ANY {
@Override
public boolean isOverlapping(SubscriptionOverlapConfig config,
int parameterDuplicationPercent,
int forecastHourDuplicationPercent,
int cycleDuplicationPercent, int spatialDuplicationPercent) {
final boolean exceedsAllowedParameterDuplication = parameterDuplicationPercent > config
.getMaxAllowedParameterDuplication();
final boolean exceedsAllowedForecastHourDuplication = forecastHourDuplicationPercent > config
.getMaxAllowedForecastHourDuplication();
final boolean exceedsAllowedCycleDuplication = cycleDuplicationPercent > config
.getMaxAllowedCycleDuplication();
final boolean exceedsAllowedSpatialDuplication = spatialDuplicationPercent > config
.getMaxAllowedSpatialDuplication();
return exceedsAllowedParameterDuplication
|| exceedsAllowedForecastHourDuplication
|| exceedsAllowedCycleDuplication
|| exceedsAllowedSpatialDuplication;
}
},
MATCH_ALL {
@Override
public boolean isOverlapping(SubscriptionOverlapConfig config,
int parameterDuplicationPercent,
int forecastHourDuplicationPercent,
int cycleDuplicationPercent, int spatialDuplicationPercent) {
final boolean exceedsAllowedParameterDuplication = parameterDuplicationPercent > config
.getMaxAllowedParameterDuplication();
final boolean exceedsAllowedForecastHourDuplication = forecastHourDuplicationPercent > config
.getMaxAllowedForecastHourDuplication();
final boolean exceedsAllowedCycleDuplication = cycleDuplicationPercent > config
.getMaxAllowedCycleDuplication();
final boolean exceedsAllowedSpatialDuplication = spatialDuplicationPercent > config
.getMaxAllowedSpatialDuplication();
return exceedsAllowedParameterDuplication
&& exceedsAllowedForecastHourDuplication
&& exceedsAllowedCycleDuplication
&& exceedsAllowedSpatialDuplication;
}
},
AT_LEAST_HALF {
@Override
public boolean isOverlapping(SubscriptionOverlapConfig config,
@ -118,6 +74,65 @@ public enum SubscriptionOverlapMatchStrategy {
}
return false;
}
@Override
public String getDisplayString() {
return "At Least Half";
}
},
MATCH_ALL {
@Override
public boolean isOverlapping(SubscriptionOverlapConfig config,
int parameterDuplicationPercent,
int forecastHourDuplicationPercent,
int cycleDuplicationPercent, int spatialDuplicationPercent) {
final boolean exceedsAllowedParameterDuplication = parameterDuplicationPercent > config
.getMaxAllowedParameterDuplication();
final boolean exceedsAllowedForecastHourDuplication = forecastHourDuplicationPercent > config
.getMaxAllowedForecastHourDuplication();
final boolean exceedsAllowedCycleDuplication = cycleDuplicationPercent > config
.getMaxAllowedCycleDuplication();
final boolean exceedsAllowedSpatialDuplication = spatialDuplicationPercent > config
.getMaxAllowedSpatialDuplication();
return exceedsAllowedParameterDuplication
&& exceedsAllowedForecastHourDuplication
&& exceedsAllowedCycleDuplication
&& exceedsAllowedSpatialDuplication;
}
@Override
public String getDisplayString() {
return "Match All";
}
},
MATCH_ANY {
@Override
public boolean isOverlapping(SubscriptionOverlapConfig config,
int parameterDuplicationPercent,
int forecastHourDuplicationPercent,
int cycleDuplicationPercent, int spatialDuplicationPercent) {
final boolean exceedsAllowedParameterDuplication = parameterDuplicationPercent > config
.getMaxAllowedParameterDuplication();
final boolean exceedsAllowedForecastHourDuplication = forecastHourDuplicationPercent > config
.getMaxAllowedForecastHourDuplication();
final boolean exceedsAllowedCycleDuplication = cycleDuplicationPercent > config
.getMaxAllowedCycleDuplication();
final boolean exceedsAllowedSpatialDuplication = spatialDuplicationPercent > config
.getMaxAllowedSpatialDuplication();
return exceedsAllowedParameterDuplication
|| exceedsAllowedForecastHourDuplication
|| exceedsAllowedCycleDuplication
|| exceedsAllowedSpatialDuplication;
}
@Override
public String getDisplayString() {
return "Match Any";
}
};
/**
@ -135,4 +150,11 @@ public enum SubscriptionOverlapMatchStrategy {
int parameterDuplicationPercent,
int forecastHourDuplicationPercent, int cycleDuplicationPercent,
int spatialDuplicationPercent);
/**
* Get the display string.
*
* @return the display string
*/
public abstract String getDisplayString();
}

View file

@ -23,13 +23,15 @@ import java.util.MissingResourceException;
import javax.xml.bind.JAXBException;
import com.google.common.annotations.VisibleForTesting;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.exception.LocalizationException;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
@ -173,22 +175,37 @@ public class SubscriptionOverlapService implements ISubscriptionOverlapService {
}
/**
* Writes the new configuration.
*
* @param config
* the configuration
* @throws SerializationException
* on error serializing the configuration
* {@inheritDoc}
*/
@VisibleForTesting
void writeNewConfig(SubscriptionOverlapConfig config)
throws SerializationException {
final LocalizationFile configFile = PathManagerFactory
.getPathManager()
.getStaticLocalizationFile(
@Override
public void writeConfig(SubscriptionOverlapConfig config)
throws LocalizationException {
final IPathManager pathManager = PathManagerFactory.getPathManager();
LocalizationContext context = pathManager.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
final LocalizationFile configFile = pathManager
.getLocalizationFile(
context,
SubscriptionOverlapService.SUBSCRIPTION_OVERLAP_CONFIG_FILE_PATH);
this.jaxbManager.jaxbMarshalToXmlFile(config, configFile.getFile()
.getAbsolutePath());
configFile.jaxbMarshal(config, jaxbManager);
}
/**
* {@inheritDoc}
*
* @throws LocalizationException
*/
@Override
public SubscriptionOverlapConfig readConfig() throws LocalizationException {
final IPathManager pathManager = PathManagerFactory.getPathManager();
final LocalizationContext context = pathManager.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
final LocalizationFile configFile = pathManager
.getLocalizationFile(
context,
SubscriptionOverlapService.SUBSCRIPTION_OVERLAP_CONFIG_FILE_PATH);
return configFile.jaxbUnmarshal(SubscriptionOverlapConfig.class,
jaxbManager);
}
}

View file

@ -18,7 +18,8 @@ import com.raytheon.uf.edex.datadelivery.harvester.crawler.CrawlLauncher;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 4, 2012 1038 dhladky Initial creation
* Oct 04, 2012 1038 dhladky Initial creation
* May 20, 2013 2000 djohnson Scheduler must now be started since quartz upgrade.
*
* </pre>
*
@ -69,6 +70,10 @@ public class HarvesterJobController<T extends CrawlLauncher> {
schedular.scheduleJob(jobDetail, trigger);
}
if (!schedular.isStarted()) {
schedular.start();
}
} catch (Exception e) {
statusHandler.error("Unable to schedule job: " + name + " error: "
+ e.getMessage());

View file

@ -28,6 +28,7 @@ import com.raytheon.uf.common.datadelivery.registry.DataDeliveryRegistryObjectTy
import com.raytheon.uf.common.datadelivery.registry.DataSet;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.event.EventBus;
import com.raytheon.uf.common.registry.event.InsertRegistryEvent;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
@ -49,6 +50,7 @@ import com.raytheon.uf.common.util.CollectionUtil;
* Feb 05, 2013 1580 mpduff EventBus refactor.
* 3/18/2013 1802 bphillip Modified to use proper transaction boundaries
* May 08, 2013 2000 djohnson Shortcut out if no subscriptions are returned for the dataset.
* May 20, 2013 2000 djohnson Shortcut out if no subscription handler is available.
*
* </pre>
*
@ -168,8 +170,13 @@ public class SubscriptionIntegrityVerifier {
*/
public void dataSetUpdated(DataSet dataSet) {
try {
final List<Subscription> subscriptions = DataDeliveryHandlers
.getSubscriptionHandler()
final ISubscriptionHandler subscriptionHandler = DataDeliveryHandlers
.getSubscriptionHandler();
if (subscriptionHandler == null) {
return;
}
final List<Subscription> subscriptions = subscriptionHandler
.getActiveByDataSetAndProvider(dataSet.getDataSetName(),
dataSet.getProviderName());

View file

@ -33,7 +33,7 @@ import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.SubscriptionFixture;
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.localization.exception.LocalizationException;
/**
* Test {@link SubscriptionOverlapService}.
@ -142,8 +142,8 @@ public class SubscriptionOverlapServiceTest {
@Test
public void matchesAnyTrueWillConsiderOneExceededValueAsOverlaps()
throws SerializationException {
service.writeNewConfig(ANY_MUST_EXCEED_65_PERCENT);
throws LocalizationException {
service.writeConfig(ANY_MUST_EXCEED_65_PERCENT);
when(duplicateChecker.getCycleDuplicationPercent(sub1, sub2))
.thenReturn(66);
@ -153,8 +153,8 @@ public class SubscriptionOverlapServiceTest {
@Test
public void matchesAnyFalseWillNotConsiderOneExceededValueAsOverlaps()
throws SerializationException {
service.writeNewConfig(ALL_MUST_EXCEED_65_PERCENT);
throws LocalizationException {
service.writeConfig(ALL_MUST_EXCEED_65_PERCENT);
when(duplicateChecker.getCycleDuplicationPercent(sub1, sub2))
.thenReturn(66);
@ -164,8 +164,8 @@ public class SubscriptionOverlapServiceTest {
@Test
public void matchesAnyTrueWillConsiderAllExceededValuesAsOverlaps()
throws SerializationException, TransformException {
service.writeNewConfig(ANY_MUST_EXCEED_65_PERCENT);
throws LocalizationException, TransformException {
service.writeConfig(ANY_MUST_EXCEED_65_PERCENT);
when(duplicateChecker.getCycleDuplicationPercent(sub1, sub2))
.thenReturn(66);
@ -181,8 +181,8 @@ public class SubscriptionOverlapServiceTest {
@Test
public void matchesAnyFalseWillConsiderAllExceededValuesAsOverlaps()
throws SerializationException, TransformException {
service.writeNewConfig(ALL_MUST_EXCEED_65_PERCENT);
throws LocalizationException, TransformException {
service.writeConfig(ALL_MUST_EXCEED_65_PERCENT);
when(duplicateChecker.getCycleDuplicationPercent(sub1, sub2))
.thenReturn(66);
@ -198,7 +198,7 @@ public class SubscriptionOverlapServiceTest {
@Test
public void whenAllComparisonsReturnOneHundredPercentReturnsDuplicate()
throws SerializationException, TransformException {
throws LocalizationException, TransformException {
when(duplicateChecker.getCycleDuplicationPercent(sub1, sub2))
.thenReturn(100);
when(duplicateChecker.getForecastHourDuplicationPercent(sub1, sub2))
@ -213,7 +213,7 @@ public class SubscriptionOverlapServiceTest {
@Test
public void whenAllComparisonsDontReturnOneHundredPercentReturnsNotDuplicate()
throws SerializationException, TransformException {
throws LocalizationException, TransformException {
when(duplicateChecker.getCycleDuplicationPercent(sub1, sub2))
.thenReturn(100);
when(duplicateChecker.getForecastHourDuplicationPercent(sub1, sub2))