package org.simantics.proconf.g3d.shapeeditor.dialogs; import java.util.List; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.simantics.db.Graph; import org.simantics.db.GraphRequestAdapter; import org.simantics.db.GraphRequestStatus; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.proconf.g3d.tools.PropertyTree; public class PropertySelectionDialog extends Dialog { String title = null; String message = null; Session session; PropertyTree propertyTree; Resource[] selectedTypes = null; List selectedPropertyInstances = null; List selectedInstances = null; public PropertySelectionDialog(Shell parentShell, String dialogTitle, String dialogMessage, Session session, List selectedResources) { super(parentShell); this.session = session; this.title = dialogTitle; this.message = dialogMessage; this.selectedInstances = selectedResources; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); if (title != null) newShell.setText(title); } protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Label label = new Label(composite, SWT.WRAP); label.setText(message); GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER); data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); label.setLayoutData(data); label.setFont(parent.getFont()); Tree tree = new Tree(composite,SWT.SINGLE); propertyTree = new PropertyTree(tree,session); GridData data2 = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); data2.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); data2.heightHint = 200; tree.setLayoutData(data2); tree.setFont(parent.getFont()); tree.showSelection(); applyDialogFont(composite); //propertyTree.setProperties(selectionAdapter.getCurrentSelection()); propertyTree.setProperties(selectedInstances); return composite; } @Override public boolean close() { TreeItem selected[] = propertyTree.getTree().getSelection(); if (selected.length == 0) { selectedTypes = null; } else { selectedTypes = new Resource[selected.length]; for (int i = 0; i < selected.length; i++) { selectedTypes[i] = (Resource)selected[i].getData(); } } //final ArrayList instances = new ArrayList(); // for (Resource rs : selectionAdapter.getCurrentSelection().getSelectionList()) { // instances.add(rs); // } session.syncRead(new GraphRequestAdapter() { @Override public GraphRequestStatus perform(Graph g) throws Exception { selectedPropertyInstances = propertyTree.findPropertyInstances(g,selectedInstances); return GraphRequestStatus.transactionComplete(); } }); return super.close(); } public List getSelectedPropertyInstances() { return selectedPropertyInstances; } }