package org.openlca.app.rcp.images;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;
import org.openlca.app.navigation.Group;
import org.openlca.app.navigation.GroupType;
import org.openlca.app.util.FileType;
import org.openlca.core.model.Category;
import org.openlca.core.model.Flow;
import org.openlca.core.model.FlowType;
import org.openlca.core.model.ModelType;
import org.openlca.core.model.Process;
import org.openlca.core.model.ProcessType;
import org.openlca.core.model.RootEntity;
import org.openlca.core.model.Source;
import org.openlca.core.model.descriptors.BaseDescriptor;
import org.openlca.core.model.descriptors.CategoryDescriptor;
import org.openlca.core.model.descriptors.FlowDescriptor;
import org.openlca.core.model.descriptors.ProcessDescriptor;
public class Images {
public static Image get(RootEntity entity) {
if (entity instanceof Source) {
Source source = (Source) entity;
if (source.getExternalFile() != null)
return get(FileType.forName(source.getExternalFile()));
}
if (entity instanceof Process)
return get(((Process) entity).getProcessType());
if (entity instanceof Flow)
return get(((Flow) entity).getFlowType());
return get(ModelType.forModelClass(entity.getClass()));
}
public static Image get(BaseDescriptor d) {
if (d == null || d.getModelType() == null)
return null;
switch (d.getModelType()) {
case PROCESS:
return get(((ProcessDescriptor) d).getProcessType());
case FLOW:
return get(((FlowDescriptor) d).getFlowType());
case CATEGORY:
CategoryDescriptor cd = (CategoryDescriptor) d;
ModelIcon icon = categoryIcon(cd.getCategoryType());
return ImageManager.get(icon);
default:
return get(d.getModelType());
}
}
public static Image get(Category category) {
if (category == null)
return null;
ModelIcon icon = categoryIcon(category.getModelType());
if (icon == null)
return Icon.FOLDER.get();
return ImageManager.get(icon);
}
public static Image get(Group group) {
if (group == null)
return null;
ModelIcon icon = icon(group.type);
if (icon == null)
return Icon.FOLDER.get();
return ImageManager.get(icon);
}
public static Image get(ModelType type) {
ModelIcon icon = icon(type);
if (icon == null)
return null;
return ImageManager.get(icon);
}
public static Image get(FlowType type) {
ModelIcon icon = icon(type);
if (icon == null)
return null;
return ImageManager.get(icon);
}
public static Image get(ProcessType type) {
ModelIcon icon = icon(type);
if (icon == null)
return null;
return ImageManager.get(icon);
}
public static Image get(GroupType type) {
ModelIcon icon = icon(type);
if (icon == null)
return Icon.FOLDER.get();
return ImageManager.get(icon);
}
public static Image get(FileType type) {
if (type == null)
return null;
FileIcon icon = icon(type);
if (icon == null)
return ImageManager.get(FileIcon.DEFAULT);
return ImageManager.get(icon);
}
public static Image get(ModelType type, Overlay overlay) {
ModelIcon icon = Images.icon(type);
if (icon == null)
return null;
if (overlay == null)
return ImageManager.get(icon);
return ImageManager.get(icon, overlay);
}
public static Image getForCategory(ModelType type) {
ModelIcon icon = categoryIcon(type);
if (icon == null)
return Icon.FOLDER.get();
return ImageManager.get(icon);
}
public static Image getForCategory(ModelType type, Overlay overlay) {
ModelIcon icon = Images.categoryIcon(type);
if (icon == null)
return null;
if (overlay == null)
return ImageManager.get(icon);
return ImageManager.get(icon, overlay);
}
public static ImageDescriptor descriptor(RootEntity entity) {
if (entity instanceof Process)
return descriptor(((Process) entity).getProcessType());
if (entity instanceof Flow)
return descriptor(((Flow) entity).getFlowType());
return descriptor(ModelType.forModelClass(entity.getClass()));
}
public static ImageDescriptor descriptor(BaseDescriptor descriptor) {
if (descriptor == null || descriptor.getModelType() == null)
return null;
switch (descriptor.getModelType()) {
case PROCESS:
return descriptor(((ProcessDescriptor) descriptor).getProcessType());
case FLOW:
return descriptor(((FlowDescriptor) descriptor).getFlowType());
default:
return descriptor(descriptor.getModelType());
}
}
public static ImageDescriptor descriptor(Category category) {
if (category == null)
return null;
ModelIcon icon = categoryIcon(category.getModelType());
if (icon == null)
return Icon.FOLDER.descriptor();
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(Group group) {
if (group == null)
return null;
ModelIcon icon = icon(group.type);
if (icon == null)
return Icon.FOLDER.descriptor();
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(ModelType type) {
ModelIcon icon = icon(type);
if (icon == null)
return null;
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(FlowType type) {
ModelIcon icon = icon(type);
if (icon == null)
return null;
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(ProcessType type) {
ModelIcon icon = icon(type);
if (icon == null)
return null;
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(GroupType type) {
ModelIcon icon = icon(type);
if (icon == null)
return Icon.FOLDER.descriptor();
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(FileType type) {
FileIcon icon = icon(type);
if (icon == null)
return ImageManager.descriptor(FileIcon.DEFAULT);
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptor(ModelType type, Overlay overlay) {
ModelIcon icon = Images.icon(type);
if (icon == null)
return null;
if (overlay == null)
return ImageManager.descriptor(icon);
return ImageManager.descriptor(icon, overlay);
}
public static ImageDescriptor descriptorForCategory(ModelType type) {
ModelIcon icon = Images.categoryIcon(type);
if (icon == null)
return ImageManager.descriptor(Icon.FOLDER);
return ImageManager.descriptor(icon);
}
public static ImageDescriptor descriptorForCategory(ModelType type, Overlay overlay) {
ModelIcon icon = Images.categoryIcon(type);
if (icon == null)
return ImageManager.descriptor(Icon.FOLDER);
if (overlay == null)
return ImageManager.descriptor(icon);
return ImageManager.descriptor(icon, overlay);
}
public static ImageDescriptor wizard(ModelType type) {
ModelIcon icon = wizardIcon(type);
if (icon == null)
return Icon.NEW_WIZARD.descriptor();
return ImageManager.descriptor(icon);
}
public static ImageDescriptor newDatabase() {
return ImageManager.descriptor(Icon.DATABASE, Overlay.NEW);
}
private static ModelIcon wizardIcon(ModelType type) {
if (type == null)
return null;
switch (type) {
case ACTOR:
return ModelIcon.ACTOR_WIZARD;
case CURRENCY:
return ModelIcon.CURRENCY_WIZARD;
case FLOW:
return ModelIcon.FLOW_WIZARD;
case FLOW_PROPERTY:
return ModelIcon.FLOW_PROPERTY_WIZARD;
case IMPACT_METHOD:
return ModelIcon.IMPACT_METHOD_WIZARD;
case LOCATION:
return ModelIcon.LOCATION_WIZARD;
case PARAMETER:
return ModelIcon.PARAMETER_WIZARD;
case PROCESS:
return ModelIcon.PROCESS_WIZARD;
case PRODUCT_SYSTEM:
return ModelIcon.PRODUCT_SYSTEM_WIZARD;
case PROJECT:
return ModelIcon.PROJECT_WIZARD;
case SOCIAL_INDICATOR:
return ModelIcon.SOCIAL_INDICATOR_WIZARD;
case SOURCE:
return ModelIcon.SOURCE_WIZARD;
case UNIT_GROUP:
return ModelIcon.UNIT_GROUP_WIZARD;
case DQ_SYSTEM:
return ModelIcon.DQ_SYSTEM_WIZARD;
default:
return null;
}
}
private static ModelIcon icon(GroupType type) {
if (type == null)
return null;
switch (type) {
case BACKGROUND_DATA:
return ModelIcon.GROUP_BACKGROUND_DATA;
case INDICATORS:
return ModelIcon.GROUP_INDICATORS;
case MODELS:
return ModelIcon.GROUP_MODELS;
default:
return null;
}
}
static ModelIcon icon(ModelType type) {
if (type == null)
return null;
switch (type) {
case ACTOR:
return ModelIcon.ACTOR;
case FLOW:
return ModelIcon.FLOW;
case FLOW_PROPERTY:
return ModelIcon.FLOW_PROPERTY;
case IMPACT_METHOD:
return ModelIcon.IMPACT_METHOD;
case IMPACT_CATEGORY:
return ModelIcon.IMPACT_CATEGORY;
case PROCESS:
return ModelIcon.PROCESS;
case PRODUCT_SYSTEM:
return ModelIcon.PRODUCT_SYSTEM;
case PROJECT:
return ModelIcon.PROJECT;
case SOURCE:
return ModelIcon.SOURCE;
case SOCIAL_INDICATOR:
return ModelIcon.SOCIAL_INDICATOR;
case LOCATION:
return ModelIcon.LOCATION;
case PARAMETER:
return ModelIcon.PARAMETER;
case CURRENCY:
return ModelIcon.CURRENCY;
case UNIT_GROUP:
case UNIT:
return ModelIcon.UNIT_GROUP;
case DQ_SYSTEM:
return ModelIcon.DQ_SYSTEM;
default:
return null;
}
}
private static ModelIcon icon(FlowType type) {
if (type == null)
return null;
switch (type) {
case ELEMENTARY_FLOW:
return ModelIcon.FLOW_ELEMENTARY;
case PRODUCT_FLOW:
return ModelIcon.FLOW_PRODUCT;
case WASTE_FLOW:
return ModelIcon.FLOW_WASTE;
default:
return null;
}
}
private static ModelIcon icon(ProcessType type) {
if (type == null)
return null;
switch (type) {
case UNIT_PROCESS:
return ModelIcon.PROCESS;
case LCI_RESULT:
return ModelIcon.PROCESS_SYSTEM;
default:
return null;
}
}
private static FileIcon icon(FileType type) {
if (type == null)
return null;
switch (type) {
case CSV:
return FileIcon.CSV;
case EXCEL:
return FileIcon.EXCEL;
case IMAGE:
return FileIcon.IMAGE;
case MARKUP:
return FileIcon.MARKUP;
case PDF:
return FileIcon.PDF;
case POWERPOINT:
return FileIcon.POWERPOINT;
case WORD:
return FileIcon.WORD;
case XML:
return FileIcon.XML;
case ZIP:
return FileIcon.ZIP;
default:
return FileIcon.DEFAULT;
}
}
static ModelIcon categoryIcon(ModelType modelType) {
if (modelType == null)
return null;
switch (modelType) {
case ACTOR:
return ModelIcon.ACTOR_CATEGORY;
case FLOW:
return ModelIcon.FLOW_CATEGORY;
case FLOW_PROPERTY:
return ModelIcon.FLOW_PROPERTY_CATEGORY;
case IMPACT_METHOD:
return ModelIcon.IMPACT_METHOD_CATEGORY;
case PROCESS:
return ModelIcon.PROCESS_CATEGORY;
case PRODUCT_SYSTEM:
return ModelIcon.PRODUCT_SYSTEM_CATEGORY;
case PROJECT:
return ModelIcon.PROJECT_CATEGORY;
case SOURCE:
return ModelIcon.SOURCE_CATEGORY;
case SOCIAL_INDICATOR:
return ModelIcon.SOCIAL_INDICATOR_CATEGORY;
case UNIT_GROUP:
return ModelIcon.UNIT_GROUP_CATEGORY;
case LOCATION:
return ModelIcon.LOCATION_CATEGORY;
case PARAMETER:
return ModelIcon.PARAMETER_CATEGORY;
case CURRENCY:
return ModelIcon.CURRENCY_CATEGORY;
case DQ_SYSTEM:
return ModelIcon.DQ_SYSTEM_CATEGORY;
default:
return null;
}
}
/**
* Returns the shared image descriptor with the given name from the Eclipse
* platform. See ISharedImages for the image names.
*/
public static ImageDescriptor platformDescriptor(String name) {
return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(name);
}
/**
* Returns the shared image with the given name from the Eclipse platform.
* See ISharedImages for the image names.
*/
public static Image platformImage(String name) {
return PlatformUI.getWorkbench().getSharedImages().getImage(name);
}
}