-package org.simantics.modeling;\r
-\r
-import org.eclipse.jface.dialogs.Dialog;\r
-import org.eclipse.jface.dialogs.IDialogConstants;\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.ModifyEvent;\r
-import org.eclipse.swt.events.ModifyListener;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.simantics.db.common.utils.VersionInfo;\r
-import org.simantics.utils.strings.AlphanumComparator;\r
-\r
-public class CreateVersionDialog extends Dialog {\r
-\r
- private final VersionInfo info;\r
-\r
- private Label errors;\r
- private Text versionTxT;\r
- private String result;\r
- \r
- public CreateVersionDialog(Shell parentShell, VersionInfo info) {\r
- super(parentShell);\r
- this.info = info;\r
- }\r
- \r
- public String mutate(String ver) {\r
- try {\r
- int currentInt = Integer.parseInt(ver);\r
- return "" + (currentInt+1);\r
- } catch (NumberFormatException e) {\r
- if(ver.length() == 1) {\r
- char c = ver.charAt(0);\r
- c++;\r
- Character ch = c; \r
- if(Character.isLetter(ch) && Character.isUpperCase(ch)) return ch.toString();\r
- }\r
- }\r
- return ver + "_1";\r
- }\r
- \r
- public String getSuggestion() {\r
- \r
- String ver = info.version;\r
- while(validateVersion(ver) != null) ver = mutate(ver);\r
- return ver;\r
- \r
- }\r
-\r
- @Override\r
- protected Control createDialogArea(Composite parent) {\r
- Composite c = (Composite) super.createDialogArea(parent);\r
- \r
- GridLayoutFactory.fillDefaults().margins(8, 8).numColumns(2).applyTo(c);\r
- GridDataFactory gd1 = GridDataFactory.fillDefaults().span(2, 1);\r
-\r
- // 1st line\r
- Label label = new Label(c, 0);\r
- label.setText("Current version identifier is: " + info.version);\r
- gd1.applyTo(label);\r
- \r
- // 2nd line\r
- label = new Label(c, 0);\r
- label.setText("New identifier:");\r
- GridDataFactory.fillDefaults().applyTo(label);\r
-\r
- versionTxT = new Text(c, SWT.BORDER);\r
- versionTxT.setText(getSuggestion());\r
- \r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(versionTxT);\r
- \r
- versionTxT.addModifyListener(new ModifyListener() {\r
-\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
-\r
- String result = validateVersion(versionTxT.getText()); \r
- if(result != null) {\r
- errors.setText(result);\r
- getButton(IDialogConstants.OK_ID).setEnabled(false);\r
- Shell shell = errors.getShell();\r
- Point ns = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
- Point cs = shell.getSize();\r
- shell.setSize(Math.max(cs.x, ns.x), Math.max(cs.y, ns.y));\r
- } else {\r
- errors.setText("");\r
- getButton(IDialogConstants.OK_ID).setEnabled(true);\r
- }\r
- \r
- }\r
- \r
- });\r
- \r
- // Errors\r
- errors= new Label(c, 0);\r
- errors.setText("");\r
- errors.setForeground(errors.getDisplay().getSystemColor(SWT.COLOR_RED));\r
- \r
- gd1.applyTo(errors);\r
- \r
- return c;\r
- }\r
- \r
- private String validateVersion(final String version) {\r
- \r
- if(info.containsVersion(version)) return "Version already in use";\r
- if(AlphanumComparator.COMPARATOR.compare(version, info.version) < 0) return "New version must be lexically greater than current";\r
- return null;\r
- \r
- }\r
- \r
- @Override\r
- protected void okPressed() {\r
- result = versionTxT.getText();\r
- super.okPressed();\r
- }\r
- \r
- public String getResult() {\r
- return result;\r
- }\r
-\r
- @Override\r
- protected int getShellStyle() {\r
- return SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.BORDER;\r
- }\r
-\r
- @Override\r
- protected void configureShell(Shell newShell) {\r
- super.configureShell(newShell);\r
- newShell.setText("Create new version of " + info.baseName);\r
- }\r
-}\r
+package org.simantics.modeling;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.db.common.utils.VersionInfo;
+import org.simantics.utils.strings.AlphanumComparator;
+
+public class CreateVersionDialog extends Dialog {
+
+ private final VersionInfo info;
+
+ private Label errors;
+ private Text versionTxT;
+ private String result;
+
+ public CreateVersionDialog(Shell parentShell, VersionInfo info) {
+ super(parentShell);
+ this.info = info;
+ }
+
+ public String mutate(String ver) {
+ try {
+ int currentInt = Integer.parseInt(ver);
+ return "" + (currentInt+1);
+ } catch (NumberFormatException e) {
+ if(ver.length() == 1) {
+ char c = ver.charAt(0);
+ c++;
+ Character ch = c;
+ if(Character.isLetter(ch) && Character.isUpperCase(ch)) return ch.toString();
+ }
+ }
+ return ver + "_1";
+ }
+
+ public String getSuggestion() {
+
+ String ver = info.version;
+ while(validateVersion(ver) != null) ver = mutate(ver);
+ return ver;
+
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite c = (Composite) super.createDialogArea(parent);
+
+ GridLayoutFactory.fillDefaults().margins(8, 8).numColumns(2).applyTo(c);
+ GridDataFactory gd1 = GridDataFactory.fillDefaults().span(2, 1);
+
+ // 1st line
+ Label label = new Label(c, 0);
+ label.setText("Current version identifier is: " + info.version);
+ gd1.applyTo(label);
+
+ // 2nd line
+ label = new Label(c, 0);
+ label.setText("New identifier:");
+ GridDataFactory.fillDefaults().applyTo(label);
+
+ versionTxT = new Text(c, SWT.BORDER);
+ versionTxT.setText(getSuggestion());
+
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(versionTxT);
+
+ versionTxT.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+
+ String result = validateVersion(versionTxT.getText());
+ if(result != null) {
+ errors.setText(result);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ Shell shell = errors.getShell();
+ Point ns = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Point cs = shell.getSize();
+ shell.setSize(Math.max(cs.x, ns.x), Math.max(cs.y, ns.y));
+ } else {
+ errors.setText("");
+ getButton(IDialogConstants.OK_ID).setEnabled(true);
+ }
+
+ }
+
+ });
+
+ // Errors
+ errors= new Label(c, 0);
+ errors.setText("");
+ errors.setForeground(errors.getDisplay().getSystemColor(SWT.COLOR_RED));
+
+ gd1.applyTo(errors);
+
+ return c;
+ }
+
+ private String validateVersion(final String version) {
+
+ if(info.containsVersion(version)) return "Version already in use";
+ if(AlphanumComparator.COMPARATOR.compare(version, info.version) < 0) return "New version must be lexically greater than current";
+ return null;
+
+ }
+
+ @Override
+ protected void okPressed() {
+ result = versionTxT.getText();
+ super.okPressed();
+ }
+
+ public String getResult() {
+ return result;
+ }
+
+ @Override
+ protected int getShellStyle() {
+ return SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.BORDER;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Create new version of " + info.baseName);
+ }
+}