use of org.netxms.client.events.EventTemplate in project netxms by netxms.
the class EventProcessingPolicyEditor method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
filterEnabled = settings.getBoolean("EventProcessingPolicyEditor.filterEnabled");
// Initiate loading of required plugins if they was not loaded yet
try {
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new ServerAction(0), "org.eclipse.ui.model.IWorkbenchAdapter");
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(session.getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
} catch (Exception e) {
}
// $NON-NLS-1$
imageStop = Activator.getImageDescriptor("icons/stop.png").createImage();
// $NON-NLS-1$
imageAlarm = Activator.getImageDescriptor("icons/alarm.png").createImage();
// $NON-NLS-1$
imageSituation = Activator.getImageDescriptor("icons/situation.gif").createImage();
// $NON-NLS-1$
imageExecute = Activator.getImageDescriptor("icons/execute.png").createImage();
// $NON-NLS-1$
imageTerminate = Activator.getImageDescriptor("icons/terminate.png").createImage();
imageCollapse = SharedIcons.COLLAPSE.createImage();
imageExpand = SharedIcons.EXPAND.createImage();
imageEdit = SharedIcons.EDIT.createImage();
parent.setLayout(new FormLayout());
// Create filter area
filterControl = new FilterText(parent, SWT.NONE);
filterControl.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterControl.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
}
});
scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
dataArea = new Composite(scroller, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
dataArea.setLayout(layout);
dataArea.setBackground(BACKGROUND_COLOR);
scroller.setContent(dataArea);
scroller.setExpandVertical(true);
scroller.setExpandHorizontal(true);
scroller.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scroller.getClientArea();
scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterControl);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
scroller.setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterControl.setLayoutData(fd);
normalFont = JFaceResources.getDefaultFont();
boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
sessionListener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
processSessionNotification(n);
}
};
session.addListener(sessionListener);
selection = new TreeSet<RuleEditor>(new Comparator<RuleEditor>() {
@Override
public int compare(RuleEditor arg0, RuleEditor arg1) {
return arg0.getRuleNumber() - arg1.getRuleNumber();
}
});
createActions();
contributeToActionBars();
openEventProcessingPolicy();
activateContext();
// Set initial focus to filter input line
if (filterEnabled)
filterControl.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
}
use of org.netxms.client.events.EventTemplate in project netxms by netxms.
the class TableThresholds method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = (Composite) super.createContents(parent);
dci = editor.getObjectAsTable();
thresholds = new ArrayList<TableThreshold>();
for (TableThreshold t : dci.getThresholds()) thresholds.add(new TableThreshold(t));
// 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");
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
Composite thresholdListArea = new Composite(dialogArea, SWT.NONE);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.horizontalSpan = 2;
thresholdListArea.setLayoutData(gd);
layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.INNER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 2;
thresholdListArea.setLayout(layout);
new Label(thresholdListArea, SWT.NONE).setText(Messages.get().TableThresholds_Thresholds);
thresholdList = new TableViewer(thresholdListArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
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(thresholdListArea, 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().TableThresholds_Up);
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
upButton.setLayoutData(rd);
upButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectionUp();
}
});
downButton = new Button(leftButtons, SWT.PUSH);
downButton.setText(Messages.get().TableThresholds_Down);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
downButton.setLayoutData(rd);
downButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectionDown();
}
});
Composite buttons = new Composite(thresholdListArea, 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().TableThresholds_Add);
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().TableThresholds_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().TableThresholds_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();
deleteButton.setEnabled(selection.size() > 0);
duplicateButton.setEnabled(selection.size() > 0);
if (selection.size() == 1) {
modifyButton.setEnabled(true);
upButton.setEnabled(thresholds.indexOf(selection.getFirstElement()) > 0);
downButton.setEnabled(thresholds.indexOf(selection.getFirstElement()) < thresholds.size() - 1);
} else {
modifyButton.setEnabled(false);
upButton.setEnabled(false);
downButton.setEnabled(false);
}
}
});
thresholdList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editThreshold();
}
});
return dialogArea;
}
use of org.netxms.client.events.EventTemplate in project netxms by netxms.
the class RuleEditor method createConditionControl.
/**
* Create condition summary control
*
* @param parent
* @param rule
* @return
*/
private Control createConditionControl(Composite parent, final EventProcessingPolicyRule rule) {
Composite clientArea = new Composite(parent, SWT.NONE);
clientArea.setBackground(SharedColors.getColor(SharedColors.RULE_EDITOR_BACKGROUND, getDisplay()));
GridLayout layout = new GridLayout();
layout.verticalSpacing = 0;
clientArea.setLayout(layout);
boolean needAnd = false;
if (((rule.getSources().size() > 0) && rule.isSourceInverted()) || ((rule.getSources().size() == 0) && (rule.getEvents().size() > 0) && rule.isEventsInverted()))
createLabel(clientArea, 0, true, Messages.get().RuleEditor_IF_NOT, null);
else
createLabel(clientArea, 0, true, Messages.get().RuleEditor_IF, null);
/* source */
if (rule.getSources().size() > 0) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleSourceObjects#0");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_SourceIs, needAnd, rule.isSourceInverted(), listener);
for (Long id : rule.getSources()) {
CLabel clabel = createCLabel(clientArea, 2, false);
clabel.addMouseListener(listener);
AbstractObject object = session.findObjectById(id);
if (object != null) {
clabel.setText(object.getObjectName());
clabel.setImage(labelProvider.getImage(object));
} else {
// $NON-NLS-1$ //$NON-NLS-2$
clabel.setText("[" + id.toString() + "]");
clabel.setImage(SharedIcons.IMG_UNKNOWN_OBJECT);
}
}
needAnd = true;
}
/* events */
if (rule.getEvents().size() > 0) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleEvents#10");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_EventIs, needAnd, rule.isEventsInverted(), listener);
List<EventObject> sortedEvents = new ArrayList<EventObject>(rule.getEvents().size());
for (Long code : rule.getEvents()) {
EventObject event = session.findEventObjectByCode(code);
if (event == null) {
event = new EventTemplate(code);
((EventTemplate) event).setSeverity(Severity.UNKNOWN);
// $NON-NLS-1$ //$NON-NLS-2$
event.setName("<" + code.toString() + ">");
}
sortedEvents.add(event);
}
Collections.sort(sortedEvents, new Comparator<EventObject>() {
@Override
public int compare(EventObject t1, EventObject t2) {
return t1.getName().compareToIgnoreCase(t2.getName());
}
});
for (EventObject e : sortedEvents) {
CLabel clabel = createCLabel(clientArea, 2, false);
clabel.addMouseListener(listener);
clabel.setText(e.getName());
if (e instanceof EventTemplate)
clabel.setImage(StatusDisplayInfo.getStatusImage(((EventTemplate) e).getSeverity()));
else
clabel.setImage(SharedIcons.IMG_CONTAINER);
}
needAnd = true;
}
/* severity */
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_ANY) != EventProcessingPolicyRule.SEVERITY_ANY) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleSeverityFilter#20");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_SeverityIs, needAnd, false, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_NORMAL) != 0)
addSeverityLabel(clientArea, Severity.NORMAL, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_WARNING) != 0)
addSeverityLabel(clientArea, Severity.WARNING, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_MINOR) != 0)
addSeverityLabel(clientArea, Severity.MINOR, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_MAJOR) != 0)
addSeverityLabel(clientArea, Severity.MAJOR, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_CRITICAL) != 0)
addSeverityLabel(clientArea, Severity.CRITICAL, listener);
needAnd = true;
}
/* script */
if ((rule.getScript() != null) && !rule.getScript().isEmpty()) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleFilterScript#30");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_ScriptIs, needAnd, false, listener);
ScriptEditor scriptEditor = new ScriptEditor(clientArea, SWT.BORDER, SWT.NONE);
GridData gd = new GridData();
gd.horizontalIndent = INDENT * 2;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
scriptEditor.setLayoutData(gd);
scriptEditor.setText(rule.getScript());
scriptEditor.getTextWidget().setEditable(false);
scriptEditor.getTextWidget().addMouseListener(listener);
}
return clientArea;
}
use of org.netxms.client.events.EventTemplate in project netxms by netxms.
the class EventSelector method selectionButtonHandler.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.widgets.AbstractSelector#selectionButtonHandler()
*/
@Override
protected void selectionButtonHandler() {
EventSelectionDialog dlg = new EventSelectionDialog(getShell(), false);
dlg.enableMultiSelection(false);
if (dlg.open() == Window.OK) {
long prevEventCode = eventCode;
EventObject[] events = dlg.getSelectedEvents();
if (events.length > 0) {
eventCode = events[0].getCode();
setText(events[0].getName());
if (events[0] instanceof EventTemplate)
setImage(StatusDisplayInfo.getStatusImage(((EventTemplate) events[0]).getSeverity()));
else
setImage(SharedIcons.IMG_CONTAINER);
getTextControl().setToolTipText(generateToolTipText(events[0]));
} else {
eventCode = 0;
setText(Messages.get().EventSelector_None);
setImage(null);
getTextControl().setToolTipText(null);
}
if (prevEventCode != eventCode)
fireModifyListeners();
}
}
use of org.netxms.client.events.EventTemplate in project netxms by netxms.
the class EventObjectList method createNewEventTemplate.
/**
* Create new event template
*/
protected void createNewEventTemplate() {
final EventTemplate etmpl = new EventTemplate(0);
EditEventTemplateDialog dlg = new EditEventTemplateDialog(getShell().getShell(), etmpl, false);
if (dlg.open() == Window.OK)
modifyEventObject(etmpl, true);
}
Aggregations