Search in sources :

Example 11 with FaultMember

use of alma.acs.alarmsystem.generated.FaultMember in project ACS by ACS-Community.

the class AlarmsView method createViewWidgets.

private void createViewWidgets(Composite parent) {
    Listener hoverTree = new Listener() {

        public void handleEvent(Event event) {
            Point coords = new Point(event.x, event.y);
            TreeItem it = _tree.getItem(coords);
            String tooltip = "";
            if (it == null) {
                _tree.setToolTipText(tooltip);
                return;
            }
            NodeType type = (NodeType) it.getData();
            switch(type) {
                case FAULT_FAMILY:
                    {
                        tooltip = _alarmManager.getFaultFamily(it.getText()).getName();
                        break;
                    }
                case FAULT_CODE_DATA:
                    {
                        tooltip = _alarmManager.getFaultCode(it.getParentItem().getParentItem().getText(), new Integer(it.getText())).getProblemDescription();
                        break;
                    }
                case FAULT_MEMBER_DATA:
                    {
                        tooltip = _alarmManager.getFaultMember(it.getParentItem().getParentItem().getText(), it.getText()).getName();
                        break;
                    }
            }
            _tree.setToolTipText(tooltip);
        }
    };
    _deleteElement = new Listener() {

        public void handleEvent(Event event) {
            boolean choice = MessageDialog.openQuestion(AlarmsView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this element");
            if (choice == true) {
                TreeItem sel = null;
                if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                    return;
                NodeType type = (NodeType) _tree.getSelection()[0].getData();
                if (type == NodeType.FAULT_CODE_LIST || type == NodeType.FAULT_MEMBER_LIST)
                    return;
                String alarm = _tree.getSelection()[0].getText();
                try {
                    if (type == NodeType.FAULT_FAMILY)
                        _alarmManager.deleteFaultFamily(_alarmManager.getFaultFamily(alarm));
                    else if (type == NodeType.FAULT_CODE_DATA) {
                        String ff = _tree.getSelection()[0].getParentItem().getParentItem().getText();
                        _alarmManager.deleteFaultCode(_alarmManager.getFaultFamily(ff), _alarmManager.getFaultCode(ff, new Integer(alarm).intValue()));
                    } else if (type == NodeType.FAULT_MEMBER_DATA) {
                        String ff = _tree.getSelection()[0].getParentItem().getParentItem().getText();
                        _alarmManager.deleteFaultMember(_alarmManager.getFaultFamily(ff), _alarmManager.getFaultMember(ff, alarm));
                    } else if (type == NodeType.FAULT_MEMBER_DEFAULT) {
                        String ff = _tree.getSelection()[0].getParentItem().getParentItem().getText();
                        _alarmManager.setFaultMemberDefault(_alarmManager.getFaultFamily(ff), null);
                    }
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                if (type != NodeType.FAULT_FAMILY) {
                    sel = _tree.getSelection()[0].getParentItem();
                    TreeItem tff = sel.getParentItem();
                    FaultFamily fft = _alarmManager.getFaultFamily(tff.getText());
                    if (fft.getFaultCodeCount() == 0 || (fft.getFaultMemberCount() == 0 && fft.getFaultMemberDefault() == null)) {
                        sel.setForeground(new Color(sel.getDisplay(), 255, 0, 0));
                        tff.setForeground(new Color(tff.getDisplay(), 255, 0, 0));
                    } else {
                        sel.setForeground(new Color(sel.getDisplay(), 0, 0, 0));
                        tff.setForeground(new Color(tff.getDisplay(), 0, 0, 0));
                    }
                    _tree.getSelection()[0].dispose();
                    _tree.setSelection(sel);
                    Event e = new Event();
                    _tree.notifyListeners(SWT.Selection, e);
                } else {
                    _tree.getSelection()[0].dispose();
                    if (_tree.getItemCount() > 0)
                        _tree.setSelection(_tree.getItems()[0]);
                    Event e = new Event();
                    _tree.notifyListeners(SWT.Selection, e);
                }
            }
        }
    };
    _addFaultMember = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            TreeItem tmp2 = null;
            while (tmp != null) {
                tmp2 = tmp;
                tmp = tmp.getParentItem();
            }
            String ff = tmp2.getText();
            InputDialog dialog = new InputDialog(AlarmsView.this.getViewSite().getShell(), "New Fault Member", "Enter the Fault Member name", null, new IInputValidator() {

                public String isValid(String newText) {
                    if (newText.trim().compareTo("") == 0)
                        return "The name is empty";
                    return null;
                }
            });
            dialog.setBlockOnOpen(true);
            dialog.open();
            int returnCode = dialog.getReturnCode();
            if (returnCode == InputDialog.OK) {
                FaultMember newFaultMember = new FaultMember();
                newFaultMember.setName(dialog.getValue());
                try {
                    _alarmManager.addFaultMember(_alarmManager.getFaultFamily(ff), newFaultMember);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                sortFaultFamilyList();
                selectElementFromTree(ff, dialog.getValue(), null);
            }
        }
    };
    _addFaultMemberDefault = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            TreeItem tmp2 = null;
            while (tmp != null) {
                tmp2 = tmp;
                tmp = tmp.getParentItem();
            }
            String ff = tmp2.getText();
            FaultMemberDefault newFaultMemberDefault = new FaultMemberDefault();
            try {
                _alarmManager.setFaultMemberDefault(_alarmManager.getFaultFamily(ff), newFaultMemberDefault);
            } catch (IllegalOperationException e) {
                ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Default Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                error.setBlockOnOpen(true);
                error.open();
                return;
            } catch (NullPointerException e) {
                ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Default Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                error.setBlockOnOpen(true);
                error.open();
                return;
            }
            sortFaultFamilyList();
            selectElementFromTree(ff, "Default Member", null);
        }
    };
    _addFaultCode = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            TreeItem tmp2 = null;
            while (tmp != null) {
                tmp2 = tmp;
                tmp = tmp.getParentItem();
            }
            String ff = tmp2.getText();
            InputDialog dialog = new InputDialog(AlarmsView.this.getViewSite().getShell(), "New Fault Code", "Enter the Fault Code Value", null, new IInputValidator() {

                public String isValid(String newText) {
                    if (newText.trim().compareTo("") == 0)
                        return "The value is empty";
                    try {
                        new Integer(newText);
                    } catch (NumberFormatException e) {
                        return "The value is not a number";
                    }
                    return null;
                }
            });
            dialog.setBlockOnOpen(true);
            dialog.open();
            int returnCode = dialog.getReturnCode();
            if (returnCode == InputDialog.OK) {
                FaultCode newFaultCode = new FaultCode();
                newFaultCode.setValue(new Integer(dialog.getValue()).intValue());
                try {
                    _alarmManager.addFaultCode(_alarmManager.getFaultFamily(ff), newFaultCode);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Code", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Code", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                sortFaultFamilyList();
                selectElementFromTree(ff, null, dialog.getValue());
            }
        }
    };
    _addFaultFamily = new Listener() {

        public void handleEvent(Event event) {
            InputDialog dialog = new InputDialog(AlarmsView.this.getViewSite().getShell(), "New Alarm", "Enter the Fault Family name", null, new IInputValidator() {

                public String isValid(String newText) {
                    if (newText.trim().compareTo("") == 0)
                        return "The name is empty";
                    return null;
                }
            });
            dialog.setBlockOnOpen(true);
            dialog.open();
            int returnCode = dialog.getReturnCode();
            if (returnCode == InputDialog.OK) {
                FaultFamily newAlarm = new FaultFamily();
                newAlarm.setName(dialog.getValue());
                try {
                    _alarmManager.addFaultFamily(newAlarm);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Alarm", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Alarm", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                sortFaultFamilyList();
                selectElementFromTree(dialog.getValue(), null, null);
            }
        }
    };
    _sash = new SashForm(parent, SWT.NONE);
    _sash.setLayout(new FillLayout());
    _alarmsComp = new Composite(_sash, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    _alarmsComp.setLayout(layout);
    _treeGroup = new Group(_alarmsComp, SWT.SHADOW_ETCHED_IN);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _treeGroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    _treeGroup.setLayout(gl);
    _treeGroup.setText("Fault Family List");
    /* The tree used to list the FF, FM and FCs */
    _tree = new Tree(_treeGroup, SWT.VIRTUAL | SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _tree.setLayoutData(gd);
    //Menu treePopUp = new Menu(parent, SWT.POP_UP);
    Menu treePopUp = new Menu(parent);
    _tree.setMenu(treePopUp);
    treePopUp.addListener(SWT.Show, new Listener() {

        public void handleEvent(Event e) {
            //Point point = new Point(e.x, e.y);
            //TreeItem sel = _tree.getItem(point);
            TreeItem[] sel = _tree.getSelection();
            Menu treePopUp = _tree.getMenu();
            MenuItem[] items = treePopUp.getItems();
            for (int i = 0; i < items.length; i++) items[i].dispose();
            MenuItem mitem;
            if (sel == null || sel.length == 0) {
                mitem = new MenuItem(treePopUp, SWT.PUSH);
                mitem.setText("Add Fault Family");
                mitem.addListener(SWT.Selection, _addFaultFamily);
                return;
            }
            NodeType type = (NodeType) sel[0].getData();
            switch(type) {
                case FAULT_FAMILY:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Family");
                    mitem.addListener(SWT.Selection, _addFaultFamily);
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Fault Family");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                case FAULT_CODE_LIST:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Code");
                    mitem.addListener(SWT.Selection, _addFaultCode);
                    break;
                case FAULT_CODE_DATA:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Code");
                    mitem.addListener(SWT.Selection, _addFaultCode);
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Fault Code");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                case FAULT_MEMBER_LIST:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Member");
                    mitem.addListener(SWT.Selection, _addFaultMember);
                    if (_alarmManager.getFaultFamily(sel[0].getParentItem().getText()).getFaultMemberDefault() == null) {
                        mitem = new MenuItem(treePopUp, SWT.PUSH);
                        mitem.setText("Add Default Fault Member");
                        mitem.addListener(SWT.Selection, _addFaultMemberDefault);
                    }
                    break;
                case FAULT_MEMBER_DATA:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Member");
                    mitem.addListener(SWT.Selection, _addFaultMember);
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Fault Member");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                case FAULT_MEMBER_DEFAULT:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Default Fault Member");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                default:
                    for (int i = 0; i < items.length; i++) items[i].dispose();
                    break;
            }
        }
    });
    _tree.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            TreeItem[] tmp = ((Tree) e.widget).getSelection();
            if (tmp == null || tmp.length == 0) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                return;
            }
            TreeItem item = tmp[0];
            NodeType type = (NodeType) item.getData();
            /* Delete the label the first time we select something */
            Control c = _compInitial.getChildren()[0];
            if (c instanceof Label) {
                c.dispose();
                _compInitial.layout();
                c = _compInitial.getChildren()[0];
            }
            if (type == NodeType.FAULT_FAMILY) {
                _FFgroup.setVisible(true);
                ((GridData) _FFgroup.getLayoutData()).exclude = false;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                //_FFgroup.moveAbove(c);
                fillFFWidgets(item.getText());
            } else if (type == NodeType.FAULT_CODE_LIST) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(true);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = false;
                fillFCFMWidgets();
            } else if (type == NodeType.FAULT_CODE_DATA) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(true);
                ((GridData) _FCgroup.getLayoutData()).exclude = false;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                //_FCgroup.moveAbove(c);
                fillFCWidgets(Integer.parseInt(item.getText()), item.getParentItem().getParentItem().getText());
            } else if (type == NodeType.FAULT_MEMBER_LIST) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(true);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = false;
                fillFCFMWidgets();
            } else if (type == NodeType.FAULT_MEMBER_DATA) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(true);
                ((GridData) _FMgroup.getLayoutData()).exclude = false;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                //_FMgroup.moveAbove(c);
                fillFMWidgets(item.getText(), item.getParentItem().getParentItem().getText());
            } else if (type == NodeType.FAULT_MEMBER_DEFAULT) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(true);
                ((GridData) _FMDgroup.getLayoutData()).exclude = false;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                fillFMDWidgets(item.getParentItem().getParentItem().getText());
            }
            _compInitial.layout();
        }
    });
    _tree.addListener(SWT.MouseHover, hoverTree);
    _alarmsButtonsComp = new Composite(_alarmsComp, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    _alarmsButtonsComp.setLayout(layout);
    _addAlarmButton = new Button(_alarmsButtonsComp, SWT.None);
    _addAlarmButton.setText("Add");
    _addAlarmButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    _deleteAlarmButton = new Button(_alarmsButtonsComp, SWT.None);
    _deleteAlarmButton.setText("Delete");
    _deleteAlarmButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
    _addAlarmButton.addListener(SWT.Selection, _addFaultFamily);
    _deleteAlarmButton.addListener(SWT.Selection, _deleteElement);
    /* Top widget of the right side */
    _compInitial = new Composite(_sash, SWT.SHADOW_ETCHED_IN);
    _compInitial.setLayout(new GridLayout());
    new Label(_compInitial, SWT.NONE).setText("Select an element");
    /* FF/FM/FC Details */
    createFFWidgets();
    createFCWidgets();
    createFMWidgets();
    createFMDWidgets();
    createFCFMWidgets();
    /* At the beginning we only show a label */
    _FFgroup.setVisible(false);
    _FCgroup.setVisible(false);
    _FMgroup.setVisible(false);
    _FMDgroup.setVisible(false);
    _FCFMgroup.setVisible(false);
    _sash.setWeights(new int[] { 3, 5 });
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) Menu(org.eclipse.swt.widgets.Menu) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) FaultMember(alma.acs.alarmsystem.generated.FaultMember) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) SashForm(org.eclipse.swt.custom.SashForm) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with FaultMember

