Search in sources :

Example 11 with Threshold

use of org.netxms.client.datacollection.Threshold in project netxms by netxms.

the class Thresholds method createContents.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    // Initiate loading of event manager plugin if it was not loaded before
    // $NON-NLS-1$
    Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
    Composite dialogArea = (Composite) super.createContents(parent);
    dci = editor.getObjectAsItem();
    thresholds = new ArrayList<Threshold>(dci.getThresholds().size());
    for (Threshold t : dci.getThresholds()) thresholds.add(new Threshold(t));
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    instance = new LabeledText(dialogArea, SWT.NONE);
    instance.setLabel(Messages.get().Thresholds_Instance);
    instance.setText(dci.getInstance());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    instance.setLayoutData(gd);
    if (// DCI created by instance discovery
    dci.getTemplateId() == dci.getNodeId())
        instance.getTextControl().setEditable(false);
    checkAllThresholds = new Button(dialogArea, SWT.CHECK);
    checkAllThresholds.setText(Messages.get().Thresholds_ProcessAll);
    checkAllThresholds.setSelection(dci.isProcessAllThresholds());
    Composite thresholdArea = new Composite(dialogArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    thresholdArea.setLayoutData(gd);
    layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    thresholdArea.setLayout(layout);
    new Label(thresholdArea, SWT.NONE).setText(Messages.get().Thresholds_Thresholds);
    thresholdList = new TableViewer(thresholdArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    thresholdList.getControl().setLayoutData(gd);
    setupThresholdList();
    thresholdList.setInput(thresholds.toArray());
    Composite leftButtons = new Composite(thresholdArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gd);
    RowLayout buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    leftButtons.setLayout(buttonsLayout);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().Thresholds_Up);
    upButton.setEnabled(false);
    upButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().Thresholds_Down);
    downButton.setEnabled(false);
    downButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    Composite buttons = new Composite(thresholdArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gd);
    buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    buttons.setLayout(buttonsLayout);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().Thresholds_Add);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            addThreshold();
        }
    });
    duplicateButton = new Button(buttons, SWT.PUSH);
    duplicateButton.setText("Duplicate");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    duplicateButton.setLayoutData(rd);
    duplicateButton.setEnabled(false);
    duplicateButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            duplicateThreshold();
        }
    });
    modifyButton = new Button(buttons, SWT.PUSH);
    modifyButton.setText(Messages.get().Thresholds_Edit);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    modifyButton.setLayoutData(rd);
    modifyButton.setEnabled(false);
    modifyButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            editThreshold();
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().Thresholds_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteThresholds();
        }
    });
    /**
     * Selection change listener for thresholds list **
     */
    thresholdList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            int index = thresholds.indexOf(selection.getFirstElement());
            upButton.setEnabled((selection.size() == 1) && (index > 0));
            downButton.setEnabled((selection.size() == 1) && (index >= 0) && (index < thresholds.size() - 1));
            modifyButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
            duplicateButton.setEnabled(selection.size() > 0);
        }
    });
    thresholdList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editThreshold();
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) EventTemplate(org.netxms.client.events.EventTemplate) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) Threshold(org.netxms.client.datacollection.Threshold) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with Threshold

use of org.netxms.client.datacollection.Threshold in project netxms by netxms.

the class Thresholds method duplicateThreshold.

/**
 * Duplicate selected threshold
 */
@SuppressWarnings("unchecked")
private void duplicateThreshold() {
    final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
    if (selection.size() > 0) {
        List<Threshold> list = selection.toList();
        for (Threshold t : list) {
            thresholds.add(thresholds.indexOf(t) + 1, new Threshold(t));
            thresholdList.setInput(thresholds.toArray());
        }
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Threshold(org.netxms.client.datacollection.Threshold)

Example 13 with Threshold

use of org.netxms.client.datacollection.Threshold in project netxms by netxms.

the class Thresholds method editThreshold.

/**
 * Edit selected threshold
 */
private void editThreshold() {
    final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
    if (selection.size() == 1) {
        final Threshold threshold = (Threshold) selection.getFirstElement();
        EditThresholdDialog dlg = new EditThresholdDialog(getShell(), threshold);
        if (dlg.open() == Window.OK) {
            thresholdList.update(threshold, null);
        }
    }
}
Also used : EditThresholdDialog(org.netxms.ui.eclipse.datacollection.dialogs.EditThresholdDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Threshold(org.netxms.client.datacollection.Threshold)

Example 14 with Threshold

use of org.netxms.client.datacollection.Threshold in project netxms by netxms.

the class Thresholds method moveDown.

/**
 * Move currently selected threshold down
 */
private void moveDown() {
    final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
    if (selection.size() == 1) {
        final Threshold threshold = (Threshold) selection.getFirstElement();
        int index = thresholds.indexOf(threshold);
        if ((index < thresholds.size() - 1) && (index >= 0)) {
            Collections.swap(thresholds, index + 1, index);
            thresholdList.setInput(thresholds.toArray());
            thresholdList.setSelection(new StructuredSelection(threshold));
        }
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Threshold(org.netxms.client.datacollection.Threshold)

Aggregations

Threshold (org.netxms.client.datacollection.Threshold)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 PartInitException (org.eclipse.ui.PartInitException)2 NXCPMessage (org.netxms.base.NXCPMessage)2 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)2 DciData (org.netxms.client.datacollection.DciData)2 EventTemplate (org.netxms.client.events.EventTemplate)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)2 EditThresholdDialog (org.netxms.ui.eclipse.datacollection.dialogs.EditThresholdDialog)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1