use of org.netxms.client.SessionNotification in project netxms by netxms.
the class ReportNavigator 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();
reportTree = new TreeViewer(parent, SWT.NONE);
reportTree.setContentProvider(new ReportTreeContentProvider());
reportTree.setLabelProvider(new ReportTreeLabelProvider());
// reportTree.setInput(session);
createActions();
contributeToActionBars();
createPopupMenu();
getSite().setSelectionProvider(reportTree);
sessionListener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if ((n.getCode() == SessionNotification.OBJECT_CHANGED) && (n.getObject() instanceof DashboardRoot)) {
reportTree.getTree().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
}
};
session.addListener(sessionListener);
refresh();
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class ServiceAvailability method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
final Composite clientArea = new Composite(parent, SWT.NONE);
colors = new ColorCache(clientArea);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
clientArea.setLayout(layout);
dayChart = createChart(clientArea, Messages.get().ServiceAvailability_Today);
weekChart = createChart(clientArea, Messages.get().ServiceAvailability_ThisWeek);
monthChart = createChart(clientArea, Messages.get().ServiceAvailability_ThisMonth);
Canvas legend = new Canvas(clientArea, SWT.NONE);
legend.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
paintLegend(e.gc);
}
});
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
legend.setLayoutData(gd);
listener = new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if (!clientArea.isDisposed() && (n.getCode() == SessionNotification.OBJECT_CHANGED) && (n.getSubCode() == object.getObjectId())) {
clientArea.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
object = (ServiceContainer) n.getObject();
refresh();
}
});
}
}
};
ConsoleSharedData.getSession().addListener(listener);
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class TabbedObjectView method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
parent.setLayout(layout);
headerFont = FontTools.createFont(HEADER_FONTS, +3, SWT.BOLD);
header = new CLabel(parent, SWT.BORDER);
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
header.setFont(headerFont);
header.setBackground(SharedColors.getColor(SharedColors.OBJECT_TAB_HEADER_BACKGROUND, parent.getDisplay()));
header.setForeground(SharedColors.getColor(SharedColors.OBJECT_TAB_HEADER, parent.getDisplay()));
tabFolder = new CTabFolder(parent, SWT.TOP | SWT.FLAT | SWT.MULTI);
tabFolder.setUnselectedImageVisible(true);
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tabFolder.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
onTabSelectionChange((e.item != null) ? (ObjectTab) ((CTabItem) e.item).getData() : null);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
tabs = new ArrayList<ObjectTab>();
addTabs();
selectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (// $NON-NLS-1$
(part.getSite().getId().equals("org.netxms.ui.eclipse.view.navigation.objectbrowser")) && (selection instanceof IStructuredSelection)) {
if (selection.isEmpty()) {
setObject(null);
} else {
Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof AbstractObject) {
setObject((AbstractObject) object);
}
}
}
}
};
selectionService.addPostSelectionListener(selectionListener);
createActions();
contributeToActionBars();
selectionProvider = new IntermediateSelectionProvider();
getSite().setSelectionProvider(selectionProvider);
final NXCSession session = ConsoleSharedData.getSession();
sessionListener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if ((n.getCode() == SessionNotification.OBJECT_CHANGED) && (objectId == n.getSubCode())) {
final AbstractObject object = (AbstractObject) n.getObject();
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
onObjectUpdate(object);
}
});
}
}
};
session.addListener(sessionListener);
CommandBridge.getInstance().registerCommand("TabbedObjectView/selectTab", new // $NON-NLS-1$
Command() {
@Override
public Object execute(String name, Object arg) {
if (arg instanceof String)
selectTab((String) arg);
return null;
}
});
CommandBridge.getInstance().registerCommand("TabbedObjectView/changeObject", new // $NON-NLS-1$
Command() {
@Override
public Object execute(String name, Object arg) {
if (arg instanceof Long)
setObject(session.findObjectById((Long) arg));
return null;
}
});
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class AlarmNotifier method init.
/**
* Initialize alarm notifier
*/
public static void init(NXCSession session) {
AlarmNotifier.session = session;
ps = Activator.getDefault().getPreferenceStore();
workspaceUrl = Platform.getInstanceLocation().getURL();
checkSounds();
lastReminderTime = System.currentTimeMillis();
try {
Map<Long, Alarm> alarms = session.getAlarms();
for (Alarm a : alarms.values()) {
alarmStates.put(a.getId(), a.getState());
if (a.getState() == Alarm.STATE_OUTSTANDING)
outstandingAlarms++;
}
} catch (Exception e) {
}
listener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if ((n.getCode() == SessionNotification.NEW_ALARM) || (n.getCode() == SessionNotification.ALARM_CHANGED)) {
processNewAlarm((Alarm) n.getObject());
} else if ((n.getCode() == SessionNotification.ALARM_TERMINATED) || (n.getCode() == SessionNotification.ALARM_DELETED)) {
Alarm a = (Alarm) n.getObject();
Integer state = alarmStates.get(a.getId());
if (state != null) {
if (state == Alarm.STATE_OUTSTANDING)
outstandingAlarms--;
alarmStates.remove(a.getId());
}
} else if (n.getCode() == SessionNotification.MULTIPLE_ALARMS_RESOLVED) {
BulkAlarmStateChangeData d = (BulkAlarmStateChangeData) n.getObject();
for (Long id : d.getAlarms()) {
Integer state = alarmStates.get(id);
if (state != null) {
if (state == Alarm.STATE_OUTSTANDING) {
outstandingAlarms--;
}
}
alarmStates.put(id, Alarm.STATE_RESOLVED);
}
} else if (n.getCode() == SessionNotification.MULTIPLE_ALARMS_TERMINATED) {
BulkAlarmStateChangeData d = (BulkAlarmStateChangeData) n.getObject();
for (Long id : d.getAlarms()) {
Integer state = alarmStates.get(id);
if (state != null) {
if (state == Alarm.STATE_OUTSTANDING)
outstandingAlarms--;
alarmStates.remove(id);
}
}
}
}
};
session.addListener(listener);
Thread reminderThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
long currTime = System.currentTimeMillis();
if (// $NON-NLS-1$
ps.getBoolean("OUTSTANDING_ALARMS_REMINDER") && (outstandingAlarms > 0) && (lastReminderTime + 300000 <= currTime)) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
soundQueue.offer(SEVERITY_TEXT[SEVERITY_TEXT.length - 1]);
AlarmReminderDialog dlg = new AlarmReminderDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
dlg.open();
}
});
lastReminderTime = currTime;
}
}
}
}, // $NON-NLS-1$
"AlarmReminderThread");
reminderThread.setDaemon(true);
reminderThread.start();
Thread playerThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
String soundId;
try {
soundId = soundQueue.take();
} catch (InterruptedException e) {
continue;
}
Clip sound = null;
try {
String fileName = getSoundAndDownloadIfRequired(soundId);
if (fileName != null) {
sound = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
sound.open(AudioSystem.getAudioInputStream(new File(workspaceUrl.getPath(), fileName).getAbsoluteFile()));
sound.start();
while (!sound.isRunning()) Thread.sleep(10);
while (sound.isRunning()) {
Thread.sleep(10);
}
}
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError("Exception in alarm sound player", e);
} finally {
if ((sound != null) && sound.isOpen())
sound.close();
}
}
}
}, "AlarmSoundPlayer");
playerThread.setDaemon(true);
playerThread.start();
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class ApplicationWorkbenchAdvisor method postStartup.
/* (non-Javadoc)
* @see org.eclipse.ui.application.WorkbenchAdvisor#postStartup()
*/
@Override
public void postStartup() {
super.postStartup();
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
shell.addShellListener(new ShellAdapter() {
public void shellIconified(ShellEvent e) {
if (// $NON-NLS-1$
Activator.getDefault().getPreferenceStore().getBoolean("HIDE_WHEN_MINIMIZED"))
shell.setVisible(false);
}
});
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
session.addListener(new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
String productName = BrandingManager.getInstance().getProductName();
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ApplicationWorkbenchAdvisor_CommunicationError, ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : ((n.getCode() == SessionNotification.SESSION_KILLED) ? Messages.get().ApplicationWorkbenchAdvisor_SessionTerminated : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName))) + Messages.get().ApplicationWorkbenchAdvisor_OKToCloseMessage);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().close();
}
});
}
}
});
}
Aggregations