use of org.netxms.client.NXCSession in project netxms by netxms.
the class SummaryTableGeneral method applyChanges.
/**
* Apply changes
*
* @param isApply true if update operation caused by "Apply" button
*/
protected void applyChanges(final boolean isApply) {
if (isApply)
setValid(false);
table.setMenuPath(menuPath.getText());
table.setTitle(title.getText());
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().SummaryTableGeneral_JobName, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
synchronized (table) {
int id = session.modifyDciSummaryTable(table);
table.setId(id);
}
}
@Override
protected String getErrorMessage() {
return Messages.get().SummaryTableGeneral_JobError;
}
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.jobs.ConsoleJob#jobFinalize()
*/
@Override
protected void jobFinalize() {
if (isApply) {
runInUIThread(new Runnable() {
@Override
public void run() {
SummaryTableGeneral.this.setValid(true);
}
});
}
}
}.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class Application method start.
/* (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
*/
public Object start(IApplicationContext context) throws Exception {
// $NON-NLS-1$
String lang = getParameter("lang");
if (lang != null)
RWT.setLocale(new Locale(lang));
final Properties properties = new AppPropertiesLoader().load();
int timeout;
try {
timeout = Integer.parseInt(properties.getProperty("sessionTimeout", "600"));
} catch (NumberFormatException e) {
timeout = 600;
}
final Display display = PlatformUI.createDisplay();
RWT.getUISession().getHttpSession().setMaxInactiveInterval(timeout);
display.disposeExec(new Runnable() {
public void run() {
NXCSession session = ConsoleSharedData.getSession();
if (session != null)
session.disconnect();
}
});
ClientInfo clientInfo = RWT.getClient().getService(ClientInfo.class);
if (clientInfo != null) {
// convert offset in minutes to milliseconds (in RAP - means ahead of UTC)
String[] tzList = TimeZone.getAvailableIDs(-clientInfo.getTimezoneOffset() * 60000);
if (tzList.length > 0) {
RWT.getUISession().setAttribute(ConsoleSharedData.ATTRIBUTE_TIMEZONE, TimeZone.getTimeZone(tzList[0]));
}
}
SharedIcons.init(display);
WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
return PlatformUI.createAndRunWorkbench(display, advisor);
}
use of org.netxms.client.NXCSession 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();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class PackageManager method installPackage.
/**
* Install new package
*/
private void installPackage() {
FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
fd.setText(Messages.get().PackageManager_SelectFile);
String npiName = fd.open();
if (npiName != null) {
try {
final File npiFile = new File(npiName);
final PackageInfo p = new PackageInfo(npiFile);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().PackageManager_InstallPackage, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final long id = session.installPackage(p, new File(npiFile.getParent(), p.getFileName()), new ProgressListener() {
long prevAmount = 0;
@Override
public void setTotalWorkAmount(long amount) {
monitor.beginTask(Messages.get(getDisplay()).PackageManager_UploadPackage, (int) amount);
}
@Override
public void markProgress(long amount) {
monitor.worked((int) (amount - prevAmount));
prevAmount = amount;
}
});
p.setId(id);
runInUIThread(new Runnable() {
@Override
public void run() {
packageList.add(p);
viewer.setInput(packageList.toArray());
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().PackageManager_InstallError;
}
}.start();
} catch (IOException e) {
MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_PkgFileOpenError + e.getLocalizedMessage());
}
}
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class PackageManager method deployPackage.
/**
* Deploy package on managed nodes
*/
private void deployPackage() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final PackageInfo pkg = (PackageInfo) selection.getFirstElement();
ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
dlg.enableMultiSelection(true);
if (dlg.open() != Window.OK)
return;
final Set<Long> objects = new HashSet<Long>();
for (AbstractObject o : dlg.getSelectedObjects()) {
objects.add(o.getObjectId());
}
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
ConsoleJob job = new ConsoleJob(Messages.get().PackageManager_DeployAgentPackage, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.deployPackage(pkg.getId(), objects.toArray(new Long[objects.size()]), new PackageDeploymentListener() {
private PackageDeploymentMonitor monitor = null;
@Override
public void statusUpdate(long nodeId, int status, String message) {
if (monitor != null)
monitor.viewStatusUpdate(nodeId, status, message);
}
@Override
public void deploymentStarted() {
final Object sync = new Object();
synchronized (sync) {
runInUIThread(new Runnable() {
@Override
public void run() {
try {
monitor = (PackageDeploymentMonitor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PackageDeploymentMonitor.ID, toString(), IWorkbenchPage.VIEW_ACTIVATE);
monitor.setPackageId(pkg.getId());
} catch (PartInitException e) {
MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_ErrorOpenView + e.getLocalizedMessage());
}
synchronized (sync) {
sync.notify();
}
}
});
try {
sync.wait();
} catch (InterruptedException e) {
}
}
}
@Override
public void deploymentComplete() {
runInUIThread(new Runnable() {
@Override
public void run() {
MessageDialogHelper.openInformation(getSite().getShell(), Messages.get().PackageManager_Information, Messages.get().PackageManager_PkgDepCompleted);
}
});
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().PackageManager_DepStartError;
}
};
job.setUser(false);
job.start();
}
Aggregations