import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ObjectsWithType;\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.layer0.Layer0;\r
\r
private void setValue(WriteGraph graph, Resource resource) throws DatabaseException {\r
Resource property = graph.getResource(propertyURI);\r
Boolean value = graph.getPossibleRelatedValue(resource, property, Bindings.BOOLEAN);\r
- if (value == null)\r
+ if (value == null) {\r
graph.claimLiteral(resource, property, !defaultValue);\r
- else\r
- graph.claimLiteral(resource, property, Boolean.FALSE.equals(value));\r
+ Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getPossibleRelatedValue2(property, Layer0.getInstance(graph).HasName, Bindings.STRING) + " for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasLabel, Bindings.STRING) + " to " + !defaultValue);\r
+ } else { \r
+ boolean newValue = Boolean.FALSE.equals(value);\r
+ graph.claimLiteral(resource, property, newValue);\r
+ Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getPossibleRelatedValue2(property, Layer0.getInstance(graph).HasName, Bindings.STRING) + " for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasLabel, Bindings.STRING) + " to " + newValue);\r
+ }\r
}\r
}
\ No newline at end of file
*******************************************************************************/\r
package org.simantics.jfreechart.chart.properties;\r
\r
+import java.util.Arrays;\r
+\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.jface.resource.ImageDescriptor;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Display;\r
import org.eclipse.swt.widgets.Shell;\r
+import org.simantics.Simantics;\r
import org.simantics.browsing.ui.swt.widgets.Button;\r
import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\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.WriteRequest;\r
+import org.simantics.db.common.request.UniqueRead;\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.db.procedure.Listener;\r
import org.simantics.db.request.Read;\r
import org.simantics.diagram.stubs.G2DResource;\r
+import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.JFreeChartResource;\r
-import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.RunnableWithObject;\r
import org.simantics.utils.datastructures.Triple;\r
import org.simantics.utils.ui.AdaptionUtils;\r
this.e = e;\r
super.widgetSelected(e);\r
}\r
+ \r
+ @Override\r
+ public void beforeApply(final Resource input) {\r
+ try {\r
+ final RGB oldRGB = Simantics.getSession().syncRequest(new UniqueRead<RGB>() {\r
+\r
+ @Override\r
+ public RGB perform(ReadGraph graph) throws DatabaseException {\r
+ Resource resource = getResource(graph, input);\r
+ return getColor(graph, resource);\r
+ }\r
+ });\r
+ \r
+ final Display display = color.getWidget().getDisplay();\r
+ \r
+ // Use color dialog to select a color\r
+ Shell shell = new Shell(display);\r
+ ColorDialog cd = new ColorDialog(shell);\r
+ Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150);\r
+ cd.getParent().setLocation(point.x, point.y);\r
+ cd.setText("Select color");\r
+ cd.setRGB(oldRGB);\r
+ rgb = cd.open();\r
+ if(rgb == null)\r
+ return;\r
+ \r
+ \r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
\r
@Override\r
public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
- if(color.getWidget().isDisposed())\r
- return;\r
- \r
- final Resource resource = getResource(graph, input);\r
- final Display display = color.getWidget().getDisplay();\r
- final RGB oldRGB = getColor(graph, resource);\r
\r
- display.asyncExec(new RunnableWithObject(oldRGB) {\r
- @Override\r
- public void run() {\r
- // Use color dialog to select a color\r
- Shell shell = new Shell(display);\r
- ColorDialog cd = new ColorDialog(shell);\r
- Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150);\r
- cd.getParent().setLocation(point.x, point.y);\r
- cd.setText("Select color");\r
- cd.setRGB((RGB)getObject());\r
- rgb = cd.open();\r
- if(rgb == null)\r
- return;\r
- \r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- G2DResource g2d = G2DResource.getInstance(graph);\r
- float[] components = new float[] {rgb.red / 255.0f, rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f};\r
- graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); \r
- }\r
- });\r
- \r
- }\r
- });\r
- \r
- \r
-\r
+ G2DResource g2d = G2DResource.getInstance(graph);\r
+ float[] components = new float[] {rgb.red / 255.0f, rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f};\r
+ Resource resource = getResource(graph, input);\r
+ float[] currentComponents = graph.getPossibleRelatedValue2(resource, getColorRelation(graph));\r
+ if (currentComponents == null || !Arrays.equals(components, currentComponents)) {\r
+ graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components);\r
+ Layer0Utils.addCommentMetadata(graph, "Modified color of " + NameUtils.getSafeName(graph, resource) + " to " + Arrays.toString(components));\r
+ }\r
}\r
-\r
}\r
\r
/**\r
float[] components = java.awt.Color.BLUE.getColorComponents(new float[4]);\r
components[3] = 1.0f;\r
graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components);\r
+ Layer0Utils.addCommentMetadata(graph, "Color for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING) + " set to custom ");\r
}\r
} else {\r
// Default selected, remove color definition\r
- graph.deny(resource, getColorRelation(graph));\r
+ Object o = graph.getPossibleObject(resource, getColorRelation(graph));\r
+ if (o != null) {\r
+ graph.deny(resource, getColorRelation(graph));\r
+ Layer0Utils.addCommentMetadata(graph, "Color for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING) + " set to Default");\r
+ }\r
}\r
}\r
}\r