-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+\r
+public class FunctionTreeFunctionLabeler extends LabelerContributor<FunctionLibraryNode<Resource>>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, FunctionLibraryNode<Resource> input)\r
+ throws DatabaseException {\r
+ String name = NameUtils.getSafeName(graph, input.data);\r
+ return name;\r
+ }\r
+\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class FunctionTreeLibraries extends ViewpointContributor<ModelNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
+ throws DatabaseException {\r
+ ArrayList<FunctionLibraryNode<Resource>> result = new ArrayList<FunctionLibraryNode<Resource>>();\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ for (Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))){\r
+ result.add(new FunctionLibraryNode<Resource>(r));\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class FunctionTreeModelLabeler extends LabelerContributorImpl<ModelNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, ModelNode input)\r
+ throws DatabaseException {\r
+ return NameUtils.getSafeName(graph, input.data);\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class FunctionTreeModels extends ViewpointContributorImpl<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ \r
+\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.SysdynModel))) {\r
+ result.add(new ModelNode(r));\r
+ }\r
+ Resource sharedlibrary = graph.getPossibleResource("http://SharedOntologies");\r
+ if (sharedlibrary != null)\r
+ result.add(new SharedFunctionsFolderNode(sharedlibrary));\r
+ \r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Function Library Import";\r
+ }\r
+ \r
+\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class FunctionTreeSharedFolderLabeler extends LabelerContributorImpl<SharedFunctionsFolderNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SharedFunctionsFolderNode input)\r
+ throws DatabaseException {\r
+ return "Shared Functions";\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class FunctionTreeSharedLibraries extends ViewpointContributor<SharedFunctionsFolderNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, SharedFunctionsFolderNode folder)\r
+ throws DatabaseException {\r
+ ArrayList<SharedFunctionLibraryNode> result = new ArrayList<SharedFunctionLibraryNode>();\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource sharedlibrary = graph.getPossibleResource("http://SharedOntologies");\r
+ for (Resource r : graph.syncRequest(new ObjectsWithType(sharedlibrary, l0.ConsistsOf, sr.SharedFunctionOntology))){\r
+ result.add(new SharedFunctionLibraryNode(r));\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class FunctionTreeSharedLibraryLabeler extends LabelerContributorImpl<SharedFunctionLibraryNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SharedFunctionLibraryNode input)\r
+ throws DatabaseException {\r
+ return NameUtils.getSafeName(graph, input.data);\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+\r
+public class FunctionTreeSubLibraries extends ViewpointContributor<FunctionLibraryNode<Resource>> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, FunctionLibraryNode<Resource> library)\r
+ throws DatabaseException {\r
+ ArrayList<FunctionLibraryNode<Resource>> result = new ArrayList<FunctionLibraryNode<Resource>>();\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ for (Resource r : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))){\r
+ result.add(new FunctionLibraryNode<Resource>(r));\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
public Resource selection;\r
\r
/**\r
- * Constructor for ExternalProjectImportWizard.\r
+ * Constructor for ImportWizardFunction.\r
*/\r
public ImportWizardFunction() {\r
this(null);\r
}\r
\r
/**\r
- * Constructor for ExternalProjectImportWizard.\r
+ * Constructor for ImportWizardFunction.\r
*/\r
public ImportWizardFunction(String initialPath)\r
{\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class SharedFunctionsFolderNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {\r
+\r
+ public SharedFunctionsFolderNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ graph.deny(data, l0.PartOf);\r
+ graph.deny(data, l0.IsLinkedTo_Inverse);\r
+\r
+ // TODO: remove file\r
+ }\r
+ });\r
+ }\r
+ \r
+ @Override\r
+ public void drop(Object data) {\r
+ final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
+ final Resource library = this.data;\r
+ if(resources.length > 0) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ for(Resource tobeMoved : resources) {\r
+ if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
+ graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
+ Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
+ graph.deny(tobeMoved, l0.PartOf);\r
+ graph.claim(tobeMoved, l0.PartOf, library);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
+ }\r
+ }\r
+ \r
+ }\r
+ });\r
+ }\r
+ }\r
+\r
+}\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
\r
import java.io.File;\r
import java.io.IOException;\r
import java.util.ArrayList;\r
\r
import org.eclipse.core.runtime.Path;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.jface.wizard.WizardPage;\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.events.SelectionListener;\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.Label;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
import org.simantics.db.request.Read;\r
import org.simantics.graph.representation.TransferableGraph1;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.datastructures.Pair;\r
\r
public class WizardFunctionsExportPage extends WizardPage {\r
private static String previouslyBrowsedFile = "";\r
\r
private Button browseDirectoriesButton;\r
-\r
- private IStructuredSelection currentSelection;\r
-\r
+ \r
+ //private IStructuredSelection currentSelection;\r
+ \r
+ GraphExplorerComposite functionLibraryExplorer;\r
+ \r
+ private boolean selectionMade = false;\r
+ \r
/**\r
* Creates a new project creation wizard page.\r
* \r
public WizardFunctionsExportPage(String pageName,String initialPath,\r
IStructuredSelection currentSelection) {\r
super(pageName);\r
- this.currentSelection = currentSelection;\r
+ //this.currentSelection = currentSelection;\r
setPageComplete(false);\r
setTitle("Export Function Library");\r
- setDescription("Choose the location where the selected Function Library is exportted. The exportted Function Library is selected from the Model Browser.");\r
+ setDescription("Choose the Function Library and the export location, then press Finish.");\r
}\r
\r
public void createControl(Composite parent) {\r
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
\r
createProjectsRoot(workArea);\r
+ createTree(workArea);\r
+ \r
}\r
\r
private void createProjectsRoot(Composite workArea) {\r
\r
- \r
- // project specification group\r
- \r
+ // set label for field\r
Label title = new Label(workArea, SWT.NONE);\r
- title.setText("Select export destination for Function Library:");\r
+ title.setText("Select the export location for Function Library:");\r
\r
Composite projectGroup = new Composite(workArea, SWT.NONE);\r
GridLayout layout = new GridLayout();\r
projectGroup.setLayout(layout);\r
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\r
\r
- // project location entry field\r
+ // function library location entry field\r
this.filePathField = new Text(projectGroup, SWT.BORDER);\r
\r
GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false);\r
directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25);\r
filePathField.setLayoutData(directoryPathData);\r
\r
+ filePathField.addModifyListener(new ModifyListener(){\r
+ @Override\r
+ public void modifyText(ModifyEvent e) {\r
+ previouslyBrowsedFile = filePathField.getText(); \r
+ }\r
+ });\r
+ if (previouslyBrowsedFile != null){\r
+ filePathField.setText(previouslyBrowsedFile);\r
+ validatePage();\r
+ }\r
+ \r
// browse button\r
browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);\r
browseDirectoriesButton.setText("Browse");\r
\r
}\r
\r
+ private void createTree(Composite workArea){\r
+ \r
+ //set label for tree\r
+ Label title = new Label(workArea, SWT.NONE);\r
+ title.setText("Select Function Library to export:");\r
+\r
+ try {\r
+ Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ Resource model = SimanticsUI.getProject().get();\r
+ return model;\r
+ }\r
+\r
+ });\r
+\r
+ functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+ functionLibraryExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/FunctionTree");\r
+\r
+ functionLibraryExplorer.finish();\r
+\r
+ functionLibraryExplorer.setInput(null, input);\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ functionLibraryExplorer);\r
+ \r
+ ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
+ \r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ setMessage(null);\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ setMessage(null);\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ });\r
+\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+\r
+ }\r
+ \r
//Set filePathField active\r
public void setVisible(boolean visible) {\r
super.setVisible(visible);\r
//Open dialog for choosing the file\r
protected void handleLocationDirectoryButtonPressed() {\r
\r
- final Resource functionLibrary2 = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
- String name = null;\r
- try {\r
- name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
-\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- if (!graph.hasStatement(functionLibrary2, Layer0.getInstance(graph).PartOf))\r
- return null;\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary2, l0.HasName, Bindings.STRING ));\r
- return name;\r
- \r
- }\r
- \r
- });\r
- } catch (DatabaseException e1) {\r
- e1.printStackTrace();\r
- }\r
- \r
final Shell shell = filePathField.getShell();\r
\r
FileDialog dialog = new FileDialog(shell, SWT.SAVE);\r
String[] ext = {"*.tg"};\r
dialog.setFilterExtensions(ext);\r
\r
- dialog.setFileName(name);\r
- \r
dialog.setText("Export Function Library");\r
\r
String dirName = filePathField.getText().trim();\r
\r
String selectedFile = dialog.open();\r
if (selectedFile != null) {\r
- previouslyBrowsedFile = selectedFile;\r
- filePathField.setText(previouslyBrowsedFile);\r
- setPageComplete(true);\r
+ filePathField.setText(selectedFile);\r
+ validatePage();\r
} \r
\r
}\r
\r
+ //Get selection from the tree\r
+ @SuppressWarnings("unchecked")\r
+ public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+ Class<T> clazz) {\r
+ if(explorer == null)\r
+ return null;\r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return null;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+ if (inc == null)\r
+ return null;\r
+ final T resource = (T) inc.getAdapter(clazz);\r
+\r
+ return resource;\r
+ }\r
+ \r
public boolean createProjects(Resource selection) {\r
\r
final String selected = previouslyBrowsedFile;\r
if(selected == null) return false;\r
- final Resource modulesymbol = selection;\r
- if(modulesymbol == null) return false;\r
- \r
- final Resource functionLibrary = selection;\r
+ \r
+ final Resource functionLibrary = getExplorerResource(functionLibraryExplorer, Resource.class);\r
+ if(functionLibrary == null) return false;\r
\r
+ String name = null;\r
+ try {\r
+ name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ if (!graph.hasStatement(functionLibrary, Layer0.getInstance(graph).PartOf))\r
+ return null;\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary, l0.HasName, Bindings.STRING ));\r
+ return name;\r
+ \r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ if(name == null) return false;\r
+ \r
SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
\r
@Override\r
\r
return true;\r
}\r
+ \r
+ void validatePage() {\r
+ \r
+ if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
+ setPageComplete(false);\r
+ return;\r
+ }\r
+ \r
+ if (functionLibraryExplorer != null){\r
+ final Resource selectedResource = getExplorerResource(functionLibraryExplorer, Resource.class);\r
+\r
+ String root = null;\r
+ try {\r
+ root = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource model = graph.getPossibleObject(selectedResource, l0.PartOf);\r
+ String rootName = NameUtils.getSafeName(graph, model);\r
+\r
+ return rootName;\r
+ }\r
+\r
+ });\r
+ if (root != null && root.equalsIgnoreCase("Development Project")){\r
+ setPageComplete(false);\r
+ setMessage("Select Function Library folder under the Model or from the Shared Functions folder.");\r
+ return;\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ setPageComplete(true);\r
+ \r
+ }\r
+ \r
}
\ No newline at end of file
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
\r
import java.io.File;\r
import java.io.IOException;\r
-import java.util.ArrayList;\r
\r
import org.eclipse.core.runtime.Path;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.eclipse.jface.viewers.IStructuredSelection;\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.events.SelectionListener;\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.MessageBox;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.WriteOnlyGraph;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
\r
public class WizardFunctionsImportPage extends WizardPage{\r
- \r
+\r
// dialog store id constants\r
private Text filePathField;\r
- \r
+\r
// Keep track of the archive that we browsed to last time\r
// the wizard was invoked.\r
private static String previouslyBrowsedFile = "";\r
\r
private Button browseDirectoriesButton;\r
- \r
+\r
private Shell shell;\r
- \r
- private IStructuredSelection currentSelection;\r
- \r
- private Resource current;\r
- \r
+\r
+ //private IStructuredSelection currentSelection;\r
+\r
private Resource selectedModel;\r
+\r
+ GraphExplorerComposite functionLibraryExplorer;\r
+ \r
+ private String error = "";\r
\r
- private String currentModelName;\r
+ private boolean selectionMade = false;\r
\r
/**\r
* Creates a new project creation wizard page.\r
public WizardFunctionsImportPage(String pageName) {\r
this(pageName,null, null);\r
}\r
- \r
+\r
/**\r
* More (many more) parameters.\r
* \r
*/\r
public WizardFunctionsImportPage(String pageName,String initialPath,\r
IStructuredSelection currentSelection) {\r
- super(pageName);\r
+ super(pageName);\r
setPageComplete(false);\r
- this.currentSelection = currentSelection;\r
- setTitle("Import Function Library to Model");\r
- setDescription("Select Function Library from the local file system to be imported to the selected Model.");\r
+ //this.currentSelection = currentSelection;\r
+ setTitle("Import Function Library");\r
+ setDescription("Choose the Function Library file and the import location, then press Finish.");\r
}\r
- \r
+\r
public void createControl(Composite parent) {\r
- \r
+\r
initializeDialogUnits(parent);\r
- \r
+\r
Composite workArea = new Composite(parent, SWT.NONE);\r
setControl(workArea);\r
- \r
+\r
workArea.setLayout(new GridLayout());\r
workArea.setLayoutData(new GridData(GridData.FILL_BOTH\r
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
- \r
+\r
createProjectsRoot(workArea);\r
+\r
+ createTree(workArea);\r
+ \r
\r
- createDropDown(workArea);\r
}\r
- \r
+\r
private void createProjectsRoot(Composite workArea) {\r
- \r
+\r
//set label for field\r
Label title = new Label(workArea, SWT.NONE);\r
title.setText("Select Function Library source:");\r
- \r
+\r
Composite projectGroup = new Composite(workArea, SWT.NONE);\r
GridLayout layout = new GridLayout();\r
layout.numColumns = 2;\r
layout.makeColumnsEqualWidth = false;\r
layout.marginWidth = 0;\r
- \r
+\r
projectGroup.setLayout(layout);\r
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\r
\r
GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false);\r
directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25);\r
filePathField.setLayoutData(directoryPathData);\r
+ \r
\r
filePathField.addModifyListener(new ModifyListener(){\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- previouslyBrowsedFile = filePathField.getText(); \r
- }\r
+ @Override\r
+ public void modifyText(ModifyEvent e) {\r
+ previouslyBrowsedFile = filePathField.getText(); \r
+ }\r
});\r
if (previouslyBrowsedFile != null){\r
filePathField.setText(previouslyBrowsedFile);\r
validatePage();\r
}\r
- \r
+\r
// browse button\r
browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);\r
browseDirectoriesButton.setText("Browse");\r
setButtonLayoutData(browseDirectoriesButton);\r
- \r
- \r
+\r
browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {\r
/*\r
* (non-Javadoc)\r
handleLocationDirectoryButtonPressed();\r
}\r
});\r
- \r
+\r
}\r
- \r
- private void createDropDown(Composite workArea) {\r
- \r
- final ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
- \r
- new Label(workArea, SWT.NONE).setText("Import target:"); \r
- \r
- //Get resources for the DropDown-selection\r
- try{\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+\r
+ private void createTree(Composite workArea){\r
+ \r
+ //set label for tree\r
+ Label title = new Label(workArea, SWT.NONE);\r
+ title.setText("Select import location:");\r
+\r
+ try {\r
+ Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ Resource model = SimanticsUI.getProject().get();\r
+ return model;\r
+ }\r
+\r
+ });\r
+\r
+ functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+ functionLibraryExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/FunctionTree");\r
+\r
+ functionLibraryExplorer.finish();\r
+\r
+ functionLibraryExplorer.setInput(null, input);\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ functionLibraryExplorer);\r
\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
+ ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
\r
- Resource model;\r
- current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
- //If there is no selection\r
- if(current == null){\r
- model = SimanticsUI.getProject().get();\r
- }\r
- else{\r
- model = graph.getPossibleObject(current, l0.PartOf);\r
- } \r
- currentModelName = NameUtils.getSafeName(graph, current);\r
- \r
- //Check if selection is not in top-level folder\r
- String modelName = NameUtils.getSafeName(graph, model);\r
- while (!modelName.equalsIgnoreCase("Development Project")){\r
- Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
- String previousName = NameUtils.getSafeName(graph, previousResource);\r
- if (previousName.equalsIgnoreCase("Development Project")){\r
- currentModelName = modelName;\r
- }\r
- //If selection is under Built-in Functions directory\r
- if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
- model = SimanticsUI.getProject().get();\r
- current = null;\r
- break;\r
- }\r
- current = model;\r
- model = graph.getPossibleObject(model, l0.PartOf);\r
- modelName = NameUtils.getSafeName(graph, model);\r
- } \r
- for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
- String name = NameUtils.getSafeName(graph, r);\r
- resources.add(Pair.make(r, name));\r
- }\r
- \r
- };\r
- });\r
- }\r
- catch (DatabaseException e) {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ });\r
+\r
+ } catch (DatabaseException e) {\r
e.printStackTrace();\r
- }\r
- //Create dropdown-bar\r
- final CCombo drop = new CCombo(workArea, SWT.BORDER);\r
- {\r
- drop.setEditable(false);\r
- drop.setText("");\r
- drop.setToolTipText("Selects the Model where to import the Module.");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop); \r
- \r
- //Fill the Dropdown-list\r
- for(int a=0; a<resources.size(); a++){\r
- drop.add(resources.get(a).second);\r
- }\r
- int selectionNumber = 0;\r
- for(int a=0; a<resources.size(); a++){\r
- if (currentModelName.equals(resources.get(a).second)){\r
- selectionNumber = a;\r
- }\r
- }\r
- //Show selected model as default\r
- drop.select(selectionNumber);\r
- selectedModel = current;\r
- if (selectedModel == null){\r
- selectedModel = resources.get(0).first;\r
- }\r
- \r
- drop.addModifyListener(new ModifyListener(){\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- \r
- for(int a=0; a<resources.size(); a++){\r
- if (drop.getText().equals(resources.get(a).second))\r
- selectedModel = resources.get(a).first;\r
- } \r
- validatePage(); \r
- }\r
- });\r
- }\r
- }\r
- \r
+ }\r
+\r
+ }\r
+\r
//Set filePathField active\r
public void setVisible(boolean visible) {\r
super.setVisible(visible);\r
this.filePathField.setFocus();\r
}\r
- \r
+\r
//Open dialog for choosing the file\r
protected void handleLocationDirectoryButtonPressed() {\r
- \r
+\r
shell = filePathField.getShell();\r
- \r
+\r
FileDialog dialog = new FileDialog(shell, SWT.OPEN);\r
- \r
+\r
String[] ext = {"*.tg"};\r
dialog.setFilterExtensions(ext);\r
- \r
+\r
dialog.setText("Import Function Library");\r
\r
String dirName = filePathField.getText().trim();\r
- \r
+\r
File path = new File(dirName);\r
if (path.exists()) {\r
dialog.setFilterPath(new Path(dirName).toOSString()); \r
}\r
- \r
+\r
String selectedFile = dialog.open();\r
if (selectedFile != null) {\r
filePathField.setText(selectedFile);\r
validatePage();\r
} \r
}\r
- \r
+\r
+ //Get selection from the tree\r
+ @SuppressWarnings("unchecked")\r
+ public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+ Class<T> clazz) {\r
+ \r
+ if(explorer == null)\r
+ return null;\r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return null;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+ if (inc == null)\r
+ return null;\r
+ final T resource = (T) inc.getAdapter(clazz);\r
+\r
+ return resource;\r
+ }\r
+\r
//Create project after finish is pressed.\r
public boolean createProjects() {\r
\r
+ selectedModel= getExplorerResource(functionLibraryExplorer, Resource.class);\r
+ if(selectedModel == null){\r
+ setErrorMessage("Error when retrieving resource");\r
+ return false;\r
+ }\r
+ \r
String selected = previouslyBrowsedFile;\r
- if(selected == null) return false;\r
- \r
+ if(selected == null){\r
+ setErrorMessage("No file selected");\r
+ return false;\r
+ }\r
+\r
TransferableGraph1 tg = null;\r
try {\r
tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
e.printStackTrace();\r
return false;\r
} catch (IOException e) {\r
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
- mb.setText("Error");\r
- mb.setMessage("The imported file is not of type: Function Library");\r
- mb.open();\r
+ setErrorMessage("The imported file is not of type: Function Library");\r
return false;\r
} \r
- if(tg == null) return false;\r
+ if(tg == null){\r
+ setErrorMessage("The imported file is not of type: Function Library");\r
+ return false;\r
+ }\r
+\r
\r
- \r
try {\r
Boolean hasSharedOntologies;\r
hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
return false;\r
}\r
\r
- \r
+\r
SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(selectedModel);\r
try {\r
DefaultPasteHandler.defaultExecute(tg, selectedModel, ia);\r
} catch (Exception e) {\r
e.printStackTrace();\r
}\r
- \r
+\r
final Resource root = ia.getRoot();\r
- \r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) {\r
- Resource library = graph.getResource("http://SharedOntologies");\r
- if(!graph.hasStatement(library, l0.ConsistsOf, root)) {\r
- graph.claim(library, l0.ConsistsOf, root);\r
- }\r
-\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Resource model = selectedModel;\r
- while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology))\r
- model = graph.getSingleObject(model, l0.PartOf);\r
- if(graph.isInstanceOf(model, sr.SysdynModel)) {\r
- graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root);\r
- }\r
-\r
- } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
- Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf);\r
- String type = "...";\r
- if(instanceOf != null)\r
- type = NameUtils.getSafeName(graph, instanceOf);\r
- else {\r
- Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits);\r
- if(inheritedFrom != null)\r
- type = NameUtils.getSafeName(graph, inheritedFrom);\r
- }\r
- final String ft = type; \r
- graph.deny(root, l0.PartOf);\r
- \r
- shell.getDisplay().asyncExec(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
- mb.setText("Error");\r
- mb.setMessage("The imported file is not of type: Function Library (" + ft +")");\r
- mb.open(); \r
+\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) {\r
+ Resource library = graph.getResource("http://SharedOntologies");\r
+ if(!graph.hasStatement(library, l0.ConsistsOf, root)) {\r
+ graph.claim(library, l0.ConsistsOf, root);\r
}\r
- });\r
- } else {\r
- FunctionUtils.updateFunctionFileForLibrary(graph, selectedModel);\r
- }\r
\r
- }\r
- });\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource model = selectedModel;\r
+ while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology))\r
+ model = graph.getSingleObject(model, l0.PartOf);\r
+ if(graph.isInstanceOf(model, sr.SysdynModel)) {\r
+ graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root);\r
+ }\r
+\r
+ } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
+ Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf);\r
+ String type = "...";\r
+ if(instanceOf != null)\r
+ type = NameUtils.getSafeName(graph, instanceOf);\r
+ else {\r
+ Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits);\r
+ if(inheritedFrom != null)\r
+ type = NameUtils.getSafeName(graph, inheritedFrom);\r
+ } \r
+ graph.deny(root, l0.PartOf);\r
+ error = type;\r
+ } else {\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, selectedModel);\r
+ }\r
+\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ if (!error.isEmpty()){\r
+ setErrorMessage("The imported file is not of type: Function Library (" + error +")");\r
+ error = "";\r
+ return false;\r
+ }\r
return true;\r
}\r
- \r
+\r
private class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor {\r
- \r
+\r
public SysdynFunctionLibraryImportAdvisor(Resource library) {\r
super(library);\r
}\r
- \r
+\r
@Override\r
public void analyzeType(ReadGraph graph, Root root) throws DatabaseException {\r
if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) {\r
}\r
}\r
}\r
- \r
+\r
@Override\r
public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException {\r
Layer0 l0 = graph.getService(Layer0.class);\r
return this.root;\r
\r
}\r
- \r
+\r
}\r
void validatePage() {\r
- \r
- if (previouslyBrowsedFile.isEmpty()){\r
+\r
+ if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
setPageComplete(false);\r
return;\r
}\r
- \r
+ setErrorMessage(null);\r
setPageComplete(true);\r
- \r
+\r
}\r
- \r
+\r
}
\ No newline at end of file
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.mdl;\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.jface.wizard.Wizard;\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.mdl;\r
\r
import java.io.File;\r
\r
super(pageName);\r
setPageComplete(false);\r
setTitle("Import Vensim model");\r
- setDescription("Select Vensim model -file (.mdl) from the local file system.");\r
+ setDescription("Choose the Vensim model file (.mdl), then press Finish.");\r
}\r
\r
public void createControl(Composite parent) {\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
\r
@Override\r
public boolean performFinish() {\r
- return mainPage.createProjects(selection);\r
+ return mainPage.createProjects();\r
}\r
\r
}
\ No newline at end of file
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.jface.wizard.Wizard;\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
\r
import java.io.File;\r
import java.io.IOException;\r
import org.eclipse.core.runtime.Path;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.eclipse.jface.viewers.IStructuredSelection;\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.events.SelectionListener;\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.Label;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
import org.simantics.db.request.Read;\r
import org.simantics.graph.representation.TransferableGraph1;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.datastructures.Pair;\r
\r
public class WizardModelsExportPage extends WizardPage {\r
\r
private Button browseDirectoriesButton;\r
\r
- private IStructuredSelection currentSelection;\r
- \r
- private Resource current;\r
+ //private IStructuredSelection currentSelection;\r
\r
private Resource selectedModel;\r
\r
- private String currentModelName;\r
+ GraphExplorerComposite modelExplorer;\r
+ \r
+ private boolean selectionMade = false;\r
+ \r
+ \r
\r
/**\r
* Creates a new project creation wizard page.\r
public WizardModelsExportPage(String pageName,String initialPath,\r
IStructuredSelection currentSelection) {\r
super(pageName);\r
- this.currentSelection = currentSelection;\r
+ //this.currentSelection = currentSelection;\r
setPageComplete(false);\r
setTitle("Export Model");\r
- setDescription("Choose the location where the selected Model is exportted. The exportted Model is selected from the dropdown-menu.");\r
+ setDescription("Choose the Model and the export location, then press Finish.");\r
}\r
\r
public void createControl(Composite parent) {\r
workArea.setLayoutData(new GridData(GridData.FILL_BOTH\r
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
\r
- createDropDown (workArea);\r
createProjectsRoot(workArea);\r
+ createTree (workArea);\r
}\r
\r
private void createProjectsRoot(Composite workArea) {\r
\r
// set label for field\r
Label title = new Label(workArea, SWT.NONE);\r
- title.setText("Select export destination for Model:");\r
+ title.setText("Select the export location for Model:");\r
\r
Composite projectGroup = new Composite(workArea, SWT.NONE);\r
GridLayout layout = new GridLayout();\r
\r
}\r
\r
- private void createDropDown(Composite workArea) {\r
- \r
- final ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
- \r
- new Label(workArea, SWT.NONE).setText("Select Model to export:"); \r
- \r
- //Get resources for the DropDown-selection\r
- try{\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+ private void createTree(Composite workArea){\r
+ \r
+ //set label for tree\r
+ Label title = new Label(workArea, SWT.NONE);\r
+ title.setText("Select Model to export:");\r
+\r
+ try {\r
+ Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ Resource model = SimanticsUI.getProject().get();\r
+ return model;\r
+ }\r
+\r
+ });\r
+\r
+ modelExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+ modelExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/ImportModuleTree");\r
+\r
+ modelExplorer.finish();\r
+\r
+ modelExplorer.setInput(null, input);\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ modelExplorer);\r
\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- \r
- Resource model;\r
- current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
- //If there is no selection\r
- if(current == null){\r
- model = SimanticsUI.getProject().get();\r
- }\r
- else{\r
- model = graph.getPossibleObject(current, l0.PartOf);\r
- }\r
- currentModelName = NameUtils.getSafeName(graph, current);\r
- \r
- //Check if selection is not in top-level folder\r
- String modelName = NameUtils.getSafeName(graph, model);\r
- while (!modelName.equalsIgnoreCase("Development Project")){\r
- Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
- String previousName = NameUtils.getSafeName(graph, previousResource);\r
- if (previousName.equalsIgnoreCase("Development Project")){\r
- currentModelName = modelName;\r
- }\r
- //If selection is under Built-in Functions directory\r
- if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
- model = SimanticsUI.getProject().get();\r
- current = null;\r
- break;\r
- }\r
- current = model;\r
- model = graph.getPossibleObject(model, l0.PartOf);\r
- modelName = NameUtils.getSafeName(graph, model);\r
- }\r
- for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
- String name = NameUtils.getSafeName(graph, r);\r
- resources.add(Pair.make(r, name));\r
- }\r
+ ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
\r
- };\r
- });\r
- }\r
- catch (DatabaseException e) {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ });\r
+ \r
+\r
+ } catch (DatabaseException e) {\r
e.printStackTrace();\r
- }\r
- //Create dropdown-bar\r
- final CCombo drop = new CCombo(workArea, SWT.BORDER);\r
- {\r
- drop.setEditable(false);\r
- drop.setText("");\r
- drop.setToolTipText("Selects the Model where to import the Module.");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop); \r
- \r
- //Fill the Dropdown-list\r
- for(int a=0; a<resources.size(); a++){\r
- drop.add(resources.get(a).second);\r
- }\r
- int selectionNumber = 0;\r
- for(int a=0; a<resources.size(); a++){\r
- if (currentModelName.equals(resources.get(a).second)){\r
- selectionNumber = a;\r
- }\r
- }\r
- //Show selected model as default\r
- drop.select(selectionNumber);\r
- selectedModel = current;\r
- if (selectedModel == null){\r
- selectedModel = resources.get(0).first;\r
- }\r
- \r
- drop.addModifyListener(new ModifyListener(){\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- \r
- for(int a=0; a<resources.size(); a++){\r
- if (drop.getText().equals(resources.get(a).second))\r
- selectedModel = resources.get(a).first;\r
- } \r
- validatePage(); \r
- }\r
- });\r
- }\r
- }\r
+ }\r
+\r
+ }\r
\r
//Set filePathField active\r
public void setVisible(boolean visible) {\r
} \r
\r
}\r
+ //Get selection from the tree\r
+ @SuppressWarnings("unchecked")\r
+ public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+ Class<T> clazz) {\r
+ \r
+ if(explorer == null)\r
+ return null;\r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return null;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+ if (inc == null)\r
+ return null;\r
+ final T resource = (T) inc.getAdapter(clazz);\r
+\r
+ return resource;\r
+ }\r
\r
- public boolean createProjects(Resource selection) {\r
+ public boolean createProjects() {\r
\r
final String selected = previouslyBrowsedFile;\r
if(selected == null) return false;\r
+ \r
+ selectedModel= getExplorerResource(modelExplorer, Resource.class);\r
+ if(selectedModel == null)\r
+ return false;\r
\r
// FIXME: Model browser doesn't change its selection even if the selected object is removed,\r
// so you can try to export a removed model \r
\r
void validatePage() {\r
\r
- if (previouslyBrowsedFile.isEmpty()){\r
+ if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
setPageComplete(false);\r
return;\r
}\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
\r
import java.io.File;\r
import java.io.IOException;\r
import java.util.HashSet;\r
import java.util.UUID;\r
\r
-import org.eclipse.core.runtime.Path;\r
+import org.eclipse.core.runtime.Platform;\r
import org.eclipse.jface.layout.PixelConverter;\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.jface.wizard.WizardPage;\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.MessageBox;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.handlers.ImportModelHandler;\r
import org.simantics.sysdyn.ui.utils.OldTransferableGraph1;\r
import org.simantics.ui.SimanticsUI;\r
\r
public class WizardModelsImportPage extends WizardPage{\r
\r
- // dialog store id constants\r
- \r
private Text filePathField;\r
\r
// Keep track of the archive that we browsed to last time\r
\r
private Shell shell;\r
\r
+ private String error = "";\r
+ \r
/**\r
* Creates a new project creation wizard page.\r
* \r
//this.currentSelection = currentSelection;\r
setPageComplete(false);\r
setTitle("Import Model");\r
- setDescription("Select Model file from the local file system.");\r
+ setDescription("Choose the Model file, then press Finish.");\r
}\r
\r
\r
filePathField.addModifyListener(new ModifyListener(){\r
@Override\r
public void modifyText(ModifyEvent e) {\r
- previouslyBrowsedFile = filePathField.getText(); \r
+ previouslyBrowsedFile = filePathField.getText();\r
}\r
});\r
if (previouslyBrowsedFile != null){\r
* elected(org.eclipse.swt.events.SelectionEvent)\r
*/\r
public void widgetSelected(SelectionEvent e) {\r
+ setErrorMessage(null);\r
handleLocationDirectoryButtonPressed();\r
}\r
}); \r
}\r
+\r
\r
//Set filePathField active\r
public void setVisible(boolean visible) {\r
\r
dialog.setText("Import Model");\r
\r
- String dirName = filePathField.getText().trim();\r
- \r
- File path = new File(dirName);\r
- if (path.exists()) {\r
- dialog.setFilterPath(new Path(dirName).toOSString()); \r
- }\r
+ String path = Activator.getDefault().getPreferenceStore().getString(ImportModelHandler.IMPORTMODELTPATH);\r
+ if(path.isEmpty() || !(new File(path).exists()))\r
+ path = Platform.getLocation().toOSString();\r
+ dialog.setFilterPath(path);\r
\r
String selectedFile = dialog.open();\r
if (selectedFile != null) {\r
filePathField.setText(selectedFile);\r
validatePage();\r
}\r
+ \r
}\r
\r
//Create project after finish is pressed.\r
public boolean createProjects() {\r
\r
Resource project = SimanticsUI.getProject().get();\r
- if(project == null) return false;\r
+ if(project == null){\r
+ setErrorMessage("Error when retrieving resource");\r
+ return false;\r
+ }\r
\r
String selected = previouslyBrowsedFile;\r
- if(selected == null) return false;\r
+ if(selected == null){\r
+ setErrorMessage("No file selected");\r
+ return false;\r
+ }\r
\r
TransferableGraph1 tg = null;\r
try {\r
} catch (RuntimeBindingConstructionException e1) {\r
e1.printStackTrace();\r
} catch (IOException e1) {\r
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
- mb.setText("Error");\r
- mb.setMessage("The imported file is not of type: Model");\r
- mb.open();\r
+ setErrorMessage("The imported file is not of type: System Dynamics Model");\r
return false;\r
}\r
}\r
- if(tg == null) return false;\r
+ if(tg == null){ \r
+ setErrorMessage("The imported file is not of type: System Dynamics Model");\r
+ return false;\r
+ }\r
\r
try {\r
\r
if(inheritedFrom != null)\r
type = NameUtils.getSafeName(graph, inheritedFrom);\r
}\r
- final String ft = type; \r
graph.deny(root, Layer0.getInstance(graph).PartOf);\r
- \r
- shell.getDisplay().asyncExec(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
- mb.setText("Error");\r
- mb.setMessage("The imported file is not of type: System Dynamics Model (" + ft +")");\r
- mb.open(); \r
- }\r
- });\r
-\r
+ error = type;\r
} else {\r
updateOldConfigurationToBaseRealization(graph, root);\r
addDefaultOntologyLinks(graph, root);\r
} catch (Exception e) {\r
e.printStackTrace();\r
}\r
- \r
+\r
+ if (!error.isEmpty()){\r
+ setErrorMessage("The imported file is not of type: System Dynamics Model (" + error +")");\r
+ error = "";\r
+ return false;\r
+ }\r
return true; \r
}\r
\r
setPageComplete(false);\r
return;\r
}\r
- \r
+ setErrorMessage(null);\r
setPageComplete(true);\r
}\r
}
\ No newline at end of file
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.modules;\r
\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.modules;\r
\r
\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.layer0.adapter.PasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class ModuleComponentTypeNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
+\r
+ \r
+ Listener<String> configurationNameSynchronizer;\r
+ private boolean disposed = false;\r
+ private Resource configuration;\r
+ \r
+ public ModuleComponentTypeNode(Resource resource) {\r
+ super(resource);\r
+\r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ configuration = graph.getPossibleObject(data, sr2.IsDefinedBy); \r
+ }\r
+ });\r
+ \r
+ // Not the best solution for name sync\r
+ configurationNameSynchronizer = new Listener<String>() {\r
+\r
+ @Override\r
+ public void execute(final String result) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ if(configuration != null)\r
+ graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result);\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return disposed;\r
+ }\r
+ };\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ return graph.getRelatedValue(data, l0.HasName);\r
+ }\r
+ \r
+ }, configurationNameSynchronizer);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ Modifier modifier = null;\r
+ try {\r
+ modifier = SimanticsUI.getSession().syncRequest(new Read<Modifier>() {\r
+\r
+ @Override\r
+ public Modifier perform(ReadGraph graph) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType);\r
+\r
+ LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), type, l0.HasName) {\r
+ @Override\r
+ public String isValid(String label) {\r
+ if (label.isEmpty())\r
+ return "Empty name not allowed";\r
+ return null;\r
+ }\r
+ };\r
+\r
+\r
+ return modifier;\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ return modifier;\r
+ }\r
+\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ disposed = true;\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ StructuralResource2 st = StructuralResource2.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+\r
+ Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType);\r
+ Resource model = graph.getSingleObject(type, l0.PartOf);\r
+ Resource modelConfiguration = graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
+ if (!graph.syncRequest(new ObjectsWithType(modelConfiguration, l0.ConsistsOf, type)).isEmpty()) {\r
+ System.out.println("The module is used at the model configuration");\r
+ return;\r
+ }\r
+ Collection<Resource> moduleTypes = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType));\r
+ for(Resource r : moduleTypes) {\r
+ Resource configuration = graph.getSingleObject(r, st.IsDefinedBy);\r
+ if(!graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, type)).isEmpty()) {\r
+ System.out.println("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName));\r
+ return;\r
+ }\r
+ }\r
+ graph.deny(model, l0.ConsistsOf, type);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if(PasteHandler.class == adapter && configuration != null) \r
+ return new DefaultPasteHandler(configuration);\r
+ return super.getAdapter(adapter);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class ModuleTreeModels extends ViewpointContributorImpl<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ \r
+\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.SysdynModel))) {\r
+ result.add(new ModelNode(r));\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Module Import";\r
+ }\r
+ \r
+\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class ModuleTreeModules extends ViewpointContributor<ModelNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
+ throws DatabaseException {\r
+ ArrayList<ModuleComponentTypeNode> result = new ArrayList<ModuleComponentTypeNode>();\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ for (Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, sr2.ComponentType))){\r
+ result.add(new ModuleComponentTypeNode(r));\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class ModuleTreeModulesLabeler extends LabelerContributorImpl<ModuleComponentTypeNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, ModuleComponentTypeNode input)\r
+ throws DatabaseException {\r
+ return NameUtils.getSafeName(graph, input.data);\r
+ }\r
+\r
+}\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.modules;\r
\r
import java.io.File;\r
import java.io.IOException;\r
import org.eclipse.core.runtime.Path;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.eclipse.jface.viewers.IStructuredSelection;\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.events.SelectionListener;\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.Label;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.datastructures.Pair;\r
\r
public class WizardModulesExportPage extends WizardPage {\r
\r
private Button browseDirectoriesButton;\r
\r
- private IStructuredSelection currentSelection;\r
- \r
- private Resource current;\r
- \r
- private Resource selectedModel;\r
- \r
private Resource selectedModule;\r
\r
- private String currentModelName;\r
- \r
- private CCombo drop;\r
- \r
- private CCombo drop2;\r
- \r
- private ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
- \r
- private ArrayList<Pair<Resource, String>> modules = new ArrayList<Pair<Resource, String>>();\r
+ GraphExplorerComposite modelExplorer;\r
\r
- \r
+ private boolean selectionMade = false;\r
\r
/**\r
* Creates a new project creation wizard page.\r
public WizardModulesExportPage(String pageName,String initialPath,\r
IStructuredSelection currentSelection) {\r
super(pageName);\r
- this.currentSelection = currentSelection;\r
+ //this.currentSelection = currentSelection;\r
setPageComplete(false);\r
setTitle("Export Module");\r
- setDescription("Choose the Module and the export location.");\r
+ setDescription("Choose the Module and the export location, then press Finish.");\r
}\r
\r
public void createControl(Composite parent) {\r
workArea.setLayoutData(new GridData(GridData.FILL_BOTH\r
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
\r
- createDropDownSelections(workArea);\r
createProjectsRoot(workArea);\r
- \r
+ createTree(workArea);\r
}\r
\r
private void createProjectsRoot(Composite workArea) {\r
\r
// set label for field\r
Label title = new Label(workArea, SWT.NONE);\r
- title.setText("Select export destination for Module:");\r
+ title.setText("Select the export location for Module:");\r
\r
Composite projectGroup = new Composite(workArea, SWT.NONE);\r
GridLayout layout = new GridLayout();\r
});\r
\r
}\r
- \r
- private void createDropDownSelections(final Composite workArea) {\r
- \r
- new Label(workArea, SWT.NONE).setText("Select the Model which contains the Module:"); \r
- \r
- //Find available models\r
- findModels();\r
- \r
- //Create Model dropdown-bar\r
- drop = new CCombo(workArea, SWT.BORDER);\r
- \r
- drop.setEditable(false);\r
- drop.setText("");\r
- drop.setToolTipText("Selects the Model where to export the Module.");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop); \r
- \r
- //Fill the Model Dropdown-list\r
- for(int a=0; a<resources.size(); a++){\r
- drop.add(resources.get(a).second);\r
- }\r
- int selectionNumber = 0;\r
- for(int a=0; a<resources.size(); a++){\r
- if (currentModelName.equals(resources.get(a).second)){\r
- selectionNumber = a;\r
- }\r
- }\r
- //Show selected model as default\r
- drop.select(selectionNumber);\r
- selectedModel = current;\r
- if (selectedModel == null){\r
- selectedModel = resources.get(0).first;\r
- }\r
- \r
- //Create Module dropdown-bar\r
- new Label(workArea, SWT.NONE).setText("Select the exportted Module:"); \r
- drop2 = new CCombo(workArea, SWT.BORDER);\r
- drop2.setEditable(false);\r
- drop2.setText("");\r
- drop2.setToolTipText("Selects the Module to be exportted.");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop2); \r
- \r
- //Update module list according to model list\r
- updateModules();\r
- \r
- //Listeners for drop downs\r
- drop.addModifyListener(new ModifyListener(){\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- \r
- for(Pair<Resource, String> resource : resources){\r
- if (drop.getText().equals(resource.second))\r
- selectedModel = resource.first;\r
- } \r
- \r
- updateModules();\r
- validatePage();\r
- }\r
- });\r
- \r
- drop2.addModifyListener(new ModifyListener(){\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- \r
- for(int a=0; a<modules.size(); a++){\r
- if (drop2.getText().equals(modules.get(a).second))\r
- selectedModule = modules.get(a).first;\r
- } \r
- validatePage(); \r
- }\r
- });\r
- \r
- }\r
+\r
+ private void createTree(Composite workArea){\r
+ \r
+ //set label for tree\r
+ Label title = new Label(workArea, SWT.NONE);\r
+ title.setText("Select Module to export:");\r
+\r
+ try {\r
+ Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ Resource model = SimanticsUI.getProject().get();\r
+ return model;\r
+ }\r
+\r
+ });\r
+\r
+ modelExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+ modelExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/ExportModuleTree");\r
+\r
+ modelExplorer.finish();\r
+ \r
+ modelExplorer.setInput(null, input);\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ modelExplorer);\r
+ \r
+ ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
+ \r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ setMessage(null);\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ setMessage(null);\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ });\r
+\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ }\r
\r
//Set filePathField active\r
public void setVisible(boolean visible) {\r
this.filePathField.setFocus();\r
}\r
\r
- \r
//Open dialog for choosing the file\r
protected void handleLocationDirectoryButtonPressed() {\r
\r
\r
}\r
\r
- private void findModels(){\r
- \r
- //Get resources for the DropDown-selection\r
- try{\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
- \r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- \r
- Resource model;\r
- current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
- //If there is no selection\r
- if(current == null){\r
- model = SimanticsUI.getProject().get();\r
- }\r
- else{\r
- model = graph.getPossibleObject(current, l0.PartOf);\r
- } \r
- currentModelName = NameUtils.getSafeName(graph, current);\r
- \r
- //Check if selection is not in top-level folder\r
- String modelName = NameUtils.getSafeName(graph, model);\r
- while (!modelName.equalsIgnoreCase("Development Project")){\r
- Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
- String previousName = NameUtils.getSafeName(graph, previousResource);\r
- if (previousName.equalsIgnoreCase("Development Project")){\r
- currentModelName = modelName;\r
- }\r
- //If selection is under Built-in Functions directory\r
- if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
- model = SimanticsUI.getProject().get();\r
- current = null;\r
- break;\r
- }\r
- current = model;\r
- model = graph.getPossibleObject(model, l0.PartOf);\r
- modelName = NameUtils.getSafeName(graph, model);\r
- }\r
- for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
- String name = NameUtils.getSafeName(graph, r);\r
- resources.add(Pair.make(r, name));\r
- }\r
- \r
- };\r
- });\r
- }\r
- catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- \r
- }\r
- \r
- \r
- private void findModules(){\r
- \r
- try{\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
- \r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- //modules.removeAll(null);\r
- modules = new ArrayList<Pair<Resource, String>>();\r
- for (Resource r : graph.syncRequest(new ObjectsWithType(selectedModel, l0.ConsistsOf, sr2.ComponentType))){\r
- String name = NameUtils.getSafeName(graph, r);\r
- modules.add(Pair.make(r, name));\r
- }\r
- \r
- };\r
- });\r
- }\r
- catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- \r
- private void updateModules(){\r
- \r
- //Get resources for the DropDown-selection\r
- findModules(); \r
- \r
- //Clear the modules dropdown-list\r
- if (drop2 != null){\r
- drop2.removeAll();\r
- \r
- \r
- //Fill the Modules dropdown-list\r
- for(Pair<Resource, String> module : modules){\r
- drop2.add(module.second);\r
- }\r
- int selectionNumber = 0;\r
- for(int a=0; a<modules.size(); a++){\r
- if (currentModelName.equals(modules.get(a).second)){\r
- selectionNumber = a;\r
- }\r
- }\r
- //Show selected module as default\r
- drop2.select(selectionNumber);\r
- selectedModel = current;\r
- if (selectedModel == null){\r
- selectedModel = modules.get(0).first;\r
- }\r
- }\r
- \r
+ //Get selection from the tree\r
+ @SuppressWarnings("unchecked")\r
+ public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+ Class<T> clazz) {\r
+ \r
+ if(explorer == null)\r
+ return null;\r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return null;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+ if (inc == null)\r
+ return null;\r
+ final T resource = (T) inc.getAdapter(clazz);\r
+\r
+ return resource;\r
}\r
\r
+ //Create export file when finish is pressed\r
public boolean createProjects() {\r
\r
final String selected = previouslyBrowsedFile;\r
if(selected == null) return false;\r
\r
+ selectedModule= getExplorerResource(modelExplorer, Resource.class);\r
+ if(selectedModule == null)\r
+ return false;\r
+ \r
String name = null;\r
try {\r
name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
\r
@Override\r
public String perform(ReadGraph graph) throws DatabaseException {\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
\r
Resource component = selectedModule;\r
- // Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf))\r
return null;\r
\r
- \r
Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
if (configuration == null)\r
return null;\r
catch (DatabaseException e1) {\r
e1.printStackTrace();\r
}\r
-// if(name == null) return false;\r
- \r
- \r
- // Activator.getDefault().getPreferenceStore().setValue(ImportModuleHandler.IMPORTMODULETPATH, (new File(selected)).getParent());\r
+ if(name == null) return false;\r
\r
SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
\r
final Resource component = selectedModule;\r
//final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
\r
void validatePage() {\r
\r
- if (previouslyBrowsedFile.isEmpty()){\r
+ if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
setPageComplete(false);\r
return;\r
}\r
\r
+ if (modelExplorer != null){\r
+ final Resource selectedResource = getExplorerResource(modelExplorer, Resource.class);\r
+\r
+ String root = null;\r
+ try {\r
+ root = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource model = graph.getPossibleObject(selectedResource, l0.PartOf);\r
+ String rootName = NameUtils.getSafeName(graph, model);\r
+\r
+ return rootName;\r
+ }\r
+\r
+ });\r
+ if (root != null && root.equalsIgnoreCase("Development Project")){\r
+ setPageComplete(false);\r
+ setMessage("Select Module under the Model.");\r
+ return;\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
setPageComplete(true);\r
\r
}\r
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.modules;\r
\r
import java.io.File;\r
import java.io.IOException;\r
-import java.util.ArrayList;\r
\r
import org.eclipse.core.runtime.Path;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.eclipse.jface.viewers.IStructuredSelection;\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.events.SelectionListener;\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.MessageBox;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.db.request.Read;\r
import org.simantics.graph.db.MissingDependencyException;\r
import org.simantics.graph.representation.TransferableGraph1;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
\r
\r
public class WizardModulesImportPage extends WizardPage{\r
\r
private Shell shell;\r
\r
- private IStructuredSelection currentSelection;\r
- \r
- private Resource current;\r
+ //private IStructuredSelection currentSelection;\r
\r
private Resource selectedModel;\r
\r
- private String currentModelName;\r
+ GraphExplorerComposite modelExplorer;\r
+ \r
+ private boolean selectionMade = false;\r
+ \r
+ private String error = "";\r
\r
/**\r
* Creates a new project creation wizard page.\r
IStructuredSelection currentSelection) {\r
super(pageName);\r
setPageComplete(false);\r
- this.currentSelection = currentSelection;\r
- setTitle("Import Module to Model");\r
- setDescription("Select Module-file from the local file system.");\r
+ //this.currentSelection = currentSelection;\r
+ setTitle("Import Module");\r
+ setDescription("Choose the Module file and the import location, then press Finish.");\r
}\r
\r
public void createControl(Composite parent) {\r
\r
createProjectsRoot(workArea);\r
\r
- createDropDown(workArea);\r
+ createTree(workArea);\r
}\r
\r
private void createProjectsRoot(Composite workArea) {\r
});\r
\r
}\r
- \r
- private void createDropDown(Composite workArea) {\r
- \r
- final ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
- \r
- new Label(workArea, SWT.NONE).setText("Import target:"); \r
- \r
- //Get resources for the DropDown-selection\r
- try{\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+\r
+ private void createTree(Composite workArea){\r
+ \r
+ //set label for tree\r
+ Label title = new Label(workArea, SWT.NONE);\r
+ title.setText("Select import location:");\r
+\r
+ try {\r
+ Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ Resource model = SimanticsUI.getProject().get();\r
+ return model;\r
+ }\r
+\r
+ });\r
+\r
+ modelExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+ modelExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/ImportModuleTree");\r
+\r
+ modelExplorer.finish();\r
+\r
+ modelExplorer.setInput(null, input);\r
\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- \r
- Resource model;\r
- current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
- //If there is no selection\r
- if(current == null){\r
- model = SimanticsUI.getProject().get();\r
- }\r
- else{\r
- model = graph.getPossibleObject(current, l0.PartOf);\r
- } \r
- currentModelName = NameUtils.getSafeName(graph, current);\r
- \r
- //Check if selection is not in top-level folder\r
- String modelName = NameUtils.getSafeName(graph, model);\r
- while (!modelName.equalsIgnoreCase("Development Project")){\r
- Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
- String previousName = NameUtils.getSafeName(graph, previousResource);\r
- if (previousName.equalsIgnoreCase("Development Project")){\r
- currentModelName = modelName;\r
- }\r
- //If selection is under Built-in Functions directory\r
- if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
- model = SimanticsUI.getProject().get();\r
- current = null;\r
- break;\r
- }\r
- current = model;\r
- model = graph.getPossibleObject(model, l0.PartOf);\r
- modelName = NameUtils.getSafeName(graph, model);\r
- }\r
- for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
- String name = NameUtils.getSafeName(graph, r);\r
- resources.add(Pair.make(r, name));\r
- }\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ modelExplorer);\r
+ \r
+ ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
\r
- };\r
- });\r
- }\r
- catch (DatabaseException e) {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ selectionMade = true;\r
+ validatePage();\r
+ }\r
+ });\r
+ \r
+\r
+ } catch (DatabaseException e) {\r
e.printStackTrace();\r
- }\r
- //Create dropdown-bar\r
- final CCombo drop = new CCombo(workArea, SWT.BORDER);\r
- {\r
- drop.setEditable(false);\r
- drop.setText("");\r
- drop.setToolTipText("Selects the Model where to import the Module.");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop); \r
- \r
- //Fill the Dropdown-list\r
- for(int a=0; a<resources.size(); a++){\r
- drop.add(resources.get(a).second);\r
- }\r
- int selectionNumber = 0;\r
- for(int a=0; a<resources.size(); a++){\r
- if (currentModelName.equals(resources.get(a).second)){\r
- selectionNumber = a;\r
- }\r
- }\r
- //Show selected model as default\r
- drop.select(selectionNumber);\r
- selectedModel = current;\r
- if (selectedModel == null){\r
- selectedModel = resources.get(0).first;\r
- }\r
- \r
- drop.addModifyListener(new ModifyListener(){\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- \r
- for(int a=0; a<resources.size(); a++){\r
- if (drop.getText().equals(resources.get(a).second))\r
- selectedModel = resources.get(a).first;\r
- } \r
- validatePage(); \r
- }\r
- });\r
- }\r
- }\r
+ }\r
+\r
+ }\r
\r
//Set filePathField active\r
public void setVisible(boolean visible) {\r
} \r
}\r
\r
+ //Get selection from the tree\r
+ @SuppressWarnings("unchecked")\r
+ public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+ Class<T> clazz) {\r
+ \r
+ if(explorer == null)\r
+ return null;\r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return null;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+ if (inc == null)\r
+ return null;\r
+ final T resource = (T) inc.getAdapter(clazz);\r
+\r
+ return resource;\r
+ }\r
+ \r
//Create project after finish is pressed.\r
public boolean createProjects() {\r
\r
String selected = previouslyBrowsedFile;\r
- if(selected == null) return false;\r
+ if(selected == null){ \r
+ setErrorMessage("Error when retrieving resource");\r
+ return false;\r
+ }\r
+ \r
+ selectedModel= getExplorerResource(modelExplorer, Resource.class);\r
+ if(selectedModel == null){\r
+ setErrorMessage("No file selected");\r
+ return false;\r
+ }\r
\r
TransferableGraph1 tg = null;\r
try {\r
} catch (RuntimeBindingConstructionException e) {\r
e.printStackTrace();\r
} catch (IOException e) {\r
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
- mb.setText("Error");\r
- mb.setMessage("The imported file is not of type: Module Type");\r
- mb.open();\r
+ setErrorMessage("The imported file is not of type: Module Type");\r
+ return false;\r
+ }\r
+ if(tg == null){\r
+ setErrorMessage("The imported file is not of type: Module Type");\r
return false;\r
}\r
- if(tg == null) return false;\r
\r
\r
DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(selectedModel);\r
\r
final Resource root = ia.getRoot();\r
\r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) {\r
- Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
- String type = "...";\r
- if(instanceOf != null)\r
- type = NameUtils.getSafeName(graph, instanceOf);\r
- else {\r
- Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
- if(inheritedFrom != null)\r
- type = NameUtils.getSafeName(graph, inheritedFrom);\r
- }\r
- final String ft = type; \r
- graph.deny(root, Layer0.getInstance(graph).PartOf);\r
- \r
- shell.getDisplay().asyncExec(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
- mb.setText("Error");\r
- mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")");\r
- mb.open(); \r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) {\r
+ Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
+ String type = "...";\r
+ if(instanceOf != null)\r
+ type = NameUtils.getSafeName(graph, instanceOf);\r
+ else {\r
+ Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
+ if(inheritedFrom != null)\r
+ type = NameUtils.getSafeName(graph, inheritedFrom);\r
}\r
- });\r
+ graph.deny(root, Layer0.getInstance(graph).PartOf);\r
+ error = type;\r
+ }\r
}\r
- }\r
- });\r
- return true;\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ if (!error.isEmpty()){\r
+ setErrorMessage("The imported file is not of type: Module Type (" + error +")");\r
+ error = "";\r
+ return false;\r
+ }\r
+ return true;\r
}\r
\r
void validatePage() {\r
\r
- if (previouslyBrowsedFile.isEmpty()){\r
+ if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
setPageComplete(false);\r
return;\r
}\r
\r
+ setErrorMessage(null);\r
setPageComplete(true);\r
\r
}\r