Search in sources :

Example 1 with NumericTextFieldValidator

use of org.netxms.ui.eclipse.tools.NumericTextFieldValidator in project netxms by netxms.

the class EditThresholdDialog method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@Override
protected void okPressed() {
    if (!WidgetHelper.validateTextInput(samples, Messages.get().EditThresholdDialog_Samples, new NumericTextFieldValidator(1, 1000), null))
        return;
    int rpt;
    if (repeatDefault.getSelection()) {
        rpt = -1;
    } else if (repeatNever.getSelection()) {
        rpt = 0;
    } else {
        if (!WidgetHelper.validateTextInput(repeatInterval, Messages.get().EditThresholdDialog_RepeatInterval, new NumericTextFieldValidator(1, 1000000), null))
            return;
        rpt = Integer.parseInt(repeatInterval.getText());
    }
    threshold.setFunction(function.getSelectionIndex());
    if (threshold.getFunction() == Threshold.F_SCRIPT) {
        threshold.setScript(script.getText());
        threshold.setValue(value.getText());
    } else {
        threshold.setOperation(operation.getSelectionIndex());
        threshold.setValue(value.getText());
    }
    threshold.setSampleCount(Integer.parseInt(samples.getText()));
    threshold.setRepeatInterval(rpt);
    threshold.setFireEvent((int) activationEvent.getEventCode());
    threshold.setRearmEvent((int) deactivationEvent.getEventCode());
    super.okPressed();
}
Also used : NumericTextFieldValidator(org.netxms.ui.eclipse.tools.NumericTextFieldValidator)

Example 2 with NumericTextFieldValidator

use of org.netxms.ui.eclipse.tools.NumericTextFieldValidator in project netxms by netxms.

the class CreateInterfaceDialog method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@Override
protected void okPressed() {
    physicalPort = checkIsPhy.getSelection();
    if (!WidgetHelper.validateTextInput(nameField, new ObjectNameValidator(), null) || !WidgetHelper.validateTextInput(macAddrField, new MacAddressValidator(true), null) || !WidgetHelper.validateTextInput(ipAddrField, new IPAddressValidator(true), null) || !WidgetHelper.validateTextInput(ipMaskField, new IPNetMaskValidator(true), null) || (physicalPort && !WidgetHelper.validateTextInput(slotField, new NumericTextFieldValidator(0, 4096), null)) || (physicalPort && !WidgetHelper.validateTextInput(portField, new NumericTextFieldValidator(0, 4096), null)))
        return;
    try {
        name = nameField.getText().trim();
        macAddress = macAddrField.getText().trim().isEmpty() ? new MacAddress() : MacAddress.parseMacAddress(macAddrField.getText());
        // $NON-NLS-1$
        InetAddress addr = ipAddrField.getText().trim().isEmpty() ? InetAddress.getByName("0.0.0.0") : InetAddress.getByName(ipAddrField.getText());
        ipAddress = new InetAddressEx(addr, getMaskBits(ipMaskField.getText().trim(), addr instanceof Inet4Address ? 32 : 128));
        slot = physicalPort ? Integer.parseInt(slotField.getText()) : 0;
        port = physicalPort ? Integer.parseInt(portField.getText()) : 0;
        super.okPressed();
    } catch (Exception e) {
        // $NON-NLS-1$
        MessageDialogHelper.openError(getShell(), Messages.get().CreateInterfaceDialog_Error, String.format("Internal error: %s", e.getMessage()));
    }
}
Also used : MacAddressValidator(org.netxms.ui.eclipse.tools.MacAddressValidator) IPAddressValidator(org.netxms.ui.eclipse.tools.IPAddressValidator) ObjectNameValidator(org.netxms.ui.eclipse.tools.ObjectNameValidator) NumericTextFieldValidator(org.netxms.ui.eclipse.tools.NumericTextFieldValidator) Inet4Address(java.net.Inet4Address) IPNetMaskValidator(org.netxms.ui.eclipse.tools.IPNetMaskValidator) InetAddressEx(org.netxms.base.InetAddressEx) MacAddress(org.netxms.base.MacAddress) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Example 3 with NumericTextFieldValidator

use of org.netxms.ui.eclipse.tools.NumericTextFieldValidator in project netxms by netxms.

the class StatusCalculation method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    if (!WidgetHelper.validateTextInput(textRelativeStatus, Messages.get().StatusCalculation_Validate_RelativeStatus, new NumericTextFieldValidator(-4, 4), this) || !WidgetHelper.validateTextInput(textSingleThreshold, Messages.get().StatusCalculation_Validate_SingleThreshold, new NumericTextFieldValidator(0, 100), this) || !WidgetHelper.validateTextInput(textThresholds[0], String.format(Messages.get().StatusCalculation_Validate_Threshold, StatusDisplayInfo.getStatusText(Severity.WARNING)), new NumericTextFieldValidator(0, 100), this) || !WidgetHelper.validateTextInput(textThresholds[1], String.format(Messages.get().StatusCalculation_Validate_Threshold, StatusDisplayInfo.getStatusText(Severity.MINOR)), new NumericTextFieldValidator(0, 100), this) || !WidgetHelper.validateTextInput(textThresholds[2], String.format(Messages.get().StatusCalculation_Validate_Threshold, StatusDisplayInfo.getStatusText(Severity.MAJOR)), new NumericTextFieldValidator(0, 100), this) || !WidgetHelper.validateTextInput(textThresholds[3], String.format(Messages.get().StatusCalculation_Validate_Threshold, StatusDisplayInfo.getStatusText(Severity.CRITICAL)), new NumericTextFieldValidator(0, 100), this))
        return false;
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setStatusCalculationMethod(calculationMethod);
    md.setStatusPropagationMethod(propagationMethod);
    md.setFixedPropagatedStatus(ObjectStatus.getByValue(comboFixedStatus.getSelectionIndex()));
    md.setStatusShift(Integer.parseInt(textRelativeStatus.getText()));
    ObjectStatus[] transformations = new ObjectStatus[4];
    for (int i = 0; i < 4; i++) transformations[i] = ObjectStatus.getByValue(comboTranslatedStatus[i].getSelectionIndex());
    md.setStatusTransformation(transformations);
    md.setStatusSingleThreshold(Integer.parseInt(textSingleThreshold.getText()));
    int[] thresholds = new int[4];
    for (int i = 0; i < 4; i++) thresholds[i] = Integer.parseInt(textThresholds[i].getText());
    md.setStatusThresholds(thresholds);
    if (!hasChanges(md))
        // Nothing to apply
        return true;
    currentState = md;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format(Messages.get().StatusCalculation_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().StatusCalculation_JobError;
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        StatusCalculation.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : NumericTextFieldValidator(org.netxms.ui.eclipse.tools.NumericTextFieldValidator) NXCSession(org.netxms.client.NXCSession) ObjectStatus(org.netxms.client.constants.ObjectStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

NumericTextFieldValidator (org.netxms.ui.eclipse.tools.NumericTextFieldValidator)3 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 InetAddressEx (org.netxms.base.InetAddressEx)1 MacAddress (org.netxms.base.MacAddress)1 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)1 NXCSession (org.netxms.client.NXCSession)1 ObjectStatus (org.netxms.client.constants.ObjectStatus)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 IPAddressValidator (org.netxms.ui.eclipse.tools.IPAddressValidator)1 IPNetMaskValidator (org.netxms.ui.eclipse.tools.IPNetMaskValidator)1 MacAddressValidator (org.netxms.ui.eclipse.tools.MacAddressValidator)1 ObjectNameValidator (org.netxms.ui.eclipse.tools.ObjectNameValidator)1