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.Display;
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;
36 * A dialog, which contains a single graph explorer composite
38 * Override getBrowseContexts() to specify the graph explorer contents.
42 public abstract class GraphExplorerDialog2 extends SimanticsDialog {
44 abstract public Set<String> getBrowseContexts();
46 private final IWorkbenchSite site;
47 private final DataContainer<Object[]> result = new DataContainer<Object[]>();
49 private GraphExplorerComposite outputExplorer;
51 public GraphExplorerDialog2(IWorkbenchSite site, String title) {
52 super(Display.getCurrent().getActiveShell(), title);
56 Column[] getColumns() {
57 return new Column[] { new Column(ColumnKeys.SINGLE, Align.RIGHT, 180, "single", true, 1) };
61 protected SessionContextInputSource getInputSource() {
62 return GraphInputSources.projectSource();
66 protected boolean isResizable() {
71 protected void createControls(Composite body, ISessionContext context, WidgetSupport support) {
73 outputExplorer = new GraphExplorerComposite(
74 ArrayMap.keys("displaySelectors", "displayFilter").values(false, false), site, body, support,
76 outputExplorer.setBrowseContexts(getBrowseContexts());
77 outputExplorer.setColumnsVisible(false);
78 outputExplorer.setColumns(getColumns());
79 outputExplorer.finish();
81 outputExplorer.setBackground(body.getDisplay().getSystemColor(SWT.COLOR_GREEN));
83 GridDataFactory.fillDefaults().grab(true, true).span(2, 1).minSize(300, 400).applyTo(outputExplorer);
88 protected void buttonPressed(int buttonId) {
89 if (buttonId == Window.OK) {
91 Tree tree = (Tree) outputExplorer.getExplorerControl();
93 TreeItem[] selectedItems = tree.getSelection();
94 Object[] res = new Object[selectedItems.length];
95 for (int i = 0; i < selectedItems.length; i++) {
96 res[i] = selectedItems[i].getData();
100 super.buttonPressed(buttonId);
104 public Object[] getSelection() {
108 public GraphExplorerComposite getGraphExplorerComposite() {
109 return outputExplorer;