use of alma.acs.alarmsystem.generated.FaultMember in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method generateAlarmsMap.

/**
	 * Generate the alarms from the definition of the fault families.
	 * The alarms will be added into the HashMap with their triplet as key.
	 * The default item has FM="*".
	 * 
	 * The sources read from the families are also added to the HashMap of the sources
	 *  
	 * @param families The FF read from the CDB
	 */
private void generateAlarmsMap(Vector<FaultFamily> families) {
    if (families == null) {
        throw new IllegalArgumentException("Invalid null vector of FFs");
    }
    for (FaultFamily family : families) {
        String FF = family.getName();
        String helpUrl = family.getHelpUrl();
        String source = family.getAlarmSource();
        Contact contactPerson = family.getContact();
        FaultMember[] FMs = family.getFaultMember();
        FaultMemberDefault defaultFM = family.getFaultMemberDefault();
        FaultCode[] FCs = family.getFaultCode();
        // There should be at least one FC in the CDB
        if (FCs == null || FCs.length == 0) {
            logger.log(AcsLogLevel.WARNING, "No FC defined for family " + family.getName());
            continue;
        }
        // There should be at least one FM or a default FM defined in the CDB
        if (defaultFM == null && (FMs == null || FMs.length == 0)) {
            logger.log(AcsLogLevel.WARNING, "No FM defined for family " + family.getName());
            continue;
        }
        // Iterate over the FCs
        for (FaultCode code : FCs) {
            int FC = code.getValue();
            int priority = code.getPriority();
            String action = code.getAction();
            String cause = code.getCause();
            String consequence = code.getConsequence();
            String problemDesc = code.getProblemDescription();
            boolean instant = code.getInstant();
            // Iterate over all the FMs
            for (FaultMember member : FMs) {
                alma.acs.alarmsystem.generated.Location loc = member.getLocation();
                if (loc == null) {
                    loc = new alma.acs.alarmsystem.generated.Location();
                }
                if (loc.getBuilding() == null) {
                    loc.setBuilding("");
                }
                if (loc.getFloor() == null) {
                    loc.setFloor("");
                }
                if (loc.getMnemonic() == null) {
                    loc.setMnemonic("");
                }
                if (loc.getPosition() == null) {
                    loc.setPosition("");
                }
                if (loc.getRoom() == null) {
                    loc.setRoom("");
                }
                String FM = member.getName();
                if (FM.equals(DEFAULT_FM)) {
                    logger.log(AcsLogLevel.ERROR, "In the CDB, FM=" + DEFAULT_FM + " in family " + FF + " is not allowed");
                }
                AlarmImpl alarm = new AlarmImpl();
                alarm.setMultiplicityChildrenIds(new HashSet());
                alarm.setMultiplicityParentIds(new HashSet());
                alarm.setNodeChildrenIds(new HashSet());
                alarm.setNodeParentIds(new HashSet());
                alarm.setAction(action);
                alarm.setTriplet(new Triplet(FF, FM, FC));
                alarm.setCategories(new HashSet<Category>());
                alarm.setCause(cause);
                alarm.setConsequence(consequence);
                alarm.setProblemDescription(problemDesc);
                try {
                    alarm.setHelpURL(new URL(helpUrl));
                } catch (MalformedURLException e) {
                    alarm.setHelpURL(null);
                }
                alarm.setInstant(instant);
                Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
                alarm.setLocation(location);
                if (contactPerson.getEmail() != null) {
                    alarm.setPiquetEmail(contactPerson.getEmail());
                } else {
                    alarm.setPiquetEmail("");
                }
                if (contactPerson.getGsm() != null) {
                    alarm.setPiquetGSM(contactPerson.getGsm());
                } else {
                    alarm.setPiquetGSM("");
                }
                alarm.setPriority(priority);
                ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
                alarm.setResponsiblePerson(responsible);
                SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
                Source src = new Source(srcDef, responsible);
                alarm.setSource(src);
                alarm.setIdentifier(alarm.getTriplet().toIdentifier());
                addAlarmToCache(alarm);
                if (!srcDefs.containsKey(source)) {
                    srcDefs.put(src.getSourceId(), src);
                    logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
                }
                logger.log(AcsLogLevel.DEBUG, "Alarm added " + alarm.getAlarmId());
            }
            // Add the default
            if (defaultFM != null) {
                alma.acs.alarmsystem.generated.Location loc = defaultFM.getLocation();
                if (loc == null) {
                    loc = new alma.acs.alarmsystem.generated.Location();
                }
                if (loc.getBuilding() == null) {
                    loc.setBuilding("");
                }
                if (loc.getFloor() == null) {
                    loc.setFloor("");
                }
                if (loc.getMnemonic() == null) {
                    loc.setMnemonic("");
                }
                if (loc.getPosition() == null) {
                    loc.setPosition("");
                }
                if (loc.getRoom() == null) {
                    loc.setRoom("");
                }
                AlarmImpl defaultAlarm = new AlarmImpl();
                defaultAlarm.setMultiplicityChildrenIds(new HashSet());
                defaultAlarm.setMultiplicityParentIds(new HashSet());
                defaultAlarm.setNodeChildrenIds(new HashSet());
                defaultAlarm.setNodeParentIds(new HashSet());
                defaultAlarm.setAction(action);
                defaultAlarm.setCategories(new HashSet<Category>());
                defaultAlarm.setCause(cause);
                defaultAlarm.setConsequence(consequence);
                defaultAlarm.setProblemDescription(problemDesc);
                try {
                    defaultAlarm.setHelpURL(new URL(helpUrl));
                } catch (MalformedURLException e) {
                    defaultAlarm.setHelpURL(null);
                }
                defaultAlarm.setInstant(instant);
                Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
                defaultAlarm.setLocation(location);
                defaultAlarm.setPiquetEmail(contactPerson.getEmail());
                defaultAlarm.setPiquetGSM(contactPerson.getGsm());
                defaultAlarm.setPriority(priority);
                ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
                defaultAlarm.setResponsiblePerson(responsible);
                SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
                Source src = new Source(srcDef, responsible);
                defaultAlarm.setSource(src);
                defaultAlarm.setIdentifier(defaultAlarm.getTriplet().toIdentifier());
                Triplet triplet = new Triplet(FF, DEFAULT_FM, FC);
                defaultAlarm.setTriplet(triplet);
                defaultAlarm.setIdentifier(triplet.toIdentifier());
                addAlarmToCache(defaultAlarm);
                if (!srcDefs.containsKey(source)) {
                    srcDefs.put(src.getSourceId(), src);
                    logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
                }
                logger.log(AcsLogLevel.DEBUG, "Default alarm added " + defaultAlarm.getAlarmId());
            }
        }
    }
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) MalformedURLException(java.net.MalformedURLException) SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) URL(java.net.URL) Source(cern.laser.business.data.Source) InputSource(org.xml.sax.InputSource) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) HashSet(java.util.HashSet) FaultMember(alma.acs.alarmsystem.generated.FaultMember) Triplet(cern.laser.business.data.Triplet) Contact(alma.acs.alarmsystem.generated.Contact) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) AlarmImpl(cern.laser.business.data.AlarmImpl) Location(cern.laser.business.data.Location)

