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