Bläddra i källkod

Added Perspective switch after creating new Statechart File

Andreas Mülder 14 år sedan
förälder
incheckning
3b06dbbb5f

+ 2 - 1
plugins/org.yakindu.sct.ui.editor/META-INF/MANIFEST.MF

@@ -39,7 +39,8 @@ Require-Bundle: org.eclipse.core.runtime,
  de.itemis.xtext.utils.jface;bundle-version="[1.0.0,2.0.0)",
  de.itemis.xtext.utils.jface;bundle-version="[1.0.0,2.0.0)",
  de.itemis.gmf.runtime.commons;bundle-version="1.0.0",
  de.itemis.gmf.runtime.commons;bundle-version="1.0.0",
  org.eclipse.gmf.runtime.notation.providers;bundle-version="1.3.0",
  org.eclipse.gmf.runtime.notation.providers;bundle-version="1.3.0",
- org.eclipse.help;bundle-version="3.5.100"
+ org.eclipse.help;bundle-version="3.5.100",
+ org.yakindu.sct.ui;bundle-version="1.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.yakindu.sct.ui.editor,
 Export-Package: org.yakindu.sct.ui.editor,

+ 64 - 0
plugins/org.yakindu.sct.ui/src/org/yakindu/sct/ui/perspectives/PerspectiveUtil.java

@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2011 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.perspectives;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IPerspectiveRegistry;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.osgi.service.prefs.BackingStoreException;
+import org.yakindu.sct.ui.UIPluginActivator;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class PerspectiveUtil {
+
+	public static final String AUTO_SWITCH_PERSPECTIVE = "AutoSwitchPerspective";
+
+	public static void switchToModelingPerspective(IWorkbenchWindow window) {
+		IPreferenceStore prefs = UIPluginActivator.getDefault()
+				.getPreferenceStore();
+		boolean hide = prefs.getBoolean(AUTO_SWITCH_PERSPECTIVE);
+		IWorkbenchPage page = window.getActivePage();
+		if (!hide) {
+			IWorkbench workbench = window.getWorkbench();
+			IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
+			IPerspectiveDescriptor descriptor = registry
+					.findPerspectiveWithId(IYakinduSctPerspectives.ID_PERSPECTIVE_SCT_MODELING);
+			if ((page != null) && (page.getPerspective() != descriptor)) {
+				MessageDialogWithToggle dialog = MessageDialogWithToggle
+						.openYesNoQuestion(
+								window.getShell(),
+								"Confirm Perspective Switch",
+								"This kind of editor is associated with the YAKINDU Modeling perspective. Do you want to switch to this perspective now?",
+								"Do not offer to switch perspective in the future",
+								hide, prefs, AUTO_SWITCH_PERSPECTIVE);
+				if (dialog.getReturnCode() == 2)
+					page.setPerspective(descriptor);
+				hide = dialog.getToggleState();
+				prefs.setValue(AUTO_SWITCH_PERSPECTIVE, hide);
+				try {
+					InstanceScope.INSTANCE.getNode(UIPluginActivator.PLUGIN_ID)
+							.flush();
+				} catch (BackingStoreException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+	}
+}