From 274dafebfa6010f020c9e0dff15d1223c97614c0 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 4 Mar 2010 15:35:01 +0000 Subject: [PATCH] Configuration rename from Configuration View git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14573 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/configuration/ConfigurationView.java | 45 +++++++++++++++---- .../sysdyn/ui/editor/SysdynDiagramEditor.java | 26 +++++++++-- 2 files changed, 60 insertions(+), 11 deletions(-) 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 35c887bc..226a2c53 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 @@ -35,8 +35,10 @@ public class ConfigurationView extends ViewPart { static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL); SysdynDiagramEditor editor; + Text name; Text startTime; Text stopTime; + String originalName; String originalStart; String originalStop; boolean disposed = false; @@ -47,18 +49,37 @@ public class ConfigurationView extends ViewPart { public void createPartControl(Composite parent) { GridDataFactory.fillDefaults().applyTo(parent); GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).spacing(3, 3).applyTo(parent); - + Label label = new Label(parent, SWT.NONE); - label.setText("Start time"); + label.setText("Name"); - startTime = new Text(parent, SWT.BORDER | SWT.RIGHT); - int columns = 10; - GC gc = new GC (startTime); + name = new Text(parent, SWT.BORDER); + int columns = 35; + GC gc = new GC (name); FontMetrics fm = gc.getFontMetrics (); int width = columns * fm.getAverageCharWidth (); int height = fm.getHeight (); gc.dispose (); - Point size = startTime.computeSize(width, height); + Point size = name.computeSize(width, height); + name.setFont(FONT); + GridDataFactory.fillDefaults().hint(size).applyTo(name); + name.addKeyListener(new EscListener()); + name.addVerifyListener(new VerifyListener() { + + @Override + public void verifyText(VerifyEvent e) { + e.doit = false; + String s = e.text; + if(!s.contains(" ")) { + e.doit = true; + } + } + }); + + label = new Label(parent, SWT.NONE); + label.setText("Start time"); + + startTime = new Text(parent, SWT.BORDER | SWT.RIGHT); startTime.setFont(FONT); GridDataFactory.fillDefaults().hint(size).applyTo(startTime); startTime.addKeyListener(new EscListener()); @@ -104,6 +125,10 @@ public class ConfigurationView extends ViewPart { Configuration conf = model.getConfiguration(); final IMapping mapping = model.getMapping(); + if(!conf.name.equals(name.getText())){ + conf.name = name.getText(); + modified = true; + } if(conf.startTime != Double.parseDouble(startTime.getText())){ conf.startTime = Double.parseDouble(startTime.getText()); modified = true; @@ -180,6 +205,8 @@ public class ConfigurationView extends ViewPart { SysdynModel model = sdm.getModel(rei.getResource()); Configuration conf = model.getConfiguration(); + originalName = conf.name; + name.setText(originalName); originalStart = conf.startTime.toString(); startTime.setText(originalStart); originalStop = conf.stopTime.toString(); @@ -195,9 +222,11 @@ public class ConfigurationView extends ViewPart { public void keyPressed(KeyEvent e) { Text text = (Text)e.widget; String originalText = null; - if(text == startTime) + if(text == name) + originalText = originalName; + else if(text == startTime) originalText = originalStart; - if(text == stopTime) + else if(text == stopTime) originalText = originalStop; if(e.keyCode == SWT.ESC && originalText != null) { text.setText(originalText); 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 1ec2b923..3e5d69f7 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 @@ -42,6 +42,10 @@ import org.simantics.sysdyn.ui.actions.CreateValve; import org.simantics.sysdyn.ui.actions.OpenContextMenu; import org.simantics.ui.SimanticsUI; import org.simantics.ui.workbench.ResourceEditorPart; +import org.simantics.ui.workbench.TitleRequest; +import org.simantics.ui.workbench.TitleUpdater; +import org.simantics.utils.datastructures.Callable; +import org.simantics.utils.datastructures.Callback; import org.simantics.utils.ui.jface.ActiveSelectionProvider; public class SysdynDiagramEditor extends ResourceEditorPart { @@ -50,7 +54,8 @@ public class SysdynDiagramEditor extends ResourceEditorPart { IDiagram diagram; IMapping mapping; Frame frame; - + boolean disposed = false; + IElementListener elementUpdateListener = new IElementListener() { @Override @@ -141,6 +146,20 @@ public class SysdynDiagramEditor extends ResourceEditorPart { } }); + + SimanticsUI.getSession().asyncRequest( + new TitleRequest(site.getId(), getResourceInput()), + 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) { // TODO Auto-generated catch block e.printStackTrace(); @@ -212,10 +231,11 @@ public class SysdynDiagramEditor extends ResourceEditorPart { public void dispose() { mapping.dispose(); frame.dispose(); - + disposed = true; } - @Override + @SuppressWarnings("unchecked") + @Override public Object getAdapter(Class adapter) { if (adapter == INode.class) { return canvas.getEditor().getSceneGraph(); -- 2.47.1