use of org.netxms.client.LibraryImage 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.client.LibraryImage in project netxms by netxms.
the class ImageSelector method selectionButtonHandler.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.widgets.AbstractSelector#selectionButtonHandler()
*/
@Override
protected void selectionButtonHandler() {
ImageSelectionDialog dlg = new ImageSelectionDialog(getShell());
if (dlg.open() == Window.OK) {
LibraryImage image = dlg.getLibraryImage();
if (image != null) {
setText(image.getName());
setImage(dlg.getImage());
imageGuid = dlg.getGuid();
} else {
setText(Messages.get().ImageSelector_Default);
setImage(null);
imageGuid = NXCommon.EMPTY_GUID;
}
getParent().layout();
}
}
use of org.netxms.client.LibraryImage in project netxms by netxms.
the class ImageProvider method syncMetaData.
/**
* @throws NXCException
* @throws IOException
*/
public void syncMetaData() throws NXCException, IOException {
List<LibraryImage> imageLibrary = session.getImageLibrary();
libraryIndex.clear();
clearCache();
for (final LibraryImage libraryImage : imageLibrary) {
libraryIndex.put(libraryImage.getGuid(), libraryImage);
}
}
use of org.netxms.client.LibraryImage in project netxms by netxms.
the class ImageProvider method loadImageFromServer.
/**
* @param guid
*/
private void loadImageFromServer(final UUID guid) {
LibraryImage libraryImage;
try {
libraryImage = session.getImage(guid);
// libraryIndex.put(guid, libraryImage); // replace existing half-loaded object w/o image data
final ByteArrayInputStream stream = new ByteArrayInputStream(libraryImage.getBinaryData());
try {
display.syncExec(new Runnable() {
@Override
public void run() {
final Image image = new Image(display, stream);
if (image != null)
cache.put(guid, image);
}
});
notifySubscribers(guid);
} catch (SWTException e) {
// $NON-NLS-1$
Activator.logError("Cannot decode image", e);
cache.put(guid, missingImage);
}
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError("Cannot retrive image from server", e);
}
}
use of org.netxms.client.LibraryImage in project netxms by netxms.
the class ImageLibrary method refreshUI.
/**
* Refresh UI after retrieving imaqe library from server
*/
private void refreshUI(List<LibraryImage> imageLibrary) {
Map<String, List<LibraryImage>> categories = new HashMap<String, List<LibraryImage>>();
for (LibraryImage image : imageLibrary) {
final String category = image.getCategory();
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 (final LibraryImage image : categoryImages) {
final GalleryItem imageItem = new GalleryItem(categoryItem, SWT.NONE);
imageItem.setText(image.getName());
final byte[] binaryData = image.getBinaryData();
if (binaryData != null) {
final ByteArrayInputStream stream = new ByteArrayInputStream(binaryData);
try {
imageItem.setImage(new Image(getSite().getShell().getDisplay(), stream));
} catch (SWTException e) {
// $NON-NLS-1$
Activator.logError("Exception in ImageLibrary.refreshUI()", e);
// show as "missing"
imageItem.setImage(ImageProvider.getInstance(getSite().getShell().getDisplay()).getImage(null));
}
} else {
// show as "missing"
imageItem.setImage(ImageProvider.getInstance(getSite().getShell().getDisplay()).getImage(null));
}
imageItem.setData(image);
}
}
gallery.redraw();
}
Aggregations