]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Deleting an item from model browser closes its editor and empties configuration view
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 30 Mar 2010 11:13:55 +0000 (11:13 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 30 Mar 2010 11:13:55 +0000 (11:13 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@15269 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/handlers/UnlinkNodeHandler.java

index 7f1bea276438323ee8b95a6da08dab25cc7c7e2f..36cd83ced91057840f23bacdac02b7cce266fa01 100644 (file)
@@ -130,6 +130,11 @@ public class ConfigurationView  extends ViewPart {
 \r
             @Override\r
             public void partClosed(IWorkbenchPartReference partRef) {\r
+                if(partRef.getPart(false) instanceof SysdynDiagramEditor) {\r
+                    if(((SysdynDiagramEditor)partRef.getPart(false)).equals(editor)) {\r
+                        initializeFields(null);\r
+                    }\r
+                }\r
             }\r
 \r
             @Override\r
@@ -202,8 +207,10 @@ public class ConfigurationView  extends ViewPart {
             this.editor = editor;\r
         } else if(PlatformUI.getWorkbench().getActiveWorkbenchWindow()\r
                 .getActivePage().getActiveEditor() instanceof SysdynDiagramEditor) {\r
-            editor = (SysdynDiagramEditor)PlatformUI.getWorkbench()\r
+            this.editor = (SysdynDiagramEditor)PlatformUI.getWorkbench()\r
             .getActiveWorkbenchWindow().getActivePage().getActiveEditor();\r
+        } else {\r
+            this.editor = null;\r
         }\r
     }\r
 \r
@@ -212,17 +219,30 @@ public class ConfigurationView  extends ViewPart {
         updateMapping();\r
         if(mapping != null)\r
             setFields((Configuration)mapping.get(editor.getResourceInput().getResource()));\r
+        else \r
+            emptyFields();\r
     }\r
 \r
+    private void emptyFields() {\r
+        name.setText("");\r
+        name.setEnabled(false);\r
+        startTime.setText("");\r
+        startTime.setEnabled(false);\r
+        stopTime.setText("");\r
+        stopTime.setEnabled(false);\r
+    }\r
     private void setFields(Configuration conf) {\r
 \r
         if(editor != null && mapping != null) {       \r
             originalName = conf.name;\r
             name.setText(originalName);\r
+            name.setEnabled(true);\r
             originalStart = conf.startTime.toString();\r
             startTime.setText(originalStart);\r
+            startTime.setEnabled(true);\r
             originalStop = conf.stopTime.toString();\r
             stopTime.setText(originalStop);\r
+            stopTime.setEnabled(true);\r
             setPartName(conf.name);\r
         }\r
 \r
@@ -341,6 +361,8 @@ public class ConfigurationView  extends ViewPart {
 \r
             };\r
             mapping.addMappingListener(mappingListener);\r
+        } else {\r
+            mapping = null;\r
         }\r
     }\r
 }\r
index 9c65ec2e0d445aa04dfd306272c854efe74ba810..307f1f205d74df9002ae6200be24c1cfd18525d1 100644 (file)
@@ -17,6 +17,8 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.IEditorReference;\r
+import org.eclipse.ui.PlatformUI;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.Resource;\r
@@ -24,6 +26,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.CancelTransactionException;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
@@ -63,6 +66,19 @@ public class UnlinkNodeHandler extends AbstractHandler {
         } catch (DatabaseException e) {\r
             ExceptionUtils.logAndShowError(e);\r
         }\r
+\r
+        for (Resource r : resources) {\r
+            IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();\r
+            for(IEditorReference er : editorReferences) {\r
+                if(er.getEditor(false) instanceof SysdynDiagramEditor) {\r
+                    SysdynDiagramEditor editor = (SysdynDiagramEditor)er.getEditor(false);\r
+                    if(editor.getResourceInput().getResource().equals(r)) {\r
+                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
     }\r
 \r
 }
\ No newline at end of file