package org.simantics.sysdyn.ui.properties;\r
\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.List;\r
\r
import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Event;\r
+import org.eclipse.swt.widgets.Listener;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Tree;\r
import org.eclipse.ui.IWorkbenchSite;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\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.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler;\r
import org.simantics.sysdyn.ui.handlers.exports.ExportExternalFunctionFilesHandler;\r
import org.simantics.sysdyn.ui.handlers.imports.ImportExternalFunctionFilesHandler;\r
-import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.threads.SWTThread;\r
\r
/**\r
* Tab for properties of a SysdynModelicaFunction containing all external files added to that function \r
Resource.class));\r
\r
externalFilesExplorer.setContextMenuId("#ExternalFunctionFileBrowser");\r
+ \r
+ externalFilesExplorer.addListenerToControl(SWT.Selection, new Listener() {\r
+ \r
+ @Override\r
+ public void handleEvent(Event event) {\r
+ updateButtons(externalFilesExplorer);\r
+ }\r
+ });\r
+ \r
externalFilesExplorer.finish();\r
-\r
+ \r
GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
externalFilesExplorer);\r
\r
importButton.setText("Import");\r
importButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
+ private Pair<String, String[]> importedFiles; \r
+ \r
+ @Override\r
+ public void beforeApply() {\r
+ Shell shell = importButton.getWidget().getShell();\r
+ importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS); \r
+ }\r
+ \r
@Override\r
- public void apply(WriteGraph graph, final Resource input)\r
- throws DatabaseException {\r
- \r
- importButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- Shell shell = importButton.getWidget().getShell();\r
- \r
- final Pair<String, String[]> importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS);\r
- \r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles);\r
- }\r
- });\r
- }\r
- });\r
-\r
-\r
+ public void apply(WriteGraph graph, final Resource input) throws DatabaseException {\r
+ graph.markUndoPoint();\r
+ ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles);\r
+ Layer0Utils.addCommentMetadata(graph, "Imported External File(s) " + Arrays.toString(importedFiles.second) + " to " + NameUtils.getSafeName(graph, input));\r
+ updateButtons(externalFilesExplorer);\r
}\r
});\r
\r
exportButton = new Button(buttonRow, support, SWT.NONE);\r
exportButton.setText("Export");\r
+ exportButton.getControl().setEnabled(false);\r
exportButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
@Override\r
ExportExternalFunctionFilesHandler.exportFiles(shell, resources);\r
}\r
});\r
-\r
-\r
}\r
});\r
\r
removeButton = new Button(buttonRow, support, SWT.NONE);\r
removeButton.setText("Remove");\r
+ removeButton.getControl().setEnabled(false);\r
removeButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
+ private int delete;\r
+ private List<Resource> resourceList;\r
+ \r
+ @Override\r
+ public void beforeApply() {\r
+ Shell shell = removeButton.getWidget().getShell();\r
+\r
+ resourceList = getSelectedResources(externalFilesExplorer);\r
+ Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+ if(resources.length > 0) {\r
+ MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0,\r
+ new String[] { "OK", "Cancel" }, 0);\r
+ dialog.create();\r
+ delete = dialog.open();\r
+ }\r
+ }\r
+ \r
@Override\r
- public void apply(WriteGraph graph, final Resource input)\r
- throws DatabaseException {\r
-\r
- removeButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- Shell shell = removeButton.getWidget().getShell();\r
-\r
- List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
- Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
- if(resources.length > 0) {\r
- MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0,\r
- new String[] { "OK", "Cancel" }, 0);\r
- dialog.create();\r
- if (dialog.open() == 0) {\r
- RemoveNodeHandler.deleteItem(resources);\r
- }\r
- }\r
- }\r
- });\r
-\r
-\r
+ public void apply(WriteGraph graph, final Resource input) throws DatabaseException {\r
+ if (delete == 0) {\r
+ Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("Removed External File(s) ");\r
+ for (Resource resource : resources) {\r
+ RemoverUtil.remove(graph, resource);\r
+ sb.append(NameUtils.getSafeName(graph, resource) + " ");\r
+ }\r
+ sb.append("from " + NameUtils.getSafeName(graph, input));\r
+ Layer0Utils.addCommentMetadata(graph, sb.toString());\r
+ \r
+ updateButtons(externalFilesExplorer);\r
+ }\r
}\r
});\r
}\r
@Override\r
public void setInput(ISessionContext context, Object input) {\r
externalFilesExplorer.setInput(context, input);\r
+ updateButtons(externalFilesExplorer);\r
}\r
\r
/**\r
*/\r
private List<Resource> getSelectedResources(GraphExplorerComposite explorer) {\r
List<Resource> result = new ArrayList<Resource>();\r
- \r
ISelection selection = ((ISelectionProvider) explorer\r
.getAdapter(ISelectionProvider.class)).getSelection();\r
if (selection == null)\r
}\r
return result;\r
}\r
-\r
+ \r
+ protected void updateButtons(final GraphExplorerComposite explorer) {\r
+ if (SWTThread.getThreadAccess().currentThreadAccess()) {\r
+ runnable.run();\r
+ } else {\r
+ SWTThread.getThreadAccess().asyncExec(runnable);\r
+ }\r
+ }\r
+ \r
+ Runnable runnable = new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ ISelection selection = ((ISelectionProvider) externalFilesExplorer.getAdapter(ISelectionProvider.class)).getSelection();\r
+ \r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ @SuppressWarnings("unchecked")\r
+ List<AdaptableHintContext> selections = iss.toList();\r
+ \r
+ boolean enabled = false;\r
+ if (!selections.isEmpty()) \r
+ enabled = true;\r
+ removeButton.getControl().setEnabled(enabled);\r
+ exportButton.getControl().setEnabled(enabled);\r
+ }\r
+ };\r
}\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Group;\r
import org.eclipse.ui.IWorkbenchSite;\r
-import org.lobobrowser.util.ID;\r
import org.simantics.browsing.ui.swt.widgets.Label;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.IsParent;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.request.Read;\r
import org.simantics.jfreechart.chart.properties.AdjustableTab;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.properties.widgets.FunctionLabelFactory;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.FunctionNameInputValidator;\r
import org.simantics.sysdyn.ui.properties.widgets.functions.FunctionCodeWidget;\r
+import org.simantics.sysdyn.utils.SelectionUtils;\r
\r
public class FunctionTab extends AdjustableTab {\r
\r
\r
@Override\r
public Boolean perform(ReadGraph graph) throws DatabaseException {\r
- boolean editable = new IsParent(SysdynResource.getInstance(graph).Built$in_Functions, r).perform(graph);\r
- return !editable;\r
+ return SelectionUtils.canEdit(graph, r);\r
}\r
});\r
information.setEditable(editable);\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.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
import org.simantics.layer0.Layer0;\r
throws DatabaseException {\r
if(selectedLibraries != null) {\r
Layer0 l0 = Layer0.getInstance(graph);\r
- for(Resource library : selectedLibraries) {\r
- graph.claim(input, l0.IsLinkedTo, library);\r
- }\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("Added Shared Function Library ");\r
+ for(Resource library : selectedLibraries) {\r
+ graph.claim(input, l0.IsLinkedTo, library);\r
+ sb.append(NameUtils.getSafeName(graph, library) + " ");\r
+ }\r
+ sb.append("to " + NameUtils.getSafeName(graph, input));\r
+ Layer0Utils.addCommentMetadata(graph, sb.toString());\r
}\r
}\r
});\r
throws DatabaseException {\r
if(selectedLibraries != null) {\r
Layer0 l0 = Layer0.getInstance(graph);\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("Removed Shared Function Library ");\r
for(Resource library : selectedLibraries) {\r
graph.deny(input, l0.IsLinkedTo, library);\r
+ sb.append(NameUtils.getSafeName(graph, library) + " ");\r
}\r
+ sb.append("from " + NameUtils.getSafeName(graph, input));\r
+ Layer0Utils.addCommentMetadata(graph, sb.toString());\r
}\r
}\r
});\r