Search in sources :

Example 26 with NXCObjectModificationData

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

the class ImportDashboard method run.

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document dom = db.parse(dlg.getImportFile());
            Element root = dom.getDocumentElement();
            if (// $NON-NLS-1$
            !root.getNodeName().equals("dashboard"))
                throw new Exception(Messages.get().ImportDashboard_InvalidFile);
            root.normalize();
            List<DashboardElement> dashboardElements = new ArrayList<DashboardElement>();
            // $NON-NLS-1$
            NodeList elementsRoot = root.getElementsByTagName("elements");
            for (int i = 0; i < elementsRoot.getLength(); i++) {
                if (elementsRoot.item(i).getNodeType() != Node.ELEMENT_NODE)
                    continue;
                // $NON-NLS-1$
                NodeList elements = ((Element) elementsRoot.item(i)).getElementsByTagName("dashboardElement");
                for (int j = 0; j < elements.getLength(); j++) {
                    Element e = (Element) elements.item(j);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    DashboardElement de = new DashboardElement(getNodeValueAsInt(e, "type", 0), getNodeValueAsXml(e, "element"));
                    // $NON-NLS-1$
                    de.setLayout(getNodeValueAsXml(e, "layout"));
                    dashboardElements.add(de);
                }
            }
            root.normalize();
            objectName = dlg.getObjectName();
            if (doIdMapping(display, session, dashboardElements, root)) {
                NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_DASHBOARD, objectName, parentId);
                final long objectId = session.createObject(cd);
                NXCObjectModificationData md = new NXCObjectModificationData(objectId);
                // $NON-NLS-1$
                md.setColumnCount(getNodeValueAsInt(root, "columns", 1));
                // $NON-NLS-1$
                md.setObjectFlags(getNodeValueAsInt(root, "options", 0));
                md.setDashboardElements(dashboardElements);
                session.modifyObject(md);
            }
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().ImportDashboard_Error, dlg.getObjectName());
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) DashboardElement(org.netxms.client.dashboards.DashboardElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) DashboardElement(org.netxms.client.dashboards.DashboardElement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ImportDashboardDialog(org.netxms.ui.eclipse.dashboard.dialogs.ImportDashboardDialog) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Display(org.eclipse.swt.widgets.Display)

Example 27 with NXCObjectModificationData

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

the class ConditionScript method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if (initialScript.equals(filterSource.getText()))
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final String newScript = filterSource.getText();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setScript(newScript);
    new ConsoleJob(Messages.get().ConditionScript_JobName, null, Activator.PLUGIN_ID, null) {

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

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

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

                    @Override
                    public void run() {
                        ConditionScript.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 28 with NXCObjectModificationData

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

the class General method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if (isApply)
        setValid(false);
    final String newName = textName.getText();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData data = new NXCObjectModificationData(object.getObjectId());
    data.setName(newName);
    new ConsoleJob(Messages.get().General_JobName, null, Activator.PLUGIN_ID, null) {

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

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

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

                    @Override
                    public void run() {
                        initialName = newName;
                        General.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 29 with NXCObjectModificationData

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

the class InterfacePolling method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if ((expectedState.getSelectionIndex() == currentExpectedState) && (pollCount.getSelection() == currentPollCount) && (checkExcludeFromTopology.getSelection() == currentExcludeFlag))
        // nothing to change
        return;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData data = new NXCObjectModificationData(object.getObjectId());
    data.setExpectedState(expectedState.getSelectionIndex());
    data.setRequiredPolls(pollCount.getSelection());
    data.setObjectFlags(checkExcludeFromTopology.getSelection() ? Interface.IF_EXCLUDE_FROM_TOPOLOGY : 0, Interface.IF_EXCLUDE_FROM_TOPOLOGY);
    new ConsoleJob(Messages.get().InterfacePolling_JobName, null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().InterfacePolling_JobError, object.getObjectName());
        }

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

                    @Override
                    public void run() {
                        currentExpectedState = data.getExpectedState();
                        currentPollCount = data.getRequiredPolls();
                        currentExcludeFlag = ((data.getObjectFlags() & Interface.IF_EXCLUDE_FROM_TOPOLOGY) != 0);
                        InterfacePolling.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 30 with NXCObjectModificationData

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

the class AutoApply method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    int flags = object.getFlags();
    if (checkboxEnableApply.getSelection())
        flags |= Template.TF_AUTO_APPLY;
    else
        flags &= ~Template.TF_AUTO_APPLY;
    if (checkboxEnableRemove.getSelection())
        flags |= Template.TF_AUTO_REMOVE;
    else
        flags &= ~Template.TF_AUTO_REMOVE;
    if ((flags == initialFlags) && initialApplyFilter.equals(filterSource.getText()))
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setAutoBindFilter(filterSource.getText());
    md.setObjectFlags(flags);
    new ConsoleJob(Messages.get().AutoApply_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
            initialFlags = md.getObjectFlags();
            initialApplyFilter = md.getAutoBindFilter();
        }

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

                    @Override
                    public void run() {
                        AutoApply.this.setValid(true);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AutoApply_JobError;
        }
    }.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)

Aggregations

NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)50 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)45 NXCSession (org.netxms.client.NXCSession)45 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)45 ArrayList (java.util.ArrayList)3 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)3 GeoLocation (org.netxms.base.GeoLocation)2 GeoLocationFormatException (org.netxms.base.GeoLocationFormatException)2 DashboardElement (org.netxms.client.dashboards.DashboardElement)2 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 TransformerException (javax.xml.transform.TransformerException)1 Point (org.eclipse.swt.graphics.Point)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1