Search in sources :

Example 76 with NXCSession

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

the class ResponsibleUsers 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 NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    List<Long> userIds = new ArrayList<Long>(userList.size());
    for (AbstractUserObject o : userList) userIds.add(o.getId());
    md.setResponsibleUsers(userIds);
    new ConsoleJob(String.format(Messages.get().AccessControl_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {

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

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

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().AccessControl_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ArrayList(java.util.ArrayList) AbstractUserObject(org.netxms.client.users.AbstractUserObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 77 with NXCSession

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

the class ObjectToolsDynamicMenu method buildNodeSet.

/**
 * Build node set from selection
 *
 * @param selection
 * @return
 */
private Set<ObjectContext> buildNodeSet(IStructuredSelection selection) {
    final Set<ObjectContext> nodes = new HashSet<ObjectContext>();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    for (Object o : selection.toList()) {
        if (o instanceof AbstractNode) {
            nodes.add(new ObjectContext((AbstractNode) o, null));
        } else if ((o instanceof Container) || (o instanceof ServiceRoot) || (o instanceof Subnet) || (o instanceof Cluster)) {
            for (AbstractObject n : ((AbstractObject) o).getAllChilds(AbstractObject.OBJECT_NODE)) nodes.add(new ObjectContext((AbstractNode) n, null));
        } else if (o instanceof Alarm) {
            AbstractNode n = (AbstractNode) session.findObjectById(((Alarm) o).getSourceObjectId(), AbstractNode.class);
            if (n != null)
                nodes.add(new ObjectContext(n, (Alarm) o));
        } else if (o instanceof ObjectWrapper) {
            AbstractObject n = ((ObjectWrapper) o).getObject();
            if ((n != null) && (n instanceof AbstractNode))
                nodes.add(new ObjectContext((AbstractNode) n, null));
        }
    }
    return nodes;
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) Cluster(org.netxms.client.objects.Cluster) ServiceRoot(org.netxms.client.objects.ServiceRoot) Container(org.netxms.client.objects.Container) AbstractObject(org.netxms.client.objects.AbstractObject) Alarm(org.netxms.client.events.Alarm) ObjectWrapper(org.netxms.ui.eclipse.objects.ObjectWrapper) AbstractObject(org.netxms.client.objects.AbstractObject) ObjectContext(org.netxms.ui.eclipse.objects.ObjectContext) Subnet(org.netxms.client.objects.Subnet) HashSet(java.util.HashSet)

Example 78 with NXCSession

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

the class WakeupToolHandler method execute.

/* (non-Javadoc)
    * @see org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler#execute(org.netxms.client.objects.AbstractNode, org.netxms.client.objecttools.ObjectTool)
    */
@Override
public void execute(final AbstractNode node, ObjectTool tool) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().WakeupToolHandler_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.wakeupNode(node.getObjectId());
        }

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

Example 79 with NXCSession

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

the class ObjectToolExecutor method executeFileDownload.

/**
 * @param node
 * @param tool
 * @param inputValues
 * @param inputValues
 */
private static void executeFileDownload(final ObjectContext node, final ObjectTool tool, final Map<String, String> inputValues) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    // $NON-NLS-1$
    String[] parameters = tool.getData().split("\u007F");
    final String fileName = parameters[0];
    final int maxFileSize = Integer.parseInt(parameters[1]);
    // $NON-NLS-1$
    final boolean follow = parameters[2].equals("true") ? true : false;
    ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected void runInternal(final IProgressMonitor monitor) throws Exception {
            final AgentFileData file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow, inputValues, node.getAlarmId(), new ProgressListener() {

                @Override
                public void setTotalWorkAmount(long workTotal) {
                    monitor.beginTask("Download file " + fileName, (int) workTotal);
                }

                @Override
                public void markProgress(long workDone) {
                    monitor.worked((int) workDone);
                }
            }, this);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8");
                        AgentFileViewer.createView(secondaryId, node.object.getObjectId(), file, follow);
                    } catch (Exception e) {
                        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                        MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
                    }
                }
            });
        }
    };
    job.start();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NXCSession(org.netxms.client.NXCSession) AgentFileData(org.netxms.client.AgentFileData) PartInitException(org.eclipse.ui.PartInitException) ConsoleJobCallingServerJob(org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressListener(org.netxms.client.ProgressListener)

Example 80 with NXCSession

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

the class ObjectToolExecutor method execute.

/**
 * Execute object tool on node set
 *
 * @param tool Object tool
 */
public static void execute(final Set<ObjectContext> nodes, final ObjectTool tool) {
    final Map<String, String> inputValues;
    final InputField[] fields = tool.getInputFields();
    if (fields.length > 0) {
        Arrays.sort(fields, new Comparator<InputField>() {

            @Override
            public int compare(InputField f1, InputField f2) {
                return f1.getSequence() - f2.getSequence();
            }
        });
        inputValues = readInputFields(fields);
        if (inputValues == null)
            // cancelled
            return;
    } else {
        inputValues = new HashMap<String, String>(0);
    }
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().ObjectToolExecutor_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            List<String> expandedText = null;
            if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0) {
                String message = tool.getConfirmationText();
                if (nodes.size() == 1) {
                    // Expand message and action for 1 node, otherwise expansion occurs after confirmation
                    List<String> textToExpand = new ArrayList<String>();
                    textToExpand.add(tool.getConfirmationText());
                    if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
                        textToExpand.add(tool.getData());
                    }
                    ObjectContext node = nodes.iterator().next();
                    expandedText = session.substitureMacross(node, textToExpand, inputValues);
                    message = expandedText.remove(0);
                } else {
                    ObjectContext node = nodes.iterator().next();
                    message = node.substituteMacrosForMultiNodes(message, inputValues);
                }
                ConfirmationRunnable runnable = new ConfirmationRunnable(message);
                getDisplay().syncExec(runnable);
                if (!runnable.isConfirmed())
                    return;
                if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
                    expandedText = session.substitureMacross(nodes.toArray(new ObjectContext[nodes.size()]), tool.getData(), inputValues);
                }
            } else {
                if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
                    expandedText = session.substitureMacross(nodes.toArray(new ObjectContext[nodes.size()]), tool.getData(), inputValues);
                }
            }
            // Check if password validation needed
            boolean validationNeeded = false;
            for (int i = 0; i < fields.length; i++) if (fields[i].getOptions().validatePassword) {
                validationNeeded = true;
                break;
            }
            if (validationNeeded) {
                for (int i = 0; i < fields.length; i++) {
                    if ((fields[i].getType() == InputFieldType.PASSWORD) && (fields[i].getOptions().validatePassword)) {
                        boolean valid = session.validateUserPassword(inputValues.get(fields[i].getName()));
                        if (!valid) {
                            final String fieldName = fields[i].getDisplayName();
                            getDisplay().syncExec(new Runnable() {

                                @Override
                                public void run() {
                                    MessageDialogHelper.openError(null, Messages.get().ObjectToolExecutor_ErrorTitle, String.format(Messages.get().ObjectToolExecutor_ErrorText, fieldName));
                                }
                            });
                            return;
                        }
                    }
                }
            }
            int i = 0;
            for (final ObjectContext n : nodes) {
                if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
                    final String tmp = expandedText.get(i++);
                    getDisplay().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            executeOnNode(n, tool, inputValues, tmp);
                        }
                    });
                } else {
                    getDisplay().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            executeOnNode(n, tool, inputValues, null);
                        }
                    });
                }
            }
        }

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

        class ConfirmationRunnable implements Runnable {

            private boolean confirmed;

            private String message;

            public ConfirmationRunnable(String message) {
                this.message = message;
            }

            @Override
            public void run() {
                confirmed = MessageDialogHelper.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ObjectToolsDynamicMenu_ConfirmExec, message);
            }

            boolean isConfirmed() {
                return confirmed;
            }
        }
    }.start();
}
Also used : InputField(org.netxms.client.objecttools.InputField) NXCSession(org.netxms.client.NXCSession) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) ObjectContext(org.netxms.ui.eclipse.objects.ObjectContext)

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