Search in sources :

Example 1 with IllegalOperationException

use of cl.utfsm.acs.acg.core.IllegalOperationException in project ACS by ACS-Community.

the class AlarmsView method createFCWidgets.

private void createFCWidgets() {
    Listener updateFaultCode = new Listener() {

        public void handleEvent(Event event) {
            int val;
            if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                return;
            TreeItem tmp = _tree.getSelection()[0];
            int tfc = Integer.parseInt(tmp.getText());
            String tff = tmp.getParentItem().getParentItem().getText();
            FaultCode fct = new FaultCode();
            try {
                val = Integer.parseInt(_fcValueText.getText());
                if (val <= 0) {
                    _fcErrorMessageLabel.setText("FaultCode is Negative or Zero. A positive number is required.");
                    return;
                }
                fct.setValue(val);
            } catch (NumberFormatException e) {
                _fcErrorMessageLabel.setText("FaultCode is not a Number. A positive number is required.");
                return;
            }
            try {
                val = Integer.parseInt(_fcPriorityText.getText());
                if (val < 0 || val > 3) {
                    _fcErrorMessageLabel.setText("Incorrect Priority. A number in the range [0;3] is required.");
                    return;
                }
                fct.setPriority(val);
            } catch (NumberFormatException e) {
                _fcErrorMessageLabel.setText("Priority is not a number. A number in the range [0;3] is required.");
                return;
            }
            if (!_fcCauseText.getText().isEmpty())
                fct.setCause(_fcCauseText.getText());
            if (!_fcActionText.getText().isEmpty())
                fct.setAction(_fcActionText.getText());
            if (!_fcConsequenceText.getText().isEmpty())
                fct.setConsequence(_fcConsequenceText.getText());
            if (_fcProblemText.getText().isEmpty()) {
                _fcErrorMessageLabel.setText("Problem Description is Required.");
                return;
            }
            fct.setProblemDescription(_fcProblemText.getText());
            _fcErrorMessageLabel.setText("");
            try {
                _alarmManager.updateFaultCode(_alarmManager.getFaultFamily(tff), _alarmManager.getFaultCode(tff, tfc), fct);
                tmp.setText(_fcValueText.getText());
                if (fct.getValue() != tfc) {
                    sortFaultFamilyList();
                    selectElementFromTree(tff, null, Integer.toString(fct.getValue()));
                }
            } catch (IllegalOperationException e) {
                _fcErrorMessageLabel.setText(e.getMessage());
            } catch (NullPointerException e) {
                _fcErrorMessageLabel.setText(e.getMessage());
            }
        }
    };
    _FCgroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    _FCgroup.setText("Fault Code detail");
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    _FCgroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    _FCgroup.setLayout(gl);
    _fcValueLabel = new Label(_FCgroup, SWT.NONE);
    _fcValueLabel.setText("Value");
    _fcValueText = new Text(_FCgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _fcValueText.setLayoutData(gd);
    _fcValueText.addListener(SWT.Modify, updateFaultCode);
    _fcPriorityLabel = new Label(_FCgroup, SWT.NONE);
    _fcPriorityLabel.setText("Priority");
    _fcPriorityText = new Text(_FCgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _fcPriorityText.setLayoutData(gd);
    _fcPriorityText.addListener(SWT.Modify, updateFaultCode);
    _fcCauseLabel = new Label(_FCgroup, SWT.NONE);
    _fcCauseLabel.setText("Cause");
    _fcCauseText = new Text(_FCgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _fcCauseText.setLayoutData(gd);
    _fcCauseText.addListener(SWT.Modify, updateFaultCode);
    _fcActionLabel = new Label(_FCgroup, SWT.NONE);
    _fcActionLabel.setText("Action");
    _fcActionText = new Text(_FCgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _fcActionText.setLayoutData(gd);
    _fcActionText.addListener(SWT.Modify, updateFaultCode);
    _fcConsequenceLabel = new Label(_FCgroup, SWT.NONE);
    _fcConsequenceLabel.setText("Consequence");
    _fcConsequenceText = new Text(_FCgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _fcConsequenceText.setLayoutData(gd);
    _fcConsequenceText.addListener(SWT.Modify, updateFaultCode);
    _fcProblemLabel = new Label(_FCgroup, SWT.NONE);
    _fcProblemLabel.setText("Problem description");
    _fcProblemText = new Text(_FCgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _fcProblemText.setLayoutData(gd);
    _fcProblemText.addListener(SWT.Modify, updateFaultCode);
    _fcErrorMessageLabel = new Label(_FCgroup, SWT.NONE);
    _fcErrorMessageLabel.setText("");
    _fcErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _fcErrorMessageLabel.setLayoutData(gd);
}
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) Text(org.eclipse.swt.widgets.Text) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with IllegalOperationException

use of cl.utfsm.acs.acg.core.IllegalOperationException in project ACS by ACS-Community.

the class AlarmsView method createFFWidgets.

private void createFFWidgets() {
    _updateFaultFamily = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            String ff = tmp.getText();
            FaultFamily fft = new FaultFamily();
            //TODO: Error icon or something similar
            if (_ffNameText.getText().isEmpty()) {
                _ffErrorMessageLabel.setText("FaultFamily Name Missing!");
                return;
            }
            if (_ffNameText.getText().contains(" ")) {
                _ffErrorMessageLabel.setText("Invalid FaultFamily Name. No spaces allowed.");
                return;
            }
            fft.setName(_ffNameText.getText());
            if (!_ffHelpURLText.getText().isEmpty()) {
                URI hurl;
                try {
                    hurl = new URI(_ffHelpURLText.getText());
                } catch (MalformedURIException e1) {
                    _ffErrorMessageLabel.setText("Malformed URL!");
                    return;
                }
                fft.setHelpUrl(hurl.toString());
            }
            fft.setAlarmSource(_ffSourceCombo.getText());
            Contact ct = new Contact();
            if (_ffContactNameText.getText().isEmpty()) {
                _ffErrorMessageLabel.setText("Contact Name Missing!");
                return;
            }
            ct.setName(_ffContactNameText.getText());
            if (!_ffContactMailText.getText().isEmpty())
                ct.setEmail(_ffContactMailText.getText());
            if (!_ffContactGSMText.getText().isEmpty())
                ct.setGsm(_ffContactGSMText.getText());
            fft.setContact(ct);
            _ffErrorMessageLabel.setText("");
            try {
                _alarmManager.updateFaultFamily(_alarmManager.getFaultFamily(ff), fft);
                tmp.setText(_ffNameText.getText());
                IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
                IViewReference[] views = _window.getActivePage().getViewReferences();
                IMyViewPart view = ((IMyViewPart) views[2].getView(false));
                view.fillWidgets();
                if (ff.compareTo(fft.getName()) != 0) {
                    sortFaultFamilyList();
                    selectElementFromTree(fft.getName(), null, null);
                }
            } catch (IllegalOperationException e) {
                _ffErrorMessageLabel.setText(e.getMessage());
            } catch (NullPointerException e) {
                e.printStackTrace();
                _ffErrorMessageLabel.setText(e.getMessage());
            }
        }
    };
    _addCategory = new Listener() {

        public void handleEvent(Event event) {
            if (event.type == SWT.KeyUp)
                if (!(event.keyCode == SWT.CR || event.keyCode == ' '))
                    return;
            if (event.type == SWT.MouseDoubleClick) {
                Point pt = new Point(event.x, event.y);
                if (_ffCategoryList.getItem(pt) == null)
                    return;
            }
            TreeItem[] tmp1 = _tree.getSelection();
            if (tmp1 == null || tmp1.length == 0)
                return;
            String ff = tmp1[0].getText();
            TableItem[] tmp2 = _ffCategoryList.getSelection();
            if (tmp2 == null || tmp2.length == 0)
                return;
            TableItem item = tmp2[0];
            Category c = _categoryManager.getCategoryByPath(item.getText());
            try {
                String[] ffs = c.getAlarms().getFaultFamily();
                for (int i = 0; i < ffs.length; i++) {
                    if (ff.compareTo(ffs[i]) == 0) {
                        c.getAlarms().removeFaultFamily(ff);
                        item.setImage((org.eclipse.swt.graphics.Image) null);
                        IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
                        IViewReference[] views = _window.getActivePage().getViewReferences();
                        IMyViewPart view = ((IMyViewPart) views[2].getView(false));
                        view.fillWidgets();
                        return;
                    }
                }
                c.getAlarms().addFaultFamily(ff);
                item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            } catch (NullPointerException e) {
                item.setImage((org.eclipse.swt.graphics.Image) null);
                Alarms alarms = new Alarms();
                alarms.addFaultFamily(ff.toString());
                alarms.setFaultFamily(0, ff.toString());
                c.setAlarms(alarms);
                item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            }
            IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
            IViewReference[] views = _window.getActivePage().getViewReferences();
            IMyViewPart view = ((IMyViewPart) views[2].getView(false));
            view.fillWidgets();
        }
    };
    _FFgroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    _FFgroup.setText("Fault Family details");
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    _FFgroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    _FFgroup.setLayout(gl);
    _ffNameLabel = new Label(_FFgroup, SWT.NONE);
    _ffNameLabel.setText("Fault Family name");
    _ffNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffNameText.setLayoutData(gd);
    _ffNameText.addListener(SWT.Modify, _updateFaultFamily);
    _ffHelpURLLabel = new Label(_FFgroup, SWT.NONE);
    _ffHelpURLLabel.setText("Help URL");
    _ffHelpURLText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffHelpURLText.setLayoutData(gd);
    _ffHelpURLText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactNameLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactNameLabel.setText("Contact name");
    _ffContactNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactNameText.setLayoutData(gd);
    _ffContactNameText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactMailLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactMailLabel.setText("Contact e-mail");
    _ffContactMailText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactMailText.setLayoutData(gd);
    _ffContactMailText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactGSMLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactGSMLabel.setText("Contact GSM");
    _ffContactGSMText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactGSMText.setLayoutData(gd);
    _ffContactGSMText.addListener(SWT.Modify, _updateFaultFamily);
    _ffSourceLabel = new Label(_FFgroup, SWT.NONE);
    _ffSourceLabel.setText("Source");
    _ffSourceCombo = new Combo(_FFgroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffSourceCombo.setLayoutData(gd);
    _ffSourceCombo.setEnabled(false);
    _ffSourceCombo.addListener(SWT.Modify, _updateFaultFamily);
    _ffCategoryLabel = new Label(_FFgroup, SWT.NONE);
    _ffCategoryLabel.setText("Categories:");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _ffCategoryLabel.setLayoutData(gd);
    _ffCategoryList = new Table(_FFgroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    _ffCategoryList.setLayoutData(gd);
    _ffCategoryList.addListener(SWT.KeyUp, _addCategory);
    _ffCategoryList.addListener(SWT.MouseDoubleClick, _addCategory);
    Menu categoryPopUp = new Menu(_ffCategoryList);
    _ffCategoryList.setMenu(categoryPopUp);
    categoryPopUp.addListener(SWT.Show, new Listener() {

        public void handleEvent(Event e) {
            TableItem[] sel = _ffCategoryList.getSelection();
            Menu categoryPopUp = _ffCategoryList.getMenu();
            MenuItem[] items = categoryPopUp.getItems();
            for (int i = 0; i < items.length; i++) items[i].dispose();
            if (sel == null || sel.length == 0)
                return;
            MenuItem mitem;
            mitem = new MenuItem(categoryPopUp, SWT.PUSH);
            if (sel[0].getImage() == null) {
                mitem.setText("Add to Category");
                mitem.addListener(SWT.Selection, _addCategory);
            } else {
                mitem.setText("Remove from Category");
                mitem.addListener(SWT.Selection, _addCategory);
            }
        }
    });
    _ffErrorMessageLabel = new Label(_FFgroup, SWT.NONE);
    _ffErrorMessageLabel.setText("");
    _ffErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _ffErrorMessageLabel.setLayoutData(gd);
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) MalformedURIException(org.apache.xerces.util.URI.MalformedURIException) Category(alma.acs.alarmsystem.generated.Category) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) URI(org.apache.xerces.util.URI) GridLayout(org.eclipse.swt.layout.GridLayout) Menu(org.eclipse.swt.widgets.Menu) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Table(org.eclipse.swt.widgets.Table) Alarms(alma.acs.alarmsystem.generated.Alarms) Text(org.eclipse.swt.widgets.Text) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) Contact(alma.acs.alarmsystem.generated.Contact) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with IllegalOperationException

use of cl.utfsm.acs.acg.core.IllegalOperationException in project ACS by ACS-Community.

the class ReductionsView method createMRParentWidgets.

private void createMRParentWidgets() {
    _updateMRParentFF = new Listener() {

        public void handleEvent(Event event) {
            _MRParentFMCombo.removeAll();
            FaultMember[] fml = _alarmManager.getFaultFamily(_MRParentFFCombo.getText()).getFaultMember();
            for (int j = 0; j < fml.length; j++) {
                _MRParentFMCombo.add(fml[j].getName());
            }
            _MRParentFCCombo.removeAll();
            FaultCode[] fcl = _alarmManager.getFaultFamily(_MRParentFFCombo.getText()).getFaultCode();
            for (int j = 0; j < fcl.length; j++) {
                _MRParentFCCombo.add(String.valueOf(fcl[j].getValue()));
            }
            //_MRParentThresholdText.setText("");
            _MRParentErrorMessageLabel.setText("Please choose a Fault Member and a Fault Code.");
        }
    };
    _updateMRParent = new Listener() {

        public void handleEvent(Event event) {
            if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                return;
            NodeType type = (NodeType) _tree.getSelection()[0].getData();
            if (type != NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA)
                return;
            if (_MRParentFMCombo.getText().isEmpty()) {
                _MRParentErrorMessageLabel.setText("Please choose a Fault Member.");
                return;
            }
            if (_MRParentFCCombo.getText().isEmpty()) {
                _MRParentErrorMessageLabel.setText("Please choose a Fault Code.");
                return;
            }
            if (_MRParentThresholdText.getText().isEmpty()) {
                _MRParentErrorMessageLabel.setText("Please set a Threshold value.");
                return;
            }
            int thr;
            try {
                thr = Integer.parseInt(_MRParentThresholdText.getText());
            } catch (NumberFormatException e) {
                _MRParentErrorMessageLabel.setText("Incorrect Threshold. A number is required.");
                return;
            }
            String[] tr = getTriplet(_tree.getSelection()[0].getText());
            ReductionRule mrr = _reductionManager.getMRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
            ReductionRule mrr2 = _reductionManager.getMRParentByTriplet(_MRParentFFCombo.getText(), _MRParentFMCombo.getText(), Integer.parseInt(_MRParentFCCombo.getText()));
            Alarm parent = null;
            Alarm mParent;
            fillMRParentChAlarmList(_MRParentFFCombo.getText(), _MRParentFMCombo.getText(), Integer.parseInt(_MRParentFCCombo.getText()));
            if (mrr == null) {
                _MRParentErrorMessageLabel.setText("There's no Reduction Rule (no children) for the selected Alarm.");
                return;
            } else
                parent = mrr.getParent();
            if (mrr2 == null)
                mParent = _alarmManager.getAlarm(new String(_MRParentFFCombo.getText() + ":" + _MRParentFMCombo.getText() + ":" + _MRParentFCCombo.getText()));
            else {
                mParent = mrr2.getParent();
                if (mrr != mrr2) {
                    ErrorDialog edialog = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Reduction Rule Already Exists", "The reduction rule you are trying to create already exists", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "The reduction rule parent already exists"), IStatus.ERROR);
                    edialog.setBlockOnOpen(true);
                    edialog.open();
                    return;
                }
            }
            if (parent != null) {
                String[] ch = parent.getMultiplicityChildren();
                //Remove all Children from mrr and add them to mrr2.
                try {
                    for (int i = 0; i < ch.length; i++) {
                        Alarm aCh = _alarmManager.getAlarm(ch[i]);
                        if (aCh != null) {
                            if (!_reductionManager.deleteMultiReductionRule(parent, aCh)) {
                                _MRParentErrorMessageLabel.setText("One or more children alarms didn't exist.");
                                continue;
                            }
                            _reductionManager.addMultiReductionRule(mParent, aCh);
                        }
                    }
                    _reductionManager.updateMultiThreshold(mParent, thr);
                } catch (IllegalOperationException e) {
                    _MRParentErrorMessageLabel.setText("The parent alarm didn't exist.");
                }
                _tree.getSelection()[0].setText("<" + mParent.getAlarmId().replace(':', ',') + ">");
                _MRParentErrorMessageLabel.setText("");
            }
            if (mrr != null && mrr.getChildrenCount() < mrr.getThreshold()) {
                _MRParentErrorMessageLabel.setText("You need to have at least threshold (" + mrr.getThreshold() + ") childs for this triplet.");
                return;
            }
            if (tr[0].compareTo(_MRParentFFCombo.getText()) != 0 || tr[1].compareTo(_MRParentFMCombo.getText()) != 0 || tr[2].compareTo(_MRParentFCCombo.getText()) != 0) {
                sortReductionRulesList();
                Triplet t = mParent.getTriplet();
                selectElementFromTree("<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">", false);
            }
        }
    };
    _updateMRParentChFF = new Listener() {

        public void handleEvent(Event event) {
            _MRParentChFMCombo.removeAll();
            _MRParentChFMCombo.add("Any");
            if (_MRParentChFFCombo.getText().compareTo("Any") != 0) {
                FaultMember[] fml = _alarmManager.getFaultFamily(_MRParentChFFCombo.getText()).getFaultMember();
                for (int j = 0; j < fml.length; j++) {
                    _MRParentChFMCombo.add(fml[j].getName());
                }
            }
            _MRParentChFMCombo.select(0);
            _MRParentChFCCombo.removeAll();
            _MRParentChFCCombo.add("Any");
            if (_MRParentChFFCombo.getText().compareTo("Any") != 0) {
                FaultCode[] fcl = _alarmManager.getFaultFamily(_MRParentChFFCombo.getText()).getFaultCode();
                for (int j = 0; j < fcl.length; j++) {
                    _MRParentChFCCombo.add(String.valueOf(fcl[j].getValue()));
                }
            }
            _MRParentChFCCombo.select(0);
            TreeItem[] tmp = _tree.getSelection();
            if (tmp == null || tmp.length == 0)
                return;
            TreeItem item = tmp[0];
            String[] triplet = getTriplet(item.getText());
            fillMRParentChAlarmList(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
        }
    };
    _updateMRParentCh = new Listener() {

        public void handleEvent(Event event) {
            TreeItem[] tmp = _tree.getSelection();
            if (tmp == null || tmp.length == 0)
                return;
            TreeItem item = tmp[0];
            String[] triplet = getTriplet(item.getText());
            fillMRParentChAlarmList(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
        }
    };
    _MRParentGroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    _MRParentGroup.setLayout(gl);
    _MRParentGroup.setLayoutData(gd);
    _MRParentFtGroup = new Group(_MRParentGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 2;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFtGroup.setLayout(gl);
    _MRParentFtGroup.setLayoutData(gd);
    _MRParentFtGroup.setText("Primary Alarm");
    _MRParentFFLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentFFLabel.setText("Fault Family:");
    _MRParentFFCombo = new Combo(_MRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFFCombo.setLayoutData(gd);
    _MRParentFFCombo.addListener(SWT.Selection, _updateMRParentFF);
    _MRParentFMLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentFMLabel.setText("Fault Member:");
    _MRParentFMCombo = new Combo(_MRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFMCombo.setLayoutData(gd);
    _MRParentFMCombo.addListener(SWT.Selection, _updateMRParent);
    _MRParentFCLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentFCLabel.setText("Fault Code:");
    _MRParentFCCombo = new Combo(_MRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFCCombo.setLayoutData(gd);
    _MRParentFCCombo.addListener(SWT.Selection, _updateMRParent);
    _MRParentThresholdLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentThresholdLabel.setText("Threshold:");
    _MRParentThresholdText = new Text(_MRParentFtGroup, SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentThresholdText.setLayoutData(gd);
    _MRParentThresholdText.addListener(SWT.Modify, _updateMRParent);
    //
    _MRParentChGroup = new Group(_MRParentGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 1;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    _MRParentChGroup.setLayout(gl);
    _MRParentChGroup.setLayoutData(gd);
    _MRParentChGroup.setText("Alarms to Ignore");
    _MRParentChFilterGroup = new Group(_MRParentChGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 2;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFilterGroup.setLayout(gl);
    _MRParentChFilterGroup.setLayoutData(gd);
    _MRParentChFilterGroup.setText("Filter Options");
    _MRParentChFilterLevelGroup = new Group(_MRParentChFilterGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 3;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFilterLevelGroup.setLayout(gl);
    _MRParentChFilterLevelGroup.setLayoutData(gd);
    _MRParentChFilterLevelGroup.setText("Show");
    _MRParentChAllRadio = new Button(_MRParentChFilterLevelGroup, SWT.RADIO);
    _MRParentChAllRadio.setText("All");
    _MRParentChAllRadio.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChSelectedRadio = new Button(_MRParentChFilterLevelGroup, SWT.RADIO);
    _MRParentChSelectedRadio.setText("Selected");
    _MRParentChSelectedRadio.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChUnselectedRadio = new Button(_MRParentChFilterLevelGroup, SWT.RADIO);
    _MRParentChUnselectedRadio.setText("Unselected");
    _MRParentChUnselectedRadio.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChFFLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFFLabel.setText("Fault Family:");
    _MRParentChFFCombo = new Combo(_MRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFFCombo.setLayoutData(gd);
    _MRParentChFFCombo.addListener(SWT.Selection, _updateMRParentChFF);
    _MRParentChFMLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFMLabel.setText("Fault Member:");
    _MRParentChFMCombo = new Combo(_MRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFMCombo.setLayoutData(gd);
    _MRParentChFMCombo.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChFCLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFCLabel.setText("Fault Code:");
    _MRParentChFCCombo = new Combo(_MRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFCCombo.setLayoutData(gd);
    _MRParentChFCCombo.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChFilterLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFilterLabel.setText("Filter RegEx:");
    _MRParentChFilterText = new Text(_MRParentChFilterGroup, SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFilterText.setLayoutData(gd);
    _MRParentChFilterText.addListener(SWT.Modify, _updateMRParentCh);
    _MRParentChAlarmList = new Table(_MRParentChGroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _MRParentChAlarmList.setLayoutData(gd);
    _MRParentChAlarmList.addListener(SWT.KeyUp, _addRule);
    _MRParentChAlarmList.addListener(SWT.MouseDoubleClick, _addRule);
    _MRParentErrorMessageLabel = new Label(_MRParentGroup, SWT.NONE);
    _MRParentErrorMessageLabel.setText("");
    _MRParentErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _MRParentErrorMessageLabel.setLayoutData(gd);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) Table(org.eclipse.swt.widgets.Table) TreeItem(org.eclipse.swt.widgets.TreeItem) Triplet(cern.laser.business.data.Triplet) Label(org.eclipse.swt.widgets.Label) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) ReductionRule(cl.utfsm.acs.acg.core.ReductionRule) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Alarm(cern.laser.business.data.Alarm) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 4 with IllegalOperationException

use of cl.utfsm.acs.acg.core.IllegalOperationException 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 5 with IllegalOperationException

use of cl.utfsm.acs.acg.core.IllegalOperationException in project ACS by ACS-Community.

the class SourcesView method createViewWidgets.

private void createViewWidgets(final Composite parent) {
    _sash = new SashForm(parent, SWT.HORIZONTAL);
    _sash.setLayout(new FillLayout());
    /* Left pane */
    _sourcesComp = new Composite(_sash, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    _sourcesComp.setLayout(layout);
    _listGroup = new Group(_sourcesComp, SWT.SHADOW_ETCHED_IN);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _listGroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    _listGroup.setLayout(gl);
    _listGroup.setText("Sources List");
    _sourcesList = new List(_listGroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _sourcesList.setLayoutData(gd);
    _sourcesButtonsComp = new Composite(_sourcesComp, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    _sourcesButtonsComp.setLayout(layout);
    _addSourceButton = new Button(_sourcesButtonsComp, SWT.None);
    _addSourceButton.setText("Add");
    _addSourceButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    _deleteSourceButton = new Button(_sourcesButtonsComp, SWT.None);
    _deleteSourceButton.setText("Delete");
    _deleteSourceButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
    /* Please change this in the future when more SOURCES will be available */
    _addSourceButton.setEnabled(false);
    _deleteSourceButton.setEnabled(false);
    _sourcesList.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            String source = _sourcesList.getSelection()[0];
            Control c = _compInitial.getChildren()[0];
            if (c instanceof Label) {
                c.dispose();
                _group.setVisible(true);
                _group.layout();
            }
            fillSource(source);
            _compInitial.layout();
        }
    });
    _addSourceButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            InputDialog dialog = new InputDialog(SourcesView.this.getViewSite().getShell(), "New source", "Enter the source 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) {
                Source newSource = new Source();
                newSource.setSourceId(dialog.getValue());
                try {
                    _sourceManager.addSource(newSource);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(SourcesView.this.getViewSite().getShell(), "Source already exist", "The source " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                refreshContents();
                if (_sourcesList.getItems().length != 0) {
                    int lenght = _sourcesList.getItems().length;
                    lenght -= 1;
                    _sourcesList.select(lenght);
                    _descriptionText.setText(_sourcesList.getItem(lenght).toString());
                }
            }
        }
    });
    _deleteSourceButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            boolean choice = MessageDialog.openQuestion(SourcesView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this Source");
            if (choice == true) {
                String[] tmp = _sourcesList.getSelection();
                if (tmp.length == 0) {
                    MessageBox box = new MessageBox(getViewSite().getShell(), SWT.OK | SWT.ICON_ERROR | SWT.APPLICATION_MODAL);
                    box.setText("Empty selection");
                    box.setMessage("There are no sources selected to be deleted");
                    box.open();
                    return;
                }
                String source = tmp[0];
                try {
                    _sourceManager.deleteSource(_sourceManager.getSource(source));
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(SourcesView.this.getViewSite().getShell(), "Cannot delete source", "The source cannot be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                }
                refreshContents();
                if (_sourcesList.getItems().length != 0) {
                    int lenght = _sourcesList.getItems().length;
                    lenght -= 1;
                    _sourcesList.select(lenght);
                    _sourceNameText.setText(_sourcesList.getItem(lenght).toString());
                }
            }
        }
    });
    /* Right pane */
    _compInitial = new Composite(_sash, SWT.NONE);
    _compInitial.setLayout(new GridLayout());
    new Label(_compInitial, SWT.NONE).setText("Select a source");
    layout = new GridLayout();
    layout.numColumns = 2;
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _group = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    _group.setText("Source information");
    _group.setLayout(layout);
    _group.setLayoutData(gd);
    _sourceNameLabel = new Label(_group, SWT.NONE);
    _sourceNameLabel.setText("Source name");
    _sourceNameText = new Text(_group, SWT.BORDER);
    _descriptionLabel = new Label(_group, SWT.NONE);
    _descriptionLabel.setText("Description");
    _descriptionText = new Text(_group, SWT.BORDER);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    _sourceNameText.setLayoutData(gd);
    _descriptionText.setLayoutData(gd);
    _group.setVisible(false);
    _sash.setWeights(new int[] { 3, 5 });
    /* TODO: This is temporal, since there is currently only
		 * one source defined in the AS, and it's hardcoded */
    //setEnabled(false);
    _descriptionText.addListener(SWT.Modify, new Listener() {

        public void handleEvent(Event e) {
            updateSource();
        }
    });
    _errorMessageLabel = new Label(_group, SWT.NONE);
    _errorMessageLabel.setText("");
    _errorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _errorMessageLabel.setLayoutData(gd);
    /* Please change this in the future when more SOURCES will be available */
    _sourceNameText.setEnabled(false);
    _descriptionText.setEnabled(false);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) Source(cern.laser.business.data.Source) MessageBox(org.eclipse.swt.widgets.MessageBox) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(org.eclipse.swt.widgets.List) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 SelectionListener (org.eclipse.swt.events.SelectionListener)10 GridData (org.eclipse.swt.layout.GridData)10 GridLayout (org.eclipse.swt.layout.GridLayout)10 Event (org.eclipse.swt.widgets.Event)10 Group (org.eclipse.swt.widgets.Group)10 Label (org.eclipse.swt.widgets.Label)10 Listener (org.eclipse.swt.widgets.Listener)10 Text (org.eclipse.swt.widgets.Text)8 TreeItem (org.eclipse.swt.widgets.TreeItem)8 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 ErrorDialog (org.eclipse.jface.dialogs.ErrorDialog)6 Button (org.eclipse.swt.widgets.Button)5 SashForm (org.eclipse.swt.custom.SashForm)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Control (org.eclipse.swt.widgets.Control)4 Menu (org.eclipse.swt.widgets.Menu)4