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