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();
}
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();
}
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();
}
}
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();
}
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();
}
Aggregations