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.browsing.ui.swt;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Display;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.IWorkbenchSite;
20 import org.simantics.Simantics;
21 import org.simantics.browsing.ui.swt.stubs.BrowsingResource;
22 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
23 import org.simantics.databoard.Bindings;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.management.ISessionContext;
28 import org.simantics.db.request.Read;
31 * @author Tuukka Lehtonen
33 public class ModelledDialog implements ModelledAction {
35 public class DialogImpl extends Dialog {
37 private final WidgetSupport widgetSupport;
38 private Runnable finishAction;
40 private final String title;
42 public DialogImpl(Shell shell, WidgetSupport support, String title) {
45 this.widgetSupport = support;
49 protected void configureShell(Shell shell) {
50 super.configureShell(shell);
57 protected boolean isResizable() {
62 protected void okPressed() {
63 if(finishAction != null) finishAction.run();
67 protected Control createDialogArea(Composite parent) {
69 Composite composite = (Composite)super.createDialogArea(parent);
73 ModelledControl modelledControl = Simantics.getSession().syncRequest(new Read<ModelledControl>() {
75 public ModelledControl perform(ReadGraph graph) throws DatabaseException {
76 BrowsingResource BRO = BrowsingResource.getInstance(graph);
77 Resource controlResource = graph.getPossibleObject(configuration, BRO.Dialog_Control);
78 return graph.adapt(controlResource, ModelledControl.class);
82 ModelledAction finishAction = Simantics.getSession().syncRequest(new Read<ModelledAction>() {
84 public ModelledAction perform(ReadGraph graph) throws DatabaseException {
85 BrowsingResource BRO = BrowsingResource.getInstance(graph);
86 Resource actionResource = graph.getPossibleObject(configuration, BRO.Dialog_FinishAction);
87 return graph.adapt(actionResource, ModelledAction.class);
91 this.finishAction = finishAction.create(null, null, widgetSupport);
93 return modelledControl.create(composite, null, null, widgetSupport);
95 } catch (DatabaseException e) {
106 protected Control createContents(Composite parent) {
107 return super.createContents(parent);
113 final Resource configuration;
115 public ModelledDialog(Resource configuration) {
116 this.configuration = configuration;
120 public Runnable create(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException {
122 final String title = Simantics.getSession().syncRequest(new Read<String>() {
125 public String perform(ReadGraph graph) throws DatabaseException {
126 BrowsingResource br = BrowsingResource.getInstance(graph);
127 return graph.getPossibleRelatedValue(configuration, br.Dialog_Title, Bindings.STRING);
132 return new Runnable() {
137 DialogImpl dialog = new DialogImpl(Display.getCurrent().getActiveShell(), support, title);