/* * AlarmGpioView.java * * Copyright (c) 2003-2004 Digi International * This program and the information contained in it is confidential and * proprietary to Digi International and may not be used, copied, or re- * produced without the prior written permission of Digi International. * */ package com.digi.config.ui; import com.digi.config.core.*; import com.digi.config.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.net.*; /** * This class is a view panel that shows the GPIO Alarm * settings for the ConnectMe device * * This view can be embedded in other panels as desired. */ public class AlarmGpioView extends ConfigViewImpl { /** A KvpNode that holds just the fields used in this view */ KvpNode viewSettingTree; /** listens to the device for changes to kvpGroup */ DeviceChangeListener settingChangeListener; /** Panel that holds the view content */ GridContentPanel content; GridContentPanel alarmContent; GridContentPanel smtpContent; GridContentPanel listContent; GridContentPanel detailContent; int MAXALARMS = 10; // Data fields currently used in this view KvpField alarmsEnabledKvpField; KvpField alarmSmtpServerKvpField; KvpField alarmSmtpFromKvpField; KvpField alarmEnabledKvpField[] = new KvpField[MAXALARMS]; KvpField alarmToKvpField[] = new KvpField[MAXALARMS]; KvpField alarmCcKvpField[] = new KvpField[MAXALARMS]; KvpField alarmSubjectKvpField[] = new KvpField[MAXALARMS]; KvpField alarmPriorityKvpField[] = new KvpField[MAXALARMS]; KvpField alarmTriggerModeKvpField[] = new KvpField[MAXALARMS]; KvpField alarmPatternKvpField[] = new KvpField[MAXALARMS]; KvpField alarmMonitorMaskKvpField[] = new KvpField[MAXALARMS]; KvpField alarmStateMaskKvpField[] = new KvpField[MAXALARMS]; KvpField alarmTriggerIntervalTimeKvpField[] = new KvpField[MAXALARMS]; KvpField alarmSendReminderEnabledKvpField[] = new KvpField[MAXALARMS]; KvpField alarmReminderIntervalTimeKvpField[] = new KvpField[MAXALARMS]; // UI Controls for each field JCheckBox alarmsEnabled_UIC; JTextField alarmSmtpServer_UIC; JTextField alarmSmtpFrom_UIC; JCheckBox alarmEnabled_UIC[] = new JCheckBox[MAXALARMS]; JTextField alarmTo_UIC[] = new JTextField[MAXALARMS]; JTextField alarmCc_UIC[] = new JTextField[MAXALARMS]; JTextField alarmSubject_UIC[] = new JTextField[MAXALARMS]; JComboBox alarmPriority_UIC[] = new JComboBox[MAXALARMS]; JComboBox alarmTriggerMode_UIC[] = new JComboBox[MAXALARMS]; JTextField alarmPattern_UIC[] = new JTextField[MAXALARMS]; BitMaskPanel alarmTrigger_UIC[] = new BitMaskPanel[MAXALARMS]; JTextField alarmTriggerIntervalTime_UIC[] = new JTextField[MAXALARMS]; JCheckBox alarmSendRemindersEnabled_UIC[] = new JCheckBox[MAXALARMS]; JTextField alarmReminderIntervalTime_UIC[] = new JTextField[MAXALARMS]; JTextField alarmMonitorMask_UIC[] = new JTextField[MAXALARMS]; JTextField alarmStateMask_UIC[] = new JTextField[MAXALARMS]; /** * Basic constructor. Sets up the tree view and the edit panel. */ public AlarmGpioView() throws Exception { super(true); // create the KvpNode and the kvpGroup change listener viewSettingTree = new KvpNode(); settingChangeListener = new DeviceChangeListener() { public void deviceChanged(DeviceChangeEvent e) { SystemLog.debug("AlarmGpioView was notified that device kvpGroup changed"); refreshViewKvpNode(); refreshViewControls(); } }; // Create the panel that will hold the view controls content = new GridContentPanel(this.getName(),1); // create a listener that will detect when a user edits the field values and update the appropriate view setting fields ControlChangeAdapter fieldListener = new ControlChangeAdapter() { public void changePerformed(Object source, ActionEvent ae, FocusEvent fe) { //SystemLog.debug("AlarmGpioView was notified that field "+source.toString()+" changed."); if (source==alarmsEnabled_UIC) { alarmsEnabledKvpField.setStringValue(RciProtocol.toString(alarmsEnabled_UIC.isSelected())); alarmContent.setContainerEnabled(alarmsEnabled_UIC.isSelected()); // Update Alarm Enable/Disable Status if (alarmsEnabled_UIC.isSelected()) { for (int i=0;i0) { try { monitorMask = Integer.parseInt(monitorMaskValue.substring(2), 16); } catch (NumberFormatException e) { SystemLog.log("GeneralException",e); } } if ((stateMaskValue!=null) && stateMaskValue.length()>0) { try { stateMask = Integer.parseInt(stateMaskValue.substring(2), 16); } catch (NumberFormatException e) { SystemLog.log("GeneralException",e); } } //SystemLog.debug("monitor mask="+monitorMask+", stateMask="+stateMask); // Walk each trigger bit and set its state for (int pin=0; pin0) { // If this pin is not in the DONT_CARE state the set the appropriate monitor mask bit monitorMask |= gpioPinMask[pin]; } } String finalMask = "0x"+Integer.toHexString(monitorMask); SystemLog.debug("computed monitor mask as: "+finalMask); return finalMask; } /** * Compute the gpio state mask from a given set of gpioTriggerBits */ protected String computeStateMask(int gpioTriggerBits[]) { int stateMask = 0; for (int pin=0; pin0) { // If this pin is not in the DONT_CARE state the set the appropraite state mask bit accordingly if (gpioTriggerBits[pin]==1) { // This pin is marked ASSERTED ... turn on the appropriate state mask bit stateMask |= gpioPinMask[pin]; } else { // This pin is marked DEASSERTED ... turn off the appropriate state mask bit // (of course its already off by default so we don't need to do anything) } } } String finalMask = "0x"+Integer.toHexString(stateMask); SystemLog.debug("computed state mask as: "+finalMask); return finalMask; } /** * This method is called to instruct the view that it is about to be made * active. When a view is active it needs to make sure its content is correct. * An example of why a panel may be inactive is if it were on a tabbed pane * and was not currently visible or if the user selected some other view. */ public void activate() { SystemLog.debug("Activating "+getName()); } /** * This method is called to instruct the view that it is about to be made * inactive. When a view is inactive, it does not need to worry * about maintaining its content in a correct state. An example of why a panel * may be inactive is if it were on a tabbed pane and was not currently visible * or if the user selected some other view. */ public void deactivate() { SystemLog.debug("Deactivating "+getName()); } /** * Indicates if any changes have been made by the user that have not yet been * saved to the device(ie committed). */ public boolean isChanged() { return viewSettingTree.hasChanged(); } /** * This method instructs the view to validate any of the changes the user has made * within the view. Any errors are to be added to the provided errorList. * * @param errorList is a collection of ViewValidationError objects */ public void validateChanges(Collection errorList) { /* Here is an example of how to create the validation error. Remember to put the msgId in the MsgResourcebundle.properties if (fieldXXValue is invalid) { errorList.add(new ValidationError("FieldXXValidationError", new Serializable[] {fieldXXValue})); } */ // If no Alarms, No Validation if (!alarmsEnabled_UIC.isSelected()) return; try { // Validate Server/From if (!ValidationHelper.isValidIPAddress(alarmSmtpServer_UIC.getText()) || InetAddress.getByName(alarmSmtpServer_UIC.getText()).equals(InetAddress.getByName("0.0.0.0"))) errorList.add(new ValidationError("AlarmSmtpServerError")); if (!ValidationHelper.isValidEmailAddress(alarmSmtpFrom_UIC.getText())) errorList.add(new ValidationError("AlarmSmtpFromError")); // Validate Each Alarm for (int i = 0; i < MAXALARMS; i++) { if (!ValidationHelper.isValidInteger(alarmTriggerIntervalTime_UIC[i].getText())) errorList.add(new ValidationError("AlarmTriggerIntervalError", new Serializable[]{ String.valueOf(i+1) })); if ((alarmTo_UIC[i].getText().length() > 0) && (!ValidationHelper.isValidEmailAddress(alarmTo_UIC[i].getText()))) errorList.add(new ValidationError("AlarmToError", new Serializable[]{ String.valueOf(i+1) })); if ((alarmCc_UIC[i].getText().length() > 0) && (!ValidationHelper.isValidEmailAddress(alarmCc_UIC[i].getText()))) errorList.add(new ValidationError("AlarmCcError", new Serializable[]{ String.valueOf(i+1) })); if (alarmEnabled_UIC[i].isSelected()) { if (alarmTo_UIC[i].getText().length() == 0) errorList.add(new ValidationError("AlarmToError", new Serializable[]{ String.valueOf(i+1) })); if (alarmSubject_UIC[i].getText().length() == 0) errorList.add(new ValidationError("AlarmSubjectError", new Serializable[]{ String.valueOf(i+1) })); } } } catch (Exception e) { System.out.println("Caught Exception in AlarmGpioView::validationChanges()"); e.printStackTrace(); } } /** * This method instructs the view to place any changes the user has made within * the view into the provided clusters. Once the changes have been saved to * to the device, a subsequent call to commitChanges() will be made. */ public void getChanges(KvpNode settingCluster, KvpNode stateCluster) { // Merge the view changes into the provided cluster settingCluster.merge(viewSettingTree, false); } /** * Instructs the view to consider any user changes within the view as * saved to the device (ie committed). */ public void commitChanges() { // simply reset flags indicating user changes in the contols viewSettingTree.resetChanged(); } /** * Instructs the view to discard any changes the user has made within the * view and revert those fields to the original state. The view is also * free to refresh all its fields to the present cached state of the device at * this time. */ public void cancelChanges() { refreshViewKvpNode(); refreshViewControls(); } }