1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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.ui.colors;
14 import org.eclipse.swt.graphics.RGB;
15 import org.simantics.databoard.Bindings;
16 import org.simantics.databoard.binding.Binding;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.adaption.ResourceAdapter;
20 import org.simantics.db.procedure.AsyncProcedure;
22 public class RGBAdapter implements ResourceAdapter<RGB> {
24 public static class RGBDouble {
30 public static final Binding BINDING = Bindings.getBindingUnchecked(RGBDouble.class);
33 public void adapt(AsyncReadGraph g, Resource source, Resource r, final AsyncProcedure<RGB> procedure) {
34 g.forValue(r, BINDING, new AsyncProcedure<RGBDouble>() {
36 public void execute(AsyncReadGraph graph, RGBDouble result) {
37 procedure.execute(graph,
39 (int)(result.red*255.0),
40 (int)(result.green*255.0),
41 (int)(result.blue*255.0)
47 public void exception(AsyncReadGraph graph, Throwable throwable) {
48 procedure.exception(graph, throwable);