Example 13 with FaultMember

use of alma.acs.alarmsystem.generated.FaultMember in project ACS by ACS-Community.

the class CDBSender method readAlarmsFromCDB.

/**
	 * Read alarms from the TM/CDB with the help of {@link ACSAlarmDAOImpl}.
	 * <P>
	 * This method can be quite slow so it would be better to run 
	 * in a dedicated thread.
	 * 
	 * @throws Exception
	 */
private void readAlarmsFromCDB() throws Exception {
    ConfigurationAccessor conf;
    conf = ConfigurationAccessorFactory.getInstance(contSvcs);
    ACSAlarmDAOImpl alarmDAO = new ACSAlarmDAOImpl(contSvcs.getLogger());
    alarmDAO.setConfAccessor(conf);
    List<FaultFamily> FFs = alarmDAO.loadAlarms();
    synchronized (alarms) {
        for (FaultFamily ff : FFs) {
            String faultFamily = ff.getName();
            for (FaultMember fm : ff.getFaultMember()) {
                for (FaultCode fc : ff.getFaultCode()) {
                    alarms.add(new AlarmRead(faultFamily + "," + fm.getName() + "," + fc.getValue(), null));
                }
            }
            // Has this FF a default fault member?
            if (ff.getFaultMemberDefault() != null) {
                System.out.println("Found a default fault member for " + ff.getName());
                for (FaultCode fc : ff.getFaultCode()) {
                    alarms.add(new AlarmRead(faultFamily + ",*," + fc.getValue(), null));
                }
            }
        }
    }
}
Also used : ConfigurationAccessor(com.cosylab.acs.laser.dao.ConfigurationAccessor) FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultCode(alma.acs.alarmsystem.generated.FaultCode) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) ACSAlarmDAOImpl(com.cosylab.acs.laser.dao.ACSAlarmDAOImpl)

