use of com.archimatetool.editor.propertysections.ImageManagerDialog in project archi by archimatetool.
the class ProfilesManagerDialog method chooseImage.
/**
* Choose an image from the dialog and apply to selected profiles
*/
private void chooseImage() {
IStructuredSelection selection = fTableViewer.getStructuredSelection();
if (!selection.isEmpty()) {
IProfile firstSelected = (IProfile) selection.getFirstElement();
ImageManagerDialog dialog = new ImageManagerDialog(getParentShell());
dialog.setSelected(fArchimateModel, firstSelected.getImagePath());
if (dialog.open() == Window.OK) {
try {
IArchiveManager archiveManager = (IArchiveManager) fArchimateModel.getAdapter(IArchiveManager.class);
String path = null;
// Image from file
if (dialog.getUserSelectedFile() != null && dialog.getUserSelectedFile().exists()) {
path = archiveManager.addImageFromFile(dialog.getUserSelectedFile());
} else // Existing image which could be in this model or a different model
if (dialog.getUserSelectedImagePath() != null) {
if (dialog.getUserSelectedModel() != fArchimateModel) {
// Different model
IArchiveManager selectedArchiveManager = (IArchiveManager) dialog.getUserSelectedModel().getAdapter(IArchiveManager.class);
path = archiveManager.copyImageBytes(selectedArchiveManager, dialog.getUserSelectedImagePath());
} else {
// Same model
path = dialog.getUserSelectedImagePath();
}
}
if (path != null) {
// Apply the image path to Profiles that can have an image
for (Object o : selection.toList()) {
IProfile profile = (IProfile) o;
if (canHaveImage(profile)) {
profile.setImagePath(path);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
// $NON-NLS-1$
Logger.logError("Could not create image!", ex);
}
// Select to update image preview
fTableViewer.setSelection(selection);
}
}
}
Aggregations