]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Configuration rename from Configuration View
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 4 Mar 2010 15:35:01 +0000 (15:35 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 4 Mar 2010 15:35:01 +0000 (15:35 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14573 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/editor/SysdynDiagramEditor.java

index 35c887bcc3b221c8a18ab322b25fe956b237d129..226a2c536cfed5cb3df0d1325580c20f05db8632 100644 (file)
@@ -35,8 +35,10 @@ public class ConfigurationView  extends ViewPart {
     static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL);\r
 \r
     SysdynDiagramEditor editor;\r
+    Text name;\r
     Text startTime;\r
     Text stopTime;\r
+    String originalName;\r
     String originalStart;\r
     String originalStop;\r
     boolean disposed = false;\r
@@ -47,18 +49,37 @@ public class ConfigurationView  extends ViewPart {
     public void createPartControl(Composite parent) {\r
         GridDataFactory.fillDefaults().applyTo(parent);\r
         GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).spacing(3, 3).applyTo(parent);\r
-\r
+        \r
         Label label = new Label(parent, SWT.NONE);\r
-        label.setText("Start time");\r
+        label.setText("Name");\r
 \r
-        startTime = new Text(parent, SWT.BORDER | SWT.RIGHT);\r
-        int columns = 10;\r
-        GC gc = new GC (startTime);\r
+        name = new Text(parent, SWT.BORDER);\r
+        int columns = 35;\r
+        GC gc = new GC (name);\r
         FontMetrics fm = gc.getFontMetrics ();\r
         int width = columns * fm.getAverageCharWidth ();\r
         int height = fm.getHeight ();\r
         gc.dispose ();        \r
-        Point size = startTime.computeSize(width, height);\r
+        Point size = name.computeSize(width, height);\r
+        name.setFont(FONT);\r
+        GridDataFactory.fillDefaults().hint(size).applyTo(name);\r
+        name.addKeyListener(new EscListener());\r
+        name.addVerifyListener(new VerifyListener() {\r
+            \r
+            @Override\r
+            public void verifyText(VerifyEvent e) {\r
+                e.doit = false;\r
+                String s = e.text;   \r
+                if(!s.contains(" ")) {\r
+                    e.doit = true;\r
+                }\r
+            }\r
+        });\r
+        \r
+        label = new Label(parent, SWT.NONE);\r
+        label.setText("Start time");\r
+\r
+        startTime = new Text(parent, SWT.BORDER | SWT.RIGHT);\r
         startTime.setFont(FONT);\r
         GridDataFactory.fillDefaults().hint(size).applyTo(startTime);\r
         startTime.addKeyListener(new EscListener());\r
@@ -104,6 +125,10 @@ public class ConfigurationView  extends ViewPart {
                     Configuration conf = model.getConfiguration();\r
 \r
                     final IMapping mapping = model.getMapping();\r
+                    if(!conf.name.equals(name.getText())){\r
+                        conf.name = name.getText();\r
+                        modified = true;\r
+                    }\r
                     if(conf.startTime != Double.parseDouble(startTime.getText())){\r
                         conf.startTime = Double.parseDouble(startTime.getText());\r
                         modified = true;\r
@@ -180,6 +205,8 @@ public class ConfigurationView  extends ViewPart {
             SysdynModel model = sdm.getModel(rei.getResource());\r
             Configuration conf = model.getConfiguration();\r
 \r
+            originalName = conf.name;\r
+            name.setText(originalName);\r
             originalStart = conf.startTime.toString();\r
             startTime.setText(originalStart);\r
             originalStop = conf.stopTime.toString();\r
@@ -195,9 +222,11 @@ public class ConfigurationView  extends ViewPart {
         public void keyPressed(KeyEvent e) {\r
             Text text = (Text)e.widget;\r
             String originalText = null;\r
-            if(text == startTime)\r
+            if(text == name)\r
+                originalText = originalName;\r
+            else if(text == startTime)\r
                 originalText = originalStart;\r
-            if(text == stopTime)\r
+            else if(text == stopTime)\r
                 originalText = originalStop;\r
             if(e.keyCode == SWT.ESC && originalText != null) {\r
                 text.setText(originalText);\r
index 1ec2b9234bcdbc8a3f09ef3c1d4ba84549b7b0dd..3e5d69f7d675c72dae61e66b77a415fc590f9a7f 100644 (file)
@@ -42,6 +42,10 @@ import org.simantics.sysdyn.ui.actions.CreateValve;
 import org.simantics.sysdyn.ui.actions.OpenContextMenu;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.workbench.ResourceEditorPart;\r
+import org.simantics.ui.workbench.TitleRequest;\r
+import org.simantics.ui.workbench.TitleUpdater;\r
+import org.simantics.utils.datastructures.Callable;\r
+import org.simantics.utils.datastructures.Callback;\r
 import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
 \r
 public class SysdynDiagramEditor extends ResourceEditorPart {\r
@@ -50,7 +54,8 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
        IDiagram diagram;\r
        IMapping mapping;\r
        Frame frame;\r
-               \r
+       boolean disposed = false;       \r
+       \r
        IElementListener elementUpdateListener = new IElementListener() {\r
         \r
         @Override\r
@@ -141,6 +146,20 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
                                }\r
                                \r
                        });\r
+                       \r
+                       SimanticsUI.getSession().asyncRequest(\r
+                               new TitleRequest(site.getId(), getResourceInput()),\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
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
@@ -212,10 +231,11 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
        public void dispose() {\r
            mapping.dispose();\r
            frame.dispose();\r
-           \r
+           disposed = true;\r
        }\r
        \r
-       @Override\r
+       @SuppressWarnings("unchecked")\r
+    @Override\r
        public Object getAdapter(Class adapter) {\r
            if (adapter == INode.class) {\r
                return canvas.getEditor().getSceneGraph();\r