1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.document.ui.dialogs;
\r
14 import org.eclipse.jface.dialogs.IDialogConstants;
\r
15 import org.eclipse.jface.dialogs.IInputValidator;
\r
16 import org.eclipse.jface.layout.GridDataFactory;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.events.ModifyEvent;
\r
19 import org.eclipse.swt.events.ModifyListener;
\r
20 import org.eclipse.swt.layout.FillLayout;
\r
21 import org.eclipse.swt.layout.GridLayout;
\r
22 import org.eclipse.swt.widgets.Composite;
\r
23 import org.eclipse.swt.widgets.Control;
\r
24 import org.eclipse.swt.widgets.Label;
\r
25 import org.eclipse.swt.widgets.Shell;
\r
26 import org.eclipse.swt.widgets.Text;
\r
27 import org.simantics.Simantics;
\r
28 import org.simantics.db.Resource;
\r
29 import org.simantics.db.exception.DatabaseException;
\r
30 import org.simantics.document.DocumentResource;
\r
31 import org.simantics.utils.ui.validators.URLValidator;
\r
34 * Dialog for adding URL links with additional information
\r
36 * Note: AnnotationConfigurator must be disposed manually.
\r
38 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
41 public class UrlDetailDialog extends TextInputDialog{
\r
44 private String name;
\r
49 IInputValidator urlValidator;
\r
50 IInputValidator nameValidator;
\r
52 Composite annotationComposite;
\r
54 AnnotationConfigurator annotationConfigurator;
\r
56 //PropertyTable annotationTable;
\r
60 public UrlDetailDialog(Shell parentShell, Resource lib) {
\r
63 annotationConfigurator = new AnnotationConfigurator(DocumentResource.getInstance(Simantics.getSession()).UrlDocument,lib);
\r
64 } catch (DatabaseException e) {
\r
69 public String getUrl() {
\r
73 public String getName() {
\r
78 protected Control createDialogArea(Composite parent) {
\r
79 Composite composite = (Composite) super.createDialogArea(parent);
\r
80 GridLayout layout = new GridLayout(2,false);
\r
81 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
\r
82 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
\r
83 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
\r
84 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
\r
85 composite.setLayout(layout);
\r
86 GridDataFactory.fillDefaults().hint(500, 500).applyTo(composite);
\r
88 Label label = new Label(composite, SWT.NONE);
\r
89 label.setText("URL:");
\r
90 urlText = new Text(composite, SWT.SINGLE|SWT.BORDER);
\r
91 label = new Label(composite, SWT.NONE);
\r
92 label.setText("Name:");
\r
93 nameText = new Text(composite, SWT.SINGLE|SWT.BORDER);
\r
94 label = new Label(composite, SWT.NONE);
\r
95 label.setText("Annotations:");
\r
96 annotationComposite = new Composite(composite, SWT.BORDER);
\r
97 annotationComposite.setLayout(new FillLayout());
\r
100 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(urlText);
\r
101 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(nameText);
\r
102 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(annotationComposite);
\r
104 urlValidator = new URLValidator();
\r
107 urlText.addModifyListener(new ModifyListener() {
\r
109 public void modifyText(ModifyEvent e) {
\r
110 if (validate(urlText, urlValidator)) {
\r
111 url = urlText.getText();
\r
118 nameText.addModifyListener(new ModifyListener() {
\r
121 public void modifyText(ModifyEvent e) {
\r
122 if (validate(nameText,nameValidator)) {
\r
123 name = nameText.getText();
\r
129 annotationConfigurator.createComposite(annotationComposite);
\r
131 //annotationHolder = createAnnotationHolder();
\r
141 private void updateName() {
\r
142 if (url.length() > 0 ) {
\r
143 String newName = updateName(url, name);
\r
144 if (newName != null) {
\r
146 nameText.setText(name);
\r
151 public void setUrlValidator(IInputValidator urlValidator) {
\r
152 this.urlValidator = urlValidator;
\r
155 public void setNameValidator(IInputValidator nameValidator) {
\r
156 this.nameValidator = nameValidator;
\r
159 public AnnotationConfigurator getAnnotationConfigurator() {
\r
160 return annotationConfigurator;
\r