Example 14 with FaultMember

use of alma.acs.alarmsystem.generated.FaultMember in project ACS by ACS-Community.

the class AlarmManager method updateFaultMember.

/**
	 * Modifies a Fault Member of a given Fault Family.
	 * @param ff The Fault Family to which belongs the Fault Member to be changed
	 * @param fm The Fault Member to be changed
	 * @param fmi The Fault Member with the new values
	 * @throws NullPointerException If any (or both) of the given Fault Members (or their names)
	 * or the Fault Family (or its name) or both are null
	 * @throws IllegalOperationException If the Fault Family doesn't exists
	 */
public void updateFaultMember(FaultFamily ff, FaultMember fm, FaultMember fmi) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) is null");
    if (fm == null || fm.getName() == null)
        throw new NullPointerException("The Fault Member (or its name) to be changed is null");
    if (fmi == null || fmi.getName() == null)
        throw new NullPointerException("The Fault Member (or its name) with the new values is null");
    for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
        FaultFamily fft = (FaultFamily) iterator.next();
        if (fft.getName().compareTo(ff.getName()) == 0) {
            for (Iterator<FaultMember> iterator2 = Arrays.asList(fft.getFaultMember()).iterator(); iterator2.hasNext(); ) {
                FaultMember fmt = (FaultMember) iterator2.next();
                if (fmt.getName().compareTo(fmi.getName()) == 0) {
                    if (fm.getName().compareTo(fmi.getName()) == 0)
                        continue;
                    throw new IllegalOperationException("The Fault Member " + fmi.getName() + " already exists");
                }
            }
            for (Iterator<FaultMember> iterator2 = Arrays.asList(fft.getFaultMember()).iterator(); iterator2.hasNext(); ) {
                FaultMember fmt = (FaultMember) iterator2.next();
                if (fmt.getName().compareTo(fm.getName()) == 0) {
                    String name = fm.getName();
                    fmt.setName(fmi.getName());
                    fmt.setLocation(fmi.getLocation());
                    ObjectState os = _objState.get(fft.getName());
                    if (os == null)
                        throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
                    os.update();
                    if (name.compareTo(fmi.getName()) != 0) {
                        Vector<FaultFamily> ffs = new Vector<FaultFamily>();
                        ffs.add(ff);
                        ((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
                        ((ACSAlarmDAOImpl) _alarmDAO).generateAlarmsMap(ffs);
                    }
                    return;
                }
            }
            throw new IllegalOperationException("The Fault Member " + fm.getName() + " doesn't exists");
        }
    }
    throw new IllegalOperationException("The Fault Family " + ff.getName() + " doesn't exists");
}
Also used : FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 15 with FaultMember

