-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in 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.Collection;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\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.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.graphics.FontData;\r
-import org.eclipse.swt.widgets.Combo;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.GraphExplorer;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.common.processors.UserSelectedViewpointFactoryQueryProcessor;\r
-import org.simantics.browsing.ui.content.ViewpointFactory;\r
-import org.simantics.db.layer0.SelectionHints;\r
-import org.simantics.utils.datastructures.Pair;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-import org.simantics.utils.ui.LayoutUtils;\r
-\r
-/**\r
- * TODO: support multiselection within the IGraphExplorer\r
- */\r
-public class ViewpointSelector extends Composite {\r
-\r
- Font smallFont;\r
-\r
- public ViewpointSelector(final GraphExplorer explorer, final UserSelectedViewpointFactoryQueryProcessor queryProcessor, Composite parent, int style) {\r
-\r
- super(parent, style);\r
-\r
- setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());\r
-\r
- setLayout(LayoutUtils.createNoBorderGridLayout(1, false));\r
-\r
- final Combo combo = new Combo(this, SWT.READ_ONLY);\r
-\r
- Font initialFont = combo.getFont();\r
- FontData[] fontData = initialFont.getFontData();\r
- for (int i = 0; i < fontData.length; i++) {\r
- fontData[i].setHeight(fontData[i].getHeight() - 1);\r
- }\r
- smallFont = new Font(getDisplay(), fontData);\r
- combo.setFont(smallFont);\r
-\r
- combo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());\r
- combo.add("-- No viewpoints --");\r
- combo.select(0);\r
-\r
- combo.addSelectionListener(new SelectionListener() {\r
-\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- widgetSelected(e);\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
-\r
- int index = combo.getSelectionIndex();\r
-\r
- Pair<ViewpointFactory, NodeContext> pair =\r
- (Pair<ViewpointFactory, NodeContext>)combo.getData(String.valueOf(index));\r
- if (pair == null)\r
- return;\r
-\r
- queryProcessor.select(pair.second, pair.first);\r
-\r
- }\r
-\r
- });\r
-\r
- IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);\r
-\r
- selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {\r
-\r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
-\r
- ISelection selection = event.getSelection();\r
- NodeContext context = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, NodeContext.class);\r
-\r
- if(context == null) {\r
- context = explorer.getRoot();\r
- }\r
-\r
- assert(context != null);\r
-\r
- Collection<ViewpointFactory> factories = explorer.query(context, BuiltinKeys.VIEWPOINT_FACTORIES);\r
-\r
- ViewpointFactory oldSelection = queryProcessor.getSelection(context);\r
-\r
- combo.removeAll();\r
- if(factories != null) {\r
- for(ViewpointFactory f : factories) {\r
- int index = combo.getItemCount();\r
- combo.add(f.toString());\r
- combo.setData(String.valueOf(index), new Pair<ViewpointFactory, NodeContext>(f, context));\r
- if(f == oldSelection) {\r
- combo.select(index);\r
- }\r
- }\r
- }\r
- if(combo.getItemCount() == 0) {\r
- combo.add("-- No viewpoints --");\r
- }\r
- if(combo.getSelectionIndex() == -1) {\r
- combo.select(0);\r
- }\r
-\r
- }\r
-\r
- });\r
-\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- if (isDisposed())\r
- return;\r
- smallFont.dispose();\r
- super.dispose();\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 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.Collection;
+
+import org.eclipse.jface.layout.GridDataFactory;
+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.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.GraphExplorer;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.processors.UserSelectedViewpointFactoryQueryProcessor;
+import org.simantics.browsing.ui.content.ViewpointFactory;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.utils.datastructures.Pair;
+import org.simantics.utils.ui.ISelectionUtils;
+import org.simantics.utils.ui.LayoutUtils;
+
+/**
+ * TODO: support multiselection within the IGraphExplorer
+ */
+public class ViewpointSelector extends Composite {
+
+ Font smallFont;
+
+ public ViewpointSelector(final GraphExplorer explorer, final UserSelectedViewpointFactoryQueryProcessor queryProcessor, Composite parent, int style) {
+
+ super(parent, style);
+
+ setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
+
+ setLayout(LayoutUtils.createNoBorderGridLayout(1, false));
+
+ final Combo combo = new Combo(this, SWT.READ_ONLY);
+
+ Font initialFont = combo.getFont();
+ FontData[] fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(fontData[i].getHeight() - 1);
+ }
+ smallFont = new Font(getDisplay(), fontData);
+ combo.setFont(smallFont);
+
+ combo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
+ combo.add("-- No viewpoints --");
+ combo.select(0);
+
+ combo.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ int index = combo.getSelectionIndex();
+
+ Pair<ViewpointFactory, NodeContext> pair =
+ (Pair<ViewpointFactory, NodeContext>)combo.getData(String.valueOf(index));
+ if (pair == null)
+ return;
+
+ queryProcessor.select(pair.second, pair.first);
+
+ }
+
+ });
+
+ IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
+
+ selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+
+ ISelection selection = event.getSelection();
+ NodeContext context = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, NodeContext.class);
+
+ if(context == null) {
+ context = explorer.getRoot();
+ }
+
+ assert(context != null);
+
+ Collection<ViewpointFactory> factories = explorer.query(context, BuiltinKeys.VIEWPOINT_FACTORIES);
+
+ ViewpointFactory oldSelection = queryProcessor.getSelection(context);
+
+ combo.removeAll();
+ if(factories != null) {
+ for(ViewpointFactory f : factories) {
+ int index = combo.getItemCount();
+ combo.add(f.toString());
+ combo.setData(String.valueOf(index), new Pair<ViewpointFactory, NodeContext>(f, context));
+ if(f == oldSelection) {
+ combo.select(index);
+ }
+ }
+ }
+ if(combo.getItemCount() == 0) {
+ combo.add("-- No viewpoints --");
+ }
+ if(combo.getSelectionIndex() == -1) {
+ combo.select(0);
+ }
+
+ }
+
+ });
+
+ }
+
+ @Override
+ public void dispose() {
+ if (isDisposed())
+ return;
+ smallFont.dispose();
+ super.dispose();
+ }
+
+}