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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.shapeeditor.dialogs;
\r
13 import java.util.List;
\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
32 public class PropertySelectionDialog extends Dialog {
\r
33 String title = null;
\r
34 String message = null;
\r
37 PropertyTree propertyTree;
\r
38 Resource[] selectedTypes = null;
\r
39 List<Resource> selectedPropertyInstances = null;
\r
40 List<Resource> selectedInstances = null;
\r
42 public PropertySelectionDialog(Shell parentShell, String dialogTitle, String dialogMessage, Session session, List<Resource> selectedResources) {
\r
44 this.session = session;
\r
45 this.title = dialogTitle;
\r
46 this.message = dialogMessage;
\r
47 this.selectedInstances = selectedResources;
\r
51 protected void configureShell(Shell newShell) {
\r
53 super.configureShell(newShell);
\r
55 newShell.setText(title);
\r
58 protected Control createDialogArea(Composite parent) {
\r
59 Composite composite = (Composite) super.createDialogArea(parent);
\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
70 Tree tree = new Tree(composite,SWT.SINGLE);
\r
71 propertyTree = new PropertyTree(tree,session);
\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
81 tree.showSelection();
\r
83 applyDialogFont(composite);
\r
85 //propertyTree.setProperties(selectionAdapter.getCurrentSelection());
\r
86 propertyTree.setProperties(selectedInstances);
\r
91 public boolean close() {
\r
92 TreeItem selected[] = propertyTree.getTree().getSelection();
\r
93 if (selected.length == 0) {
\r
94 selectedTypes = null;
\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
101 //final ArrayList<Resource> instances = new ArrayList<Resource>();
\r
102 // for (Resource rs : selectionAdapter.getCurrentSelection().getSelectionList()) {
\r
103 // instances.add(rs);
\r
107 session.syncRead(new GraphRequestAdapter() {
\r
109 public GraphRequestStatus perform(Graph g) throws Exception {
\r
110 selectedPropertyInstances = propertyTree.findPropertyInstances(g,selectedInstances);
\r
111 return GraphRequestStatus.transactionComplete();
\r
115 return super.close();
\r
118 public List<Resource> getSelectedPropertyInstances() {
\r
119 return selectedPropertyInstances;
\r