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