1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.swt;
\r
14 import org.eclipse.jface.dialogs.Dialog;
\r
15 import org.eclipse.swt.widgets.Composite;
\r
16 import org.eclipse.swt.widgets.Control;
\r
17 import org.eclipse.swt.widgets.Display;
\r
18 import org.eclipse.swt.widgets.Shell;
\r
19 import org.eclipse.ui.IWorkbenchSite;
\r
20 import org.simantics.Simantics;
\r
21 import org.simantics.browsing.ui.swt.stubs.BrowsingResource;
\r
22 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
23 import org.simantics.databoard.Bindings;
\r
24 import org.simantics.db.ReadGraph;
\r
25 import org.simantics.db.Resource;
\r
26 import org.simantics.db.exception.DatabaseException;
\r
27 import org.simantics.db.management.ISessionContext;
\r
28 import org.simantics.db.request.Read;
\r
31 * @author Tuukka Lehtonen
\r
33 public class ModelledDialog implements ModelledAction {
\r
35 public class DialogImpl extends Dialog {
\r
37 private final WidgetSupport widgetSupport;
\r
38 private Runnable finishAction;
\r
40 private final String title;
\r
42 public DialogImpl(Shell shell, WidgetSupport support, String title) {
\r
45 this.widgetSupport = support;
\r
49 protected void configureShell(Shell shell) {
\r
50 super.configureShell(shell);
\r
51 if (title != null) {
\r
52 shell.setText(title);
\r
57 protected boolean isResizable() {
\r
62 protected void okPressed() {
\r
63 if(finishAction != null) finishAction.run();
\r
67 protected Control createDialogArea(Composite parent) {
\r
69 Composite composite = (Composite)super.createDialogArea(parent);
\r
73 ModelledControl modelledControl = Simantics.getSession().syncRequest(new Read<ModelledControl>() {
\r
75 public ModelledControl perform(ReadGraph graph) throws DatabaseException {
\r
76 BrowsingResource BRO = BrowsingResource.getInstance(graph);
\r
77 Resource controlResource = graph.getPossibleObject(configuration, BRO.Dialog_Control);
\r
78 return graph.adapt(controlResource, ModelledControl.class);
\r
82 ModelledAction finishAction = Simantics.getSession().syncRequest(new Read<ModelledAction>() {
\r
84 public ModelledAction perform(ReadGraph graph) throws DatabaseException {
\r
85 BrowsingResource BRO = BrowsingResource.getInstance(graph);
\r
86 Resource actionResource = graph.getPossibleObject(configuration, BRO.Dialog_FinishAction);
\r
87 return graph.adapt(actionResource, ModelledAction.class);
\r
91 this.finishAction = finishAction.create(null, null, widgetSupport);
\r
93 return modelledControl.create(composite, null, null, widgetSupport);
\r
95 } catch (DatabaseException e) {
\r
97 e.printStackTrace();
\r
106 protected Control createContents(Composite parent) {
\r
107 return super.createContents(parent);
\r
113 final Resource configuration;
\r
115 public ModelledDialog(Resource configuration) {
\r
116 this.configuration = configuration;
\r
120 public Runnable create(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException {
\r
122 final String title = Simantics.getSession().syncRequest(new Read<String>() {
\r
125 public String perform(ReadGraph graph) throws DatabaseException {
\r
126 BrowsingResource br = BrowsingResource.getInstance(graph);
\r
127 return graph.getPossibleRelatedValue(configuration, br.Dialog_Title, Bindings.STRING);
\r
132 return new Runnable() {
\r
135 public void run() {
\r
137 DialogImpl dialog = new DialogImpl(Display.getCurrent().getActiveShell(), support, title);
\r