Search in sources :

Example 11 with NXCException

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

the class AgentFileManager method copyFile.

/**
 * Copy agent file
 *
 * @param target where the file will be moved
 * @param object file being moved
 */
private void copyFile(final AgentFile target, final AgentFile object) {
    new ConsoleJob("Copying file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return "Cannot copy file";
        }

        @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.copyAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                    // $NON-NLS-1$
                    session.copyAgentFile(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(target, 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 12 with NXCException

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

the class AgentFileManager method doRename.

/**
 * Do actual rename
 *
 * @param AgentFile
 * @param newName
 */
private void doRename(final AgentFile agentFile, final String newName) {
    new ConsoleJob("Rename file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

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

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

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

                    @Override
                    public void run() {
                        if (verify.isOkPressed())
                            refreshFileOrDirectory();
                        agentFile.setName(newName);
                        viewer.refresh(agentFile, 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 13 with NXCException

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

the class TemplateGraphView method saveGraph.

/**
 * Save this graph as predefined
 */
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten) {
    SaveGraphDlg dlg = new SaveGraphDlg(getSite().getShell(), graphName, errorMessage, canBeOverwritten);
    int result = dlg.open();
    if (result == Window.CANCEL)
        return;
    final GraphSettings gs = new GraphSettings(0, session.getUserId(), 0, new ArrayList<AccessListElement>(0));
    gs.setName(dlg.getName());
    gs.setFlags(GraphSettings.GRAPH_FLAG_TEMPLATE);
    if (result == SaveGraphDlg.OVERRIDE) {
        new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.saveGraph(gs, canBeOverwritten);
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().HistoricalGraphView_SaveSettingsError;
            }
        }.start();
    } else {
        new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                try {
                    session.saveGraph(gs, canBeOverwritten);
                } catch (NXCException e) {
                    if (e.getErrorCode() == RCC.OBJECT_ALREADY_EXISTS) {
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExist, true);
                            }
                        });
                    } else {
                        if (e.getErrorCode() == RCC.ACCESS_DENIED) {
                            runInUIThread(new Runnable() {

                                @Override
                                public void run() {
                                    saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false);
                                }
                            });
                        } else {
                            throw e;
                        }
                    }
                }
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().HistoricalGraphView_SaveError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) SaveGraphDlg(org.netxms.ui.eclipse.perfview.dialogs.SaveGraphDlg) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Example 14 with NXCException

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

the class ComponentsTab method objectChanged.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#objectChanged(org.netxms.client.objects.AbstractObject)
	 */
@Override
public void objectChanged(final AbstractObject object) {
    viewer.setInput(new Object[0]);
    if (object == null)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().ComponentsTab_JobName, getViewPart(), Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final PhysicalComponent root = session.getNodePhysicalComponents(object.getObjectId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (viewer.getTree().isDisposed())
                            return;
                        if ((ComponentsTab.this.getObject() != null) && (ComponentsTab.this.getObject().getObjectId() == object.getObjectId())) {
                            viewer.setInput(new Object[] { root });
                            viewer.expandAll();
                        }
                    }
                });
            } catch (NXCException e) {
                if (e.getErrorCode() != RCC.NO_COMPONENT_DATA)
                    throw e;
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (viewer.getTree().isDisposed())
                            return;
                        if ((ComponentsTab.this.getObject() != null) && (ComponentsTab.this.getObject().getObjectId() == object.getObjectId())) {
                            viewer.setInput(new Object[0]);
                        }
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().ComponentsTab_JobError, object.getObjectName());
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) PhysicalComponent(org.netxms.client.PhysicalComponent) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException)

Example 15 with NXCException

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

the class ReportNavigator method refresh.

/**
 * Refresh reports tree
 */
private void refresh() {
    new ConsoleJob("Load Reports", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<UUID> notGeneratedReport = new ArrayList<UUID>(0);
            final List<ReportDefinition> definitions = new ArrayList<ReportDefinition>();
            final List<UUID> reportIds = session.listReports();
            for (UUID reportId : reportIds) {
                try {
                    final ReportDefinition definition = session.getReportDefinition(reportId);
                    definitions.add(definition);
                } catch (NXCException e) {
                    if (e.getErrorCode() == RCC.INTERNAL_ERROR)
                        notGeneratedReport.add(reportId);
                }
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    reportTree.setInput(definitions);
                    if (notGeneratedReport.size() > 0) {
                        String errorMessage = "Can't load compiled report: ";
                        for (int i = 0; i < notGeneratedReport.size(); i++) errorMessage += notGeneratedReport.get(i).toString() + (i == notGeneratedReport.size() - 1 ? "" : ", ");
                        MessageDialog.openError(null, "Error", errorMessage);
                    }
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Failed to load reports from the server";
        }
    }.start();
}
Also used : NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) UUID(java.util.UUID) ReportDefinition(org.netxms.client.reporting.ReportDefinition)

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