Search in sources :

Example 11 with GalleryItem

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

the class GalleryTreeViewer method remove.

/**
 * Removes the element at the specified index of the parent. The selection
 * is updated if required.
 *
 * @param parentOrTreePath
 *            the parent element, the input element, or a tree path to the
 *            parent element
 * @param index
 *            child index
 * @since 3.3
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public void remove(final Object parentOrTreePath, final int index) {
    // if (isBusy())
    // return;
    final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths()));
    preservingSelection(new Runnable() {

        public void run() {
            TreePath removedPath = null;
            if (internalIsInputOrEmptyPath(parentOrTreePath)) {
                Gallery gallery = (Gallery) getControl();
                if (index < gallery.getItemCount()) {
                    GalleryItem item = gallery.getItem(index);
                    if (item.getData() != null) {
                        removedPath = getTreePathFromItem(item);
                        disassociate(item);
                    }
                    item.dispose();
                }
            } else {
                Widget[] parentItems = internalFindItems(parentOrTreePath);
                for (int i = 0; i < parentItems.length; i++) {
                    GalleryItem parentItem = (GalleryItem) parentItems[i];
                    if (index < parentItem.getItemCount()) {
                        GalleryItem item = parentItem.getItem(index);
                        if (item.getData() != null) {
                            removedPath = getTreePathFromItem(item);
                            disassociate(item);
                        }
                        item.dispose();
                    }
                }
            }
            if (removedPath != null) {
                boolean removed = false;
                for (Iterator it = oldSelection.iterator(); it.hasNext(); ) {
                    TreePath path = (TreePath) it.next();
                    if (path.startsWith(removedPath, getComparer())) {
                        it.remove();
                        removed = true;
                    }
                }
                if (removed) {
                    setSelection(new TreeSelection((TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()]), getComparer()), false);
                }
            }
        }
    });
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Gallery(org.netxms.nebula.widgets.gallery.Gallery) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) LinkedList(java.util.LinkedList)

Example 12 with GalleryItem

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

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

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

the class Bug216204Test method testBug212182OnGalleryMulti.

public void testBug212182OnGalleryMulti() {
    Gallery g = new Gallery(s, SWT.V_SCROLL | SWT.MULTI);
    // Set Renderers
    DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
    g.setGroupRenderer(gr);
    DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
    g.setItemRenderer(ir);
    // Create an item
    GalleryItem item1 = new GalleryItem(g, SWT.NONE);
    g.setSelection(new GalleryItem[] { item1 });
    GalleryItem[] selection = g.getSelection();
    assertEquals(1, selection.length);
    assertEquals(item1, selection[0]);
    // Dispose item
    item1.dispose();
    selection = g.getSelection();
    assertEquals(0, selection.length);
    // Create a lot of items
    GalleryItem[] items = new GalleryItem[10];
    GalleryItem[] children = new GalleryItem[10];
    for (int i = 0; i < 10; i++) {
        items[i] = new GalleryItem(g, SWT.None);
        items[i].setText("G" + i);
    }
    for (int i = 0; i < 10; i++) {
        children[i] = new GalleryItem(items[0], SWT.None);
        children[i].setText("G0-" + i);
    }
    assertEquals(10, g.getItemCount());
    assertEquals(10, items[0].getItemCount());
    g.setSelection(new GalleryItem[] { children[5], items[5] });
    selection = g.getSelection();
    assertEquals(2, selection.length);
    assertEquals(children[5], selection[0]);
    assertEquals(items[5], selection[1]);
    items[0].dispose();
    selection = g.getSelection();
    // Since we disposed the parent of a selected item, it should have been
    // removed from the selection
    assertEquals(1, selection.length);
    assertEquals(items[5], selection[0]);
    // Clean
    g.dispose();
}
Also used : Gallery(org.netxms.nebula.widgets.gallery.Gallery) DefaultGalleryGroupRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer) DefaultGalleryItemRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryItemRenderer) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem)

Example 15 with GalleryItem

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

the class Bug212182Test method testBug212182OnGallery.

public void testBug212182OnGallery() {
    Gallery g = new Gallery(s, SWT.V_SCROLL);
    // Set Renderers
    DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
    g.setGroupRenderer(gr);
    DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
    g.setItemRenderer(ir);
    // Check for NPE or Null
    GalleryItem[] items = g.getItems();
    assertNotNull(items);
    assertEquals(0, items.length);
    g.dispose();
}
Also used : Gallery(org.netxms.nebula.widgets.gallery.Gallery) DefaultGalleryGroupRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer) DefaultGalleryItemRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryItemRenderer) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem)

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