Search in sources :

Example 6 with LibraryImage

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

the class ImageSelectionDialog method refreshImages.

/**
 */
private void refreshImages() {
    final ImageProvider provider = ImageProvider.getInstance(getShell().getDisplay());
    final List<LibraryImage> imageLibrary = provider.getImageLibrary();
    Map<String, List<LibraryImage>> categories = new HashMap<String, List<LibraryImage>>();
    for (LibraryImage image : imageLibrary) {
        final String category = image.getCategory();
        final Image swtImage = provider.getImage(image.getGuid());
        final Rectangle bounds = swtImage.getBounds();
        if (bounds.height <= maxHeight && bounds.width <= maxWidth) {
            if (!categories.containsKey(category)) {
                categories.put(category, new ArrayList<LibraryImage>());
            }
            categories.get(category).add(image);
        }
    }
    // this.knownCategories = categories.keySet();
    gallery.removeAll();
    for (String category : categories.keySet()) {
        final GalleryItem categoryItem = new GalleryItem(gallery, SWT.NONE);
        categoryItem.setText(category);
        final List<LibraryImage> categoryImages = categories.get(category);
        for (LibraryImage image : categoryImages) {
            final GalleryItem imageItem = new GalleryItem(categoryItem, SWT.NONE);
            imageItem.setText(image.getName());
            imageItem.setImage(provider.getImage(image.getGuid()));
            imageItem.setData(image);
        }
    }
    gallery.redraw();
}
Also used : HashMap(java.util.HashMap) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) List(java.util.List) LibraryImage(org.netxms.client.LibraryImage) Image(org.eclipse.swt.graphics.Image) LibraryImage(org.netxms.client.LibraryImage) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) ImageProvider(org.netxms.ui.eclipse.imagelibrary.shared.ImageProvider)

Example 7 with LibraryImage

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

the class ImageSelector method selectionButtonHandler.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.widgets.AbstractSelector#selectionButtonHandler()
	 */
@Override
protected void selectionButtonHandler() {
    ImageSelectionDialog dlg = new ImageSelectionDialog(getShell());
    if (dlg.open() == Window.OK) {
        LibraryImage image = dlg.getLibraryImage();
        if (image != null) {
            setText(image.getName());
            setImage(dlg.getImage());
            imageGuid = dlg.getGuid();
        } else {
            setText(Messages.get().ImageSelector_Default);
            setImage(null);
            imageGuid = NXCommon.EMPTY_GUID;
        }
        getParent().layout();
    }
}
Also used : LibraryImage(org.netxms.client.LibraryImage) ImageSelectionDialog(org.netxms.ui.eclipse.imagelibrary.dialogs.ImageSelectionDialog)

Example 8 with LibraryImage

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

the class ImageProvider method syncMetaData.

/**
 * @throws NXCException
 * @throws IOException
 */
public void syncMetaData() throws NXCException, IOException {
    List<LibraryImage> imageLibrary = session.getImageLibrary();
    libraryIndex.clear();
    clearCache();
    for (final LibraryImage libraryImage : imageLibrary) {
        libraryIndex.put(libraryImage.getGuid(), libraryImage);
    }
}
Also used : LibraryImage(org.netxms.client.LibraryImage)

Example 9 with LibraryImage

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

the class ImageProvider method loadImageFromServer.

/**
 * @param guid
 */
private void loadImageFromServer(final UUID guid) {
    LibraryImage libraryImage;
    try {
        libraryImage = session.getImage(guid);
        // libraryIndex.put(guid, libraryImage); // replace existing half-loaded object w/o image data
        final ByteArrayInputStream stream = new ByteArrayInputStream(libraryImage.getBinaryData());
        try {
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    final Image image = new Image(display, stream);
                    if (image != null)
                        cache.put(guid, image);
                }
            });
            notifySubscribers(guid);
        } catch (SWTException e) {
            // $NON-NLS-1$
            Activator.logError("Cannot decode image", e);
            cache.put(guid, missingImage);
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        Activator.logError("Cannot retrive image from server", e);
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) ByteArrayInputStream(java.io.ByteArrayInputStream) LibraryImage(org.netxms.client.LibraryImage) LibraryImage(org.netxms.client.LibraryImage) Image(org.eclipse.swt.graphics.Image) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) SWTException(org.eclipse.swt.SWTException)

Example 10 with LibraryImage

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

the class ImageLibrary method refreshUI.

/**
 * Refresh UI after retrieving imaqe library from server
 */
private void refreshUI(List<LibraryImage> imageLibrary) {
    Map<String, List<LibraryImage>> categories = new HashMap<String, List<LibraryImage>>();
    for (LibraryImage image : imageLibrary) {
        final String category = image.getCategory();
        if (!categories.containsKey(category)) {
            categories.put(category, new ArrayList<LibraryImage>());
        }
        categories.get(category).add(image);
    }
    this.knownCategories = categories.keySet();
    gallery.removeAll();
    for (String category : categories.keySet()) {
        final GalleryItem categoryItem = new GalleryItem(gallery, SWT.NONE);
        categoryItem.setText(category);
        final List<LibraryImage> categoryImages = categories.get(category);
        for (final LibraryImage image : categoryImages) {
            final GalleryItem imageItem = new GalleryItem(categoryItem, SWT.NONE);
            imageItem.setText(image.getName());
            final byte[] binaryData = image.getBinaryData();
            if (binaryData != null) {
                final ByteArrayInputStream stream = new ByteArrayInputStream(binaryData);
                try {
                    imageItem.setImage(new Image(getSite().getShell().getDisplay(), stream));
                } catch (SWTException e) {
                    // $NON-NLS-1$
                    Activator.logError("Exception in ImageLibrary.refreshUI()", e);
                    // show as "missing"
                    imageItem.setImage(ImageProvider.getInstance(getSite().getShell().getDisplay()).getImage(null));
                }
            } else {
                // show as "missing"
                imageItem.setImage(ImageProvider.getInstance(getSite().getShell().getDisplay()).getImage(null));
            }
            imageItem.setData(image);
        }
    }
    gallery.redraw();
}
Also used : SWTException(org.eclipse.swt.SWTException) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) ArrayList(java.util.ArrayList) LibraryImage(org.netxms.client.LibraryImage) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) Image(org.eclipse.swt.graphics.Image) 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