1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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.modeling.template2d.ui.actions;
14 import java.awt.Color;
16 import org.eclipse.swt.graphics.RGB;
17 import org.eclipse.swt.widgets.ColorDialog;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.PlatformUI;
21 import org.simantics.db.Resource;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.layer0.adapter.ActionFactory;
26 import org.simantics.diagram.G2DUtils;
27 import org.simantics.diagram.stubs.G2DResource;
28 import org.simantics.modeling.template2d.ontology.Template2dResource;
29 import org.simantics.ui.SimanticsUI;
31 public class SetBorderColor implements ActionFactory {
34 public Runnable create(Object target) {
35 if(!(target instanceof Resource))
37 final Resource parent = (Resource)target;
39 return new Runnable() {
42 // PlatformUI.getWorkbench().getDisplay().getActiveShell()
43 IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); //.getDisplay().getActiveShell()
44 //Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
48 Shell shell = win.getShell();
52 ColorDialog dia = new ColorDialog(shell); //.get Display.getDefault().getActiveShell()
53 final RGB rgb = dia.open();
58 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
60 public void perform(WriteGraph g) throws DatabaseException {
63 // Layer0 L0 = Layer0.getInstance(g);
64 Template2dResource TEMPLATE2D = Template2dResource.getInstance(g);
65 G2DResource G2D = G2DResource.getInstance(g);
67 if (!g.isInstanceOf(parent, TEMPLATE2D.Border))
70 Resource oldColor = g.getPossibleObject(parent, G2D.HasColor);
71 Resource color = G2DUtils.createColor(g, new Color(rgb.red, rgb.green, rgb.blue));
74 g.claim(parent, G2D.HasColor, color);