Search in sources :

Example 6 with NXCException

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

the class TableColumns method updateColumnsFromAgent.

/**
 * Update columns from real table
 */
private void updateColumnsFromAgent(final String name, final boolean interactive, final AbstractObject queryObject) {
    final NXCSession session = ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().TableColumns_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final org.netxms.client.Table table;
                if (editor.getSourceNode() != 0) {
                    table = session.queryAgentTable(editor.getSourceNode(), name);
                } else {
                    table = session.queryAgentTable((queryObject != null) ? queryObject.getObjectId() : dci.getNodeId(), name);
                }
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        columns.clear();
                        for (int i = 0; i < table.getColumnCount(); i++) {
                            ColumnDefinition c = new ColumnDefinition(table.getColumnName(i), table.getColumnDisplayName(i));
                            c.setDataType(table.getColumnDefinition(i).getDataType());
                            c.setInstanceColumn(table.getColumnDefinition(i).isInstanceColumn());
                            columns.add(c);
                        }
                        columnList.setInput(columns.toArray());
                    }
                });
            } catch (Exception e) {
                Activator.logError("Cannot read table column definition from agent", e);
                if (interactive) {
                    final String msg = (e instanceof NXCException) ? e.getLocalizedMessage() : "Internal error";
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialogHelper.openError(getShell(), "Error", String.format("Cannot read table column definition from agent (%s)", msg));
                        }
                    });
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return null;
        }
    };
    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) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Example 7 with NXCException

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

the class PackageManager method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    final String[] names = { Messages.get().PackageManager_ColumnID, Messages.get().PackageManager_ColumnName, Messages.get().PackageManager_ColumnVersion, Messages.get().PackageManager_ColumnPlatform, Messages.get().PackageManager_ColumnFile, Messages.get().PackageManager_ColumnDescription };
    final int[] widths = { 70, 120, 90, 120, 150, 400 };
    viewer = new SortableTableViewer(parent, names, widths, COLUMN_ID, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PackageLabelProvider());
    viewer.setComparator(new PackageComparator());
    createActions();
    contributeToActionBars();
    createPopupMenu();
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            actionDeploy.setEnabled(selection.size() == 1);
            actionRemove.setEnabled(selection.size() > 0);
        }
    });
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().PackageManager_OpenDatabase, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                session.lockPackageDatabase();
            } catch (NXCException e) {
                // New versions may not require package DB lock
                if (e.getErrorCode() != RCC.NOT_IMPLEMENTED)
                    throw e;
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    refresh();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().PackageManager_OpenError;
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) PackageComparator(org.netxms.ui.eclipse.agentmanager.views.helpers.PackageComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageLabelProvider(org.netxms.ui.eclipse.agentmanager.views.helpers.PackageLabelProvider) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 8 with NXCException

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

the class AlarmLogViewer method fillContextMenu.

/* (non-Javadoc)
    * @see org.netxms.ui.eclipse.logviewer.views.LogViewer#fillContextMenu(org.eclipse.jface.action.IMenuManager)
    */
@Override
protected void fillContextMenu(final IMenuManager mgr) {
    super.fillContextMenu(mgr);
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (// selection.size() == 0 && session.isHelpdeskLinkActive())
    true) {
        try {
            Alarm alarm = session.getAlarm(Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue()));
            if (alarm.getHelpdeskState() == Alarm.HELPDESK_STATE_IGNORED)
                mgr.add(actionCreateIssue);
            else {
                mgr.add(actionShowIssue);
                if ((session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_UNLINK_ISSUES) != 0)
                    mgr.add(actionUnlinkIssue);
            }
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException | IOException | NXCException e) {
            Activator.logError("Error finding alarm", e);
        }
    }
}
Also used : Alarm(org.netxms.client.events.Alarm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 9 with NXCException

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

the class AgentFileManager method moveFile.

/**
 * Move selected file
 */
private void moveFile(final AgentFile target, final AgentFile object) {
    new ConsoleJob(Messages.get().AgentFileManager_MoveFile, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(object.getType(), object.getName(), true, true, false) {

                @Override
                public void executeAction() throws NXCException, IOException {
                    // $NON-NLS-1$
                    session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                    // $NON-NLS-1$
                    session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), true);
                }
            };
            verify.run(viewer.getControl().getDisplay());
            if (verify.isOkPressed()) {
                target.setChildren(session.listAgentFiles(target, target.getFullName(), objectId));
                object.getParent().setChildren(session.listAgentFiles(object.getParent(), object.getParent().getFullName(), objectId));
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.refresh(object.getParent(), true);
                        object.setParent(target);
                        viewer.refresh(object.getParent(), true);
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Example 10 with NXCException

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

the class AgentFileManager method createFolder.

/**
 * Create new folder
 */
private void createFolder() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final Object[] objects = selection.toArray();
    final AgentFile parentFolder = ((AgentFile) objects[0]).isDirectory() ? ((AgentFile) objects[0]) : ((AgentFile) objects[0]).getParent();
    final CreateFolderDialog dlg = new CreateFolderDialog(getSite().getShell());
    if (dlg.open() != Window.OK)
        return;
    final String newFolder = dlg.getNewName();
    new ConsoleJob(Messages.get().AgentFileManager_CreatingFolder, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, newFolder, true, true, false) {

                @Override
                public void executeAction() throws NXCException, IOException {
                    // $NON-NLS-1$
                    session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                // do nothing
                }
            };
            verify.run(viewer.getControl().getDisplay());
            parentFolder.setChildren(session.listAgentFiles(parentFolder, parentFolder.getFullName(), objectId));
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.refresh(parentFolder, true);
                }
            });
        }
    }.start();
}
Also used : AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) CreateFolderDialog(org.netxms.ui.eclipse.filemanager.dialogs.CreateFolderDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

NXCException (org.netxms.client.NXCException)34 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)20 NXCSession (org.netxms.client.NXCSession)16 PartInitException (org.eclipse.ui.PartInitException)13 IOException (java.io.IOException)12 AbstractObject (org.netxms.client.objects.AbstractObject)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 List (java.util.List)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 Alarm (org.netxms.client.events.Alarm)3 AbstractNode (org.netxms.client.objects.AbstractNode)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AccessListElement (org.netxms.client.AccessListElement)2 DataCollectionConfiguration (org.netxms.client.datacollection.DataCollectionConfiguration)2 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)2 GraphSettings (org.netxms.client.datacollection.GraphSettings)2 AgentPolicy (org.netxms.client.objects.AgentPolicy)2 Node (org.netxms.client.objects.Node)2