Search in sources :

Example 1 with Category

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

the class AlarmsView method sortCategoryList.

public void sortCategoryList(String name) {
    _ffCategoryList.removeAll();
    List<Category> catList = _categoryManager.getAllCategories();
    List<String> sortedCatList = new ArrayList<String>();
    for (Category cat : catList) sortedCatList.add(cat.getPath().toLowerCase());
    Collections.sort(sortedCatList);
    for (String sc : sortedCatList) {
        Category cat = null;
        for (Category c : catList) if (c.getPath().toLowerCase().compareTo(sc) == 0)
            cat = c;
        if (cat == null)
            return;
        if (cat.getAlarms() == null) {
            TableItem t = new TableItem(_ffCategoryList, SWT.None);
            t.setText(cat.getPath());
            if (cat.getIsDefault()) {
                FontData fd = t.getFont().getFontData()[0];
                fd.setStyle(SWT.BOLD);
                t.setFont(new Font(_shell.getDisplay(), fd));
            }
        } else {
            String[] ffs = cat.getAlarms().getFaultFamily();
            TableItem t = new TableItem(_ffCategoryList, SWT.None);
            t.setText(cat.getPath());
            if (cat.getIsDefault()) {
                FontData fd = t.getFont().getFontData()[0];
                fd.setStyle(SWT.BOLD);
                t.setFont(new Font(_shell.getDisplay(), fd));
            }
            for (int i = 0; i < ffs.length; i++) {
                if (ffs[i].compareTo(name) == 0)
                    t.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            }
        }
    }
}
Also used : Category(alma.acs.alarmsystem.generated.Category) TableItem(org.eclipse.swt.widgets.TableItem) FontData(org.eclipse.swt.graphics.FontData) ArrayList(java.util.ArrayList) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 2 with Category

use of alma.acs.alarmsystem.generated.Category 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 Category

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

the class CategoriesView method fillCategoryInfo.

private void fillCategoryInfo(String string) {
    Category cat = _categoryManager.getCategoryByPath(string);
    if (cat == null)
        return;
    String descriptionText = "";
    String pathText = "";
    boolean isDefaultCheck = false;
    _ffList.removeAll();
    if (cat.getDescription() != null)
        descriptionText = cat.getDescription().trim();
    if (cat.getPath() != null)
        pathText = cat.getPath().trim();
    if (cat.hasIsDefault())
        isDefaultCheck = cat.getIsDefault();
    sortCategoryFaultFamilyList(string);
    if (_ffList.getItemCount() == 0)
        _errorMessageLabel.setText("You have to select at least one Fault Family");
    _descriptionText.setText(descriptionText);
    _pathText.setText(pathText);
    _isDefaultCheck.setSelection(isDefaultCheck);
    _compInitial.layout();
}
Also used : Category(alma.acs.alarmsystem.generated.Category)

Example 4 with Category

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

the class CategoriesView method sortCategoryFaultFamilyList.

public void sortCategoryFaultFamilyList(String string) {
    Category cat = _categoryManager.getCategoryByPath(string);
    _ffList.removeAll();
    if (cat == null)
        return;
    if (cat.getAlarms() == null)
        return;
    String[] ffs = cat.getAlarms().getFaultFamily();
    java.util.List<String> sortedFFs = new ArrayList<String>();
    for (String ff : ffs) sortedFFs.add(ff.toLowerCase());
    Collections.sort(sortedFFs);
    for (String sff : sortedFFs) for (String ff : ffs) if (sff.compareTo(ff.toLowerCase()) == 0)
        _ffList.add(ff);
}
Also used : Category(alma.acs.alarmsystem.generated.Category) ArrayList(java.util.ArrayList)

Example 5 with Category

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

the class AlarmManager method deleteFaultFamily.

/**
	 * Deletes a Fault Family. The Fault Family to be deleted is checked 
	 * against the existing Reduction Rules in order to preserve the 
	 * consistency of the application (i.e., a Fault Code cannot be 
	 * deleted if it is currently present in a Reduction Rule).
	 * @param ff The Fault Family to be deleted
	 * @return True if it deletes the given Fault Family, false otherwise
	 * @throws NullPointerException If the given Fault Family (or its name)
	 * is null
	 * @throws IllegalOperationException If the Fault Family is part of an 
	 * existing Reduction Rule
	 */
public boolean deleteFaultFamily(FaultFamily ff) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) to be deleted is null");
    //Check Reduction Rules
    List<ReductionRule> rrL = _reductionManager.getNodeReductionRules();
    for (ReductionRule rr : rrL) {
        String[] tr = rr.getParent().getAlarmId().split(":");
        if (tr[0].compareTo(ff.getName()) == 0)
            throw new IllegalOperationException("The Fault Family is currently associated to a Reduction Rule");
    }
    //Check Categories
    List<Category> catL = _categoryManager.getAllCategories();
    for (Category c : catL) {
        String[] sFFL = c.getAlarms().getFaultFamily();
        if (sFFL.length > 1)
            continue;
        for (String sFF : sFFL) {
            if (sFF.compareTo(ff.getName()) == 0)
                throw new IllegalOperationException("There is a category that only has this FaultFamily");
        }
    }
    for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
        FaultFamily fft = (FaultFamily) iterator.next();
        if (fft.getName().compareTo(ff.getName()) == 0) {
            iterator.remove();
            ObjectState os = _objState.get(fft.getName());
            if (os == null)
                throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
            os.delete();
            for (Category c : catL) {
                Alarms als = c.getAlarms();
                if (als.removeFaultFamily(ff.getName())) {
                    c.setAlarms(als);
                    _categoryManager.updateCategory(c, c);
                }
            }
            Vector<FaultFamily> ffs = new Vector<FaultFamily>();
            ffs.add(ff);
            ((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
            return true;
        }
    }
    return false;
}
Also used : Category(alma.acs.alarmsystem.generated.Category) Alarms(alma.acs.alarmsystem.generated.Alarms) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Aggregations

Category (alma.acs.alarmsystem.generated.Category)22 Alarms (alma.acs.alarmsystem.generated.Alarms)8 ArrayList (java.util.ArrayList)5 Categories (alma.acs.alarmsystem.generated.Categories)4 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)4 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 ACSAlarmDAOImpl (cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)2 Vector (java.util.Vector)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Event (org.eclipse.swt.widgets.Event)2 Group (org.eclipse.swt.widgets.Group)2 Label (org.eclipse.swt.widgets.Label)2 Listener (org.eclipse.swt.widgets.Listener)2 Menu (org.eclipse.swt.widgets.Menu)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2