From: lempinen Date: Thu, 20 May 2010 09:53:17 +0000 (+0000) Subject: fixed focus problems caused by unsuccessful focus commands X-Git-Tag: simantics-1.2.0~241 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=59869cca97bf7ee54dd83886a46f7a024679ce7f;p=simantics%2Fsysdyn.git fixed focus problems caused by unsuccessful focus commands git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@15785 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/configuration/ConfigurationView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/configuration/ConfigurationView.java index 240b19ab..bd4c4c67 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/configuration/ConfigurationView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/configuration/ConfigurationView.java @@ -194,12 +194,6 @@ public class ConfigurationView extends ViewPart { initializeFields(null); } - - @Override - public void setFocus() { - - } - @Override public void dispose() { this.getViewSite().getPage().removePartListener(editorSelectionListener); @@ -373,4 +367,10 @@ public class ConfigurationView extends ViewPart { mapping = null; } } + + @Override + public void setFocus() { + name.setFocus(); + name.setSelection(name.getCharCount()); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java index 7383d030..eb347f41 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java @@ -35,6 +35,7 @@ public class DependencyView extends ViewPart { private Resource currentSelection; private int levels = 3; private ISelectionListener selectionListener; + private Composite baseComposite; static int MAXLEVELS = 4; static int MINLEVELS = 1; @@ -43,8 +44,12 @@ public class DependencyView extends ViewPart { public void createPartControl(Composite parent) { disposed = false; GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(parent); + baseComposite = new Composite(parent, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + GridLayoutFactory.fillDefaults().applyTo(baseComposite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(baseComposite); - component = new GraphvizComponent(parent, SWT.BORDER); + component = new GraphvizComponent(baseComposite, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, true).applyTo(component); Composite composite = new Composite(parent, SWT.NULL); @@ -96,7 +101,7 @@ public class DependencyView extends ViewPart { if(currentSelection != null) { readGraph(currentSelection); } - + } }); @@ -162,11 +167,21 @@ public class DependencyView extends ViewPart { @Override public void setFocus() { - if (component != null && !component.isDisposed()) - component.requestFocus(); + if(component == null || (!component.isDisposed() && !component.forceFocus())) { + getBaseComposite().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if(!getBaseComposite().isDisposed()) { + getBaseComposite().setFocus(); + } + } + }); + } } - + + + @Override public void dispose() { super.dispose(); @@ -174,4 +189,8 @@ public class DependencyView extends ViewPart { disposed = true; } + private Composite getBaseComposite() { + return this.baseComposite; + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java index 1c795cfb..ae757994 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java @@ -62,44 +62,45 @@ import org.simantics.utils.ui.jface.ActiveSelectionProvider; public class SysdynDiagramEditor extends ResourceEditorPart { - EditorCanvas canvas; - IDiagram diagram; - IMapping mapping; - Frame frame; - boolean disposed = false; - - IElementListener elementUpdateListener = new IElementListener() { - + EditorCanvas canvas; + IDiagram diagram; + IMapping mapping; + Frame frame; + boolean disposed = false; + Composite frameComposite; + + IElementListener elementUpdateListener = new IElementListener() { + @Override public void elementUpdated(IElement element) { mapping.rangeModified(element); } - + @Override public void elementRemoved(IElement element) { mapping.rangeModified(element); mapping.rangeModified(diagram); } }; - - protected void readDiagram(ReadGraph g) throws DatabaseException { - SysdynDiagramSchema schema = new SysdynDiagramSchema(g); - mapping = Mappings.createWithListening(schema); - - try { - diagram = (IDiagram)mapping.map(g, getInputResource()); - for(IElement element : diagram.getElements()) - element.addListener(elementUpdateListener); - } catch (MappingException e) { - e.printStackTrace(); - } - - final Session session = g.getSession(); - mapping.addMappingListener(new IMappingListener() { - - @Override - public void rangeModified() { - SwingUtilities.invokeLater(new Runnable() { + + protected void readDiagram(ReadGraph g) throws DatabaseException { + SysdynDiagramSchema schema = new SysdynDiagramSchema(g); + mapping = Mappings.createWithListening(schema); + + try { + diagram = (IDiagram)mapping.map(g, getInputResource()); + for(IElement element : diagram.getElements()) + element.addListener(elementUpdateListener); + } catch (MappingException e) { + e.printStackTrace(); + } + + final Session session = g.getSession(); + mapping.addMappingListener(new IMappingListener() { + + @Override + public void rangeModified() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -107,7 +108,7 @@ public class SysdynDiagramEditor extends ResourceEditorPart { session.syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) - throws DatabaseException { + throws DatabaseException { mapping.updateDomain(graph); } }); @@ -115,13 +116,13 @@ public class SysdynDiagramEditor extends ResourceEditorPart { e.printStackTrace(); } } - - }); - } - - @Override - public void domainModified() { - SwingUtilities.invokeLater(new Runnable() { + + }); + } + + @Override + public void domainModified() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -136,146 +137,157 @@ public class SysdynDiagramEditor extends ResourceEditorPart { e.printStackTrace(); } } - - }); - } - - }); - - diagram.addDiagramListener(new IDiagramListener() { - - @Override - public void elementAdded(IElement element) { - mapping.rangeModified(diagram); - element.addListener(elementUpdateListener); - } - - @Override - public void elementRemoved(IElement element) { - } - - }); - } - - @Override - public void init(IEditorSite site, IEditorInput input) - throws PartInitException { - super.init(site, input); - - try { - SimanticsUI.getSession().syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph g) throws DatabaseException { - readDiagram(g); - } - - }); - - SimanticsUI.getSession().asyncRequest( - new TitleRequest(site.getId(), getResourceInput()) { - @Override - public String perform(ReadGraph graph) throws DatabaseException { - Builtins b = graph.getBuiltins(); - Resource r = graph.getSingleObject( - getResourceInput().getResource(), - b.IsConfigurationOf); - String label = graph.getPossibleRelatedValue(r, b.HasLabel); - return label; - } - }, - new TitleUpdater(site.getShell().getDisplay(), new Callback() { - @Override - public void run(String partName) { - setPartName(partName); - } - }, new Callable() { - @Override - public Boolean call() { - return disposed; - } - })); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - @Override - public void createPartControl(final Composite parent) { - final Composite composite = new Composite(parent, - SWT.NO_BACKGROUND | SWT.EMBEDDED); - frame = SWT_AWT.new_Frame(composite); - + + }); + } + + }); + + diagram.addDiagramListener(new IDiagramListener() { + + @Override + public void elementAdded(IElement element) { + mapping.rangeModified(diagram); + element.addListener(elementUpdateListener); + } + + @Override + public void elementRemoved(IElement element) { + } + + }); + } + + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + super.init(site, input); + + try { + SimanticsUI.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph g) throws DatabaseException { + readDiagram(g); + } + + }); + + SimanticsUI.getSession().asyncRequest( + new TitleRequest(site.getId(), getResourceInput()) { + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Builtins b = graph.getBuiltins(); + Resource r = graph.getSingleObject( + getResourceInput().getResource(), + b.IsConfigurationOf); + String label = graph.getPossibleRelatedValue(r, b.HasLabel); + return label; + } + }, + new TitleUpdater(site.getShell().getDisplay(), new Callback() { + @Override + public void run(String partName) { + setPartName(partName); + } + }, new Callable() { + @Override + public Boolean call() { + return disposed; + } + })); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + @Override + public void createPartControl(final Composite parent) { + frameComposite = new Composite(parent, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + frame = SWT_AWT.new_Frame(frameComposite); + final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider(); getSite().setSelectionProvider(selectionProvider); - + final OpenContextMenu openContextMenu = new OpenContextMenu( parent, getSite(), "#SysdynDiagramPopup"); - + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - DiagramEditor editor = new DiagramEditor(null, diagram); - - DefaultEventHandlers.configure(editor); - editor.addEventHandler(1, "key(A)", new CreateAuxiliary()); - editor.addEventHandler(1, "key(S)", new CreateStock()); - editor.addEventHandler(1, "key(V)", new CreateValve()); - editor.addEventHandler(1, "key(C)", new CreateCloud()); - editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency()); - editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow()); - editor.addEventHandler(1, "release(right)", openContextMenu); - - canvas = new EditorCanvas(editor); + DiagramEditor editor = new DiagramEditor(null, diagram); + + DefaultEventHandlers.configure(editor); + editor.addEventHandler(1, "key(A)", new CreateAuxiliary()); + editor.addEventHandler(1, "key(S)", new CreateStock()); + editor.addEventHandler(1, "key(V)", new CreateValve()); + editor.addEventHandler(1, "key(C)", new CreateCloud()); + editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency()); + editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow()); + editor.addEventHandler(1, "release(right)", openContextMenu); + + canvas = new EditorCanvas(editor); frame.add(canvas); - - canvas.requestFocus(); - + + setFocus(); + editor.getSelection().addSelectionListener(new ISelectionListener() { - + @Override public void selectionChanged(ISelection selection) { final ArrayList resources = new ArrayList(selection.size()); for(IElement element : selection) resources.add(mapping.inverseGet(element)); - composite.getDisplay().asyncExec(new Runnable() { + getFrameComposite().getDisplay().asyncExec(new Runnable() { @Override public void run() { - if(!composite.isDisposed()) + if(!getFrameComposite().isDisposed()) selectionProvider.setSelection(new StructuredSelection(resources)); } - + }); } - + }); } - + }); - } - - @Override - public void setFocus() { - if(canvas != null) - canvas.requestFocus(); - } - - @Override - public void dispose() { - mapping.dispose(); - frame.dispose(); - disposed = true; - } - - @SuppressWarnings("unchecked") + } + @Override - public Object getAdapter(Class adapter) { - if (adapter == INode.class) { - return canvas.getEditor().getSceneGraph(); - } - return super.getAdapter(adapter); - } + public void setFocus() { + if(canvas == null || !canvas.requestFocusInWindow()) { + getFrameComposite().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if(!getFrameComposite().isDisposed()) + getFrameComposite().setFocus(); + } + }); + } + } + + @Override + public void dispose() { + mapping.dispose(); + frame.dispose(); + disposed = true; + } + + @SuppressWarnings("unchecked") + @Override + public Object getAdapter(Class adapter) { + if (adapter == INode.class) { + return canvas.getEditor().getSceneGraph(); + } + return super.getAdapter(adapter); + } + + private Composite getFrameComposite() { + return this.frameComposite; + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java index 5994b54c..dacca6c0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java @@ -265,8 +265,10 @@ public class EquationView extends ViewPart implements ISelectionListener { @Override public void setFocus() { - if(expressionComposite != null) + if(expressionComposite.getExpressionViewFactor() != null) expressionComposite.focus(); + else + nameComposite.setFocus(); } @Override