-/*******************************************************************************\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 java.io.File;\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.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.FileDialog;\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.FileNameValidator;\r
-\r
-/**\r
- * Dialog for adding URL links with additional information\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class FileDetailDialog extends TextInputDialog{\r
-\r
- private String fileName;\r
- private String name;\r
- \r
- Text fileText;\r
- Text nameText;\r
- \r
- IInputValidator fileValidator;\r
- IInputValidator nameValidator;\r
- \r
- Composite annotationComposite;\r
- \r
- AnnotationConfigurator annotationConfigurator;\r
- \r
- public FileDetailDialog(Shell parentShell, Resource lib) {\r
- super(parentShell);\r
- try {\r
- annotationConfigurator = new AnnotationConfigurator(DocumentResource.getInstance(Simantics.getSession()).FileDocument,lib);\r
- } catch (DatabaseException e) {\r
- \r
- }\r
- }\r
- \r
- public String getFileName() {\r
- return fileName;\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(3,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("File:");\r
- fileText = new Text(composite, SWT.SINGLE|SWT.BORDER);\r
- Button browseButton = new Button(composite, SWT.PUSH);\r
- browseButton.setText("Browse");\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 = new Label(composite, SWT.NONE);\r
- label.setText("Annotations:");\r
- annotationComposite = new Composite(composite, SWT.NONE);\r
- annotationComposite.setLayout(new FillLayout());\r
- \r
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fileText);\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
- fileValidator = new FileNameValidator();\r
- \r
- fileText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- if (validate(fileText, fileValidator)) {\r
- fileName = fileText.getText();\r
- updateName();\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
- browseButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- FileDialog dialog = new FileDialog(e.display.getActiveShell(),SWT.OPEN);\r
- dialog.setFilterExtensions(new String[]{"*.*"});\r
- String s = dialog.open();\r
- if (s != null) {\r
- name = null;\r
- fileText.setText(s);\r
- }\r
- }\r
- });\r
- \r
- annotationConfigurator.createComposite(annotationComposite);\r
- \r
- return composite;\r
- }\r
- \r
- private void updateName() {\r
- if (fileName.length() > 0) {\r
- String proposal = new File(fileName).getName();\r
- String newName = updateName(proposal, name);\r
- if (newName != null) {\r
- name = newName;\r
- nameText.setText(name);\r
- }\r
- }\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
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.document.ui.dialogs;
+
+import java.io.File;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.document.DocumentResource;
+import org.simantics.utils.ui.validators.FileNameValidator;
+
+/**
+ * Dialog for adding URL links with additional information
+ *
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class FileDetailDialog extends TextInputDialog{
+
+ private String fileName;
+ private String name;
+
+ Text fileText;
+ Text nameText;
+
+ IInputValidator fileValidator;
+ IInputValidator nameValidator;
+
+ Composite annotationComposite;
+
+ AnnotationConfigurator annotationConfigurator;
+
+ public FileDetailDialog(Shell parentShell, Resource lib) {
+ super(parentShell);
+ try {
+ annotationConfigurator = new AnnotationConfigurator(DocumentResource.getInstance(Simantics.getSession()).FileDocument,lib);
+ } catch (DatabaseException e) {
+
+ }
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout layout = new GridLayout(3,false);
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ GridDataFactory.fillDefaults().hint(500, 500).applyTo(composite);
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("File:");
+ fileText = new Text(composite, SWT.SINGLE|SWT.BORDER);
+ Button browseButton = new Button(composite, SWT.PUSH);
+ browseButton.setText("Browse");
+ label = new Label(composite, SWT.NONE);
+ label.setText("Name:");
+ nameText = new Text(composite, SWT.SINGLE|SWT.BORDER);
+ label = new Label(composite, SWT.NONE);
+ label = new Label(composite, SWT.NONE);
+ label.setText("Annotations:");
+ annotationComposite = new Composite(composite, SWT.NONE);
+ annotationComposite.setLayout(new FillLayout());
+
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fileText);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(nameText);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(annotationComposite);
+
+ fileValidator = new FileNameValidator();
+
+ fileText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (validate(fileText, fileValidator)) {
+ fileName = fileText.getText();
+ updateName();
+ }
+ }
+ });
+
+ nameText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (validate(nameText,nameValidator)) {
+ name = nameText.getText();
+ }
+
+ }
+ });
+
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(e.display.getActiveShell(),SWT.OPEN);
+ dialog.setFilterExtensions(new String[]{"*.*"});
+ String s = dialog.open();
+ if (s != null) {
+ name = null;
+ fileText.setText(s);
+ }
+ }
+ });
+
+ annotationConfigurator.createComposite(annotationComposite);
+
+ return composite;
+ }
+
+ private void updateName() {
+ if (fileName.length() > 0) {
+ String proposal = new File(fileName).getName();
+ String newName = updateName(proposal, name);
+ if (newName != null) {
+ name = newName;
+ nameText.setText(name);
+ }
+ }
+ }
+
+ public void setNameValidator(IInputValidator nameValidator) {
+ this.nameValidator = nameValidator;
+ }
+
+ public AnnotationConfigurator getAnnotationConfigurator() {
+ return annotationConfigurator;
+ }
+
+
+}