Search in sources :

Example 11 with Gallery

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

the class GalleryTreeViewer method getSelection.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.viewers.AbstractTreeViewer#getSelection(org.eclipse
	 * .swt.widgets.Control)
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Item[] getSelection(Control control) {
    Item[] selection = ((Gallery) control).getSelection();
    if (selection == null) {
        return new GalleryItem[0];
    }
    List notDisposed = new ArrayList(selection.length);
    for (int i = 0; i < selection.length; i++) {
        if (!selection[i].isDisposed()) {
            notDisposed.add(selection[i]);
        } else {
            System.out.println("GalleryItem was disposed (ignoring)");
        }
    }
    selection = (GalleryItem[]) notDisposed.toArray(new GalleryItem[notDisposed.size()]);
    return selection;
}
Also used : GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) Item(org.eclipse.swt.widgets.Item) Gallery(org.netxms.nebula.widgets.gallery.Gallery) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) Point(org.eclipse.swt.graphics.Point)

Example 12 with Gallery

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

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

the class ImageLibrary method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(final Composite parent) {
    final IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    // $NON-NLS-1$
    currentIconSize = ps.getInt("IMAGE_LIBRARY.ZOOM");
    if (currentIconSize == 0)
        currentIconSize = MIN_GRID_ICON_SIZE;
    final FillLayout layout = new FillLayout();
    parent.setLayout(layout);
    display = getSite().getShell().getDisplay();
    session = (NXCSession) ConsoleSharedData.getSession();
    gallery = new Gallery(parent, SWT.V_SCROLL | SWT.MULTI);
    DefaultGalleryGroupRenderer galleryGroupRenderer = new DefaultGalleryGroupRenderer();
    galleryGroupRenderer.setMinMargin(2);
    galleryGroupRenderer.setItemHeight(currentIconSize);
    galleryGroupRenderer.setItemWidth(currentIconSize);
    galleryGroupRenderer.setAutoMargin(true);
    galleryGroupRenderer.setAlwaysExpanded(true);
    gallery.setGroupRenderer(galleryGroupRenderer);
    DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer();
    gallery.setItemRenderer(itemRenderer);
    createActions();
    createPopupMenu();
    contributeToActionBars();
    gallery.addMenuDetectListener(new MenuDetectListener() {

        @Override
        public void menuDetected(MenuDetectEvent e) {
            menuEvent = e;
        }
    });
    try {
        refreshImages();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    ImageProvider.getInstance(display).addUpdateListener(this);
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            ps.setValue("IMAGE_LIBRARY.ZOOM", currentIconSize);
            ImageProvider.getInstance(display).removeUpdateListener(ImageLibrary.this);
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) Gallery(org.netxms.nebula.widgets.gallery.Gallery) DefaultGalleryGroupRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) FillLayout(org.eclipse.swt.layout.FillLayout) DefaultGalleryItemRenderer(org.netxms.nebula.widgets.gallery.DefaultGalleryItemRenderer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SWTException(org.eclipse.swt.SWTException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 14 with Gallery

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

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

Gallery (org.netxms.nebula.widgets.gallery.Gallery)16 GalleryItem (org.netxms.nebula.widgets.gallery.GalleryItem)11 DefaultGalleryGroupRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer)10 DefaultGalleryItemRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryItemRenderer)10 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 SWTException (org.eclipse.swt.SWTException)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 MenuDetectEvent (org.eclipse.swt.events.MenuDetectEvent)1 MenuDetectListener (org.eclipse.swt.events.MenuDetectListener)1