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