Pārlūkot izejas kodu

Added Preference Page for YAKINDU Statechart Tools

Andreas Mülder 13 gadi atpakaļ
vecāks
revīzija
a8674e5536

+ 15 - 0
plugins/org.yakindu.sct.simulation.ui/plugin.xml

@@ -98,4 +98,19 @@
        </adapter>
     </factory>
  </extension>
+ <extension
+       point="org.eclipse.ui.preferencePages">
+    <page
+          class="org.yakindu.sct.simulation.ui.preferences.SimulationPreferencePage"
+          id="org.yakindu.sct.simulation.ui.preferences.SimulationPreferencePage"
+          name="Simulation"
+          category="org.yakindu.sct.ui.preferences.root">
+    </page>
+ </extension>
+ <extension
+       point="org.eclipse.core.runtime.preferences">
+    <initializer
+          class="org.yakindu.sct.simulation.ui.preferences.PreferenceInitializer">
+    </initializer>
+ </extension>
 </plugin>

+ 23 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/AbstractDynamicNotationHandler.java

@@ -1,7 +1,11 @@
 package org.yakindu.sct.simulation.ui.model.presenter;
 
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.widgets.Display;
 import org.yakindu.sct.model.sexec.Trace;
+import org.yakindu.sct.simulation.ui.SimulationActivator;
+import org.yakindu.sct.simulation.ui.preferences.SimulationPreferenceConstants;
 
 import de.itemis.gmf.runtime.commons.highlighting.IHighlightingSupport;
 
@@ -10,10 +14,17 @@ import de.itemis.gmf.runtime.commons.highlighting.IHighlightingSupport;
  * 
  */
 public abstract class AbstractDynamicNotationHandler implements
-		IDynamicNotationHandler {
+		IDynamicNotationHandler, IPropertyChangeListener {
 
 	protected abstract void visualizeStep(Trace trace);
 
+	protected abstract void updatePreferences();
+
+	public AbstractDynamicNotationHandler() {
+		SimulationActivator.getDefault().getPreferenceStore()
+				.addPropertyChangeListener(this);
+	}
+
 	private IHighlightingSupport support;
 
 	public IHighlightingSupport getHighlightingSupport() {
@@ -31,4 +42,15 @@ public abstract class AbstractDynamicNotationHandler implements
 			}
 		});
 	}
+
+	public void propertyChange(PropertyChangeEvent event) {
+		if (SimulationPreferenceConstants.STATE_BACKGROUND_HIGHLIGHTING_COLOR
+				.equals(event.getProperty())
+				|| SimulationPreferenceConstants.TRANSITION_HIGHLIGHTING_COLOR
+						.equals(event.getProperty())
+				|| SimulationPreferenceConstants.STATE_FOREGROUND_HIGHLIGHTING_COLOR
+						.equals(event.getProperty())) {
+			updatePreferences();
+		}
+	}
 }

+ 49 - 8
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/DefaultDynamicNotationHandler.java

@@ -1,10 +1,29 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
 package org.yakindu.sct.simulation.ui.model.presenter;
 
+import static org.yakindu.sct.simulation.ui.preferences.SimulationPreferenceConstants.STATE_FOREGROUND_HIGHLIGHTING_COLOR;
+import static org.yakindu.sct.simulation.ui.preferences.SimulationPreferenceConstants.STATE_BACKGROUND_HIGHLIGHTING_COLOR;
+import static org.yakindu.sct.simulation.ui.preferences.SimulationPreferenceConstants.TRANSITION_HIGHLIGHTING_COLOR;
+
 import java.util.ArrayList;
 import java.util.List;
 
 import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
 import org.yakindu.sct.model.sexec.ReactionFired;
 import org.yakindu.sct.model.sexec.Trace;
 import org.yakindu.sct.model.sexec.TraceNodeExecuted;
@@ -12,6 +31,7 @@ import org.yakindu.sct.model.sexec.TraceStateEntered;
 import org.yakindu.sct.model.sexec.TraceStateExited;
 import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.simulation.core.runtime.IExecutionContext;
+import org.yakindu.sct.simulation.ui.SimulationActivator;
 
 import de.itemis.gmf.runtime.commons.highlighting.HighlightingParameters;
 
