]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/LiftPropertiesDialog.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / componentTypeEditor / LiftPropertiesDialog.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.ui.componentTypeEditor;\r
13 \r
14 import java.util.Map;\r
15 \r
16 import org.eclipse.jface.dialogs.IDialogSettings;\r
17 import org.eclipse.jface.layout.GridDataFactory;\r
18 import org.eclipse.jface.layout.GridLayoutFactory;\r
19 import org.eclipse.jface.resource.ImageDescriptor;\r
20 import org.eclipse.swt.SWT;\r
21 import org.eclipse.swt.events.SelectionEvent;\r
22 import org.eclipse.swt.events.SelectionListener;\r
23 import org.eclipse.swt.widgets.Button;\r
24 import org.eclipse.swt.widgets.Composite;\r
25 import org.eclipse.swt.widgets.Control;\r
26 import org.eclipse.swt.widgets.Shell;\r
27 import org.simantics.db.Resource;\r
28 import org.simantics.modeling.ui.componentTypeEditor.LiftPropertiesDialog.LiftedProperty;\r
29 import org.simantics.scl.runtime.tuple.Tuple3;\r
30 import org.simantics.ui.workbench.dialogs.ResourceSelectionDialog3;\r
31 import org.simantics.utils.datastructures.Pair;\r
32 \r
33 public class LiftPropertiesDialog extends ResourceSelectionDialog3<LiftedProperty> {\r
34 \r
35         private boolean mapProperties = false;\r
36         private Button checkbox;\r
37 \r
38         public static class LiftedProperty extends Tuple3 {\r
39 \r
40                 public LiftedProperty(Resource component, Resource componentType, Resource predicate) {\r
41                         super(component, componentType, predicate);\r
42                 }\r
43                 \r
44                 public Resource getComponent() {\r
45                         return (Resource)get(0);\r
46                 }\r
47 \r
48                 public Resource getComponentType() {\r
49                         return (Resource)get(1);\r
50                 }\r
51 \r
52                 public Resource getPredicate() {\r
53                         return (Resource)get(2);\r
54                 }\r
55 \r
56         }\r
57         \r
58         public LiftPropertiesDialog(Shell shell,\r
59                         Map<LiftedProperty, Pair<String, ImageDescriptor>> parameter, String title) {\r
60                 super(shell, parameter, title);\r
61         }\r
62 \r
63         @Override\r
64         protected IDialogSettings getBaseDialogSettings() {\r
65                 return null;\r
66         }\r
67 \r
68         @Override\r
69         protected Control createExtendedContentArea(Composite parent) {\r
70                 Composite c = new Composite(parent, SWT.NONE);\r
71                 GridDataFactory.fillDefaults().grab(true, false).applyTo(c);\r
72                 GridLayoutFactory.swtDefaults().numColumns(2).applyTo(c);\r
73 //              Label l = new Label(c, SWT.NONE); \r
74 //              l.setText("Map lifted properties into interface");\r
75 //              GridDataFactory.fillDefaults().grab(false, false).applyTo(l);\r
76                 checkbox = new Button(c, SWT.CHECK);\r
77                 checkbox.setText("Map lifted properties into interface");\r
78                 checkbox.addSelectionListener(new SelectionListener() {\r
79                         \r
80                         @Override\r
81                         public void widgetSelected(SelectionEvent e) {\r
82                                 widgetDefaultSelected(e);\r
83                         }\r
84                         \r
85                         @Override\r
86                         public void widgetDefaultSelected(SelectionEvent e) {\r
87                                 mapProperties = checkbox.getSelection();\r
88                         }\r
89                 });\r
90                 GridDataFactory.fillDefaults().grab(true, false).applyTo(checkbox);\r
91                 return super.createExtendedContentArea(parent);\r
92         }\r
93 \r
94         @Override\r
95         public void create() {\r
96                 super.create();\r
97                 checkbox.setFocus();\r
98         }\r
99 \r
100         public boolean getMapProperties() {\r
101                 return mapProperties;\r
102         }\r
103 \r
104 }