use of alma.acs.alarmsystem.generated.FaultMember in project ACS by ACS-Community.

the class AlarmManager method checkCDB.

public String checkCDB() {
    List<FaultFamily> ffs = _ffList;
    String error = "";
    for (FaultFamily ff : ffs) {
        if (ff.getName() == null || ff.getName().length() == 0)
            error += "Fault Family " + ff.getName() + " doesn't have a name.\n";
        try {
            new URI(ff.getHelpUrl());
        } catch (MalformedURIException e1) {
            error += "Fault Family " + ff.getName() + " has malformed URL.\n";
        }
        if (ff.getContact() == null)
            error += "Fault Family " + ff.getName() + " doesn't define Contact entity.\n";
        if (ff.getContact().getName() == null || ff.getContact().getName().length() == 0)
            error += "Fault Family " + ff.getName() + " doesn't define Contact name.\n";
        if (ff.getAlarmSource().compareTo("ALARM_SYSTEM_SOURCES") != 0)
            error += "Fault Family " + ff.getName() + " has wrong Source defined.\n";
        if (ff.getFaultMemberCount() == 0 && ff.getFaultMemberDefault() == null)
            error += "Fault Family " + ff.getName() + " doesn't define any Fault Member and doesn't have a Default Fault Member.\n";
        FaultMember[] fms = ff.getFaultMember();
        for (FaultMember fm : fms) {
            if (fm.getName() == null || fm.getName().length() == 0)
                error += "Fault Member " + fm.getName() + " defined in Fault Family " + ff.getName() + " doesn't have a name.\n";
        }
        FaultCode[] fcs = ff.getFaultCode();
        for (FaultCode fc : fcs) {
            if (fc.getValue() <= 0)
                error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " has an invalid value (Must be > 0).\n";
            if (!fc.hasPriority())
                error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " doesn't define a priority.\n";
            if (fc.getPriority() < 0 || fc.getPriority() > 3)
                error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " has an invalid a priority (Must be in [0;3]).\n";
            if (fc.getProblemDescription() == null || fc.getProblemDescription().length() == 0)
                error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " doesn't define a problem description.\n";
        }
    }
    return error;
}
Also used : FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultCode(alma.acs.alarmsystem.generated.FaultCode) MalformedURIException(org.apache.xerces.util.URI.MalformedURIException) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) URI(org.apache.xerces.util.URI)

Aggregations

FaultMember (alma.acs.alarmsystem.generated.FaultMember)22 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)19 FaultCode (alma.acs.alarmsystem.generated.FaultCode)12 FaultMemberDefault (alma.acs.alarmsystem.generated.FaultMemberDefault)7 Contact (alma.acs.alarmsystem.generated.Contact)6 Alarm (cern.laser.business.data.Alarm)6 Location (alma.acs.alarmsystem.generated.Location)5 ArrayList (java.util.ArrayList)4 Point (org.eclipse.swt.graphics.Point)4 Triplet (cern.laser.business.data.Triplet)3 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 ReductionRule (cl.utfsm.acs.acg.core.ReductionRule)3 ACSAlarmDAOImpl (cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)3 Vector (java.util.Vector)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Event (org.eclipse.swt.widgets.Event)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3