Search in sources :

Example 6 with SessionNotification

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();
}
Also used : ReportTreeLabelProvider(org.netxms.ui.eclipse.reporter.widgets.internal.ReportTreeLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DashboardRoot(org.netxms.client.objects.DashboardRoot) SessionListener(org.netxms.client.SessionListener) ReportTreeContentProvider(org.netxms.ui.eclipse.reporter.widgets.internal.ReportTreeContentProvider) SessionNotification(org.netxms.client.SessionNotification)

Example 7 with SessionNotification

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);
}
Also used : ColorCache(org.netxms.ui.eclipse.tools.ColorCache) GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Example 8 with SessionNotification

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;
        }
    });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) IntermediateSelectionProvider(org.netxms.ui.eclipse.tools.IntermediateSelectionProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CTabItem(org.eclipse.swt.custom.CTabItem) ISelectionListener(org.eclipse.ui.ISelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) AbstractObject(org.netxms.client.objects.AbstractObject) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification) ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab) ISelectionListener(org.eclipse.ui.ISelectionListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 9 with SessionNotification

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();
}
Also used : BulkAlarmStateChangeData(org.netxms.client.events.BulkAlarmStateChangeData) StatusDisplayInfo(org.netxms.ui.eclipse.console.resources.StatusDisplayInfo) IOException(java.io.IOException) Clip(javax.sound.sampled.Clip) AlarmReminderDialog(org.netxms.ui.eclipse.alarmviewer.dialogs.AlarmReminderDialog) Alarm(org.netxms.client.events.Alarm) SessionListener(org.netxms.client.SessionListener) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) SessionNotification(org.netxms.client.SessionNotification) File(java.io.File)

Example 10 with SessionNotification

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();
                    }
                });
            }
        }
    });
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ShellAdapter(org.eclipse.swt.events.ShellAdapter) NXCSession(org.netxms.client.NXCSession) ShellEvent(org.eclipse.swt.events.ShellEvent) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Aggregations

SessionListener (org.netxms.client.SessionListener)18 SessionNotification (org.netxms.client.SessionNotification)18 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)6 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)5 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)4 Composite (org.eclipse.swt.widgets.Composite)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 NXCSession (org.netxms.client.NXCSession)3 AbstractObject (org.netxms.client.objects.AbstractObject)3 IOException (java.io.IOException)2 Action (org.eclipse.jface.action.Action)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2