Search in sources :

Example 16 with GalleryItem

use of org.netxms.nebula.widgets.gallery.GalleryItem in project netxms by netxms.

the class GalleryViewerRow method getRowBelow.

protected ViewerRow getRowBelow() {
    if (item.getParentItem() == null) {
        int index = item.getParent().indexOf(item) + 1;
        if (index < item.getParent().getItemCount()) {
            GalleryItem tmp = item.getParent().getItem(index);
            if (tmp != null) {
                return new GalleryViewerRow(tmp);
            }
        }
    } else {
        GalleryItem parentItem = item.getParentItem();
        int index = parentItem.indexOf(item) + 1;
        if (index < parentItem.getItemCount()) {
            GalleryItem tmp = parentItem.getItem(index);
            if (tmp != null) {
                return new GalleryViewerRow(tmp);
            }
        }
    }
    return null;
}
Also used : GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem)

Example 17 with GalleryItem

use of org.netxms.nebula.widgets.gallery.GalleryItem 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)

Example 18 with GalleryItem

use of org.netxms.nebula.widgets.gallery.GalleryItem in project netxms by netxms.

the class ImageLibrary method deleteImage.

/**
 */
protected void deleteImage() {
    final GalleryItem[] selection = gallery.getSelection();
    for (GalleryItem item : selection) {
        try {
            session.deleteImage((LibraryImage) item.getData());
            final GalleryItem category = item.getParentItem();
            gallery.remove(item);
            if (category != null) {
                if (category.getItemCount() == 0) {
                    gallery.remove(category);
                }
            }
        } catch (NXCException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : IOException(java.io.IOException) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) NXCException(org.netxms.client.NXCException)

Example 19 with GalleryItem

use of org.netxms.nebula.widgets.gallery.GalleryItem in project netxms by netxms.

the class GalleryTreeViewer method editElement.

public void editElement(Object element, int column) {
    if (element instanceof TreePath) {
        setSelection(new TreeSelection((TreePath) element));
        GalleryItem[] items = gallery.getSelection();
        if (items.length == 1) {
            ViewerRow row = getViewerRowFromItem(items[0]);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    getControl().setRedraw(false);
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                    getControl().setRedraw(true);
                }
            }
        }
    } else {
        super.editElement(element, column);
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Aggregations

GalleryItem (org.netxms.nebula.widgets.gallery.GalleryItem)19 Gallery (org.netxms.nebula.widgets.gallery.Gallery)11 ArrayList (java.util.ArrayList)5 DefaultGalleryGroupRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer)5 DefaultGalleryItemRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryItemRenderer)5 List (java.util.List)4 LinkedList (java.util.LinkedList)3 TreePath (org.eclipse.jface.viewers.TreePath)3 LibraryImage (org.netxms.client.LibraryImage)3 HashMap (java.util.HashMap)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 Image (org.eclipse.swt.graphics.Image)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 ColumnViewerEditorActivationEvent (org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)1 ViewerCell (org.eclipse.jface.viewers.ViewerCell)1 ViewerRow (org.eclipse.jface.viewers.ViewerRow)1