@@ -20,13 +40,20 @@ import de.itemis.gmf.runtime.commons.highlighting.HighlightingParameters;
  * @author axel terfloth - Additions
  * 
  */
-public class DefaultDynamicNotationHandler extends AbstractDynamicNotationHandler {
+public class DefaultDynamicNotationHandler extends
+		AbstractDynamicNotationHandler {
 
-	private static final HighlightingParameters TRANSITION_PARAMS = new HighlightingParameters(
+	private static HighlightingParameters TRANSITION_PARAMS = new HighlightingParameters(
 			0, ColorConstants.darkGreen, ColorConstants.gray, false);
 
+	private static HighlightingParameters STATE_PARAMS = HighlightingParameters.DEFAULT;
+
 	private List<EObject> lastTransitionPath = new ArrayList<EObject>();
 
+	public DefaultDynamicNotationHandler() {
+		updatePreferences();
+	}
+
 	public void restoreNotationState(IExecutionContext context) {
 		for (Vertex vertex : context.getAllActiveStates()) {
 			getHighlightingSupport().fadeIn(vertex,
@@ -48,7 +75,7 @@ public class DefaultDynamicNotationHandler extends AbstractDynamicNotationHandle
 		getHighlightingSupport().fadeOut(
 				((TraceStateExited) trace).getState().getSourceElement(),
 				HighlightingParameters.DEFAULT);
-		
+
 		for (EObject obj : lastTransitionPath) {
 			getHighlightingSupport().fadeOut(obj, TRANSITION_PARAMS);
 		}
@@ -57,17 +84,12 @@ public class DefaultDynamicNotationHandler extends AbstractDynamicNotationHandle
 
 	public void visualizeStep(final ReactionFired trace) {
 		EObject transition = trace.getReaction().getSourceElement();
-//		if (lastTransitionPath != null) {
-//			getHighlightingSupport().fadeOut(lastTransitionPath,
-//					TRANSITION_PARAMS);
-//		}
 		getHighlightingSupport().fadeIn(transition, TRANSITION_PARAMS);
 		lastTransitionPath.add(transition);
 	}
 
 	public void visualizeStep(final TraceNodeExecuted trace) {
 		EObject node = trace.getNode().getSourceElement();
-//		getHighlightingSupport().flash(node, HighlightingParameters.DEFAULT);
 		getHighlightingSupport().fadeIn(node, TRANSITION_PARAMS);
 		lastTransitionPath.add(node);
 	}
@@ -83,4 +105,23 @@ public class DefaultDynamicNotationHandler extends AbstractDynamicNotationHandle
 		if (trace instanceof TraceNodeExecuted)
 			visualizeStep((TraceNodeExecuted) trace);
 	}
+
+	protected void updatePreferences() {
+		IPreferenceStore store = SimulationActivator.getDefault()
+				.getPreferenceStore();
+		// read out the new colors
+		RGB foregroundColor = PreferenceConverter.getColor(store,
+				STATE_FOREGROUND_HIGHLIGHTING_COLOR);
+		RGB backgroundColor = PreferenceConverter.getColor(store,
+				STATE_BACKGROUND_HIGHLIGHTING_COLOR);
+		RGB transitionColor = PreferenceConverter.getColor(store,
+				TRANSITION_HIGHLIGHTING_COLOR);
+		// Set the new colors
+		STATE_PARAMS.foregroundFadingColor = new Color(Display.getDefault(),
+				foregroundColor);
+		STATE_PARAMS.backgroundFadingColor = new Color(Display.getDefault(),
+				backgroundColor);
+		TRANSITION_PARAMS.foregroundFadingColor = new Color(
+				Display.getDefault(), transitionColor);
+	}
 }

+ 44 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/preferences/PreferenceInitializer.java

@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.ui.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.swt.graphics.Color;
+
+import org.yakindu.sct.simulation.ui.SimulationActivator;
+import static org.yakindu.sct.simulation.ui.preferences.SimulationPreferenceConstants.*;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ *
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+	private static final Color lightRed = new Color(null, 255, 128, 128);
+
+	public void initializeDefaultPreferences() {
+		IPreferenceStore store = SimulationActivator.getDefault()
+				.getPreferenceStore();
+		PreferenceConverter.setDefault(store,
+				STATE_FOREGROUND_HIGHLIGHTING_COLOR,
+				ColorConstants.red.getRGB());
+
+		PreferenceConverter.setDefault(store,
+				STATE_BACKGROUND_HIGHLIGHTING_COLOR, lightRed.getRGB());
+
+		PreferenceConverter.setDefault(store, TRANSITION_HIGHLIGHTING_COLOR,
+				ColorConstants.green.getRGB());
+	}
+}

+ 26 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/preferences/SimulationPreferenceConstants.java

@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.ui.preferences;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ *
+ */
+public class SimulationPreferenceConstants {
+
+	public static final String STATE_FOREGROUND_HIGHLIGHTING_COLOR = "stateForegroundHighlightingColor";
+
+	public static final String STATE_BACKGROUND_HIGHLIGHTING_COLOR = "stateBackgroundHighlightingColor";
+
+	public static final String TRANSITION_HIGHLIGHTING_COLOR = "transitionHighlightingColor";
+
+}

+ 57 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/preferences/SimulationPreferencePage.java

@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.ui.preferences;
+
+import org.eclipse.jface.preference.*;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.yakindu.sct.simulation.ui.SimulationActivator;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class SimulationPreferencePage extends FieldEditorPreferencePage
+		implements IWorkbenchPreferencePage {
+
+	public SimulationPreferencePage() {
+		super(GRID);
+		setPreferenceStore(SimulationActivator.getDefault()
+				.getPreferenceStore());
+		setDescription("Preference Page for simulation preferences");
+	}
+
+	public void createFieldEditors() {
+		addField(new ColorFieldEditor(
+				SimulationPreferenceConstants.STATE_FOREGROUND_HIGHLIGHTING_COLOR,
+				"&state highlighting foreground color:", getFieldEditorParent()));
+
+		addField(new ColorFieldEditor(
+				SimulationPreferenceConstants.STATE_BACKGROUND_HIGHLIGHTING_COLOR,
+				"&state highlighting background color:", getFieldEditorParent()));
+
+		addField(new ColorFieldEditor(
+				SimulationPreferenceConstants.TRANSITION_HIGHLIGHTING_COLOR,
+				"&transition highlighting color", getFieldEditorParent()));
+	}
+
+	@Override
+	protected void performDefaults() {
+		super.performDefaults();
+	}
+
+	public void init(IWorkbench workbench) {
+		setPreferenceStore(SimulationActivator.getDefault()
+				.getPreferenceStore());
+	}
+
+}

+ 8 - 0
plugins/org.yakindu.sct.ui/plugin.xml

@@ -18,4 +18,12 @@
             name="SC Simulation">
       </perspective>
    </extension>
+   <extension
+         point="org.eclipse.ui.preferencePages">
+      <page
+            class="org.yakindu.sct.ui.preferences.YakinduRootPreferencePage"
+            id="org.yakindu.sct.ui.preferences.root"
+            name="YAKINDU SCT2">
+      </page>
+   </extension>
 </plugin>

+ 68 - 0
plugins/org.yakindu.sct.ui/src/org/yakindu/sct/ui/preferences/YakinduRootPreferencePage.java

@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class YakinduRootPreferencePage extends PreferencePage implements
+		IWorkbenchPreferencePage {
+
+	//Visit us ;-)
+	private static final String YAKINDU_ORG = "http://www.yakindu.org/";
+
+	@Override
+	protected Control createContents(Composite parent) {
+		Label label = new Label(parent, SWT.NONE);
+		label.setText("YAKINDU Statechart Tools general settings.");
+		Link link = new Link(parent, SWT.NONE);
+		link.setText("For more information visit <a>www.yakindu.org</a>");
+		link.addListener(SWT.Selection, new Listener() {
+			@Override
+			public void handleEvent(Event event) {
+				org.eclipse.swt.program.Program
+						.launch(YAKINDU_ORG);
+			}
+		});
+		return parent;
+	}
+
+	@Override
+	public void createControl(Composite parent) {
+		Composite content = new Composite(parent, SWT.NONE);
+		setControl(content);
+		GridLayout layout = new GridLayout();
+		layout.marginWidth = 0;
+		layout.marginHeight = 0;
+		content.setLayout(layout);
+		createContents(content);
+	}
+
+	@Override
+	public void init(IWorkbench workbench) {
+		// Nothing to do
+	}
+
+}