]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/selection/DocumentTabContributor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / selection / DocumentTabContributor.java
index 66ecb7ebe814b5fde29d9d9b483d857922380a45..6abe392697032e76db8da33e79a31627c1dc2ad9 100644 (file)
-package org.simantics.document.swt.core.selection;\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.db.ReadGraph;\r
-import org.simantics.db.common.procedure.adapter.ListenerSupport;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.document.swt.core.SWTDocumentClient;\r
-import org.simantics.document.swt.core.SWTViews;\r
-import org.simantics.selectionview.IPropertyTab;\r
-import org.simantics.selectionview.IPropertyTab2;\r
-import org.simantics.selectionview.PropertyTabContributor;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
-\r
-final public class DocumentTabContributor implements PropertyTabContributor, ListenerSupport {\r
-\r
-    // For ListenerSupport (supporting DB request listeners)\r
-    protected boolean    disposed = false;\r
-    protected ISelection input    = StructuredSelection.EMPTY;\r
-    final protected String documentURI;\r
-    private SWTDocumentClient client;\r
-    \r
-    protected ISelectionProvider selectionProvider = new ActiveSelectionProvider();\r
-    \r
-    public DocumentTabContributor(String documentURI) {\r
-       this.documentURI = documentURI;\r
-    }\r
-\r
-    public void createControls(Composite body, IWorkbenchSite site) {\r
-       \r
-       client = new SWTDocumentClient(SWTViews.getMapping(), selectionProvider, site, body);\r
-       \r
-    }\r
-\r
-    public IFilterArea getFilterArea() {\r
-        return null;\r
-    }\r
-\r
-    public void requestFocus() {\r
-    }\r
-\r
-    public ISelectionProvider getSelectionProvider() {\r
-        return selectionProvider; \r
-    }\r
-\r
-    public Read<String> getPartNameReadRequest(ISelection forSelection) {\r
-        return null;\r
-    }\r
-\r
-    public void updatePartName(ISelection forSelection, Consumer<String> updateCallback) {\r
-        Read<String> read = getPartNameReadRequest(forSelection);\r
-        if (read == null) {\r
-            updateCallback.accept("Selection");\r
-        } else {\r
-            Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback, this));\r
-        }\r
-    }\r
-\r
-    public void updatePartName(Consumer<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("PropertyTabContributorImpl 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) {\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
-                       DocumentTabContributor.this.createControls(body, site);\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
-               DocumentTabContributor.this.dispose();\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
-    class Tab extends Composite implements IPropertyTab2, IFilterAreaProvider {\r
-\r
-        final IWorkbenchSite    site;\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
-               DocumentTabContributor.this.createControl(parent, site);\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
-               DocumentTabContributor.this.requestFocus();\r
-        }\r
-\r
-        @Override\r
-        public void setInput(ISessionContext context, ISelection selection, boolean force) {\r
-               \r
-               DocumentTabContributor.this.input = selection;\r
-\r
-                       try {\r
-                               \r
-                               String input = Simantics.getSession().syncRequest(new UniqueRead<String>() {\r
-\r
-                                       @Override\r
-                                       public String perform(ReadGraph graph) throws DatabaseException {\r
-                                               Variable var = ISelectionUtils.filterSingleSelection(DocumentTabContributor.this.input, Variable.class);\r
-                                               if(var == null) return null;\r
-                                               return var.getURI(graph).substring("http:/".length());\r
-                                       }\r
-\r
-                               });\r
-                               \r
-                               ListenerSupport support = new ListenerSupport() {\r
-\r
-                                       @Override\r
-                                       public void exception(Throwable t) {\r
-                                               Logger.defaultLogError(t);\r
-                                       }\r
-\r
-                                       @Override\r
-                                       public boolean isDisposed() {\r
-                                               return DocumentTabContributor.this.isDisposed();\r
-                                       }\r
-                                       \r
-                               };\r
-                               \r
-                               if(input != null) {\r
-                                       client.track(support, documentURI, input);\r
-                                       layout(true, true);\r
-                               }\r
-                       \r
-                       } catch (DatabaseException e) {\r
-                               Logger.defaultLogError(e);\r
-                       }\r
-            \r
-        }\r
-\r
-        @Override\r
-        public ISelectionProvider getSelectionProvider() {\r
-            return DocumentTabContributor.this.getSelectionProvider();\r
-        }\r
-\r
-        @Override\r
-        public IFilterArea getFilterArea() {\r
-            return DocumentTabContributor.this.getFilterArea();\r
-        }\r
-\r
-        @Override\r
-        public void updatePartName(Consumer<String> updateCallback) {\r
-               DocumentTabContributor.this.updatePartName(input, updateCallback);\r
-        }\r
-\r
-    }\r
-    \r
-    @Override\r
-    public int hashCode() {\r
-       return documentURI.hashCode();\r
-    }\r
-    \r
-    @Override\r
-    public boolean equals(Object object) {\r
-       \r
-        if (this == object)\r
-            return true;\r
-        else if (object == null)\r
-            return false;\r
-        else if (!(object instanceof DocumentTabContributor))\r
-            return false;\r
-\r
-        DocumentTabContributor dtc = (DocumentTabContributor)object;\r
-        return documentURI.equals(dtc.documentURI);\r
-        \r
-    }\r
-       \r
-}\r
+package org.simantics.document.swt.core.selection;
+
+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.db.ReadGraph;
+import org.simantics.db.common.procedure.adapter.ListenerSupport;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.request.Read;
+import org.simantics.document.swt.core.SWTDocumentClient;
+import org.simantics.document.swt.core.SWTViews;
+import org.simantics.selectionview.IPropertyTab;
+import org.simantics.selectionview.IPropertyTab2;
+import org.simantics.selectionview.PropertyTabContributor;
+import org.simantics.utils.ui.ISelectionUtils;
+import org.simantics.utils.ui.jface.ActiveSelectionProvider;
+
+final public class DocumentTabContributor implements PropertyTabContributor, ListenerSupport {
+
+    // For ListenerSupport (supporting DB request listeners)
+    protected boolean    disposed = false;
+    protected ISelection input    = StructuredSelection.EMPTY;
+    final protected String documentURI;
+    private SWTDocumentClient client;
+    
+    protected ISelectionProvider selectionProvider = new ActiveSelectionProvider();
+    
+    public DocumentTabContributor(String documentURI) {
+       this.documentURI = documentURI;
+    }
+
+    public void createControls(Composite body, IWorkbenchSite site) {
+       
+       client = new SWTDocumentClient(SWTViews.getMapping(), selectionProvider, site, body);
+       
+    }
+
+    public IFilterArea getFilterArea() {
+        return null;
+    }
+
+    public void requestFocus() {
+    }
+
+    public ISelectionProvider getSelectionProvider() {
+        return selectionProvider; 
+    }
+
+    public Read<String> getPartNameReadRequest(ISelection forSelection) {
+        return null;
+    }
+
+    public void updatePartName(ISelection forSelection, Consumer<String> updateCallback) {
+        Read<String> read = getPartNameReadRequest(forSelection);
+        if (read == null) {
+            updateCallback.accept("Selection");
+        } else {
+            Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback, this));
+        }
+    }
+
+    public void updatePartName(Consumer<String> updateCallback) {
+        updatePartName(input, updateCallback);
+    }
+
+    protected void dispose() {
+        this.disposed = true;
+    }
+
+    @Override
+    public void exception(Throwable t) {
+        ErrorLogger.defaultLogError("PropertyTabContributorImpl received unexpected exception.", t);
+    }
+
+    @Override
+    public boolean isDisposed() {
+        return disposed;
+    }
+
+    public void createControl(Composite parent, final IWorkbenchSite site) {
+
+        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 {
+                       DocumentTabContributor.this.createControls(body, site);
+                } catch (Throwable t) {
+                    ErrorLogger.defaultLogError(t);
+                }
+            }
+        }
+
+        final TabComposite tc = new TabComposite(parent);
+        tc.addListener(SWT.Dispose, new Listener() {
+            public void handleEvent(Event e) {
+               DocumentTabContributor.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;
+    }
+
+    class Tab extends Composite implements IPropertyTab2, IFilterAreaProvider {
+
+        final IWorkbenchSite    site;
+        
+        public Tab(IWorkbenchSite site, Composite parent) {
+            super(parent, SWT.NONE);
+            this.site = site;
+        }
+
+        @Override
+        public void createControl(Composite parent, ISessionContext context) {
+               DocumentTabContributor.this.createControl(parent, site);
+        }
+
+        @Override
+        public Control getControl() {
+            return this;
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return super.isDisposed();
+        }
+
+        @Override
+        public void requestFocus() {
+               DocumentTabContributor.this.requestFocus();
+        }
+
+        @Override
+        public void setInput(ISessionContext context, ISelection selection, boolean force) {
+               
+               DocumentTabContributor.this.input = selection;
+
+                       try {
+                               
+                               String input = Simantics.getSession().syncRequest(new UniqueRead<String>() {
+
+                                       @Override
+                                       public String perform(ReadGraph graph) throws DatabaseException {
+                                               Variable var = ISelectionUtils.filterSingleSelection(DocumentTabContributor.this.input, Variable.class);
+                                               if(var == null) return null;
+                                               return var.getURI(graph).substring("http:/".length());
+                                       }
+
+                               });
+                               
+                               ListenerSupport support = new ListenerSupport() {
+
+                                       @Override
+                                       public void exception(Throwable t) {
+                                               Logger.defaultLogError(t);
+                                       }
+
+                                       @Override
+                                       public boolean isDisposed() {
+                                               return DocumentTabContributor.this.isDisposed();
+                                       }
+                                       
+                               };
+                               
+                               if(input != null) {
+                                       client.track(support, documentURI, input);
+                                       layout(true, true);
+                               }
+                       
+                       } catch (DatabaseException e) {
+                               Logger.defaultLogError(e);
+                       }
+            
+        }
+
+        @Override
+        public ISelectionProvider getSelectionProvider() {
+            return DocumentTabContributor.this.getSelectionProvider();
+        }
+
+        @Override
+        public IFilterArea getFilterArea() {
+            return DocumentTabContributor.this.getFilterArea();
+        }
+
+        @Override
+        public void updatePartName(Consumer<String> updateCallback) {
+               DocumentTabContributor.this.updatePartName(input, updateCallback);
+        }
+
+    }
+    
+    @Override
+    public int hashCode() {
+       return documentURI.hashCode();
+    }
+    
+    @Override
+    public boolean equals(Object object) {
+       
+        if (this == object)
+            return true;
+        else if (object == null)
+            return false;
+        else if (!(object instanceof DocumentTabContributor))
+            return false;
+
+        DocumentTabContributor dtc = (DocumentTabContributor)object;
+        return documentURI.equals(dtc.documentURI);
+        
+    }
+       
+}