]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.selectionview/src/org/simantics/selectionview/PropertyTabContributorImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / PropertyTabContributorImpl.java
index bf64f3bcf56c0ca64ae95f5fc013c85ef62e156b..24b74746eb8c5aad8f17553213ea67760b6c80ad 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 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.selectionview;\r
-\r
-import java.util.function.Consumer;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionProvider;\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.ui.IWorkbenchSite;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.common.ErrorLogger;\r
-import org.simantics.browsing.ui.common.views.IFilterArea;\r
-import org.simantics.browsing.ui.common.views.IFilterAreaProvider;\r
-import org.simantics.browsing.ui.swt.PartNameListener;\r
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
-import org.simantics.db.Disposable;\r
-import org.simantics.db.common.procedure.adapter.ListenerSupport;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.request.Read;\r
-\r
-/**\r
- * Important points of customization:\r
- * <ul>\r
- * <li>{@link #createControls(Composite, IWorkbenchSite, ISessionContext, WidgetSupport)}</li>\r
- * <li>{@link #getSelectionProvider()}</li>\r
- * <li>{@link #getPartNameReadRequest(ISelection)}</li>\r
- * </ul>\r
-\r
- * @author Antti Villberg\r
- * @author Tuukka Lehtonen\r
- * @see ModelledTabContributor ModelledTabContributor for graph-modelled tab contributions\r
- */\r
-public abstract class PropertyTabContributorImpl implements PropertyTabContributor, Disposable /*, ListenerSupport*/ {\r
-\r
-    // For ListenerSupport (supporting DB request listeners)\r
-//    protected boolean    disposed = false;\r
-//    protected ISelection input    = StructuredSelection.EMPTY;\r
-//    private Object identity;\r
-\r
-    abstract public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support);\r
-\r
-    public PropertyTabContributorImpl() {\r
-    }\r
-\r
-    public IFilterArea getFilterArea() {\r
-        return null;\r
-    }\r
-\r
-    public void requestFocus() {\r
-    }\r
-\r
-    public ISelectionProvider getSelectionProvider() {\r
-        return null;\r
-    }\r
-\r
-    public String getPartName(ISelection forSelection) {\r
-       return null;\r
-    }\r
-    \r
-    public Read<String> getPartNameReadRequest(ISelection forSelection) {\r
-        return null;\r
-    }\r
-\r
-//    public void updatePartName(ISelection forSelection, Callback<String> updateCallback) {\r
-//        Read<String> read = getPartNameReadRequest(forSelection);\r
-//        if (read == null) {\r
-//            updateCallback.run("Override to control part name (PropertyTabContributorImpl.updatePartName)");\r
-//        } else {\r
-//            Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback, this));\r
-//        }\r
-//    }\r
-\r
-//    public void updatePartName(Callback<String> updateCallback) {\r
-//        updatePartName(input, updateCallback);\r
-//    }\r
-\r
-//    protected void dispose() {\r
-//        this.disposed = true;\r
-//    }\r
-\r
-//    @Override\r
-//    public void exception(Throwable t) {\r
-//        ErrorLogger.defaultLogError(getClass().getSimpleName() + " received unexpected exception.", t);\r
-//    }\r
-\r
-//    @Override\r
-//    public boolean isDisposed() {\r
-//        return disposed;\r
-//    }\r
-\r
-    public void createControl(Composite parent, final IWorkbenchSite site, final ISessionContext context, final WidgetSupportImpl support) {\r
-\r
-        class TabComposite extends Composite {\r
-            public TabComposite(Composite parent) {\r
-                super(parent, 0);\r
-\r
-                GridLayoutFactory.fillDefaults().applyTo(parent);\r
-                GridDataFactory.fillDefaults().span(1, 1).grab(true, true).applyTo(this);\r
-\r
-                Composite body = this;\r
-                GridLayoutFactory.fillDefaults().spacing(0, 0).equalWidth(false).numColumns(1).applyTo(body);\r
-\r
-                try {\r
-                    PropertyTabContributorImpl.this.createControls(body, site, context, support);\r
-                } catch (Throwable t) {\r
-                    ErrorLogger.defaultLogError(t);\r
-                }\r
-            }\r
-        }\r
-\r
-        final TabComposite tc = new TabComposite(parent);\r
-        tc.addListener(SWT.Dispose, new Listener() {\r
-               public void handleEvent(Event e) {\r
-                       if(support instanceof Disposable)\r
-                               ((Disposable)support).dispose();\r
-                       PropertyTabContributorImpl.this.dispose();\r
-            }\r
-        });\r
-        \r
-    }\r
-\r
-    @Override\r
-    public IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {\r
-        IPropertyTab tab = new Tab(site, parent);\r
-        tab.createControl((Composite) tab.getControl(), context);\r
-        return tab;\r
-    }\r
-\r
-    protected WidgetSupportImpl createSupport() {\r
-       return new WidgetSupportImpl();\r
-    }\r
-    \r
-    class Tab extends Composite implements IPropertyTab2, IFilterAreaProvider, ListenerSupport {\r
-\r
-        final IWorkbenchSite    site;\r
-        final WidgetSupportImpl support = createSupport();\r
-        protected ISelection input    = StructuredSelection.EMPTY;\r
-\r
-        public Tab(IWorkbenchSite site, Composite parent) {\r
-            super(parent, SWT.NONE);\r
-            this.site = site;\r
-        }\r
-\r
-        @Override\r
-        public void createControl(Composite parent, ISessionContext context) {\r
-            PropertyTabContributorImpl.this.createControl(parent, site, context, support);\r
-        }\r
-\r
-        @Override\r
-        public Control getControl() {\r
-            return this;\r
-        }\r
-\r
-        @Override\r
-        public boolean isDisposed() {\r
-            return super.isDisposed();\r
-        }\r
-\r
-        @Override\r
-        public void requestFocus() {\r
-            PropertyTabContributorImpl.this.requestFocus();\r
-        }\r
-\r
-        @Override\r
-        public void setInput(ISessionContext context, ISelection selection, boolean force) {\r
-            this.input = selection;\r
-            support.fireInput(context, selection);\r
-        }\r
-\r
-        @Override\r
-        public ISelectionProvider getSelectionProvider() {\r
-            return PropertyTabContributorImpl.this.getSelectionProvider();\r
-        }\r
-\r
-        @Override\r
-        public IFilterArea getFilterArea() {\r
-            return PropertyTabContributorImpl.this.getFilterArea();\r
-        }\r
-\r
-        @Override\r
-        public void updatePartName(Consumer<String> updateCallback) {\r
-               String partName = PropertyTabContributorImpl.this.getPartName(input);\r
-               if(partName != null) {\r
-                       updateCallback.accept(partName);\r
-                       return;\r
-               }\r
-               Read<String> read = getPartNameReadRequest(input);\r
-               if (read == null) {\r
-                       updateCallback.accept("Override to control part name (PropertyTabContributorImpl.updatePartName)");\r
-               } else {\r
-                       Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback, this));\r
-               }\r
-            //PropertyTabContributorImpl.this.updatePartName(input, updateCallback);\r
-        }\r
-\r
-               @Override\r
-               public void exception(Throwable t) {\r
-               ErrorLogger.defaultLogError(getClass().getSimpleName() + " received unexpected exception.", t);\r
-               }\r
-\r
-    }\r
-    \r
-    @Override\r
-    public void dispose() {\r
-    }\r
-    \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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.selectionview;
+
+import java.util.function.Consumer;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.common.ErrorLogger;
+import org.simantics.browsing.ui.common.views.IFilterArea;
+import org.simantics.browsing.ui.common.views.IFilterAreaProvider;
+import org.simantics.browsing.ui.swt.PartNameListener;
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;
+import org.simantics.db.Disposable;
+import org.simantics.db.common.procedure.adapter.ListenerSupport;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.request.Read;
+
+/**
+ * Important points of customization:
+ * <ul>
+ * <li>{@link #createControls(Composite, IWorkbenchSite, ISessionContext, WidgetSupport)}</li>
+ * <li>{@link #getSelectionProvider()}</li>
+ * <li>{@link #getPartNameReadRequest(ISelection)}</li>
+ * </ul>
+
+ * @author Antti Villberg
+ * @author Tuukka Lehtonen
+ * @see ModelledTabContributor ModelledTabContributor for graph-modelled tab contributions
+ */
+public abstract class PropertyTabContributorImpl implements PropertyTabContributor, Disposable /*, ListenerSupport*/ {
+
+    // For ListenerSupport (supporting DB request listeners)
+//    protected boolean    disposed = false;
+//    protected ISelection input    = StructuredSelection.EMPTY;
+//    private Object identity;
+
+    abstract public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support);
+
+    public PropertyTabContributorImpl() {
+    }
+
+    public IFilterArea getFilterArea() {
+        return null;
+    }
+
+    public void requestFocus() {
+    }
+
+    public ISelectionProvider getSelectionProvider() {
+        return null;
+    }
+
+    public String getPartName(ISelection forSelection) {
+       return null;
+    }
+    
+    public Read<String> getPartNameReadRequest(ISelection forSelection) {
+        return null;
+    }
+
+//    public void updatePartName(ISelection forSelection, Callback<String> updateCallback) {
+//        Read<String> read = getPartNameReadRequest(forSelection);
+//        if (read == null) {
+//            updateCallback.run("Override to control part name (PropertyTabContributorImpl.updatePartName)");
+//        } else {
+//            Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback, this));
+//        }
+//    }
+
+//    public void updatePartName(Callback<String> updateCallback) {
+//        updatePartName(input, updateCallback);
+//    }
+
+//    protected void dispose() {
+//        this.disposed = true;
+//    }
+
+//    @Override
+//    public void exception(Throwable t) {
+//        ErrorLogger.defaultLogError(getClass().getSimpleName() + " received unexpected exception.", t);
+//    }
+
+//    @Override
+//    public boolean isDisposed() {
+//        return disposed;
+//    }
+
+    public void createControl(Composite parent, final IWorkbenchSite site, final ISessionContext context, final WidgetSupportImpl support) {
+
+        class TabComposite extends Composite {
+            public TabComposite(Composite parent) {
+                super(parent, 0);
+
+                GridLayoutFactory.fillDefaults().applyTo(parent);
+                GridDataFactory.fillDefaults().span(1, 1).grab(true, true).applyTo(this);
+
+                Composite body = this;
+                GridLayoutFactory.fillDefaults().spacing(0, 0).equalWidth(false).numColumns(1).applyTo(body);
+
+                try {
+                    PropertyTabContributorImpl.this.createControls(body, site, context, support);
+                } catch (Throwable t) {
+                    ErrorLogger.defaultLogError(t);
+                }
+            }
+        }
+
+        final TabComposite tc = new TabComposite(parent);
+        tc.addListener(SWT.Dispose, new Listener() {
+               public void handleEvent(Event e) {
+                       if(support instanceof Disposable)
+                               ((Disposable)support).dispose();
+                       PropertyTabContributorImpl.this.dispose();
+            }
+        });
+        
+    }
+
+    @Override
+    public IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {
+        IPropertyTab tab = new Tab(site, parent);
+        tab.createControl((Composite) tab.getControl(), context);
+        return tab;
+    }
+
+    protected WidgetSupportImpl createSupport() {
+       return new WidgetSupportImpl();
+    }
+    
+    class Tab extends Composite implements IPropertyTab2, IFilterAreaProvider, ListenerSupport {
+
+        final IWorkbenchSite    site;
+        final WidgetSupportImpl support = createSupport();
+        protected ISelection input    = StructuredSelection.EMPTY;
+
+        public Tab(IWorkbenchSite site, Composite parent) {
+            super(parent, SWT.NONE);
+            this.site = site;
+        }
+
+        @Override
+        public void createControl(Composite parent, ISessionContext context) {
+            PropertyTabContributorImpl.this.createControl(parent, site, context, support);
+        }
+
+        @Override
+        public Control getControl() {
+            return this;
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return super.isDisposed();
+        }
+
+        @Override
+        public void requestFocus() {
+            PropertyTabContributorImpl.this.requestFocus();
+        }
+
+        @Override
+        public void setInput(ISessionContext context, ISelection selection, boolean force) {
+            this.input = selection;
+            support.fireInput(context, selection);
+        }
+
+        @Override
+        public ISelectionProvider getSelectionProvider() {
+            return PropertyTabContributorImpl.this.getSelectionProvider();
+        }
+
+        @Override
+        public IFilterArea getFilterArea() {
+            return PropertyTabContributorImpl.this.getFilterArea();
+        }
+
+        @Override
+        public void updatePartName(Consumer<String> updateCallback) {
+               String partName = PropertyTabContributorImpl.this.getPartName(input);
+               if(partName != null) {
+                       updateCallback.accept(partName);
+                       return;
+               }
+               Read<String> read = getPartNameReadRequest(input);
+               if (read == null) {
+                       updateCallback.accept("Override to control part name (PropertyTabContributorImpl.updatePartName)");
+               } else {
+                       Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback, this));
+               }
+            //PropertyTabContributorImpl.this.updatePartName(input, updateCallback);
+        }
+
+               @Override
+               public void exception(Throwable t) {
+               ErrorLogger.defaultLogError(getClass().getSimpleName() + " received unexpected exception.", t);
+               }
+
+    }
+    
+    @Override
+    public void dispose() {
+    }
+    
+}