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