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();
}
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()));
}
}
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;
}
Aggregations