From: jsimomaa Date: Tue, 15 Jul 2014 08:02:30 +0000 (+0000) Subject: refs #5092 X-Git-Tag: v1.29.0~242 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1dffd74bc8fa504b2f12e73e77fee4eca762d11d;p=simantics%2Fsysdyn.git refs #5092 Fixing undo problems in platform by adding graph.markUndoPoint() calls in write transactions git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29886 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/BooleanSelectionListener.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/BooleanSelectionListener.java index 3fe269b9..ff27eb2e 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/BooleanSelectionListener.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/BooleanSelectionListener.java @@ -17,6 +17,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; @@ -85,9 +86,13 @@ public class BooleanSelectionListener extends SelectionListenerImpl { private void setValue(WriteGraph graph, Resource resource) throws DatabaseException { Resource property = graph.getResource(propertyURI); Boolean value = graph.getPossibleRelatedValue(resource, property, Bindings.BOOLEAN); - if (value == null) + if (value == null) { graph.claimLiteral(resource, property, !defaultValue); - else - graph.claimLiteral(resource, property, Boolean.FALSE.equals(value)); + 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); + } else { + boolean newValue = Boolean.FALSE.equals(value); + graph.claimLiteral(resource, property, newValue); + 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); + } } } \ No newline at end of file diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java index e5f003f8..7a0d9ce5 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.simantics.jfreechart.chart.properties; +import java.util.Arrays; + import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.ImageDescriptor; @@ -24,22 +26,26 @@ import org.eclipse.swt.widgets.ColorDialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import org.simantics.Simantics; import org.simantics.browsing.ui.swt.widgets.Button; import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.ui.SimanticsUI; import org.simantics.utils.RunnableWithObject; import org.simantics.utils.datastructures.Triple; import org.simantics.utils.ui.AdaptionUtils; @@ -264,47 +270,50 @@ public class ColorPicker extends Composite implements Widget { this.e = e; super.widgetSelected(e); } + + @Override + public void beforeApply(final Resource input) { + try { + final RGB oldRGB = Simantics.getSession().syncRequest(new UniqueRead() { + + @Override + public RGB perform(ReadGraph graph) throws DatabaseException { + Resource resource = getResource(graph, input); + return getColor(graph, resource); + } + }); + + final Display display = color.getWidget().getDisplay(); + + // Use color dialog to select a color + Shell shell = new Shell(display); + ColorDialog cd = new ColorDialog(shell); + Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150); + cd.getParent().setLocation(point.x, point.y); + cd.setText("Select color"); + cd.setRGB(oldRGB); + rgb = cd.open(); + if(rgb == null) + return; + + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } @Override public void apply(WriteGraph graph, Resource input) throws DatabaseException { - if(color.getWidget().isDisposed()) - return; - - final Resource resource = getResource(graph, input); - final Display display = color.getWidget().getDisplay(); - final RGB oldRGB = getColor(graph, resource); - display.asyncExec(new RunnableWithObject(oldRGB) { - @Override - public void run() { - // Use color dialog to select a color - Shell shell = new Shell(display); - ColorDialog cd = new ColorDialog(shell); - Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150); - cd.getParent().setLocation(point.x, point.y); - cd.setText("Select color"); - cd.setRGB((RGB)getObject()); - rgb = cd.open(); - if(rgb == null) - return; - - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - G2DResource g2d = G2DResource.getInstance(graph); - float[] components = new float[] {rgb.red / 255.0f, rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f}; - graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); - } - }); - - } - }); - - - + G2DResource g2d = G2DResource.getInstance(graph); + float[] components = new float[] {rgb.red / 255.0f, rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f}; + Resource resource = getResource(graph, input); + float[] currentComponents = graph.getPossibleRelatedValue2(resource, getColorRelation(graph)); + if (currentComponents == null || !Arrays.equals(components, currentComponents)) { + graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); + Layer0Utils.addCommentMetadata(graph, "Modified color of " + NameUtils.getSafeName(graph, resource) + " to " + Arrays.toString(components)); + } } - } /** @@ -376,10 +385,15 @@ public class ColorPicker extends Composite implements Widget { float[] components = java.awt.Color.BLUE.getColorComponents(new float[4]); components[3] = 1.0f; graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); + Layer0Utils.addCommentMetadata(graph, "Color for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING) + " set to custom "); } } else { // Default selected, remove color definition - graph.deny(resource, getColorRelation(graph)); + Object o = graph.getPossibleObject(resource, getColorRelation(graph)); + if (o != null) { + graph.deny(resource, getColorRelation(graph)); + Layer0Utils.addCommentMetadata(graph, "Color for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING) + " set to Default"); + } } } }