Search in sources :

Example 1 with LibraryImage

use of org.netxms.client.LibraryImage in project netxms by netxms.

the class ImageLibrary method fillContextMenu.

/**
 * @param manager
 */
protected void fillContextMenu(IMenuManager manager) {
    manager.add(actionNew);
    final int selectionCount = gallery.getSelectionCount();
    if (selectionCount == 1) {
        manager.add(actionEdit);
    }
    if (selectionCount > 0) {
        final GalleryItem[] items = gallery.getSelection();
        boolean protectedFound = false;
        for (GalleryItem item : items) {
            if (((LibraryImage) item.getData()).isProtected()) {
                protectedFound = true;
                break;
            }
        }
        if (!protectedFound) {
            manager.add(actionDelete);
        }
    }
}
Also used : LibraryImage(org.netxms.client.LibraryImage) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem)

Example 2 with LibraryImage

use of org.netxms.client.LibraryImage in project netxms by netxms.

the class ImageLibrary method editImage.

/**
 * @param galleryItem
 * @param name
 * @param category
 * @param fileName
 */
protected void editImage(final GalleryItem galleryItem, final String name, final String category, final String fileName) {
    final LibraryImage image = (LibraryImage) galleryItem.getData();
    new ConsoleJob(Messages.get().ImageLibrary_UpdateJob, this, Activator.PLUGIN_ID, null) {

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

                private long prevDone = 0;

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

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

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

Example 3 with LibraryImage

use of org.netxms.client.LibraryImage 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 4 with LibraryImage

use of org.netxms.client.LibraryImage in project netxms by netxms.

the class ImageLibrary method createActions.

/**
 * Create actions
 */
private void createActions() {
    actionNew = new Action(Messages.get().ImageLibrary_ActionUpload) {

        @Override
        public void run() {
            final ImagePropertiesDialog dialog = new ImagePropertiesDialog(getSite().getShell(), knownCategories, imageLibrary, false);
            final GalleryItem[] selection = gallery.getSelection();
            if (selection.length > 0) {
                LibraryImage image = (LibraryImage) selection[0].getData();
                dialog.setDefaultCategory(image.getCategory());
            }
            if (dialog.open() == Dialog.OK) {
                uploadNewImage(dialog.getName(), dialog.getCategory(), dialog.getFileName());
            }
        }
    };
    actionNew.setImageDescriptor(SharedIcons.ADD_OBJECT);
    actionEdit = new Action(Messages.get().ImageLibrary_ActionEdit) {

        @Override
        public void run() {
            final GalleryItem[] selection = gallery.getSelection();
            if (selection.length == 1) {
                final ImagePropertiesDialog dialog = new ImagePropertiesDialog(getSite().getShell(), knownCategories, imageLibrary, true);
                LibraryImage image = (LibraryImage) selection[0].getData();
                dialog.setName(image.getName());
                dialog.setDefaultCategory(image.getCategory());
                if (dialog.open() == Dialog.OK) {
                    editImage(selection[0], dialog.getName(), dialog.getCategory(), dialog.getFileName());
                }
            }
        }
    };
    actionEdit.setImageDescriptor(SharedIcons.EDIT);
    actionDelete = new Action(Messages.get().ImageLibrary_ActionDelete) {

        @Override
        public void run() {
            deleteImage();
        }
    };
    actionDelete.setImageDescriptor(SharedIcons.DELETE_OBJECT);
    actionRefresh = new RefreshAction(this) {

        @Override
        public void run() {
            try {
                refreshImages();
            } catch (Exception e) {
                // $NON-NLS-1$
                Activator.logError("ImageLibrary view: Exception in refresh action", e);
            }
        }
    };
    actionZoomIn = new Action(Messages.get().ImageLibrary_ActionZoomIn) {

        @Override
        public void run() {
            final DefaultGalleryGroupRenderer groupRenderer = (DefaultGalleryGroupRenderer) gallery.getGroupRenderer();
            if (currentIconSize < MAX_GRID_ICON_SIZE) {
                currentIconSize += 16;
                groupRenderer.setItemHeight(currentIconSize);
                groupRenderer.setItemWidth(currentIconSize);
            }
        }
    };
    actionZoomIn.setImageDescriptor(SharedIcons.ZOOM_IN);
    actionZoomOut = new Action(Messages.get().ImageLibrary_ActionZoomOut) {

        @Override
        public void run() {
            final DefaultGalleryGroupRenderer groupRenderer = (DefaultGalleryGroupRenderer) gallery.getGroupRenderer();
            if (currentIconSize > MIN_GRID_ICON_SIZE) {
                currentIconSize -= 16;
                groupRenderer.setItemHeight(currentIconSize);
                groupRenderer.setItemWidth(currentIconSize);
            }
        }
    };
    actionZoomOut.setImageDescriptor(SharedIcons.ZOOM_OUT);
}
Also used : RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) DefaultGalleryGroupRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer) ImagePropertiesDialog(org.netxms.ui.eclipse.imagelibrary.dialogs.ImagePropertiesDialog) LibraryImage(org.netxms.client.LibraryImage) SWTException(org.eclipse.swt.SWTException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 5 with LibraryImage

use of org.netxms.client.LibraryImage in project netxms by netxms.

the class ImageSelectionDialog method defaultPressed.

private void defaultPressed() {
    imageObject = null;
    libraryImage = new LibraryImage();
    saveSettings();
    super.okPressed();
}
Also used : LibraryImage(org.netxms.client.LibraryImage)

Aggregations

LibraryImage (org.netxms.client.LibraryImage)11 SWTException (org.eclipse.swt.SWTException)5 IOException (java.io.IOException)4 NXCException (org.netxms.client.NXCException)4 Image (org.eclipse.swt.graphics.Image)3 GalleryItem (org.netxms.nebula.widgets.gallery.GalleryItem)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressListener (org.netxms.client.ProgressListener)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 Action (org.eclipse.jface.action.Action)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 DefaultGalleryGroupRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer)1 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)1 ImagePropertiesDialog (org.netxms.ui.eclipse.imagelibrary.dialogs.ImagePropertiesDialog)1