1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.simantics.browsing.ui.BuiltinKeys;
16 import org.simantics.browsing.ui.BuiltinKeys.ImagerKey;
17 import org.simantics.browsing.ui.DataSource;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
20 import org.simantics.browsing.ui.common.ColumnKeys;
21 import org.simantics.browsing.ui.common.imagers.ContainerImager;
22 import org.simantics.browsing.ui.common.property.IArrayProperty;
23 import org.simantics.browsing.ui.content.Imager;
24 import org.simantics.browsing.ui.content.ImagerFactory;
25 import org.simantics.db.ReadGraph;
26 import org.simantics.db.Resource;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.ui.icons.ImageUtil;
29 import org.simantics.utils.ui.BundleUtils;
32 * A basic imager factory with support for both Resource and IArrayProperty.
34 * @author Tuukka Lehtonen
36 public class ArrayPropertyImagerFactory implements ImagerFactory {
38 @SuppressWarnings("unchecked")
40 public Imager create(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) {
41 assert updater != null;
42 assert context != null;
44 @SuppressWarnings("rawtypes")
45 final ContainerImager result = new ContainerImager();
46 final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
50 Object o = context.getConstant(BuiltinKeys.INPUT);
51 if (o instanceof IArrayProperty) {
52 IArrayProperty prop = (IArrayProperty) o;
54 if (prop.getRange().size() > 1) {
55 // Only show the segment image for non-single-item slices of the
56 // property root node. Otherwise just use the image resolved
57 // through normal means.
59 result.setImage(ColumnKeys.PROPERTY,
60 BundleUtils.getImageDescriptorFromPlugin(
61 "org.simantics.browsing.ui.common", "/icons/segment_edit.gif"));
65 // No image for single-item slices of the property.
70 final Resource inputResource = (Resource) context.getAdapter(Resource.class);
71 if (inputResource == null)
74 source.schedule(graph -> {
75 ImageDescriptor descriptor;
77 descriptor = ImageUtil.adaptImageDescriptor(graph, inputResource);
78 result.setImage(ColumnKeys.PROPERTY, descriptor);
79 updater.scheduleReplace(context, key, result);
80 } catch (DatabaseException e) {