Search in sources :

Example 71 with NXCSession

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

the class ObjectBrowser method createContent.

/* (non-Javadoc)
    * @see org.netxms.webui.mobile.pages.AbstractPage#createContent(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Composite createContent(Composite parent) {
    viewer = new TableViewer(parent, SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ObjectListLabelProvider());
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((AbstractObject) e1).getObjectName().compareToIgnoreCase(((AbstractObject) e2).getObjectName());
        }
    });
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            AbstractObject o = (AbstractObject) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            handleSelection(o);
        }
    });
    NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    viewer.setInput(session.findObjectById(rootObjectId).getChildsAsArray());
    setTitle(session.getObjectName(rootObjectId));
    return null;
}
Also used : ObjectListLabelProvider(org.netxms.webui.mobile.pages.helpers.ObjectListLabelProvider) NXCSession(org.netxms.client.NXCSession) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) AbstractObject(org.netxms.client.objects.AbstractObject) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) AbstractObject(org.netxms.client.objects.AbstractObject) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 72 with NXCSession

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

the class Agent method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    final NXCObjectModificationData md = new NXCObjectModificationData(node.getObjectId());
    if (isApply)
        setValid(false);
    try {
        md.setAgentPort(Integer.parseInt(agentPort.getText(), 10));
    } catch (NumberFormatException e) {
        MessageDialog.openWarning(getShell(), Messages.get().Communication_Warning, Messages.get().Communication_WarningInvalidAgentPort);
        if (isApply)
            setValid(true);
        return false;
    }
    md.setAgentProxy(agentProxy.getObjectId());
    md.setAgentAuthMethod(agentAuthMethod.getSelectionIndex());
    md.setAgentSecret(agentSharedSecret.getText());
    md.setAgentCompressionMode(collectAgentCompressionMode());
    md.setObjectFlags(agentForceEncryption.getSelection() ? AbstractNode.NF_FORCE_ENCRYPTION : 0, AbstractNode.NF_FORCE_ENCRYPTION);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format("Updating agent communication settings for node %s", node.getObjectName()), null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return String.format("Cannot update communication settings for node %s", node.getObjectName());
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Agent.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 73 with NXCSession

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

the class ClusterNetworks method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if (!isModified)
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setNetworkList(networks);
    new ConsoleJob(Messages.get().ClusterNetworks_JobName, null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().ClusterNetworks_JobError;
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        ClusterNetworks.this.setValid(true);
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 74 with NXCSession

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

the class Location method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    int type = GeoLocation.UNSET;
    if (radioTypeManual.getSelection())
        type = GeoLocation.MANUAL;
    else if (radioTypeAuto.getSelection())
        type = GeoLocation.GPS;
    GeoLocation location;
    if (type == GeoLocation.MANUAL) {
        try {
            location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        } catch (GeoLocationFormatException e) {
            MessageDialogHelper.openError(getShell(), Messages.get().Location_Error, Messages.get().Location_FormatError);
            return false;
        }
    } else {
        location = new GeoLocation(type == GeoLocation.GPS);
    }
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setGeolocation(location);
    md.setPostalAddress(new PostalAddress(country.getText().trim(), city.getText().trim(), streetAddress.getText().trim(), postcode.getText().trim()));
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format(Messages.get().Location_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().Location_JobError;
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Location.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : PostalAddress(org.netxms.base.PostalAddress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException)

Example 75 with NXCSession

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

the class MapSeedNodes method createContents.

/* (non-Javadoc)
    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (AbstractObject) getElement().getAdapter(AbstractObject.class);
    if (object == null || !(object instanceof NetworkMap))
        return dialogArea;
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.BORDER);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        /* (non-Javadoc)
          * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
          */
        @Override
        public String getText(Object element) {
            return ((AbstractObject) element).getObjectName();
        }
    });
    NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    seedNodes = new HashSet<AbstractObject>(session.findMultipleObjects(((NetworkMap) object).getSeedObjectIds(), false));
    viewer.setInput(seedNodes);
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    viewer.getControl().setLayoutData(gridData);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    buttons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gridData);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText("Add...");
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
          */
        @Override
        public void widgetSelected(SelectionEvent e) {
            final ObjectSelectionDialog dlg = new ObjectSelectionDialog(getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
            dlg.enableMultiSelection(true);
            if (dlg.open() == Window.OK) {
                List<AbstractObject> selected = dlg.getSelectedObjects();
                if (selected.size() > 0) {
                    seedNodes.addAll(selected);
                    viewer.setInput(seedNodes);
                    isModified = true;
                }
            }
        }

        /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
          */
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText("Delete");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.addSelectionListener(new SelectionListener() {

        /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
          */
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection.size() > 0) {
                seedNodes.removeAll(selection.toList());
                viewer.setInput(seedNodes);
                isModified = true;
            }
        }

        /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
          */
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    return dialogArea;
}
Also used : NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) AbstractObject(org.netxms.client.objects.AbstractObject) RowLayout(org.eclipse.swt.layout.RowLayout) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractObject(org.netxms.client.objects.AbstractObject) ArrayList(java.util.ArrayList) List(java.util.List) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) NetworkMap(org.netxms.client.objects.NetworkMap) SelectionListener(org.eclipse.swt.events.SelectionListener)

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