Просмотр исходного кода

Enabled reuse of creationWizard with different preferenceHint

benjamin.schwertfeger@gmail.com 13 лет назад
Родитель
Сommit
234da92afa

+ 19 - 11
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/factories/FactoryUtils.java

@@ -12,6 +12,7 @@ package org.yakindu.sct.ui.editor.factories;
 
 import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
 import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
 import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
@@ -85,6 +86,17 @@ public final class FactoryUtils {
 	 * @return instanceof {@link Statechart}
 	 */
 	public static void createStatechartModel(Resource resource) {
+		createStatechartModel(resource,
+				DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+	}
+
+	/**
+	 * Creates a Statechart with an initial Region and an initial State
+	 * 
+	 * @return instanceof {@link Statechart}
+	 */
+	public static void createStatechartModel(Resource resource,
+			PreferencesHint preferencesHint) {
 		// Create a statechart
 		Statechart statechart = SGraphFactory.eINSTANCE.createStatechart();
 		String lastSegment = resource.getURI().lastSegment();
@@ -93,8 +105,7 @@ public final class FactoryUtils {
 		statechart.setName(statechartName);
 
 		Diagram diagram = ViewService.createDiagram(statechart,
-				StatechartDiagramEditor.ID,
-				DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+				StatechartDiagramEditor.ID, preferencesHint);
 		diagram.setElement(statechart);
 		// Add to resource
 		resource.getContents().add(statechart);
@@ -103,9 +114,8 @@ public final class FactoryUtils {
 		Region region = SGraphFactory.eINSTANCE.createRegion();
 		region.setName(INITIAL_REGION_NAME);
 		statechart.getRegions().add(region);
-		Node regionView = ViewService
-				.createNode(diagram, region, SemanticHints.REGION,
-						DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+		Node regionView = ViewService.createNode(diagram, region,
+				SemanticHints.REGION, preferencesHint);
 		setRegionViewLayoutConstraint(regionView);
 		// // Create an initial state
 		Entry initialState = SGraphFactory.eINSTANCE.createEntry();
@@ -113,14 +123,14 @@ public final class FactoryUtils {
 		region.getVertices().add(initialState);
 		Node initialStateView = ViewService.createNode(
 				getRegionCompartmentView(regionView), initialState,
-				SemanticHints.ENTRY, DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+				SemanticHints.ENTRY, preferencesHint);
 		setInitialStateViewLayoutConstraint(initialStateView);
 		// Create the first state
 		State state = SGraphFactory.eINSTANCE.createState();
 		region.getVertices().add(state);
 		Node stateNode = ViewService.createNode(
 				getRegionCompartmentView(regionView), state,
-				SemanticHints.STATE, DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+				SemanticHints.STATE, preferencesHint);
 		setStateViewLayoutConstraint(stateNode);
 		// Create the transition from Initial State to State
 		Transition transition = SGraphFactory.eINSTANCE.createTransition();
@@ -128,12 +138,10 @@ public final class FactoryUtils {
 		transition.setTarget(state);
 		initialState.getOutgoingTransitions().add(transition);
 		ViewService.createEdge(initialStateView, stateNode, transition,
-				SemanticHints.TRANSITION,
-				DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+				SemanticHints.TRANSITION, preferencesHint);
 		// Create the textcompartment for events / variables
 		Node textCompartment = ViewService.createNode(diagram, statechart,
-				SemanticHints.STATECHART_TEXT,
-				DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+				SemanticHints.STATECHART_TEXT, preferencesHint);
 		setTextCompartmentLayoutConstraint(textCompartment);
 
 	}

+ 17 - 3
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/wizards/CreationWizard.java

@@ -30,6 +30,7 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
 import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
 import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
 import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -43,6 +44,7 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.WorkspaceModifyOperation;
 import org.eclipse.ui.part.FileEditorInput;
+import org.yakindu.sct.ui.editor.DiagramActivator;
 import org.yakindu.sct.ui.editor.StatechartImages;
 import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
 import org.yakindu.sct.ui.editor.factories.FactoryUtils;
@@ -65,6 +67,8 @@ public class CreationWizard extends Wizard implements INewWizard {
 
 	private boolean openOnCreate = true;
 
+	protected PreferencesHint preferencesHint = DiagramActivator.DIAGRAM_PREFERENCES_HINT;
+
 	private IWorkbench workbench;
 
 	public void init(IWorkbench workbench, IStructuredSelection selection) {
@@ -72,7 +76,6 @@ public class CreationWizard extends Wizard implements INewWizard {
 		this.selection = selection;
 		setWindowTitle("New YAKINDU Statechart");
 		setNeedsProgressMonitor(true);
-
 	}
 
 	@Override
@@ -126,7 +129,7 @@ public class CreationWizard extends Wizard implements INewWizard {
 		return false;
 	}
 
-	protected Resource createDiagram(URI diagramURI, URI modelURI,
+	protected Resource createDiagram(final URI diagramURI, final URI modelURI,
 			IProgressMonitor progressMonitor) {
 		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
 				.createEditingDomain();
@@ -141,7 +144,7 @@ public class CreationWizard extends Wizard implements INewWizard {
 					IProgressMonitor monitor, IAdaptable info)
 					throws ExecutionException {
 
-				FactoryUtils.createStatechartModel(resource);
+				FactoryUtils.createStatechartModel(resource, preferencesHint);
 
 				try {
 					resource.save(getSaveOptions());
@@ -197,4 +200,15 @@ public class CreationWizard extends Wizard implements INewWizard {
 		this.openOnCreate = openOnCreate;
 	}
 
+	/**
+	 * Set the preference hint for preferences of new created diagrams
+	 * 
+	 * @param hint
+	 *            the PreferenceHint for the PreferenceStore (mostly from
+	 *            Activator)
+	 */
+	protected void setPreferenceHint(PreferencesHint hint) {
+		preferencesHint = hint;
+	}
+
 }