1 package org.simantics.proconf.g3d.shapeeditor.dialogs;
\r
3 import java.util.List;
\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
22 public class PropertySelectionDialog extends Dialog {
\r
23 String title = null;
\r
24 String message = null;
\r
27 PropertyTree propertyTree;
\r
28 Resource[] selectedTypes = null;
\r
29 List<Resource> selectedPropertyInstances = null;
\r
30 List<Resource> selectedInstances = null;
\r
32 public PropertySelectionDialog(Shell parentShell, String dialogTitle, String dialogMessage, Session session, List<Resource> selectedResources) {
\r
34 this.session = session;
\r
35 this.title = dialogTitle;
\r
36 this.message = dialogMessage;
\r
37 this.selectedInstances = selectedResources;
\r
41 protected void configureShell(Shell newShell) {
\r
43 super.configureShell(newShell);
\r
45 newShell.setText(title);
\r
48 protected Control createDialogArea(Composite parent) {
\r
49 Composite composite = (Composite) super.createDialogArea(parent);
\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
60 Tree tree = new Tree(composite,SWT.SINGLE);
\r
61 propertyTree = new PropertyTree(tree,session);
\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
71 tree.showSelection();
\r
73 applyDialogFont(composite);
\r
75 //propertyTree.setProperties(selectionAdapter.getCurrentSelection());
\r
76 propertyTree.setProperties(selectedInstances);
\r
81 public boolean close() {
\r
82 TreeItem selected[] = propertyTree.getTree().getSelection();
\r
83 if (selected.length == 0) {
\r
84 selectedTypes = null;
\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
91 //final ArrayList<Resource> instances = new ArrayList<Resource>();
\r
92 // for (Resource rs : selectionAdapter.getCurrentSelection().getSelectionList()) {
\r
93 // instances.add(rs);
\r
97 session.syncRead(new GraphRequestAdapter() {
\r
99 public GraphRequestStatus perform(Graph g) throws Exception {
\r
100 selectedPropertyInstances = propertyTree.findPropertyInstances(g,selectedInstances);
\r
101 return GraphRequestStatus.transactionComplete();
\r
105 return super.close();
\r
108 public List<Resource> getSelectedPropertyInstances() {
\r
109 return selectedPropertyInstances;
\r