Search in sources :

Example 76 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class MapObjectFilter method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    final String filter = filterSource.getText();
    if (initialFilter.equals(filter) && (checkboxEnableFilter.getSelection() == initialEnable))
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setFilter(filter);
    md.setObjectFlags(checkboxEnableFilter.getSelection() ? NetworkMap.MF_FILTER_OBJECTS : 0, NetworkMap.MF_FILTER_OBJECTS);
    new ConsoleJob(Messages.get().MapObjectFilter_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        initialFilter = filter;
                        initialEnable = checkboxEnableFilter.getSelection();
                        MapObjectFilter.this.setValid(true);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().MapObjectFilter_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 77 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AbstractNetworkMapView method openLinkDci.

/**
 * Handler for opening network map dci on double click
 */
private void openLinkDci() {
    final NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
    if (!link.hasDciData())
        return;
    new ConsoleJob("Open link dci job", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
          */
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            DciValue[] values = session.getLastValues(link.getDciAsList());
            final StringBuilder sb = new StringBuilder();
            for (DciValue v : values) {
                sb.append("&");
                sb.append(Integer.toString(v instanceof SimpleDciValue ? ChartDciConfig.ITEM : ChartDciConfig.TABLE));
                sb.append("@");
                sb.append(Long.toString(v.getNodeId()));
                sb.append("@");
                sb.append(Long.toString(v.getId()));
                sb.append("@");
                sb.append(URLEncoder.encode(v.getDescription(), "UTF-8"));
                sb.append("@");
                sb.append(URLEncoder.encode(v.getName(), "UTF-8"));
            }
            runInUIThread(new Runnable() {

                /* (non-Javadoc)
                * @see java.lang.Runnable#run()
                */
                @Override
                public void run() {
                    try {
                        getSite().getPage().showView(HistoricalGraphView.ID, sb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
                    } catch (PartInitException e) {
                        MessageDialogHelper.openError(getSite().getShell(), "Error", String.format("Error opening view: %s", e.getLocalizedMessage()));
                    }
                }
            });
        }

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
          */
        @Override
        protected String getErrorMessage() {
            return "Cannot open dci link historical graph view";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciValue(org.netxms.client.datacollection.DciValue) SimpleDciValue(org.netxms.client.datacollection.SimpleDciValue) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SimpleDciValue(org.netxms.client.datacollection.SimpleDciValue) PartInitException(org.eclipse.ui.PartInitException) NetworkMapLink(org.netxms.client.maps.NetworkMapLink) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 78 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class PredefinedMap method init.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.netxms.ui.eclipse.networkmaps.views.NetworkMap#init(org.eclipse.ui
	 * .IViewSite)
	 */
@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    mapObject = (NetworkMap) rootObject;
    setPartName(rootObject.getObjectName());
    ConsoleJob job = new ConsoleJob("Get map effective rights", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            readOnly = ((mapObject.getEffectiveRights() & UserAccessRights.OBJECT_ACCESS_MODIFY) == 0);
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot get effective rights for map";
        }
    };
    job.start();
    // FIXME: rewrite waiting
    try {
        job.join();
    } catch (InterruptedException e) {
    }
    allowManualLayout = !readOnly;
    if (mapObject.getLayout() == MapLayoutAlgorithm.MANUAL) {
        automaticLayoutEnabled = false;
    } else {
        automaticLayoutEnabled = true;
        layoutAlgorithm = mapObject.getLayout();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 79 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class SelectScriptDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    dialogArea.setLayout(layout);
    new Label(dialogArea, SWT.NONE).setText(Messages.get().SelectScriptDialog_AvailableScripts);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | (multiSelection ? SWT.MULTI : 0));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Script) element).getName();
        }
    });
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            Script s1 = (Script) e1;
            Script s2 = (Script) e2;
            return s1.getName().compareToIgnoreCase(s2.getName());
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            SelectScriptDialog.this.okPressed();
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    gd.widthHint = 400;
    viewer.getControl().setLayoutData(gd);
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SelectScriptDialog_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<Script> scripts = session.getScriptLibrary();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(scripts.toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SelectScriptDialog_JobError;
        }
    }.start();
    return dialogArea;
}
Also used : Script(org.netxms.client.Script) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 80 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class ScriptExecutor method intermediateSave.

/**
 * Update script
 */
public void intermediateSave(boolean saveOnSelectionChange) {
    final Script s = library.get(saveOnSelectionChange ? previousSelection : scriptCombo.getSelectionIndex());
    final String scriptSource = scriptEditor.getText();
    new ConsoleJob(Messages.get().ScriptExecutor_JobName_Update, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyScript(s.getId(), s.getName(), scriptSource);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    clearDirtyFlags();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ScriptExecutor_JobError_Update;
        }
    }.start();
}
Also used : Script(org.netxms.client.Script) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Aggregations

ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)330 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)329 NXCSession (org.netxms.client.NXCSession)163 PartInitException (org.eclipse.ui.PartInitException)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)81 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 NXCException (org.netxms.client.NXCException)44 List (java.util.List)38 ArrayList (java.util.ArrayList)34 AbstractObject (org.netxms.client.objects.AbstractObject)33 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 IOException (java.io.IOException)27 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)16 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)13 File (java.io.File)12 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)10 Script (org.netxms.client.Script)10 Table (org.netxms.client.Table)10 CoreException (org.eclipse.core.runtime.CoreException)9 GridData (org.eclipse.swt.layout.GridData)9