Search in sources :

Example 71 with ConsoleJob

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

the class ImageLibrary method uploadNewImage.

/**
 * @param name
 * @param category
 * @param fileName
 */
protected void uploadNewImage(final String name, final String category, final String fileName) {
    new ConsoleJob(Messages.get().ImageLibrary_UploadJob, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(final IProgressMonitor monitor) throws Exception {
            verifyImageFile(fileName);
            final LibraryImage image = new LibraryImage();
            final long fileSize = new File(fileName).length();
            FileInputStream stream = null;
            try {
                stream = new FileInputStream(fileName);
                byte[] imageData = new byte[(int) fileSize];
                stream.read(imageData);
                image.setBinaryData(imageData);
                image.setName(name);
                image.setCategory(category);
            } finally {
                if (stream != null)
                    stream.close();
            }
            session.createImage(image, new ProgressListener() {

                private long prevDone = 0;

                @Override
                public void setTotalWorkAmount(long workTotal) {
                    monitor.beginTask(Messages.get(getDisplay()).ImageLibrary_UploadImage, (int) workTotal);
                }

                @Override
                public void markProgress(long workDone) {
                    monitor.worked((int) (workDone - prevDone));
                    prevDone = workDone;
                }
            });
            // TODO: check
            ImageProvider.getInstance(display).syncMetaData();
            refreshImages();
            /* TODO: update local copy */
            monitor.done();
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ImageLibrary_UploadError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressListener(org.netxms.client.ProgressListener) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) LibraryImage(org.netxms.client.LibraryImage) File(java.io.File) SWTException(org.eclipse.swt.SWTException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) FileInputStream(java.io.FileInputStream)

Example 72 with ConsoleJob

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

the class ViewAgentFilesProvider method getChildren.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
	 */
@Override
public Object[] getChildren(final Object parentElement) {
    if (((AgentFile) parentElement).getChildren() == null) {
        ConsoleJob job = new ConsoleJob(Messages.get().ViewAgentFilesProvider_JobTitle, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final List<AgentFile> files = session.listAgentFiles(((AgentFile) parentElement), ((AgentFile) parentElement).getFullName(), ((AgentFile) parentElement).getNodeId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        ((AgentFile) parentElement).setChildren(files);
                        ((StructuredViewer) viewer).refresh(parentElement);
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().ViewAgentFilesProvider_JobError;
            }
        };
        job.setUser(false);
        job.start();
        return new AgentFile[] { new AgentFile(Messages.get().ViewAgentFilesProvider_Loading, AgentFile.PLACEHOLDER, (AgentFile) parentElement, ((AgentFile) parentElement).getNodeId()) };
    }
    return ((AgentFile) parentElement).getChildren().toArray();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 73 with ConsoleJob

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

the class DynamicFileViewer method startTracking.

/**
 * Start file change tracking
 *
 * @param nodeId
 * @param fileId
 */
public void startTracking(final long nodeId, final String fileId, final String remoteFileName) {
    if (restartJob != null)
        restartJob.cancel();
    if (monitoringJob != null)
        monitoringJob.cancel();
    hideMessage();
    this.fileId = fileId;
    this.nodeId = nodeId;
    this.remoteFileName = remoteFileName;
    // text.setTopIndex(text.getLineCount() - 1);
    monitoringJob = new ConsoleJob(Messages.get().DynamicFileViewer_TrackFileChanges, null, Activator.PLUGIN_ID, null) {

        private boolean tracking = true;

        @Override
        protected void canceling() {
            tracking = false;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            while (tracking) {
                final String s = session.waitForFileTail(fileId, 3000);
                if (s != null) {
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            if (!text.isDisposed()) {
                                append(s);
                            } else {
                                tracking = false;
                            }
                        }
                    });
                }
            }
            session.cancelFileMonitoring(nodeId, fileId);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DynamicFileViewer_FileTrackingFailed;
        }
    };
    monitoringJob.setUser(false);
    monitoringJob.setSystem(true);
    monitoringJob.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 74 with ConsoleJob

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

the class EventObjectList method refreshView.

/**
 * Refresh view
 */
private void refreshView() {
    new ConsoleJob(Messages.get().EventConfigurator_OpenJob_Title, null, Activator.PLUGIN_ID, JOB_FAMILY) {

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
          */
        @Override
        protected String getErrorMessage() {
            return Messages.get().EventConfigurator_OpenJob_Error;
        }

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
          */
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<EventObject> list = session.getEventObjects();
            runInUIThread(new Runnable() {

                /* (non-Javadoc)
                * @see java.lang.Runnable#run()
                */
                @Override
                public void run() {
                    eventObjects = new HashMap<Long, EventObject>(list.size());
                    for (final EventObject o : list) {
                        if ((o instanceof EventGroup) && !showGroups)
                            continue;
                        eventObjects.put(o.getCode(), o);
                    }
                    viewer.setInput(eventObjects.values().toArray());
                }
            });
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) EventObject(org.netxms.client.events.EventObject) EventGroup(org.netxms.client.events.EventGroup)

Example 75 with ConsoleJob

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

the class MapBackground method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    if (radioTypeNone.getSelection()) {
        md.setMapBackground(NXCommon.EMPTY_GUID, new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
    } else if (radioTypeImage.getSelection()) {
        md.setMapBackground(image.getImageGuid(), new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
    } else if (!disableGeolocationBackground && radioTypeGeoMap.getSelection()) {
        GeoLocation location;
        try {
            location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        } catch (GeoLocationFormatException e) {
            MessageDialogHelper.openError(getShell(), Messages.get().MapBackground_Error, Messages.get().MapBackground_GeoLocFormatError);
            return false;
        }
        md.setMapBackground(NetworkMap.GEOMAP_BACKGROUND, location, zoomSpinner.getSelection(), ColorConverter.rgbToInt(backgroundColor.getColorValue()));
    }
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().MapBackground_JobTitle + object.getObjectName(), null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().MapBackground_JobError + object.getObjectName();
        }

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

                    @Override
                    public void run() {
                        MapBackground.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException)

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