1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
16 import org.eclipse.jface.layout.GridDataFactory;
17 import org.eclipse.jface.window.Window;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.swt.widgets.Tree;
22 import org.eclipse.swt.widgets.TreeItem;
23 import org.eclipse.ui.IWorkbenchSite;
24 import org.simantics.browsing.ui.Column;
25 import org.simantics.browsing.ui.Column.Align;
26 import org.simantics.browsing.ui.common.ColumnKeys;
27 import org.simantics.browsing.ui.graph.impl.GraphInputSources;
28 import org.simantics.browsing.ui.graph.impl.SessionContextInputSource;
29 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
30 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
31 import org.simantics.db.management.ISessionContext;
32 import org.simantics.utils.DataContainer;
33 import org.simantics.utils.datastructures.ArrayMap;
34 import org.simantics.utils.datastructures.UnaryFunction;
38 * A dialog, which contains a single graph explorer composite
40 * Override getBrowseContexts() to specify the graph explorer contents.
44 public abstract class GraphExplorerDialog implements UnaryFunction<SimanticsDialog, Shell> {
46 abstract public Set<String> getBrowseContexts();
48 Column[] getColumns() {
49 return new Column[] { new Column(ColumnKeys.SINGLE, Align.RIGHT, 180, "single", true, 1) };
52 protected SessionContextInputSource getInputSource() {
53 return GraphInputSources.projectSource();
56 private final String title;
57 private final IWorkbenchSite site;
58 private final DataContainer<Object[]> result = new DataContainer<Object[]>();
60 public GraphExplorerDialog(IWorkbenchSite site, String title) {
65 class Dialog extends SimanticsDialog {
67 private GraphExplorerComposite outputExplorer;
69 public Dialog(Shell shell, String title) {
74 protected boolean isResizable() {
79 protected SessionContextInputSource getInputSource() {
80 return GraphExplorerDialog.this.getInputSource();
84 protected void createControls(Composite body, ISessionContext context, WidgetSupport support) {
86 outputExplorer = new GraphExplorerComposite(ArrayMap.keys("displaySelectors", "displayFilter").values(false, false), site, body, support, SWT.BORDER);
87 outputExplorer.setBrowseContexts(getBrowseContexts());
88 outputExplorer.setColumnsVisible(false);
89 outputExplorer.setColumns(getColumns());
90 outputExplorer.finish();
92 outputExplorer.setBackground(body.getDisplay().getSystemColor(SWT.COLOR_GREEN));
94 GridDataFactory.fillDefaults().grab(true, true).span(2, 1).minSize(300, 400).applyTo(outputExplorer);
99 protected void buttonPressed(int buttonId) {
101 if(buttonId == Window.OK) {
103 Tree tree = (Tree)outputExplorer.getExplorerControl();
105 TreeItem[] selectedItems = tree.getSelection();
106 Object[] res = new Object[selectedItems.length];
107 for(int i=0;i<selectedItems.length;i++) {
108 res[i] = selectedItems[i].getData();
114 super.buttonPressed(buttonId);
119 protected Object getSelection() {
126 public SimanticsDialog call(Shell shell) {
127 return new Dialog(shell, title);
131 public Object[] getSelection() {