Search in sources :

Example 6 with DefaultGalleryGroupRenderer

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

the class Bug276435Test method testBug276435.

public void testBug276435() {
    Gallery g = new Gallery(s, SWT.V_SCROLL);
    // Set Renderers
    DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
    g.setGroupRenderer(gr);
    DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
    g.setItemRenderer(ir);
    GalleryItem group = new GalleryItem(g, SWT.NONE);
    GalleryItem item1 = new GalleryItem(group, SWT.NONE);
    GalleryItem item2 = new GalleryItem(group, SWT.NONE);
    g.remove(item2);
    assertEquals(0, g.indexOf(group));
    assertEquals(0, g.indexOf(item1));
    assertEquals(-1, g.indexOf(item2));
    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 7 with DefaultGalleryGroupRenderer

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

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

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

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

DefaultGalleryGroupRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryGroupRenderer)11 DefaultGalleryItemRenderer (org.netxms.nebula.widgets.gallery.DefaultGalleryItemRenderer)10 Gallery (org.netxms.nebula.widgets.gallery.Gallery)10 GalleryItem (org.netxms.nebula.widgets.gallery.GalleryItem)5 IOException (java.io.IOException)2 SWTException (org.eclipse.swt.SWTException)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 NXCException (org.netxms.client.NXCException)2 Action (org.eclipse.jface.action.Action)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)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 Composite (org.eclipse.swt.widgets.Composite)1 LibraryImage (org.netxms.client.LibraryImage)1 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)1 ImagePropertiesDialog (org.netxms.ui.eclipse.imagelibrary.dialogs.ImagePropertiesDialog)1