Search in sources :

Example 36 with NXCSession

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 37 with NXCSession

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);
}
Also used : Locale(java.util.Locale) NXCSession(org.netxms.client.NXCSession) WorkbenchAdvisor(org.eclipse.ui.application.WorkbenchAdvisor) Properties(java.util.Properties) ClientInfo(org.eclipse.rap.rwt.client.service.ClientInfo) Display(org.eclipse.swt.widgets.Display)

Example 38 with NXCSession

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();
}
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 39 with NXCSession

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());
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ProgressListener(org.netxms.client.ProgressListener) PackageInfo(org.netxms.client.packages.PackageInfo) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 40 with NXCSession

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();
}
Also used : NXCSession(org.netxms.client.NXCSession) PackageInfo(org.netxms.client.packages.PackageInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageDeploymentListener(org.netxms.client.packages.PackageDeploymentListener) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10