]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
fixed focus problems caused by unsuccessful focus commands
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 20 May 2010 09:53:17 +0000 (09:53 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 20 May 2010 09:53:17 +0000 (09:53 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@15785 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/configuration/ConfigurationView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java

index 240b19ab5dfb299485a928f34589c39b6fc70ca4..bd4c4c6729e0949aa54aa79e93f81aa4c8d05d3c 100644 (file)
@@ -194,12 +194,6 @@ public class ConfigurationView  extends ViewPart {
             initializeFields(null);\r
     }\r
 \r
-\r
-    @Override\r
-    public void setFocus() {\r
-\r
-    }\r
-\r
     @Override\r
     public void dispose() {\r
         this.getViewSite().getPage().removePartListener(editorSelectionListener);\r
@@ -373,4 +367,10 @@ public class ConfigurationView  extends ViewPart {
             mapping = null;\r
         }\r
     }\r
+\r
+    @Override\r
+    public void setFocus() {\r
+        name.setFocus();\r
+        name.setSelection(name.getCharCount());\r
+    }\r
 }\r
index 7383d0302031f5373d018afb01ffa8449f13bbae..eb347f4188c4f0a3c7e85c1eda7c690046e3590d 100644 (file)
@@ -35,6 +35,7 @@ public class DependencyView extends ViewPart {
     private Resource currentSelection;\r
     private int levels = 3;\r
     private ISelectionListener selectionListener;\r
+    private Composite baseComposite;\r
 \r
     static int MAXLEVELS = 4;\r
     static int MINLEVELS = 1;\r
@@ -43,8 +44,12 @@ public class DependencyView extends ViewPart {
     public void createPartControl(Composite parent) {\r
         disposed = false;\r
         GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(parent);\r
+        baseComposite = new Composite(parent, \r
+                SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
+        GridLayoutFactory.fillDefaults().applyTo(baseComposite);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(baseComposite);\r
 \r
-        component = new GraphvizComponent(parent, SWT.BORDER);\r
+        component = new GraphvizComponent(baseComposite, SWT.BORDER);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(component);\r
 \r
         Composite composite = new Composite(parent, SWT.NULL);\r
@@ -96,7 +101,7 @@ public class DependencyView extends ViewPart {
                 if(currentSelection != null) {\r
                     readGraph(currentSelection);\r
                 }\r
-                    \r
+\r
             }\r
         });\r
 \r
@@ -162,11 +167,21 @@ public class DependencyView extends ViewPart {
 \r
     @Override\r
     public void setFocus() {\r
-        if (component != null && !component.isDisposed())\r
-            component.requestFocus();\r
+        if(component == null || (!component.isDisposed() && !component.forceFocus())) {\r
+            getBaseComposite().getDisplay().asyncExec(new Runnable() {\r
+                @Override\r
+                public void run() {\r
+                    if(!getBaseComposite().isDisposed()) {\r
+                        getBaseComposite().setFocus();    \r
+                    }\r
+                }\r
+            });\r
+        }\r
     }\r
 \r
-    \r
+\r
+\r
+\r
     @Override\r
     public void dispose() {\r
         super.dispose();\r
@@ -174,4 +189,8 @@ public class DependencyView extends ViewPart {
         disposed = true;\r
     }\r
 \r
+    private Composite getBaseComposite() {\r
+        return this.baseComposite;\r
+    }\r
+\r
 }\r
index 1c795cfb3268648a8a3500cb865957405e121c9d..ae75799487a4d42740c44f6292ee8cc568ca265b 100644 (file)
@@ -62,44 +62,45 @@ import org.simantics.utils.ui.jface.ActiveSelectionProvider;
 \r
 public class SysdynDiagramEditor extends ResourceEditorPart {\r
 \r
-       EditorCanvas canvas;\r
-       IDiagram diagram;\r
-       IMapping mapping;\r
-       Frame frame;\r
-       boolean disposed = false;       \r
-       \r
-       IElementListener elementUpdateListener = new IElementListener() {\r
-        \r
+    EditorCanvas canvas;\r
+    IDiagram diagram;\r
+    IMapping mapping;\r
+    Frame frame;\r
+    boolean disposed = false;  \r
+    Composite frameComposite;\r
+\r
+    IElementListener elementUpdateListener = new IElementListener() {\r
+\r
         @Override\r
         public void elementUpdated(IElement element) {\r
             mapping.rangeModified(element);\r
         }\r
-        \r
+\r
         @Override\r
         public void elementRemoved(IElement element) {\r
             mapping.rangeModified(element);\r
             mapping.rangeModified(diagram);\r
         }\r
     };\r
-       \r
-       protected void readDiagram(ReadGraph g) throws DatabaseException {\r
-               SysdynDiagramSchema schema = new SysdynDiagramSchema(g);\r
-               mapping = Mappings.createWithListening(schema);\r
-                               \r
-               try {\r
-                       diagram = (IDiagram)mapping.map(g, getInputResource());\r
-                       for(IElement element : diagram.getElements())\r
-                           element.addListener(elementUpdateListener);\r
-               } catch (MappingException e) {\r
-                       e.printStackTrace();\r
-               }\r
-               \r
-               final Session session = g.getSession();\r
-               mapping.addMappingListener(new IMappingListener() {\r
-                       \r
-                       @Override\r
-                       public void rangeModified() {\r
-                           SwingUtilities.invokeLater(new Runnable() {\r
+\r
+    protected void readDiagram(ReadGraph g) throws DatabaseException {\r
+        SysdynDiagramSchema schema = new SysdynDiagramSchema(g);\r
+        mapping = Mappings.createWithListening(schema);\r
+\r
+        try {\r
+            diagram = (IDiagram)mapping.map(g, getInputResource());\r
+            for(IElement element : diagram.getElements())\r
+                element.addListener(elementUpdateListener);\r
+        } catch (MappingException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        final Session session = g.getSession();\r
+        mapping.addMappingListener(new IMappingListener() {\r
+\r
+            @Override\r
+            public void rangeModified() {\r
+                SwingUtilities.invokeLater(new Runnable() {\r
 \r
                     @Override\r
                     public void run() {\r
@@ -107,7 +108,7 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
                             session.syncRequest(new WriteRequest() {                                \r
                                 @Override\r
                                 public void perform(WriteGraph graph)\r
-                                        throws DatabaseException {\r
+                                throws DatabaseException {\r
                                     mapping.updateDomain(graph);\r
                                 }                                \r
                             });\r
@@ -115,13 +116,13 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
                             e.printStackTrace();\r
                         }                        \r
                     }\r
-                               \r
-                           });                         \r
-                       }\r
-                       \r
-                       @Override\r
-                       public void domainModified() {\r
-                           SwingUtilities.invokeLater(new Runnable() {\r
+\r
+                });                            \r
+            }\r
+\r
+            @Override\r
+            public void domainModified() {\r
+                SwingUtilities.invokeLater(new Runnable() {\r
 \r
                     @Override\r
                     public void run() {\r
@@ -136,146 +137,157 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
                             e.printStackTrace();\r
                         }          \r
                     }\r
-                    \r
-                           });                             \r
-                       }\r
-                                               \r
-               });\r
-               \r
-               diagram.addDiagramListener(new IDiagramListener() {\r
-                       \r
-                       @Override\r
-                       public void elementAdded(IElement element) {\r
-                               mapping.rangeModified(diagram);                 \r
-                               element.addListener(elementUpdateListener);\r
-                       }\r
-                       \r
-                       @Override\r
-                       public void elementRemoved(IElement element) {\r
-                       }\r
-                       \r
-               });\r
-       }\r
-       \r
-       @Override\r
-       public void init(IEditorSite site, IEditorInput input)\r
-                       throws PartInitException {\r
-               super.init(site, input);\r
-               \r
-               try {\r
-                       SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
-                               \r
-                               @Override\r
-                               public void run(ReadGraph g) throws DatabaseException {\r
-                                       readDiagram(g);                 \r
-                               }\r
-                               \r
-                       });\r
-                       \r
-                       SimanticsUI.getSession().asyncRequest(\r
-                               new TitleRequest(site.getId(), getResourceInput()) {\r
-                                   @Override\r
-                                   public String perform(ReadGraph graph) throws DatabaseException {\r
-                                       Builtins b = graph.getBuiltins();\r
-                                       Resource r = graph.getSingleObject(\r
-                                               getResourceInput().getResource(),\r
-                                               b.IsConfigurationOf);\r
-                                       String label = graph.getPossibleRelatedValue(r, b.HasLabel);\r
-                                       return label;\r
-                                   }\r
-                               },\r
-                               new TitleUpdater(site.getShell().getDisplay(), new Callback<String>() {\r
-                                   @Override\r
-                                   public void run(String partName) {\r
-                                       setPartName(partName);\r
-                                   }\r
-                               }, new Callable<Boolean>() {\r
-                                   @Override\r
-                                   public Boolean call() {\r
-                                       return disposed;\r
-                                   }\r
-                               }));\r
-               } catch (DatabaseException e) {\r
-                       e.printStackTrace();\r
-               }               \r
-       }\r
-       \r
-       @Override\r
-       public void createPartControl(final Composite parent) {\r
-        final Composite composite = new Composite(parent, \r
-                       SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
-        frame = SWT_AWT.new_Frame(composite);\r
-        \r
+\r
+                });                                \r
+            }\r
+\r
+        });\r
+\r
+        diagram.addDiagramListener(new IDiagramListener() {\r
+\r
+            @Override\r
+            public void elementAdded(IElement element) {\r
+                mapping.rangeModified(diagram);                        \r
+                element.addListener(elementUpdateListener);\r
+            }\r
+\r
+            @Override\r
+            public void elementRemoved(IElement element) {\r
+            }\r
+\r
+        });\r
+    }\r
+\r
+    @Override\r
+    public void init(IEditorSite site, IEditorInput input)\r
+    throws PartInitException {\r
+        super.init(site, input);\r
+\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+\r
+                @Override\r
+                public void run(ReadGraph g) throws DatabaseException {\r
+                    readDiagram(g);                    \r
+                }\r
+\r
+            });\r
+\r
+            SimanticsUI.getSession().asyncRequest(\r
+                    new TitleRequest(site.getId(), getResourceInput()) {\r
+                        @Override\r
+                        public String perform(ReadGraph graph) throws DatabaseException {\r
+                            Builtins b = graph.getBuiltins();\r
+                            Resource r = graph.getSingleObject(\r
+                                    getResourceInput().getResource(),\r
+                                    b.IsConfigurationOf);\r
+                            String label = graph.getPossibleRelatedValue(r, b.HasLabel);\r
+                            return label;\r
+                        }\r
+                    },\r
+                    new TitleUpdater(site.getShell().getDisplay(), new Callback<String>() {\r
+                        @Override\r
+                        public void run(String partName) {\r
+                            setPartName(partName);\r
+                        }\r
+                    }, new Callable<Boolean>() {\r
+                        @Override\r
+                        public Boolean call() {\r
+                            return disposed;\r
+                        }\r
+                    }));\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }              \r
+    }\r
+\r
+    @Override\r
+    public void createPartControl(final Composite parent) {\r
+        frameComposite = new Composite(parent, \r
+                SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
+        frame = SWT_AWT.new_Frame(frameComposite);\r
+\r
         final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
         getSite().setSelectionProvider(selectionProvider);\r
-        \r
+\r
         final OpenContextMenu openContextMenu = new OpenContextMenu(\r
                 parent, getSite(), "#SysdynDiagramPopup");\r
-        \r
+\r
         SwingUtilities.invokeLater(new Runnable() {\r
 \r
             @Override\r
             public void run() {                \r
-                       DiagramEditor editor = new DiagramEditor(null, diagram);                \r
-                       \r
-                       DefaultEventHandlers.configure(editor);\r
-                       editor.addEventHandler(1, "key(A)", new CreateAuxiliary());\r
-                       editor.addEventHandler(1, "key(S)", new CreateStock());\r
-                       editor.addEventHandler(1, "key(V)", new CreateValve());\r
-                       editor.addEventHandler(1, "key(C)", new CreateCloud());\r
-                       editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency());\r
-                       editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow());\r
-                       editor.addEventHandler(1, "release(right)", openContextMenu); \r
-                       \r
-               canvas = new EditorCanvas(editor);\r
+                DiagramEditor editor = new DiagramEditor(null, diagram);                       \r
+\r
+                DefaultEventHandlers.configure(editor);\r
+                editor.addEventHandler(1, "key(A)", new CreateAuxiliary());\r
+                editor.addEventHandler(1, "key(S)", new CreateStock());\r
+                editor.addEventHandler(1, "key(V)", new CreateValve());\r
+                editor.addEventHandler(1, "key(C)", new CreateCloud());\r
+                editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency());\r
+                editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow());\r
+                editor.addEventHandler(1, "release(right)", openContextMenu); \r
+\r
+                canvas = new EditorCanvas(editor);\r
                 frame.add(canvas);\r
-                \r
-                canvas.requestFocus();           \r
-                \r
+\r
+                setFocus();\r
+\r
                 editor.getSelection().addSelectionListener(new ISelectionListener() {\r
-                    \r
+\r
                     @Override\r
                     public void selectionChanged(ISelection selection) {\r
                         final ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
                         for(IElement element : selection)\r
                             resources.add(mapping.inverseGet(element));\r
-                        composite.getDisplay().asyncExec(new Runnable() {\r
+                        getFrameComposite().getDisplay().asyncExec(new Runnable() {\r
 \r
                             @Override\r
                             public void run() {\r
-                                if(!composite.isDisposed())\r
+                                if(!getFrameComposite().isDisposed())\r
                                     selectionProvider.setSelection(new StructuredSelection(resources));\r
                             }\r
-                            \r
+\r
                         });\r
                     }\r
-                    \r
+\r
                 });\r
             }\r
-            \r
+\r
         });\r
-       }\r
-\r
-       @Override\r
-       public void setFocus() {\r
-               if(canvas != null)\r
-            canvas.requestFocus();             \r
-       }\r
-       \r
-       @Override\r
-       public void dispose() {\r
-           mapping.dispose();\r
-           frame.dispose();\r
-           disposed = true;\r
-       }\r
-       \r
-       @SuppressWarnings("unchecked")\r
+    }\r
+\r
     @Override\r
-       public Object getAdapter(Class adapter) {\r
-           if (adapter == INode.class) {\r
-               return canvas.getEditor().getSceneGraph();\r
-           }\r
-           return super.getAdapter(adapter);\r
-       }\r
+    public void setFocus() {     \r
+        if(canvas == null || !canvas.requestFocusInWindow()) {\r
+            getFrameComposite().getDisplay().asyncExec(new Runnable() {\r
+                @Override\r
+                public void run() {\r
+                    if(!getFrameComposite().isDisposed())\r
+                        getFrameComposite().setFocus();                    \r
+                }\r
+            });\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void dispose() {\r
+        mapping.dispose();\r
+        frame.dispose();\r
+        disposed = true;\r
+    }\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Override\r
+    public Object getAdapter(Class adapter) {\r
+        if (adapter == INode.class) {\r
+            return canvas.getEditor().getSceneGraph();\r
+        }\r
+        return super.getAdapter(adapter);\r
+    }\r
+\r
+    private Composite getFrameComposite() {\r
+        return this.frameComposite;\r
+    }\r
 \r
 }\r
index 5994b54c9c1901ceaa0097bb453403a84c4eb205..dacca6c0b4dbe37b15bcb6bf216e779db91088cf 100644 (file)
@@ -265,8 +265,10 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
     @Override\r
     public void setFocus() {\r
-        if(expressionComposite != null)\r
+        if(expressionComposite.getExpressionViewFactor() != null)\r
             expressionComposite.focus();\r
+        else\r
+            nameComposite.setFocus();\r
     }\r
 \r
     @Override\r