+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.ui.configuration;\r
-\r
-import javax.swing.SwingUtilities;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.events.KeyListener;\r
-import org.eclipse.swt.events.VerifyEvent;\r
-import org.eclipse.swt.events.VerifyListener;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.graphics.FontMetrics;\r
-import org.eclipse.swt.graphics.GC;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IPartListener2;\r
-import org.eclipse.ui.IWorkbenchPartReference;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.part.ViewPart;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.objmap.IMapping;\r
-import org.simantics.objmap.IMappingListener;\r
-import org.simantics.sysdyn.manager.SysdynModel;\r
-import org.simantics.sysdyn.manager.SysdynModelManager;\r
-import org.simantics.sysdyn.representation.Configuration;\r
-import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.workbench.ResourceEditorInput;\r
-\r
-public class ConfigurationView extends ViewPart {\r
-\r
- static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL);\r
-\r
- IMapping mapping;\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
-\r
- IPartListener2 editorSelectionListener;\r
- IMappingListener mappingListener;\r
-\r
- @Override\r
- 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
- Label label = new Label(parent, SWT.NONE);\r
- label.setText("Name");\r
-\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 = 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
- startTime.addVerifyListener(new DoubleVerify());\r
-\r
- label = new Label(parent, SWT.NONE);\r
- label.setText("Stop time");\r
-\r
- stopTime = new Text(parent, SWT.BORDER | SWT.RIGHT);\r
- stopTime.setFont(FONT);\r
- GridDataFactory.fillDefaults().hint(size).applyTo(stopTime);\r
- stopTime.addKeyListener(new EscListener());\r
- stopTime.addVerifyListener(new DoubleVerify());\r
-\r
- editorSelectionListener = new IPartListener2() {\r
-\r
-\r
- @Override\r
- public void partActivated(IWorkbenchPartReference partRef) {\r
- if(partRef.getPart(false) instanceof SysdynDiagramEditor) {\r
- if(!((SysdynDiagramEditor)partRef.getPart(false)).equals(editor)) {\r
- initializeFields((SysdynDiagramEditor)partRef.getPart(false));\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public void partBroughtToTop(IWorkbenchPartReference partRef) {\r
- }\r
-\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
- public void partDeactivated(IWorkbenchPartReference partRef) {\r
- if(partRef.getPart(false) instanceof ConfigurationView && !disposed && editor != null && mapping != null) {\r
- boolean modified = false;\r
-\r
- Configuration conf = (Configuration)mapping.get(editor.getResourceInput().getResource());\r
-\r
- if(!conf.name.equals(name.getText())){\r
- conf.name = name.getText();\r
- modified = true;\r
- }\r
- if(startTime.getText().length() > 0 &&\r
- conf.startTime != Double.parseDouble(startTime.getText())){\r
- conf.startTime = Double.parseDouble(startTime.getText());\r
- modified = true;\r
- }\r
- if(stopTime.getText().length() > 0 &&\r
- conf.stopTime != Double.parseDouble(stopTime.getText())) { \r
- conf.stopTime = Double.parseDouble(stopTime.getText());\r
- modified = true;\r
- }\r
-\r
- if(modified) {\r
- mapping.rangeModified(conf); \r
- }\r
-\r
-\r
-\r
- }\r
- }\r
-\r
- @Override\r
- public void partHidden(IWorkbenchPartReference partRef) {\r
- }\r
-\r
- @Override\r
- public void partInputChanged(IWorkbenchPartReference partRef) {\r
- }\r
-\r
- @Override\r
- public void partOpened(IWorkbenchPartReference partRef) {\r
- }\r
-\r
- @Override\r
- public void partVisible(IWorkbenchPartReference partRef) {\r
- }\r
- };\r
- this.getViewSite().getPage().addPartListener(editorSelectionListener); \r
-\r
- IEditorPart iep = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();\r
- if (iep != null && iep instanceof SysdynDiagramEditor)\r
- initializeFields((SysdynDiagramEditor)iep);\r
- else\r
- initializeFields(null);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- this.getViewSite().getPage().removePartListener(editorSelectionListener);\r
- if(this.mapping != null)\r
- this.mapping.removeMappingListener(mappingListener);\r
- disposed = true;\r
- super.dispose();\r
- }\r
-\r
- private void updateEditor(SysdynDiagramEditor editor) {\r
- if(editor != null) {\r
- this.editor = editor;\r
- } else if(PlatformUI.getWorkbench().getActiveWorkbenchWindow()\r
- .getActivePage().getActiveEditor() instanceof SysdynDiagramEditor) {\r
- this.editor = (SysdynDiagramEditor)PlatformUI.getWorkbench()\r
- .getActiveWorkbenchWindow().getActivePage().getActiveEditor();\r
- } else {\r
- this.editor = null;\r
- }\r
- }\r
-\r
- private void initializeFields(SysdynDiagramEditor editor) {\r
- updateEditor(editor);\r
- updateMapping();\r
- if(mapping != null && editor != 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
- setPartName("Configuration View");\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
- }\r
-\r
- private class EscListener implements KeyListener {\r
-\r
- @Override\r
- public void keyPressed(KeyEvent e) {\r
- if(e.keyCode == SWT.ESC) {\r
- Text text = (Text)e.widget;\r
- if(text == name) {\r
- text.setText(originalName);\r
- text.setSelection(text.getCharCount());\r
- } else if(text == startTime) {\r
- text.setText(originalStart);\r
- text.setSelection(0);\r
- } else if(text == stopTime) {\r
- text.setText(originalStop);\r
- text.setSelection(0);\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public void keyReleased(KeyEvent e) { \r
- }\r
-\r
- }\r
-\r
- private class DoubleVerify implements VerifyListener {\r
-\r
- @Override\r
- public void verifyText(VerifyEvent e) {\r
- e.doit = true;\r
- for(int i = 0; i < e.text.length(); i++){\r
- if(!Character.isDigit(e.text.charAt(i))){\r
- if(e.text.charAt(i) != '.') {\r
- e.doit = false;\r
- break; \r
- } else if(e.text.indexOf('.') != e.text.lastIndexOf('.')) {\r
- e.doit = false;\r
- break; \r
- } else if(((Text)e.widget).getText().substring(0, e.start).contains(".") ||\r
- ((Text)e.widget).getText().substring(e.end, ((Text)e.widget).getText().length()).contains(".")) {\r
- e.doit = false;\r
- break; \r
- }\r
- } \r
- }\r
- }\r
- }\r
-\r
- private void updateMapping() {\r
- if(editor != null) {\r
- IEditorInput input = editor.getEditorInput();\r
- ResourceEditorInput rei = (ResourceEditorInput) input;\r
- SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession());\r
- SysdynModel model = sdm.getModel(rei.getResource()); \r
- mapping = model.getMapping();\r
- mappingListener = new IMappingListener() {\r
-\r
- @Override\r
- public void rangeModified() {\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- try {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() { \r
- @Override\r
- public void perform(WriteGraph graph)\r
- throws DatabaseException {\r
- mapping.updateDomain(graph);\r
- } \r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- } \r
- }\r
-\r
- }); \r
- }\r
-\r
- @Override\r
- public void domainModified() {\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- try {\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() { \r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- mapping.updateRange(graph);\r
- if(editor != null && !disposed) {\r
- name.getDisplay().asyncExec(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- Configuration conf = (Configuration)mapping.get(editor.getResourceInput().getResource());\r
- setFields(conf); \r
- }\r
- });\r
-\r
- }\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- } \r
- }\r
-\r
- }); \r
- }\r
-\r
- };\r
- mapping.addMappingListener(mappingListener);\r
- } else {\r
- mapping = null;\r
- }\r
- }\r
-\r
- @Override\r
- public void setFocus() {\r
- name.setFocus();\r
- name.setSelection(name.getCharCount());\r
- }\r
-}\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.FocusListener;\r
+import org.eclipse.swt.events.VerifyEvent;\r
+import org.eclipse.swt.events.VerifyListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Group;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.TextWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+\r
+public class VariableInformationTab extends PropertyTabContributorImpl {\r
+\r
+ TextWidget information, rangeStart, rangeEnd, rangeStep;\r
+ \r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+ Composite composite = new Composite(body, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite);\r
+ \r
+ Group informationGroup = new Group(composite, SWT.SHADOW_ETCHED_IN);\r
+ informationGroup.setText("Information");\r
+ GridDataFactory.fillDefaults().grab(false, true).applyTo(informationGroup);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(informationGroup);\r
+ \r
+ information = new TextWidget(informationGroup, support, SWT.MULTI | SWT.BORDER);\r
+ information.setTextFactory(new StringPropertyFactory(context, Builtins.URIs.HasDescription));\r
+ information.addFocusListener(new SaveListener());\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getTextWidget());\r
+ \r
+ \r
+ Group rangeGroup = new Group(composite, SWT.SHADOW_ETCHED_IN);\r
+ rangeGroup.setText("Range");\r
+ GridDataFactory.fillDefaults().applyTo(rangeGroup);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(rangeGroup);\r
+ \r
+ Label label = new Label(rangeGroup, SWT.NONE);\r
+ label.setText("Start");\r
+ \r
+ rangeStart = new TextWidget(rangeGroup, support, SWT.BORDER | SWT.RIGHT);\r
+ rangeStart.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasRangeStart));\r
+ rangeStart.addFocusListener(new SaveListener());\r
+ rangeStart.addVerifyListener(new DoubleVerify());\r
+\r
+ label = new Label(rangeGroup, SWT.NONE);\r
+ label.setText("End");\r
+ \r
+ rangeEnd = new TextWidget(rangeGroup, support, SWT.BORDER | SWT.RIGHT);\r
+ rangeEnd.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasRangeEnd));\r
+ rangeEnd.addFocusListener(new SaveListener());\r
+ rangeEnd.addVerifyListener(new DoubleVerify());\r
+\r
+ label = new Label(rangeGroup, SWT.NONE);\r
+ label.setText("Step");\r
+ \r
+ rangeStep = new TextWidget(rangeGroup, support, SWT.BORDER | SWT.RIGHT);\r
+ rangeStep.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasRangeStep));\r
+ rangeStep.addFocusListener(new SaveListener());\r
+ rangeStep.addVerifyListener(new DoubleVerify());\r
+ \r
+ }\r
+ \r
+ \r
+ private class SaveListener implements FocusListener {\r
+\r
+ @Override\r
+ public void focusGained(FocusEvent e) {\r
+ }\r
+\r
+ @Override\r
+ public void focusLost(FocusEvent e) {\r
+ save();\r
+ }\r
+ \r
+ }\r
+ \r
+ private void save() {\r
+ this.information.save();\r
+ this.rangeStart.save();\r
+ this.rangeEnd.save();\r
+ this.rangeStep.save();\r
+ }\r
+\r
+ private class DoubleVerify implements VerifyListener {\r
+\r
+ @Override\r
+ public void verifyText(VerifyEvent e) {\r
+ e.doit = true;\r
+ for(int i = 0; i < e.text.length(); i++){\r
+ if(!Character.isDigit(e.text.charAt(i))){\r
+ if(e.text.charAt(i) != '.') {\r
+ e.doit = false;\r
+ break; \r
+ } else if(e.text.indexOf('.') != e.text.lastIndexOf('.')) {\r
+ e.doit = false;\r
+ break; \r
+ } else if(((Text)e.widget).getText().substring(0, e.start).contains(".") ||\r
+ ((Text)e.widget).getText().substring(e.end, ((Text)e.widget).getText().length()).contains(".")) {\r
+ e.doit = false;\r
+ break; \r
+ }\r
+ } \r
+ }\r
+ }\r
+ }\r
+}\r