--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.ui.part.IPage;\r
+import org.eclipse.ui.part.IPageSite;\r
+import org.simantics.browsing.ui.GraphExplorer;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.platform.PropertyPageView;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class EnumerationIndexRenameNodeHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ ISelection sel2 = HandlerUtil.getActiveMenuSelection(event);\r
+ NodeContext ctx = ISelectionUtils.filterSingleSelection(sel2, NodeContext.class);\r
+ if (ctx == null)\r
+ return null;\r
+\r
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
+ if (part == null)\r
+ return null;\r
+\r
+ PropertyPageView ppv = (PropertyPageView) part;\r
+ IPage p = ppv.getCurrentPage();\r
+ Control control = p.getControl();\r
+ \r
+ Control geComposite = findGEComposite(control);\r
+ GraphExplorerComposite ge = (GraphExplorerComposite) geComposite;\r
+ ge.getExplorer().startEditing(ctx, ColumnKeys.SINGLE);\r
+ \r
+ return null;\r
+ }\r
+ \r
+ private Control findGEComposite(Control control) {\r
+ Control[] comp = ((Composite) control).getChildren();\r
+ Control ge = null;\r
+ for (Control cont : comp) {\r
+ if (cont instanceof GraphExplorerComposite)\r
+ return cont;\r
+ else if (cont instanceof Composite) {\r
+ ge = findGEComposite(cont);\r
+ return ge;\r
+ }\r
+ else\r
+ continue;\r
+ }\r
+ return ge;\r
+ }\r
+}\r
import java.util.HashSet;\r
import java.util.List;\r
\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.eclipse.swt.widgets.Tree;\r
import org.eclipse.swt.widgets.TreeItem;\r
import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.Simantics;\r
import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
import org.simantics.browsing.ui.swt.widgets.Button;\r
import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.db.common.utils.ListUtils;\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.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableIndexesWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameInputValidator;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
-import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.utils.threads.SWTThread;\r
import org.simantics.utils.ui.AdaptionUtils;\r
\r
public class EnumerationTab extends LabelPropertyTabContributor implements Widget {\r
Variable variable;\r
\r
Table table;\r
+\r
+ private Button add;\r
+ private Button remove;\r
+ \r
@Override\r
public void createControls(Composite body, IWorkbenchSite site,\r
final ISessionContext context, WidgetSupport support) {\r
indexExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
"displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);\r
\r
+ indexExplorer.setContextMenuId("#EnumerationTabPopup");\r
+ \r
indexExplorer\r
.setBrowseContexts(SysdynResource.URIs.EnumerationIndexes);\r
indexExplorer.setInputSource(new SingleSelectionInputSource(\r
final EnumerationIndexNode node = (EnumerationIndexNode) context.getAdapter(EnumerationIndexNode.class);\r
node.setShowInChartsSelected(checked);\r
\r
- SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ Simantics.getSession().asyncRequest(new ReadRequest() {\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
updateModelResults(graph);\r
}\r
});\r
\r
-\r
+ \r
indexExplorer.finish();\r
\r
GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(\r
((Tree) c).setLinesVisible(true);\r
\r
\r
- final Button add = new Button(container, support, SWT.None);\r
+ add = new Button(container, support, SWT.None);\r
add.setText("Add");\r
- add.addSelectionListener(new addEnumerationIndexListener(support));\r
+ add.addSelectionListener(new AddEnumerationIndexListener(support));\r
\r
- final Button remove = new Button(container, support, SWT.None);\r
+ remove = new Button(container, support, SWT.None);\r
remove.setText("Remove");\r
- remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
+ remove.addSelectionListener(new RemoveEnumerationIndexListener(support));\r
\r
ReplaceableIndexesWidget externalIndexes = new ReplaceableIndexesWidget(container, support, SWT.NULL);\r
GridDataFactory.fillDefaults().applyTo(externalIndexes.getWidget());\r
\r
}\r
\r
- private class addEnumerationIndexListener implements SelectionListener, Widget {\r
+ private class AddEnumerationIndexListener implements SelectionListener, Widget {\r
\r
Resource enumerationIndexes;\r
\r
- public addEnumerationIndexListener(WidgetSupport support) {\r
+ public AddEnumerationIndexListener(WidgetSupport support) {\r
support.register(this);\r
}\r
\r
@Override\r
public void widgetSelected(SelectionEvent e) {\r
try {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ \r
+ currentItemCount = getCurrentItemCount();\r
+ lastItemCount = currentItemCount;\r
+ \r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.markUndoPoint();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
\r
ArrayList<Resource> index = new ArrayList<Resource>();\r
index.add(ei);\r
ListUtils.insertBack(graph, enumerationIndexes, index);\r
+ \r
+ List<Resource> list = ListUtils.toList(graph, enumerationIndexes);\r
+ if (!list.isEmpty())\r
+ updateRemoveButton(true);\r
+ \r
+ Layer0Utils.addCommentMetadata(graph, "Added new Enumeration Index " + NameUtils.getSafeName(graph, ei) + " to " + enumerationIndexes);\r
}\r
});\r
+ \r
+ enableItemForRename();\r
+ \r
} catch (DatabaseException e1) {\r
e1.printStackTrace();\r
}\r
\r
@Override\r
public void widgetDefaultSelected(SelectionEvent e) {\r
-\r
+ System.out.println("asd");\r
}\r
\r
}\r
\r
- private class removeEnumerationIndexListener implements SelectionListener, Widget {\r
+ private class RemoveEnumerationIndexListener implements SelectionListener, Widget {\r
\r
Resource enumerationIndexes;\r
\r
- public removeEnumerationIndexListener(WidgetSupport support) {\r
+ public RemoveEnumerationIndexListener(WidgetSupport support) {\r
support.register(this);\r
}\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).Enumeration_enumerationIndexList);\r
+ List<Resource> list = ListUtils.toList(graph, enumerationIndexes);\r
+ if (list.isEmpty())\r
+ updateRemoveButton(false);\r
}\r
});\r
} catch (DatabaseException e) {\r
final IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();\r
\r
try {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.markUndoPoint();\r
for(Object o : selection.toList()) {\r
Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
if(r == null)\r
continue;\r
ListUtils.removeElement(graph, enumerationIndexes, r);\r
}\r
+ List<Resource> list = ListUtils.toList(graph, enumerationIndexes);\r
+ if (list.isEmpty())\r
+ updateRemoveButton(false);\r
+ Layer0Utils.addCommentMetadata(graph, "Removed Enumeration Index " );\r
}\r
});\r
} catch (DatabaseException e1) {\r
public void widgetSelected(SelectionEvent e) {\r
final boolean selected = showAll.getWidget().getSelection();\r
try {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.markUndoPoint();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
List<Resource> indexes = ListUtils.toList(graph, enumerationIndexes);\r
for(Resource index : indexes) {\r
graph.claimLiteral(index, sr.EnumerationIndex_showEnumerationIndexInCharts, false, Bindings.BOOLEAN);\r
}\r
}\r
- \r
+ Layer0Utils.addCommentMetadata(graph, "Modified Show all in charts");\r
updateModelResults(graph);\r
}\r
});\r
public void setInput(ISessionContext context, Object input) {\r
variable = AdaptionUtils.adaptToSingle(input, Variable.class);\r
}\r
+ \r
+ private void updateRemoveButton(final boolean enable) {\r
+ SWTThread.getThreadAccess().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ remove.getWidget().setEnabled(enable);\r
+ if (!enable)\r
+ add.getWidget().setFocus();\r
+ }\r
+ });\r
+ }\r
+ \r
+ private int currentItemCount = 0;\r
+ private int lastItemCount = 0;\r
+ \r
+ private void enableItemForRename() {\r
+ \r
+ \r
+ \r
+ Job j = new Job("") {\r
+\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ \r
+ while (lastItemCount == currentItemCount) {\r
+ SWTThread.getThreadAccess().syncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ lastItemCount = getCurrentItemCount();\r
+ }\r
+ });\r
+ try {\r
+ Thread.sleep(50);\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ SWTThread.getThreadAccess().syncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ Control c = indexExplorer.getExplorer().getControl();\r
+ if (c instanceof Tree) {\r
+ Tree tree = (Tree) c; \r
+ TreeItem[] items = tree.getItems();\r
+ TreeItem lastItem = items[items.length - 1];\r
+ tree.setSelection(lastItem);\r
+ }\r
+ }\r
+ });\r
+ \r
+ SWTThread.getThreadAccess().syncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ Control c = indexExplorer.getExplorer().getControl();\r
+ if (c instanceof Tree) {\r
+ Tree tree = (Tree) c; \r
+ TreeItem[] items = tree.getItems();\r
+ TreeItem lastItem = items[items.length - 1];\r
+ NodeContext context = (NodeContext)lastItem.getData();\r
+ tree.setSelection(lastItem);\r
+ indexExplorer.getExplorer().startEditing(context, ColumnKeys.SINGLE); \r
+ tree.setSelection(lastItem);\r
+ }\r
+ }\r
+ });\r
+ \r
+ return Status.OK_STATUS;\r
+ }\r
+ };\r
+ j.schedule();\r
+ }\r
+ \r
+ public int getCurrentItemCount() {\r
+ Control c = indexExplorer.getExplorer().getControl();\r
+ Tree tree = (Tree) c; \r
+ return tree.getItemCount();\r
+ }\r
}\r
+\r
package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
\r
+import org.simantics.Simantics;\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
import org.simantics.browsing.ui.common.node.IModifiableNode;\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.request.Read;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.utils.VariableNameValidator;\r
-import org.simantics.ui.SimanticsUI;\r
\r
public class EnumerationIndexNode extends AbstractNode<Resource> implements IModifiableNode, IDoubleClickableNode {\r
\r
\r
};\r
try {\r
- return SimanticsUI.getSession().syncRequest(request);\r
+ return Simantics.getSession().syncRequest(request);\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
return "";\r
\r
@Override\r
public void modify(final String label) {\r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ Simantics.getSession().asyncRequest(new WriteRequest() {\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
\r
public void setShowInChartsSelected(final boolean selected) {\r
try {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.markUndoPoint();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
graph.claimLiteral(data, sr.EnumerationIndex_showEnumerationIndexInCharts, selected);\r
+ Layer0Utils.addCommentMetadata(graph, "Modified show in chart of " + NameUtils.getSafeName(graph, data) + " to " + selected);\r
}\r
});\r
} catch (DatabaseException e) {\r