]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.ui/src/org/simantics/document/ui/dialogs/UrlDetailDialog.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.document.ui / src / org / simantics / document / ui / dialogs / UrlDetailDialog.java
diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/dialogs/UrlDetailDialog.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/dialogs/UrlDetailDialog.java
new file mode 100644 (file)
index 0000000..cd2e02d
--- /dev/null
@@ -0,0 +1,165 @@
+/*******************************************************************************\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.document.ui.dialogs;\r
+\r
+import org.eclipse.jface.dialogs.IDialogConstants;\r
+import org.eclipse.jface.dialogs.IInputValidator;\r
+import org.eclipse.jface.layout.GridDataFactory;\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.layout.FillLayout;\r
+import org.eclipse.swt.layout.GridLayout;\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.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.document.DocumentResource;\r
+import org.simantics.utils.ui.validators.URLValidator;\r
+\r
+/**\r
+ * Dialog for adding URL links with additional information\r
+ * \r
+ * Note: AnnotationConfigurator must be disposed manually.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class UrlDetailDialog extends TextInputDialog{\r
+\r
+       private String url;\r
+       private String name;\r
+       \r
+       Text urlText;\r
+       Text nameText;\r
+       \r
+       IInputValidator urlValidator;\r
+       IInputValidator nameValidator;\r
+       \r
+       Composite annotationComposite;\r
+       \r
+       AnnotationConfigurator annotationConfigurator;\r
+\r
+       //PropertyTable annotationTable;\r
+       \r
+\r
+       \r
+       public UrlDetailDialog(Shell parentShell, Resource lib) {\r
+               super(parentShell);\r
+               try {\r
+                       annotationConfigurator = new AnnotationConfigurator(DocumentResource.getInstance(Simantics.getSession()).UrlDocument,lib);\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       public String getUrl() {\r
+               return url;\r
+       }\r
+       \r
+       public String getName() {\r
+               return name;\r
+       }\r
+       \r
+       @Override\r
+       protected Control createDialogArea(Composite parent) {\r
+               Composite composite = (Composite) super.createDialogArea(parent);\r
+               GridLayout layout = new GridLayout(2,false);\r
+               layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);\r
+               layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);\r
+               layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);\r
+               layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);\r
+               composite.setLayout(layout);\r
+               GridDataFactory.fillDefaults().hint(500, 500).applyTo(composite);\r
+               \r
+               Label label = new Label(composite, SWT.NONE);\r
+               label.setText("URL:");\r
+               urlText = new Text(composite, SWT.SINGLE|SWT.BORDER);\r
+               label = new Label(composite, SWT.NONE);\r
+               label.setText("Name:");\r
+               nameText = new Text(composite, SWT.SINGLE|SWT.BORDER);\r
+               label = new Label(composite, SWT.NONE);\r
+               label.setText("Annotations:");\r
+               annotationComposite = new Composite(composite, SWT.BORDER);\r
+               annotationComposite.setLayout(new FillLayout());\r
+//             \r
+               \r
+               GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(urlText);\r
+               GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(nameText);\r
+               GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(annotationComposite);\r
+               \r
+               urlValidator = new URLValidator();\r
+               \r
+               \r
+               urlText.addModifyListener(new ModifyListener() {\r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               if (validate(urlText, urlValidator)) {\r
+                                       url = urlText.getText();\r
+                                       updateName();\r
+                               }\r
+                               \r
+                       }\r
+               });\r
+               \r
+               nameText.addModifyListener(new ModifyListener() {\r
+                       \r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               if (validate(nameText,nameValidator)) {\r
+                                       name = nameText.getText();\r
+                               }\r
+                               \r
+                       }\r
+               });\r
+               \r
+               annotationConfigurator.createComposite(annotationComposite);\r
+               \r
+               //annotationHolder = createAnnotationHolder();\r
+               \r
+               \r
+               \r
+               \r
+\r
+               \r
+               return composite;\r
+       }\r
+       \r
+       private void updateName() {\r
+               if (url.length() > 0 ) {\r
+                       String newName = updateName(url, name);\r
+                       if (newName != null) {\r
+                               name = newName;\r
+                               nameText.setText(name);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public void setUrlValidator(IInputValidator urlValidator) {\r
+               this.urlValidator = urlValidator;\r
+       }\r
+       \r
+       public void setNameValidator(IInputValidator nameValidator) {\r
+               this.nameValidator = nameValidator;\r
+       }\r
+       \r
+       public AnnotationConfigurator getAnnotationConfigurator() {\r
+               return annotationConfigurator;\r
+       }\r
+       \r
+\r
+       \r
+}\r