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();
}
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);
}
});
}
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);
}
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();
}
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();
}
Aggregations