use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class OpenAgentConfig method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
IViewReference vr = window.getActivePage().findViewReference(AgentConfigEditorView.ID, Long.toString(nodeId));
if (vr != null) {
AgentConfigEditorView view = (AgentConfigEditorView) vr.getView(true);
if (view != null) {
window.getActivePage().activate(view);
}
} else {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().OpenAgentConfig_GetConfig, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final String config = session.getAgentConfig(nodeId);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
AgentConfigEditorView view = (AgentConfigEditorView) window.getActivePage().showView(AgentConfigEditorView.ID, Long.toString(nodeId), IWorkbenchPage.VIEW_ACTIVATE);
view.setConfig(config);
} catch (PartInitException e) {
MessageDialogHelper.openError(window.getShell(), Messages.get().OpenAgentConfig_Error, Messages.get().OpenAgentConfig_OpenErrorPrefix + e.getLocalizedMessage());
}
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().OpenAgentConfig_OpenError;
}
}.start();
}
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class ActionSelectionDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
final Composite dialogArea = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
dialogArea.setLayout(layout);
viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ActionSelectionDialogLabelProvider());
viewer.setComparator(new ViewerComparator() {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
return ((ServerAction) e1).getName().compareToIgnoreCase(((ServerAction) e2).getName());
}
});
final NXCSession session = ConsoleSharedData.getSession();
new ConsoleJob("Get server actions", null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<ServerAction> list = session.getActions();
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.setInput(list.toArray());
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot get server actions";
}
}.start();
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.heightHint = 400;
viewer.getControl().setLayoutData(gd);
return dialogArea;
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class TunnelManager method refresh.
/**
* Refresh view
*/
private void refresh() {
final NXCSession session = ConsoleSharedData.getSession();
new ConsoleJob("Get list of active agent tunnels", this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<AgentTunnel> tunnels = session.getAgentTunnels();
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.setInput(tunnels);
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot get list of active agent tunnels";
}
}.start();
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class LocalCommandResults method runCommand.
/**
* Run command (called by tool execution action)
*
* @param command
*/
public void runCommand(final String command) {
synchronized (mutex) {
if (running) {
process.destroy();
try {
mutex.wait();
} catch (InterruptedException e) {
}
}
running = true;
lastCommand = command;
actionTerminate.setEnabled(true);
actionRestart.setEnabled(false);
}
final IOConsoleOutputStream out = console.newOutputStream();
ConsoleJob job = new ConsoleJob(Messages.get().LocalCommandResults_JobTitle, this, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return Messages.get().LocalCommandResults_JobError;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
process = Runtime.getRuntime().exec(command);
InputStream in = process.getInputStream();
try {
byte[] data = new byte[16384];
boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
while (true) {
int bytes = in.read(data);
if (bytes == -1)
break;
String s = new String(Arrays.copyOf(data, bytes));
// ending in 0x0D 0x0D 0x0A
if (isWindows)
// $NON-NLS-1$ //$NON-NLS-2$
out.write(s.replace("\r\r\n", " \r\n"));
else
out.write(s);
}
out.write(Messages.get().LocalCommandResults_Terminated);
} catch (IOException e) {
// $NON-NLS-1$
Activator.logError("Exception while running local command", e);
} finally {
in.close();
out.close();
}
}
@Override
protected void jobFinalize() {
synchronized (mutex) {
running = false;
process = null;
mutex.notifyAll();
}
runInUIThread(new Runnable() {
@Override
public void run() {
synchronized (mutex) {
actionTerminate.setEnabled(running);
actionRestart.setEnabled(!running);
}
}
});
}
};
job.setUser(false);
job.setSystem(true);
job.start();
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class SummaryTablesDynamicMenu method queryTable.
/**
* Query table using selected base object
*
* @param baseObjectId
* @param tableId
*/
private void queryTable(final long baseObjectId, final int tableId) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().SummaryTablesDynamicMenu_QueryTableJob, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final Table results = session.queryDciSummaryTable(tableId, baseObjectId);
runInUIThread(new Runnable() {
@Override
public void run() {
// $NON-NLS-1$
String secondaryId = Integer.toString(tableId) + "&" + Long.toString(baseObjectId);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
SummaryTable view = (SummaryTable) window.getActivePage().showView(SummaryTable.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
view.setTable(results);
} catch (PartInitException e) {
MessageDialogHelper.openError(window.getShell(), Messages.get().SummaryTablesDynamicMenu_Error, String.format(Messages.get().SummaryTablesDynamicMenu_CannotOpenView, e.getLocalizedMessage()));
}
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().SummaryTablesDynamicMenu_CannotReadData;
}
}.start();
}
Aggregations