]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportPage.java
Option for exporting tg and pgraph with sharedlibrary
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / sharedontology / wizard / SharedOntologyImportPage.java
index 5b032a3d3464c1e7689c225877e68cd9c057afdf..b947981ec4976b0d5eb7c3371b5bb375b9a4a83c 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * 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.modeling.ui.sharedontology.wizard;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CCombo;\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.GridData;\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.FileDialog;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.adapter.AdaptException;\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.databoard.container.DataContainer;\r
-import org.simantics.databoard.container.DataContainers;\r
-import org.simantics.db.common.NamedResource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.util.DraftStatusBean;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class SharedOntologyImportPage extends WizardPage {\r
-\r
-    /**\r
-     * If non-null, the wizard cannot continue. This message tells why.\r
-     */\r
-    String              failure;\r
-\r
-    ImportPlan          importModel;\r
-\r
-    Composite           draft;\r
-    \r
-    Text                importTarget;\r
-    CCombo              importLocation;\r
-\r
-    List<NamedResource> models = Collections.emptyList();\r
-    Label               author;\r
-    Label               status;\r
-\r
-    protected SharedOntologyImportPage(ImportPlan model) {\r
-        super("Import Shared Library", "Define Import Location", null);\r
-        this.importModel = model;\r
-    }\r
-\r
-    @Override\r
-    public void createControl(Composite parent) {\r
-        Composite container = new Composite(parent, SWT.NONE);\r
-        {\r
-            GridLayout layout = new GridLayout();\r
-            layout.horizontalSpacing = 20;\r
-            layout.verticalSpacing = 10;\r
-            layout.numColumns = 3;\r
-            container.setLayout(layout);\r
-        }\r
-\r
-        draft = new Composite(container, SWT.NONE);\r
-        draft.setBackground(draft.getDisplay().getSystemColor(SWT.COLOR_RED));\r
-        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(draft);\r
-       GridLayoutFactory.swtDefaults().numColumns(0).margins(0, 0).applyTo(draft);\r
-        \r
-        Composite draft2 = new Composite(draft, SWT.NONE);\r
-        GridLayoutFactory.swtDefaults().applyTo(draft2);\r
-        GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(draft2);\r
-        new Label(draft2, SWT.NONE).setText("This library draft was not finished for publishing.");\r
-        \r
-        new Label(container, SWT.NONE).setText("&Shared library file:");\r
-        importLocation = new CCombo(container, SWT.BORDER);\r
-        {\r
-            importLocation.setText("");\r
-            GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(importLocation);\r
-            importLocation.addModifyListener(new ModifyListener(){\r
-                @Override\r
-                public void modifyText(ModifyEvent e) {\r
-                    validatePage();\r
-                }\r
-            });\r
-        }\r
-        Button browseFileButton = new Button(container, SWT.PUSH);\r
-        {\r
-            browseFileButton.setText("Br&owse...");\r
-            browseFileButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-            browseFileButton.addSelectionListener(new SelectionAdapter() {\r
-                @Override\r
-                public void widgetSelected(SelectionEvent e) {\r
-                    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);\r
-                    dialog.setText("Choose Shared Library to Import");\r
-                    String loc = importLocation.getText();\r
-                    dialog.setFilterPath(loc);\r
-                    dialog.setFilterExtensions(new String[] { "*.sharedLibrary" });\r
-                    dialog.setFilterNames(new String[] { "Shared Library (*.sharedLibrary)" });\r
-                    String file = dialog.open();\r
-                    if (file == null)\r
-                        return;\r
-                    importLocation.setText(file);\r
-                    validatePage();\r
-                }\r
-            });\r
-        }\r
-        \r
-        author = new Label(container, SWT.NONE);\r
-        author.setText("");\r
-        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(author);\r
-\r
-        status = new Label(container, SWT.NONE);\r
-        status.setText("");\r
-        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(status);\r
-\r
-        try {\r
-            initializeData();\r
-        } catch (DatabaseException e) {\r
-            ErrorLogger.defaultLogError(e);\r
-        }\r
-\r
-        setControl(container);\r
-        validatePage();\r
-    }\r
-\r
-    private void initializeData() throws DatabaseException {\r
-        for (String path : importModel.recentLocations) {\r
-            importLocation.add(path);\r
-        }\r
-        if (importLocation.getItemCount() > 0)\r
-            importLocation.select(0);\r
-    }\r
-\r
-    void validatePage() {\r
-       \r
-        if (failure != null) {\r
-            setErrorMessage(failure);\r
-            setPageComplete(false);\r
-            return;\r
-        }\r
-        String importLoc = importLocation.getText();\r
-        if (importLoc.isEmpty()) {\r
-            setMessage("Select file to import.");\r
-            setErrorMessage(null);\r
-            setPageComplete(false);\r
-            return;\r
-        }\r
-        File file = new File(importLoc);\r
-        if (!file.exists() || !file.isFile()) {\r
-            setErrorMessage("Selected file is invalid.");\r
-            setPageComplete(false);\r
-            return;\r
-        }\r
-        importModel.importLocation = file;\r
-\r
-        try {\r
-\r
-               DataContainer container = DataContainers.readHeader(file);\r
-               Variant draftStatus = container.metadata.get(DraftStatusBean.EXTENSION_KEY);\r
-               if(draftStatus != null) {\r
-                       GridLayoutFactory.swtDefaults().spacing(5, 5).applyTo(draft);\r
-                       draft.getParent().layout(true);\r
-               } else {\r
-                       GridLayoutFactory.swtDefaults().numColumns(0).margins(0, 0).applyTo(draft);\r
-                       draft.getParent().layout(true);\r
-               }\r
-               \r
-               Variant authorVariant = container.metadata.get("author");\r
-               Variant dateVariant = container.metadata.get("date");\r
-               \r
-               if(authorVariant != null && dateVariant != null) {\r
-                       String auth = (String)authorVariant.getValue(Bindings.STRING);\r
-                       String date = (String)dateVariant.getValue(Bindings.STRING);\r
-                       author.setText("Created by " + auth + " on " + date);\r
-               } else {\r
-                       author.setText("");\r
-               }\r
-\r
-        } catch (IOException e) {\r
-               setErrorMessage("Could not read header information from " + file.getAbsolutePath());\r
-               setPageComplete(false);\r
-               return;\r
-        } catch (AdaptException e) {\r
-               setErrorMessage("Could not read header information from " + file.getAbsolutePath());\r
-               setPageComplete(false);\r
-               return;\r
-               }           \r
-        \r
-        setErrorMessage(null);\r
-        setMessage("Ready to import " + file.getName() + "");\r
-        setPageComplete(true);\r
-        \r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 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.modeling.ui.sharedontology.wizard;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+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.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.databoard.container.DataContainer;
+import org.simantics.databoard.container.DataContainers;
+import org.simantics.db.common.NamedResource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.DraftStatusBean;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class SharedOntologyImportPage extends WizardPage {
+
+    /**
+     * If non-null, the wizard cannot continue. This message tells why.
+     */
+    String              failure;
+
+    ImportPlan          importModel;
+
+    Composite           draft;
+    
+    Text                importTarget;
+    CCombo              importLocation;
+
+    List<NamedResource> models = Collections.emptyList();
+    Label               author;
+    Label               status;
+
+    protected SharedOntologyImportPage(ImportPlan model) {
+        super("Import Shared Library", "Define Import Location", null);
+        this.importModel = model;
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        Composite container = new Composite(parent, SWT.NONE);
+        {
+            GridLayout layout = new GridLayout();
+            layout.horizontalSpacing = 20;
+            layout.verticalSpacing = 10;
+            layout.numColumns = 3;
+            container.setLayout(layout);
+        }
+
+        draft = new Composite(container, SWT.NONE);
+        draft.setBackground(draft.getDisplay().getSystemColor(SWT.COLOR_RED));
+        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(draft);
+       GridLayoutFactory.swtDefaults().numColumns(0).margins(0, 0).applyTo(draft);
+        
+        Composite draft2 = new Composite(draft, SWT.NONE);
+        GridLayoutFactory.swtDefaults().applyTo(draft2);
+        GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(draft2);
+        new Label(draft2, SWT.NONE).setText("This library draft was not finished for publishing.");
+        
+        new Label(container, SWT.NONE).setText("&Shared library file:");
+        importLocation = new CCombo(container, SWT.BORDER);
+        {
+            importLocation.setText("");
+            GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(importLocation);
+            importLocation.addModifyListener(new ModifyListener(){
+                @Override
+                public void modifyText(ModifyEvent e) {
+                    validatePage();
+                }
+            });
+        }
+        Button browseFileButton = new Button(container, SWT.PUSH);
+        {
+            browseFileButton.setText("Br&owse...");
+            browseFileButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+            browseFileButton.addSelectionListener(new SelectionAdapter() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
+                    dialog.setText("Choose Shared Library to Import");
+                    String loc = importLocation.getText();
+                    dialog.setFilterPath(loc);
+                    dialog.setFilterExtensions(new String[] { "*.sharedLibrary" });
+                    dialog.setFilterNames(new String[] { "Shared Library (*.sharedLibrary)" });
+                    String file = dialog.open();
+                    if (file == null)
+                        return;
+                    importLocation.setText(file);
+                    validatePage();
+                }
+            });
+        }
+        
+        author = new Label(container, SWT.NONE);
+        author.setText("");
+        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(author);
+
+        status = new Label(container, SWT.NONE);
+        status.setText("");
+        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(status);
+
+        try {
+            initializeData();
+        } catch (DatabaseException e) {
+            ErrorLogger.defaultLogError(e);
+        }
+
+        setControl(container);
+        validatePage();
+    }
+
+    private void initializeData() throws DatabaseException {
+        for (String path : importModel.recentLocations) {
+            importLocation.add(path);
+        }
+        if (importLocation.getItemCount() > 0)
+            importLocation.select(0);
+    }
+
+    void validatePage() {
+       
+        if (failure != null) {
+            setErrorMessage(failure);
+            setPageComplete(false);
+            return;
+        }
+        String importLoc = importLocation.getText();
+        if (importLoc.isEmpty()) {
+            setMessage("Select file to import.");
+            setErrorMessage(null);
+            setPageComplete(false);
+            return;
+        }
+        File file = new File(importLoc);
+        if (!file.exists() || !file.isFile()) {
+            setErrorMessage("Selected file is invalid.");
+            setPageComplete(false);
+            return;
+        }
+        importModel.importLocation = file;
+
+        try {
+
+               DataContainer container = DataContainers.readHeader(file);
+               Variant draftStatus = container.metadata.get(DraftStatusBean.EXTENSION_KEY);
+               if(draftStatus != null) {
+                       GridLayoutFactory.swtDefaults().spacing(5, 5).applyTo(draft);
+                       draft.getParent().layout(true);
+               } else {
+                       GridLayoutFactory.swtDefaults().numColumns(0).margins(0, 0).applyTo(draft);
+                       draft.getParent().layout(true);
+               }
+               
+               Variant authorVariant = container.metadata.get("author");
+               Variant dateVariant = container.metadata.get("date");
+               
+               if(authorVariant != null && dateVariant != null) {
+                       String auth = (String)authorVariant.getValue(Bindings.STRING);
+                       String date = (String)dateVariant.getValue(Bindings.STRING);
+                       author.setText("Created by " + auth + " on " + date);
+               } else {
+                       author.setText("");
+               }
+
+        } catch (IOException e) {
+               setErrorMessage("Could not read header information from " + file.getAbsolutePath());
+               setPageComplete(false);
+               return;
+        } catch (AdaptException e) {
+               setErrorMessage("Could not read header information from " + file.getAbsolutePath());
+               setPageComplete(false);
+               return;
+               }           
+        
+        setErrorMessage(null);
+        setMessage("Ready to import " + file.getName() + "");
+        setPageComplete(true);
+        
+    }
+
+}