Search in sources :

Example 6 with SessionListener

use of org.netxms.client.SessionListener in project netxms by netxms.

the class DashboardView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    selectionProvider = new IntermediateSelectionProvider();
    getSite().setSelectionProvider(selectionProvider);
    ConsoleJob job = new ConsoleJob(Messages.get().DashboardView_GetEffectiveRights, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            readOnly = ((dashboard.getEffectiveRights() & UserAccessRights.OBJECT_ACCESS_MODIFY) == 0);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DashboardView_GetEffectiveRightsError;
        }
    };
    job.start();
    // FIXME: rewrite waiting
    try {
        job.join();
    } catch (InterruptedException e) {
    }
    parentComposite = parent;
    dbc = new DashboardControl(parent, SWT.NONE, dashboard, this, selectionProvider, false);
    if (!readOnly) {
        dbcModifyListener = new DashboardModifyListener() {

            @Override
            public void save() {
                actionSave.setEnabled(false);
                firePropertyChange(PROP_DIRTY);
            }

            @Override
            public void modify() {
                actionSave.setEnabled(true);
                firePropertyChange(PROP_DIRTY);
            }
        };
        dbc.setModifyListener(dbcModifyListener);
    }
    activateContext();
    createActions();
    contributeToActionBars();
    clientListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() == SessionNotification.OBJECT_CHANGED && dashboard.getObjectId() == n.getSubCode()) {
                parentComposite.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        rebuildDashboard(true);
                    }
                });
            }
        }
    };
    session.addListener(clientListener);
}
Also used : IntermediateSelectionProvider(org.netxms.ui.eclipse.tools.IntermediateSelectionProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DashboardControl(org.netxms.ui.eclipse.dashboard.widgets.DashboardControl) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DashboardModifyListener(org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardModifyListener) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Example 7 with SessionListener

use of org.netxms.client.SessionListener in project netxms by netxms.

the class AbstractNetworkMapView method createPartControl.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.part.ViewPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public final void createPartControl(Composite parent) {
    FillLayout layout = new FillLayout();
    parent.setLayout(layout);
    viewer = new ExtendedGraphViewer(parent, SWT.NONE);
    viewer.setContentProvider(new MapContentProvider(viewer));
    labelProvider = new MapLabelProvider(viewer);
    viewer.setLabelProvider(labelProvider);
    viewer.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    try {
        // $NON-NLS-1$
        alwaysFitLayout = settings.getBoolean(viewId + ".alwaysFitLayout");
    } catch (Exception e) {
    }
    // Zoom level restore and save
    try {
        // $NON-NLS-1$
        viewer.zoomTo(settings.getDouble(viewId + ".zoom"));
    } catch (NumberFormatException e) {
    }
    viewer.getGraphControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            IDialogSettings settings = Activator.getDefault().getDialogSettings();
            // $NON-NLS-1$
            settings.put(viewId + ".zoom", viewer.getZoom());
        }
    });
    getSite().setSelectionProvider(this);
    ISelectionChangedListener listener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            if (bendpointEditor != null) {
                bendpointEditor.stop();
                bendpointEditor = null;
            }
            currentSelection = transformSelection(e.getSelection());
            if (currentSelection.size() == 1) {
                int selectionType = analyzeSelection(currentSelection);
                if (selectionType == SELECTION_OBJECTS) {
                    AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
                    actionOpenDrillDownObject.setEnabled(object.getDrillDownObjectId() != 0);
                } else {
                    actionOpenDrillDownObject.setEnabled(false);
                    if (selectionType == SELECTION_LINKS) {
                        NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
                        actionLockLink.setChecked(link.isLocked());
                        if (!link.isLocked() && link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS) {
                            bendpointEditor = new BendpointEditor(link, (GraphConnection) viewer.getGraphControl().getSelection().get(0), viewer);
                        }
                    }
                }
            } else {
                actionOpenDrillDownObject.setEnabled(false);
            }
            if (selectionListeners.isEmpty())
                return;
            SelectionChangedEvent event = new SelectionChangedEvent(AbstractNetworkMapView.this, currentSelection);
            for (ISelectionChangedListener l : selectionListeners) {
                l.selectionChanged(event);
            }
        }
    };
    viewer.addPostSelectionChangedListener(listener);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            int selectionType = analyzeSelection(currentSelection);
            if (selectionType == SELECTION_EMPTY)
                return;
            if (selectionType == SELECTION_OBJECTS) {
                AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
                if (object instanceof Rack) {
                    openRackView(Long.toString(object.getObjectId()));
                    return;
                }
                for (DoubleClickHandlerData h : doubleClickHandlers) {
                    if ((h.enabledFor == null) || (h.enabledFor.isInstance(object))) {
                        if (h.handler.onDoubleClick(object)) {
                            return;
                        }
                    }
                }
            } else if (((NetworkMapLink) currentSelection.getFirstElement()).isLocked() && selectionType == SELECTION_LINKS) {
                openLinkDci();
            }
            // Default behavior
            actionOpenDrillDownObject.run();
        }
    });
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(final SessionNotification n) {
            if (n.getCode() == SessionNotification.OBJECT_CHANGED) {
                viewer.getControl().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        onObjectChange((AbstractObject) n.getObject());
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    if (automaticLayoutEnabled) {
        setLayoutAlgorithm(layoutAlgorithm, true);
    } else {
        viewer.setLayoutAlgorithm(new ManualLayout());
    }
    activateContext();
    registerDoubleClickHandlers();
    setupMapControl();
    refreshMap();
}
Also used : ExtendedGraphViewer(org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer) DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MapLabelProvider(org.netxms.ui.eclipse.networkmaps.views.helpers.MapLabelProvider) Rack(org.netxms.client.objects.Rack) MapContentProvider(org.netxms.ui.eclipse.networkmaps.views.helpers.MapContentProvider) GraphConnection(org.eclipse.gef4.zest.core.widgets.GraphConnection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SessionNotification(org.netxms.client.SessionNotification) NetworkMapLink(org.netxms.client.maps.NetworkMapLink) BendpointEditor(org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Point(org.eclipse.draw2d.geometry.Point) ManualLayout(org.netxms.ui.eclipse.networkmaps.algorithms.ManualLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) AbstractObject(org.netxms.client.objects.AbstractObject) SessionListener(org.netxms.client.SessionListener)

Example 8 with SessionListener

use of org.netxms.client.SessionListener 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 9 with SessionListener

use of org.netxms.client.SessionListener 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 10 with SessionListener

use of org.netxms.client.SessionListener 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)

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