-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.eclipse.jface.action.IMenuManager;\r
-import org.eclipse.jface.viewers.IPostSelectionProvider;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionChangedListener;\r
-import org.eclipse.jface.viewers.SelectionChangedEvent;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.ui.IWorkbenchSite;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.GraphExplorer;\r
-import org.simantics.browsing.ui.swt.stubs.BrowsingResource;\r
-import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
-import org.simantics.browsing.ui.swt.widgets.ModelBrowser;\r
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.request.Read;\r
-\r
-public class ModelledGraphExplorerComposite implements ModelledControl {\r
-\r
- final private Resource configuration;\r
- \r
- public ModelledGraphExplorerComposite(Resource configuration) {\r
- this.configuration = configuration;\r
- }\r
- \r
- @Override\r
- public Composite create(Composite parent, IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException {\r
-\r
- int style = Simantics.getSession().syncRequest(new Read<Integer>() {\r
-\r
- @Override\r
- public Integer perform(ReadGraph graph) throws DatabaseException {\r
- int style = SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI;\r
- BrowsingResource br = BrowsingResource.getInstance(graph);\r
- Boolean check = graph.getPossibleRelatedValue(configuration, br.GraphExplorerComposite_Check, Bindings.BOOLEAN);\r
- if(check != null && check) style |= SWT.CHECK;\r
- return style;\r
- \r
- }\r
- \r
- });\r
- \r
- Map<String, Object> args = Simantics.getSession().syncRequest(new Read<Map<String, Object>>() {\r
-\r
- @Override\r
- public Map<String, Object> perform(ReadGraph graph) throws DatabaseException {\r
- \r
- Map<String, Object> args = new HashMap<String, Object>();\r
- args.put("displaySelectors", Boolean.FALSE);\r
- args.put("displayFilter", Boolean.FALSE);\r
- \r
- BrowsingResource br = BrowsingResource.getInstance(graph);\r
- Boolean displayFilter = graph.getPossibleRelatedValue(configuration, br.GraphExplorerComposite_DisplayFilter, Bindings.BOOLEAN);\r
- if(displayFilter != null) args.put("displayFilter", displayFilter);\r
- \r
- return args;\r
- \r
- }\r
- \r
- });\r
-\r
- String browseContextURI = Simantics.getSession().syncRequest(new Read<String>() {\r
-\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- BrowsingResource br = BrowsingResource.getInstance(graph);\r
- Resource browseContext = graph.getSingleObject(configuration, br.GraphExplorerComposite_BrowseContext);\r
- return graph.getURI(browseContext);\r
- }\r
- \r
- });\r
- \r
- final GraphExplorerComposite explorer = new ModelBrowser(Collections.singleton(browseContextURI), args, site, parent, support, style) {\r
- @Override\r
- protected void addListeners(GraphExplorer explorer, IMenuManager menuManager) {\r
- // No mouse/key listeners in this explorer.\r
- // Prevents unwanted contributions from interfering\r
- // with how the control works.\r
- }\r
- };\r
- \r
- GridData gridData = Simantics.getSession().syncRequest(new Read<GridData>() {\r
-\r
- @Override\r
- public GridData perform(ReadGraph graph) throws DatabaseException {\r
- BrowsingResource br = BrowsingResource.getInstance(graph);\r
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); \r
- Integer span = graph.getPossibleRelatedValue(configuration, br.Control_HorizontalSpan, Bindings.INTEGER);\r
- if(span != null) {\r
- data.horizontalSpan = span;\r
- }\r
- Integer preferredWidth = graph.getPossibleRelatedValue(configuration, br.Control_PreferredWidth, Bindings.INTEGER);\r
- data.widthHint = preferredWidth != null ? preferredWidth : SWT.DEFAULT;\r
- Integer preferredHeight = graph.getPossibleRelatedValue(configuration, br.Control_PreferredHeight, Bindings.INTEGER);\r
- data.heightHint = preferredHeight != null ? preferredHeight : SWT.DEFAULT;\r
- return data;\r
- }\r
-\r
- });\r
- \r
- explorer.setLayoutData(gridData);\r
- \r
-// explorer.setBrowseContexts(Collections.singleton(browseContextURI));\r
- \r
- explorer.setInputSource(new InputSourceImpl<Object>() {\r
-\r
- @Override\r
- public Object get(ISessionContext ctx, Object selection) {\r
- new Exception(""+selection).printStackTrace();\r
- return selection;\r
- }\r
- });\r
- \r
- Listener selectionListener = Simantics.getSession().syncRequest(new Read<Listener>() {\r
-\r
- @Override\r
- public Listener perform(ReadGraph graph) throws DatabaseException {\r
- BrowsingResource br = BrowsingResource.getInstance(graph);\r
- Resource listener = graph.getPossibleObject(configuration, br.GraphExplorerComposite_SelectionListener);\r
- if(listener == null) return null;\r
- return graph.adapt(listener, Listener.class);\r
- }\r
- \r
- });\r
- \r
- if(selectionListener != null) explorer.addListenerToControl(SWT.Selection, selectionListener);\r
- \r
- final String selectionParameter = Simantics.getSession().syncRequest(new Read<String>() {\r
-\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- BrowsingResource br = BrowsingResource.getInstance(graph);\r
- Resource parameter = graph.getPossibleObject(configuration, br.GraphExplorerComposite_SelectionParameter);\r
- if(parameter == null) return null;\r
- return graph.getPossibleURI(parameter);\r
- }\r
- \r
- });\r
- \r
- \r
- if(selectionParameter != null) {\r
- IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getExplorer().getAdapter(IPostSelectionProvider.class);\r
- selectionProvider.addPostSelectionChangedListener(new ISelectionChangedListener() {\r
- \r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
- ISelection selection = event.getSelection();\r
- support.setParameter(selectionParameter, selection);\r
- }\r
- \r
- });\r
- }\r
- \r
- explorer.finish();\r
- \r
- return explorer;\r
- \r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.swt;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.GraphExplorer;
+import org.simantics.browsing.ui.swt.stubs.BrowsingResource;
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
+import org.simantics.browsing.ui.swt.widgets.ModelBrowser;
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.request.Read;
+
+public class ModelledGraphExplorerComposite implements ModelledControl {
+
+ final private Resource configuration;
+
+ public ModelledGraphExplorerComposite(Resource configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public Composite create(Composite parent, IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException {
+
+ int style = Simantics.getSession().syncRequest(new Read<Integer>() {
+
+ @Override
+ public Integer perform(ReadGraph graph) throws DatabaseException {
+ int style = SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI;
+ BrowsingResource br = BrowsingResource.getInstance(graph);
+ Boolean check = graph.getPossibleRelatedValue(configuration, br.GraphExplorerComposite_Check, Bindings.BOOLEAN);
+ if(check != null && check) style |= SWT.CHECK;
+ return style;
+
+ }
+
+ });
+
+ Map<String, Object> args = Simantics.getSession().syncRequest(new Read<Map<String, Object>>() {
+
+ @Override
+ public Map<String, Object> perform(ReadGraph graph) throws DatabaseException {
+
+ Map<String, Object> args = new HashMap<String, Object>();
+ args.put("displaySelectors", Boolean.FALSE);
+ args.put("displayFilter", Boolean.FALSE);
+
+ BrowsingResource br = BrowsingResource.getInstance(graph);
+ Boolean displayFilter = graph.getPossibleRelatedValue(configuration, br.GraphExplorerComposite_DisplayFilter, Bindings.BOOLEAN);
+ if(displayFilter != null) args.put("displayFilter", displayFilter);
+
+ return args;
+
+ }
+
+ });
+
+ String browseContextURI = Simantics.getSession().syncRequest(new Read<String>() {
+
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ BrowsingResource br = BrowsingResource.getInstance(graph);
+ Resource browseContext = graph.getSingleObject(configuration, br.GraphExplorerComposite_BrowseContext);
+ return graph.getURI(browseContext);
+ }
+
+ });
+
+ final GraphExplorerComposite explorer = new ModelBrowser(Collections.singleton(browseContextURI), args, site, parent, support, style) {
+ @Override
+ protected void addListeners(GraphExplorer explorer, IMenuManager menuManager) {
+ // No mouse/key listeners in this explorer.
+ // Prevents unwanted contributions from interfering
+ // with how the control works.
+ }
+ };
+
+ GridData gridData = Simantics.getSession().syncRequest(new Read<GridData>() {
+
+ @Override
+ public GridData perform(ReadGraph graph) throws DatabaseException {
+ BrowsingResource br = BrowsingResource.getInstance(graph);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ Integer span = graph.getPossibleRelatedValue(configuration, br.Control_HorizontalSpan, Bindings.INTEGER);
+ if(span != null) {
+ data.horizontalSpan = span;
+ }
+ Integer preferredWidth = graph.getPossibleRelatedValue(configuration, br.Control_PreferredWidth, Bindings.INTEGER);
+ data.widthHint = preferredWidth != null ? preferredWidth : SWT.DEFAULT;
+ Integer preferredHeight = graph.getPossibleRelatedValue(configuration, br.Control_PreferredHeight, Bindings.INTEGER);
+ data.heightHint = preferredHeight != null ? preferredHeight : SWT.DEFAULT;
+ return data;
+ }
+
+ });
+
+ explorer.setLayoutData(gridData);
+
+// explorer.setBrowseContexts(Collections.singleton(browseContextURI));
+
+ explorer.setInputSource(new InputSourceImpl<Object>() {
+
+ @Override
+ public Object get(ISessionContext ctx, Object selection) {
+ new Exception(""+selection).printStackTrace();
+ return selection;
+ }
+ });
+
+ Listener selectionListener = Simantics.getSession().syncRequest(new Read<Listener>() {
+
+ @Override
+ public Listener perform(ReadGraph graph) throws DatabaseException {
+ BrowsingResource br = BrowsingResource.getInstance(graph);
+ Resource listener = graph.getPossibleObject(configuration, br.GraphExplorerComposite_SelectionListener);
+ if(listener == null) return null;
+ return graph.adapt(listener, Listener.class);
+ }
+
+ });
+
+ if(selectionListener != null) explorer.addListenerToControl(SWT.Selection, selectionListener);
+
+ final String selectionParameter = Simantics.getSession().syncRequest(new Read<String>() {
+
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ BrowsingResource br = BrowsingResource.getInstance(graph);
+ Resource parameter = graph.getPossibleObject(configuration, br.GraphExplorerComposite_SelectionParameter);
+ if(parameter == null) return null;
+ return graph.getPossibleURI(parameter);
+ }
+
+ });
+
+
+ if(selectionParameter != null) {
+ IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getExplorer().getAdapter(IPostSelectionProvider.class);
+ selectionProvider.addPostSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection = event.getSelection();
+ support.setParameter(selectionParameter, selection);
+ }
+
+ });
+ }
+
+ explorer.finish();
+
+ return explorer;
+
+ }
+
+}