Search in sources :

Example 61 with NXCSession

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

the class HistoryView method init.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
	 */
@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    // Initiate loading of required plugins if they was not loaded yet
    try {
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(((NXCSession) ConsoleSharedData.getSession()).getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
    } catch (Exception e) {
    }
    try {
        long id = Long.parseLong(site.getSecondaryId());
        object = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(id);
        setPartName(Messages.get().LocationMap_PartNamePrefix + object.getObjectName());
    } catch (Exception e) {
        throw new PartInitException(Messages.get().LocationMap_InitError1, e);
    }
    if (object == null)
        throw new PartInitException(Messages.get().LocationMap_InitError2);
}
Also used : NXCSession(org.netxms.client.NXCSession) PartInitException(org.eclipse.ui.PartInitException) PartInitException(org.eclipse.ui.PartInitException)

Example 62 with NXCSession

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

the class WorldMap method placeObject.

/**
 * Place object on map at mouse position
 */
private void placeObject() {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(true));
    if (dlg.open() == Window.OK) {
        final NXCObjectModificationData md = new NXCObjectModificationData(dlg.getSelectedObjects().get(0).getObjectId());
        md.setGeolocation(map.getLocationAtPoint(map.getCurrentPoint()));
        final NXCSession session = ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().WorldMap_JobTitle, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.modifyObject(md);
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().WorldMap_JobError;
            }
        }.start();
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 63 with NXCSession

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

the class GeoLocationHistoryViewer method updateHistory.

/**
 * Updates points for historical view
 */
private void updateHistory() {
    final NXCSession session = ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().GeoMapViewer_DownloadJob_Title, viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<GeoLocation> pl = session.getLocationHistory(historyObject.getObjectId(), timePeriod.getPeriodStart(), timePeriod.getPeriodEnd());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    points = pl;
                    locationTree.removeAll();
                    for (int i = 0; i < points.size(); i++) locationTree.insert(points.get(i).getLatitude(), points.get(i).getLongitude(), points.get(i));
                    redraw();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().GeoMapViewer_DownloadError;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocation(org.netxms.base.GeoLocation)

Example 64 with NXCSession

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

the class ChildObjectListDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    AbstractObject object = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(parentObject);
    AbstractObject[] sourceObjects = (object != null) ? object.getChildsAsArray() : new AbstractObject[0];
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    dialogArea.setLayout(layout);
    // Create filter area
    Composite filterArea = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    filterArea.setLayout(layout);
    filterArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label filterLabel = new Label(filterArea, SWT.NONE);
    filterLabel.setText(Messages.get().ChildObjectListDialog_Filter);
    filterText = new Text(filterArea, SWT.BORDER);
    filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            filter.setFilterString(filterText.getText());
            objectList.refresh(false);
            AbstractObject obj = filter.getLastMatch();
            if (obj != null) {
                objectList.setSelection(new StructuredSelection(obj), true);
                objectList.reveal(obj);
            }
        }
    });
    // Create object list
    objectList = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    TableColumn tc = new TableColumn(objectList.getTable(), SWT.LEFT);
    tc.setText(Messages.get().ChildObjectListDialog_Name);
    tc.setWidth(280);
    objectList.getTable().setHeaderVisible(false);
    objectList.setContentProvider(new ArrayContentProvider());
    objectList.setLabelProvider(new WorkbenchLabelProvider());
    objectList.setComparator(new ViewerComparator());
    filter = new ObjectFilter(null, sourceObjects, classFilter);
    objectList.addFilter(filter);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    objectList.getControl().setLayoutData(gd);
    objectList.getTable().addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            Table table = objectList.getTable();
            int w = table.getSize().x - table.getBorderWidth() * 2;
            ScrollBar sc = table.getVerticalBar();
            if ((sc != null) && sc.isVisible())
                w -= sc.getSize().x;
            table.getColumn(0).setWidth(w);
        }
    });
    if (object != null)
        objectList.setInput(sourceObjects);
    filterText.setFocus();
    return dialogArea;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) NXCSession(org.netxms.client.NXCSession) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Text(org.eclipse.swt.widgets.Text) ObjectFilter(org.netxms.ui.eclipse.objectbrowser.widgets.internal.ObjectFilter) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 65 with NXCSession

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

the class CreateRack method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    final CreateObjectDialog dlg = new CreateObjectDialog(window.getShell(), Messages.get().CreateRack_Rack);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().CreateRack_JobTitle, part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_RACK, dlg.getObjectName(), parentId);
            cd.setHeight(42);
            session.createObject(cd);
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().CreateRack_JobError, dlg.getObjectName());
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateObjectDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog) NXCSession(org.netxms.client.NXCSession) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10