use of org.netxms.client.LibraryImage 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.client.LibraryImage in project netxms by netxms.
the class ImageLibrary method editImage.
/**
* @param galleryItem
* @param name
* @param category
* @param fileName
*/
protected void editImage(final GalleryItem galleryItem, final String name, final String category, final String fileName) {
final LibraryImage image = (LibraryImage) galleryItem.getData();
new ConsoleJob(Messages.get().ImageLibrary_UpdateJob, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
if (fileName != null) {
verifyImageFile(fileName);
FileInputStream stream = null;
try {
final long fileSize = new File(fileName).length();
stream = new FileInputStream(fileName);
byte[] imageData = new byte[(int) fileSize];
stream.read(imageData);
image.setBinaryData(imageData);
} finally {
if (stream != null)
stream.close();
}
}
if (!image.isProtected()) {
image.setName(name);
image.setCategory(category);
}
session.modifyImage(image, new ProgressListener() {
private long prevDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).ImageLibrary_UpdateImage, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevDone));
prevDone = workDone;
}
});
ImageProvider.getInstance(display).syncMetaData();
refreshImages();
/* TODO: update single element */
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().ImageLibrary_UpdateError;
}
}.start();
}
use of org.netxms.client.LibraryImage in project netxms by netxms.
the class ImageLibrary method uploadNewImage.
/**
* @param name
* @param category
* @param fileName
*/
protected void uploadNewImage(final String name, final String category, final String fileName) {
new ConsoleJob(Messages.get().ImageLibrary_UploadJob, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
verifyImageFile(fileName);
final LibraryImage image = new LibraryImage();
final long fileSize = new File(fileName).length();
FileInputStream stream = null;
try {
stream = new FileInputStream(fileName);
byte[] imageData = new byte[(int) fileSize];
stream.read(imageData);
image.setBinaryData(imageData);
image.setName(name);
image.setCategory(category);
} finally {
if (stream != null)
stream.close();
}
session.createImage(image, new ProgressListener() {
private long prevDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).ImageLibrary_UploadImage, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevDone));
prevDone = workDone;
}
});
// TODO: check
ImageProvider.getInstance(display).syncMetaData();
refreshImages();
/* TODO: update local copy */
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().ImageLibrary_UploadError;
}
}.start();
}
use of org.netxms.client.LibraryImage 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.client.LibraryImage in project netxms by netxms.
the class ImageSelectionDialog method defaultPressed.
private void defaultPressed() {
imageObject = null;
libraryImage = new LibraryImage();
saveSettings();
super.okPressed();
}
Aggregations