]> gerrit.simantics Code Review - simantics/3d.git/blob
09a5addb1225979c42bf0e031a7b4d5be6c5ccc3
[simantics/3d.git] /
1 package org.simantics.proconf.g3d.shapeeditor.dialogs;\r
2 \r
3 import java.util.List;\r
4 \r
5 import org.eclipse.jface.dialogs.Dialog;\r
6 import org.eclipse.jface.dialogs.IDialogConstants;\r
7 import org.eclipse.swt.SWT;\r
8 import org.eclipse.swt.layout.GridData;\r
9 import org.eclipse.swt.widgets.Composite;\r
10 import org.eclipse.swt.widgets.Control;\r
11 import org.eclipse.swt.widgets.Label;\r
12 import org.eclipse.swt.widgets.Shell;\r
13 import org.eclipse.swt.widgets.Tree;\r
14 import org.eclipse.swt.widgets.TreeItem;\r
15 import org.simantics.db.Graph;\r
16 import org.simantics.db.GraphRequestAdapter;\r
17 import org.simantics.db.GraphRequestStatus;\r
18 import org.simantics.db.Resource;\r
19 import org.simantics.db.Session;\r
20 import org.simantics.proconf.g3d.tools.PropertyTree;\r
21 \r
22 public class PropertySelectionDialog extends Dialog {\r
23     String title = null;\r
24     String message = null;\r
25     \r
26     Session session;\r
27     PropertyTree propertyTree;\r
28     Resource[] selectedTypes = null;\r
29     List<Resource> selectedPropertyInstances = null;\r
30     List<Resource> selectedInstances = null;\r
31     \r
32     public PropertySelectionDialog(Shell parentShell, String dialogTitle, String dialogMessage, Session session, List<Resource> selectedResources) {\r
33         super(parentShell);\r
34         this.session = session;\r
35         this.title = dialogTitle;\r
36         this.message = dialogMessage;\r
37         this.selectedInstances = selectedResources;\r
38     }\r
39     \r
40     @Override\r
41     protected void configureShell(Shell newShell) {\r
42         \r
43         super.configureShell(newShell);\r
44         if (title != null)\r
45             newShell.setText(title);\r
46     }\r
47     \r
48     protected Control createDialogArea(Composite parent) {\r
49         Composite composite = (Composite) super.createDialogArea(parent);\r
50         \r
51         Label label = new Label(composite, SWT.WRAP);\r
52         label.setText(message);\r
53         GridData data = new GridData(GridData.GRAB_HORIZONTAL\r
54                 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
55                 | GridData.VERTICAL_ALIGN_CENTER);\r
56         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
57         label.setLayoutData(data);\r
58         label.setFont(parent.getFont());\r
59         \r
60         Tree tree = new Tree(composite,SWT.SINGLE);\r
61         propertyTree = new PropertyTree(tree,session);\r
62 \r
63         GridData data2 = new GridData(GridData.GRAB_HORIZONTAL\r
64                 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
65                 | GridData.VERTICAL_ALIGN_FILL);\r
66         data2.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
67         data2.heightHint = 200;\r
68         tree.setLayoutData(data2);\r
69         tree.setFont(parent.getFont());\r
70         \r
71         tree.showSelection();\r
72         \r
73         applyDialogFont(composite);\r
74         \r
75         //propertyTree.setProperties(selectionAdapter.getCurrentSelection());\r
76         propertyTree.setProperties(selectedInstances);\r
77         return composite;\r
78     }\r
79     \r
80     @Override\r
81     public boolean close() {\r
82         TreeItem selected[] = propertyTree.getTree().getSelection();\r
83         if (selected.length == 0) {\r
84             selectedTypes = null;\r
85         } else {\r
86             selectedTypes = new Resource[selected.length];\r
87             for (int i = 0; i < selected.length; i++) {\r
88                 selectedTypes[i] = (Resource)selected[i].getData();\r
89             }\r
90         }\r
91         //final ArrayList<Resource> instances = new ArrayList<Resource>();\r
92 //        for (Resource rs : selectionAdapter.getCurrentSelection().getSelectionList()) {\r
93 //            instances.add(rs);\r
94 //        }\r
95 \r
96         \r
97         session.syncRead(new GraphRequestAdapter() {\r
98                 @Override\r
99                 public GraphRequestStatus perform(Graph g) throws Exception {\r
100                         selectedPropertyInstances = propertyTree.findPropertyInstances(g,selectedInstances);\r
101                         return GraphRequestStatus.transactionComplete();\r
102                 }\r
103         });\r
104 \r
105         return super.close();\r
106     }\r
107     \r
108     public List<Resource> getSelectedPropertyInstances() {\r
109         return selectedPropertyInstances;\r
110     }\r
111 \r
112 }