From 780e471916c34c1c5af49600953b35651d465458 Mon Sep 17 00:00:00 2001
From: Stefano Puri <stefano.puri@intecs.it>
Date: Wed, 31 Jan 2018 18:30:19 +0100
Subject: [PATCH] fixed state machines palettes

---
 .../managers/PaletteManager.java              | 324 +++++------
 .../ClassDiag-DependAnalysis.Palette.xml      |  76 +--
 .../StateMachineDiag-ErrorModel.Palette.xml   | 185 +++----
 .../palettes/StateMachineDiag-FV.Palette.xml  |  57 +-
 .../internal/palette/PaletteManager.java      | 520 ++++++++++--------
 5 files changed, 589 insertions(+), 573 deletions(-)

diff --git a/plugins/contracts/org.polarsys.chess.contracts.chessextension/src/org/polarsys/chess/contracts/chessextension/managers/PaletteManager.java b/plugins/contracts/org.polarsys.chess.contracts.chessextension/src/org/polarsys/chess/contracts/chessextension/managers/PaletteManager.java
index de9fbcf47..6c60b7f8f 100644
--- a/plugins/contracts/org.polarsys.chess.contracts.chessextension/src/org/polarsys/chess/contracts/chessextension/managers/PaletteManager.java
+++ b/plugins/contracts/org.polarsys.chess.contracts.chessextension/src/org/polarsys/chess/contracts/chessextension/managers/PaletteManager.java
@@ -1,160 +1,164 @@
-/*******************************************************************************
- *
- * Copyright (c) 2013, 2015 Intecs SpA 
- * 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:
- * Nicholas Pacini nicholas.pacini@intecs.it 
- * Stefano Puri stefano.puri@intecs.it
- * Laura Baracchi  laura.baracchi@intecs.it  
- * Initial API and implementation and/or initial documentation
- *******************************************************************************/
-
-package org.polarsys.chess.contracts.chessextension.managers;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.gef.palette.PaletteDrawer;
-import org.eclipse.gef.ui.palette.PaletteViewer;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
-import org.eclipse.ui.IEditorPart;
-import org.polarsys.chess.contracts.chessextension.Activator;
-import org.polarsys.chess.core.constraint.PreferenceProperties;
-import org.polarsys.chess.core.profiles.CHESSProfileManager;
-import org.polarsys.chess.core.views.DiagramStatus;
-
-public class PaletteManager {
-	
-	protected static List<Object> lookupSelectedElements(ISelection selection) {
-		if (selection instanceof IStructuredSelection) {
-			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-			return structuredSelection.toList();
-		} else if (selection instanceof TreeSelection) {
-			TreeSelection treeSelection = (TreeSelection) selection;
-			return treeSelection.toList();
-		}
-		return null;
-	}
-	
-	//TODO this class should be reengineered so to have a parent one common to all the chess plugins
-	public static void setPaletteVisibility(PapyrusMultiDiagramEditor editor, DiagramStatus ds) {
-		
-		Boolean checkPalette =
-				org.polarsys.chess.core.Activator.getDefault().getPreferenceStore().getBoolean(PreferenceProperties.PALETTES_IN_VIEW);
-		
-		if (!checkPalette)
-			return;
-		
-		try {
-					
-			IEditorPart ep = editor.getActiveEditor();
-			if (ep == null)
-				return;
-			ISelection selection = ep.getSite().getSelectionProvider().getSelection();
-			List<Object> selections = lookupSelectedElements(selection);
-			DiagramEditDomain de = null;
-			if (selections.get(0) instanceof GraphicalEditPart){
-				GraphicalEditPart a = (GraphicalEditPart) selections.get(0);
-				de = (DiagramEditDomain) a.getDiagramEditDomain();
-			}
-			else{
-				if (selections.get(0) instanceof ConnectionEditPart){
-					ConnectionEditPart a = (ConnectionEditPart) selections.get(0);
-					de = (DiagramEditDomain) a.getDiagramEditDomain();
-				}
-			}
-			
-			if (de == null){
-				Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "cannot retrieve DiagramEditDomain"));
-				return;
-			}
-			
-			PaletteViewer pv = de.getPaletteViewer();
-			
-//			String viewName = ds.getCurrentView().getName();
-			String viewName = ds.getActiveView();
-			//System.out.println("activew view" + viewName);
-			
-			String diagramName = ds.getCurrentView().getCurrentDiagramName();
-			
-			for (Object o : pv.getPaletteRoot().getChildren()){
-				if (o instanceof PaletteDrawer){
-					PaletteDrawer d = (PaletteDrawer) o;
-					setPaletteVisibility(d, viewName, diagramName);
-				}
-			}
-		} catch (Exception e) {
-			Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage()));
-			e.printStackTrace();
-		}
-		//final List<String> hiddenPalettes = PapyrusPalettePreferences.getHiddenPalettes(part);
-		
-		//PapyrusPaletteService ps = PapyrusPaletteService.getInstance();
-		
-		
-//		for(PapyrusPaletteService.ProviderDescriptor descriptor : ps.getContributingProviders(part, pv.getPaletteRoot())) {
-//			
-//			String id = descriptor.getContributionID();
-//			String name = descriptor.getContributionName();
-//			CHESSProjectSupport.printlnToCHESSConsole(id + " " + name);
-//			//TODO what are the palette to hide/show given the current view and diagram?
-//			//PapyrusPalettePreferences.changePaletteVisibility(id, editor.getActiveEditor().getClass().getName(), false);
-//		}
-	}
-	//TODO the policy of the palette visibility should be re-engineered to allow CHESS external plugins "like 
-	//CHESSContract, to add palettes to the ones already managed by CHESS. Now the CHESSContract palettes which regard the 
-	//component view are managed in CHESS, not here. 
-	private static void setPaletteVisibility(PaletteDrawer paletteDrawer, String viewName,
-			String diagramName) {
-		
-		if (! viewName.equals(CHESSProfileManager.SYSTEM_VIEW)){
-			//no restriction upon the CHESS main view
-			return;
-		}
-		
-			
-		paletteDrawer.setVisible(true);
-		String label = paletteDrawer.getLabel();
-		String paletteId = paletteDrawer.getId();
-		if (viewName.equals(CHESSProfileManager.SYSTEM_VIEW)){
-			if (diagramName.compareTo("BlockDefinition")==0){
-				//set visibility only for the palette's functional tools
-				paletteDrawer.setVisible(false);
-				if (paletteId.compareTo("ForeverBDDAssociationsDrawerID")==0|| paletteId.compareTo("ForeverBDDModelElementsDrawerID")==0
-						|| paletteId.compareTo("ForeverBDDPortAndFlowsDrawerID")==0
-						|| paletteId.compareTo("ForeverBDDDataTypesDrawerID")==0 
-						|| paletteId.compareTo("ForeverBDDContractsDrawerID")==0 )
-					paletteDrawer.setVisible(true);
-			}
-			if (diagramName.equals("InternalBlock")){
-				paletteDrawer.setVisible(false);
-				if (paletteId.compareTo("ForeverIBDNodesDrawerID")==0 || paletteId.compareTo("ForeverIBDEdgesDrawerID")==0)
-					paletteDrawer.setVisible(true);
-			}
-			
-			if (diagramName.equals("PapyrusUMLClassDiagram")){
-				paletteDrawer.setVisible(true);
-			}
-			
-			if (diagramName.equals("CompositeStructure")){
-				paletteDrawer.setVisible(true);
-			}
-			
-			
-		}
-		
-	
-	}
-
-}
+/*******************************************************************************
+ *
+ * Copyright (c) 2013, 2015 Intecs SpA 
+ * 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:
+ * Nicholas Pacini nicholas.pacini@intecs.it 
+ * Stefano Puri stefano.puri@intecs.it
+ * Laura Baracchi  laura.baracchi@intecs.it  
+ * Initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.polarsys.chess.contracts.chessextension.managers;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.gef.palette.PaletteDrawer;
+import org.eclipse.gef.ui.palette.PaletteViewer;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
+import org.eclipse.ui.IEditorPart;
+import org.polarsys.chess.contracts.chessextension.Activator;
+import org.polarsys.chess.core.constraint.PreferenceProperties;
+import org.polarsys.chess.core.profiles.CHESSProfileManager;
+import org.polarsys.chess.core.views.DiagramStatus;
+
+public class PaletteManager {
+	
+	protected static List<Object> lookupSelectedElements(ISelection selection) {
+		if (selection instanceof IStructuredSelection) {
+			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+			return structuredSelection.toList();
+		} else if (selection instanceof TreeSelection) {
+			TreeSelection treeSelection = (TreeSelection) selection;
+			return treeSelection.toList();
+		}
+		return null;
+	}
+	
+	//TODO this class should be reengineered so to have a parent one common to all the chess plugins
+	public static void setPaletteVisibility(PapyrusMultiDiagramEditor editor, DiagramStatus ds) {
+		
+		Boolean checkPalette =
+				org.polarsys.chess.core.Activator.getDefault().getPreferenceStore().getBoolean(PreferenceProperties.PALETTES_IN_VIEW);
+		
+		if (!checkPalette)
+			return;
+		
+		try {
+					
+			IEditorPart ep = editor.getActiveEditor();
+			if (ep == null)
+				return;
+			ISelection selection = ep.getSite().getSelectionProvider().getSelection();
+			List<Object> selections = lookupSelectedElements(selection);
+			DiagramEditDomain de = null;
+			if (selections.get(0) instanceof GraphicalEditPart){
+				GraphicalEditPart a = (GraphicalEditPart) selections.get(0);
+				de = (DiagramEditDomain) a.getDiagramEditDomain();
+			}
+			else{
+				if (selections.get(0) instanceof ConnectionEditPart){
+					ConnectionEditPart a = (ConnectionEditPart) selections.get(0);
+					de = (DiagramEditDomain) a.getDiagramEditDomain();
+				}
+			}
+			
+			if (de == null){
+				Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "cannot retrieve DiagramEditDomain"));
+				return;
+			}
+			
+			PaletteViewer pv = de.getPaletteViewer();
+			
+//			String viewName = ds.getCurrentView().getName();
+			String viewName = ds.getActiveView();
+			//System.out.println("activew view" + viewName);
+			
+			String diagramName = ds.getCurrentView().getCurrentDiagramName();
+			
+			for (Object o : pv.getPaletteRoot().getChildren()){
+				if (o instanceof PaletteDrawer){
+					PaletteDrawer d = (PaletteDrawer) o;
+					setPaletteVisibility(d, viewName, diagramName);
+				}
+			}
+		} catch (Exception e) {
+			Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage()));
+			e.printStackTrace();
+		}
+		//final List<String> hiddenPalettes = PapyrusPalettePreferences.getHiddenPalettes(part);
+		
+		//PapyrusPaletteService ps = PapyrusPaletteService.getInstance();
+		
+		
+//		for(PapyrusPaletteService.ProviderDescriptor descriptor : ps.getContributingProviders(part, pv.getPaletteRoot())) {
+//			
+//			String id = descriptor.getContributionID();
+//			String name = descriptor.getContributionName();
+//			CHESSProjectSupport.printlnToCHESSConsole(id + " " + name);
+//			//TODO what are the palette to hide/show given the current view and diagram?
+//			//PapyrusPalettePreferences.changePaletteVisibility(id, editor.getActiveEditor().getClass().getName(), false);
+//		}
+	}
+	//TODO the policy of the palette visibility should be re-engineered to allow CHESS external plugins "like 
+	//CHESSContract, to add palettes to the ones already managed by CHESS. Now the CHESSContract palettes which regard the 
+	//component view are managed in CHESS, not here. 
+	private static void setPaletteVisibility(PaletteDrawer paletteDrawer, String viewName,
+			String diagramName) {
+		
+		if (! viewName.equals(CHESSProfileManager.SYSTEM_VIEW)){
+			//no restriction upon the CHESS main view
+			return;
+		}
+		
+		if (diagramName.equals("PapyrusUMLStateMachineDiagram")){
+			return;
+		}
+		
+			
+		paletteDrawer.setVisible(true);
+		String label = paletteDrawer.getLabel();
+		String paletteId = paletteDrawer.getId();
+		if (viewName.equals(CHESSProfileManager.SYSTEM_VIEW)){
+			if (diagramName.compareTo("BlockDefinition")==0){
+				//set visibility only for the palette's functional tools
+				paletteDrawer.setVisible(false);
+				if (paletteId.compareTo("ForeverBDDAssociationsDrawerID")==0|| paletteId.compareTo("ForeverBDDModelElementsDrawerID")==0
+						|| paletteId.compareTo("ForeverBDDPortAndFlowsDrawerID")==0
+						|| paletteId.compareTo("ForeverBDDDataTypesDrawerID")==0 
+						|| paletteId.compareTo("ForeverBDDContractsDrawerID")==0 )
+					paletteDrawer.setVisible(true);
+			}
+			if (diagramName.equals("InternalBlock")){
+				paletteDrawer.setVisible(false);
+				if (paletteId.compareTo("ForeverIBDNodesDrawerID")==0 || paletteId.compareTo("ForeverIBDEdgesDrawerID")==0)
+					paletteDrawer.setVisible(true);
+			}
+			
+			if (diagramName.equals("PapyrusUMLClassDiagram")){
+				paletteDrawer.setVisible(true);
+			}
+			
+			if (diagramName.equals("CompositeStructure")){
+				paletteDrawer.setVisible(true);
+			}
+			
+			
+		}
+		
+	
+	}
+
+}
diff --git a/plugins/org.polarsys.chess.chessmlprofile/palettes/ClassDiag-DependAnalysis.Palette.xml b/plugins/org.polarsys.chess.chessmlprofile/palettes/ClassDiag-DependAnalysis.Palette.xml
index 82c70cbc3..12dc6f998 100644
--- a/plugins/org.polarsys.chess.chessmlprofile/palettes/ClassDiag-DependAnalysis.Palette.xml
+++ b/plugins/org.polarsys.chess.chessmlprofile/palettes/ClassDiag-DependAnalysis.Palette.xml
@@ -1,32 +1,44 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<paletteDefinition>
-	<content>
-		<drawer iconpath="platform:/plugin/org.polarsys.chess.core/resources/CHESSicon.gif"
-			id="DepAnalysisViewDrawer__1317300165546"
-			name="DependabilityAnalysis">
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Component.gif"
-				id="clazz.tool.component_1301932923050_1317300366021" name="StateBasedAnalysis (Component)"
-				refToolId="clazz.tool.component">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::StateBased::StateBasedAnalysis::StateBasedAnalysis" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Component.gif"
-				id="clazz.tool.component_1316779916487_1317300377613" name="FailurePropagationAnalysis (Component)"
-				refToolId="clazz.tool.component">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::FailurePropagation::FailurePropagationAnalysis" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-		</drawer>
-
-	</content>
-</paletteDefinition>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<paletteDefinition>
+	<content>
+		<drawer iconpath="platform:/plugin/org.polarsys.chess.core/resources/CHESSicon.gif"
+			id="DepAnalysisViewDrawer__1317300165546"
+			name="DependabilityAnalysis">
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Component.gif"
+				id="clazz.tool.component_1301932923050_1317300366021" name="StateBasedAnalysis (Component)"
+				refToolId="clazz.tool.component">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype
+							stereotypeName="CHESS::Dependability::StateBased::StateBasedAnalysis::StateBasedAnalysis" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Component.gif"
+				id="clazz.tool.component_1316779916487_1317300377613" name="FailurePropagationAnalysis (Component)"
+				refToolId="clazz.tool.component">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype
+							stereotypeName="CHESS::Dependability::FailurePropagation::FailurePropagationAnalysis" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+			
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Component.gif"
+				id="clazz.tool.component_1316779916487_1317300377614" name="xSAP FTA Analysis (Component)"
+				refToolId="clazz.tool.component">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype
+							stereotypeName="MARTE::MARTE_AnalysisModel::GQAM::GaAnalysisContext" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+		</drawer>
+
+	</content>
+</paletteDefinition>
diff --git a/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-ErrorModel.Palette.xml b/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-ErrorModel.Palette.xml
index 2867a115a..5ba208e7e 100644
--- a/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-ErrorModel.Palette.xml
+++ b/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-ErrorModel.Palette.xml
@@ -1,118 +1,69 @@
-<paletteDefinition>
-	<content>
-		<drawer iconpath="platform:/plugin/org.polarsys.chess.core/resources/CHESSicon.gif"
-			id="SM_ErrorModelDrawer__1317126136270" name="Error Model">
-			<aspectTool description="Initial"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_initial.gif"
-				id="createInitialCreationTool_1317125016987" name="Initial"
-				refToolId="createInitialCreationTool" />
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
-				id="createTransitionCreationTool_1317126191843" name="ExternalFault (Transition)"
-				refToolId="createTransitionCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::ThreatsPropagation::ExternalFault" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
-				id="createTransitionCreationTool_1317126216631" name="InternalFault (Transition)"
-				refToolId="createTransitionCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::ThreatsPropagation::InternalFault" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
-				id="createTransitionCreationTool_1317225825026" name="Propagation (Transition)"
-				refToolId="createTransitionCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::DependableComponent::Propagation" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-
-
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412_1317128380376" name="UnclassifiedError (State)"
-				refToolId="createStateCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::ThreatsPropagation::UnclassifiedError" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412_1317126453052" name="Error (State)"
-				refToolId="createStateCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype stereotypeName="CHESS::Dependability::ThreatsPropagation::Error" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412_1317128350603" name="ErrorFree (State)"
-				refToolId="createStateCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype stereotypeName="CHESS::Dependability::ThreatsPropagation::ErrorFree" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412_1317128364963" name="FailureFree (State)"
-				refToolId="createStateCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::ThreatsPropagation::FailureFree" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412_1317128368235" name="FailureMode (State)"
-				refToolId="createStateCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::ThreatsPropagation::FailureMode" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-			<!--aspectTool description="Create an element with a stereotype" iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif" 
-				id="createStateCreationTool_1317125014412_1317128376004" name="ThreatState 
-				(State)" refToolId="createStateCreationTool"> <postAction id="org.eclipse.papyrus.applystereotypeactionprovider"> 
-				<stereotypesToApply> <stereotype stereotypeName="CHESS::Dependability::ThreatsPropagation::ThreatState" 
-				/> </stereotypesToApply> </postAction> </aspectTool -->
-
-			<aspectTool description="Create an element with a stereotype"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412_1317128385259" name="UnclassifiedFailure (State)"
-				refToolId="createStateCreationTool">
-				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
-					<stereotypesToApply>
-						<stereotype
-							stereotypeName="CHESS::Dependability::ThreatsPropagation::UnclassifiedFailure" />
-					</stereotypesToApply>
-				</postAction>
-			</aspectTool>
-		</drawer>
-	</content>
+<paletteDefinition>
+	<content>
+		<drawer iconpath="platform:/plugin/org.polarsys.chess.core/resources/CHESSicon.gif"
+			id="SM_ErrorModelDrawer__1317126136270" name="Error Model">
+			<aspectTool description="Initial"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_initial.gif"
+				id="createInitialCreationTool_1317125016987" name="Initial"
+				refToolId="statemachine.createNodesGroup.initial" />
+				
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
+				id="createStateCreationTool_1317125014412_1317126453052" name="Error (State)"
+				refToolId="statemachine.createNodesGroup.state">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype stereotypeName="CHESS::Dependability::ThreatsPropagation::ErrorState" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+				
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
+				id="createTransitionCreationTool_1317126191843" name="InternalPropagation (Transition)"
+				refToolId="statemachine.createEdgesGroup.transition">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype
+							stereotypeName="CHESS::Dependability::ThreatsPropagation::InternalPropagation" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
+				id="createTransitionCreationTool_1317126216631" name="InternalFault (Transition)"
+				refToolId="statemachine.createEdgesGroup.transition">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype
+							stereotypeName="CHESS::Dependability::ThreatsPropagation::InternalFault" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
+				id="createTransitionCreationTool_1317225825026" name="Failure (Transition)"
+				refToolId="statemachine.createEdgesGroup.transition">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype
+							stereotypeName="CHESS::Dependability::ThreatsPropagation::Failure" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+
+			<aspectTool description="Create an element with a stereotype"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
+				id="createStateCreationTool_1317125014412_1317126453052" name="Error (State)"
+				refToolId="statemachine.createNodesGroup.state">
+				<postAction id="org.eclipse.papyrus.applystereotypeactionprovider">
+					<stereotypesToApply>
+						<stereotype stereotypeName="CHESS::Dependability::ThreatsPropagation::ErrorState" />
+					</stereotypesToApply>
+				</postAction>
+			</aspectTool>
+			
+		</drawer>
+	</content>
 </paletteDefinition>
\ No newline at end of file
diff --git a/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-FV.Palette.xml b/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-FV.Palette.xml
index 003f9e1dd..a9e10638e 100644
--- a/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-FV.Palette.xml
+++ b/plugins/org.polarsys.chess.chessmlprofile/palettes/StateMachineDiag-FV.Palette.xml
@@ -1,27 +1,32 @@
-<paletteDefinition>
-	<content>
-		<drawer iconpath="platform:/plugin/org.polarsys.chess.core/resources/CHESSicon.gif"
-			id="SM_FunctionalDrawer__1317124986519" name="Functional View">
-			<aspectTool description="State"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
-				id="createStateCreationTool_1317125014412" name="State"
-				refToolId="createStateCreationTool" />
-			<aspectTool description="Initial"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_initial.gif"
-				id="createInitialCreationTool_1317125016986" name="Initial"
-				refToolId="createInitialCreationTool" />
-			<aspectTool description="FinalState"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/FinalState.gif"
-				id="createFinalStateCreationTool_1317125020980" name="FinalState"
-				refToolId="createFinalStateCreationTool" />
-			<!--aspectTool description="Choice" iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_choice.gif" 
-				id="createChoiceCreationTool_1317125031260" name="Choice" refToolId="createChoiceCreationTool"/ -->
-			<!--aspectTool description="Junction" iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_junction.gif" 
-				id="createJunctionCreationTool_1317125035519" name="Junction" refToolId="createJunctionCreationTool"/ -->
-			<aspectTool description="Transition"
-				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
-				id="createTransitionCreationTool_1317125071228" name="Transition"
-				refToolId="createTransitionCreationTool" />
-		</drawer>
-	</content>
+<paletteDefinition>
+	<content>
+		<drawer iconpath="platform:/plugin/org.polarsys.chess.core/resources/CHESSicon.gif"
+			id="SM_FunctionalDrawer__1317124986519" name="Functional View">
+			
+			<aspectTool description="Initial"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_initial.gif"
+				id="createInitialCreationTool_1317125016986" name="Initial"
+				refToolId="statemachine.createNodesGroup.initial" />
+			
+			<aspectTool description="State"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/State.gif"
+				id="createStateCreationTool_1317125014412" name="State"
+				refToolId="statemachine.createNodesGroup.state" />
+				
+			<aspectTool description="Transition"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Transition_local.gif"
+				id="createTransitionCreationTool_1317125071228" name="Transition"
+				refToolId="statemachine.createEdgesGroup.transition" />
+			
+			<aspectTool description="FinalState"
+				iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/FinalState.gif"
+				id="createFinalStateCreationTool_1317125020980" name="FinalState"
+				refToolId="statemachine.createNodesGroup.finalstate" />
+			<!--aspectTool description="Choice" iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_choice.gif" 
+				id="createChoiceCreationTool_1317125031260" name="Choice" refToolId="createChoiceCreationTool"/ -->
+			<!--aspectTool description="Junction" iconpath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Pseudostate_junction.gif" 
+				id="createJunctionCreationTool_1317125035519" name="Junction" refToolId="createJunctionCreationTool"/ -->
+			
+		</drawer>
+	</content>
 </paletteDefinition>
\ No newline at end of file
diff --git a/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/internal/palette/PaletteManager.java b/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/internal/palette/PaletteManager.java
index b4c1717a4..27f2b47cb 100644
--- a/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/internal/palette/PaletteManager.java
+++ b/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/internal/palette/PaletteManager.java
@@ -1,238 +1,282 @@
-/*
------------------------------------------------------------------------
---          			CHESS editor plugin							 --
---                                                                   --
---                    Copyright (C) 2011-2012                        --
---                 University of Padova, ITALY                       --
---                                                                   --
--- Author: Alessandro Zovi         azovi@math.unipd.it 		         --
---                                                                   --
--- 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                         --
------------------------------------------------------------------------
-*/
-
-package org.polarsys.chess.service.internal.palette;
-
-import java.util.List;
-
-import org.eclipse.gef.palette.PaletteDrawer;
-import org.eclipse.gef.ui.palette.PaletteViewer;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
-import org.eclipse.ui.IEditorPart;
-import org.polarsys.chess.core.constraint.PreferenceProperties;
-import org.polarsys.chess.core.profiles.CHESSProfileManager;
-import org.polarsys.chess.core.views.DiagramStatus;
-import org.polarsys.chess.core.views.ViewDiagramAssociations;
-
-
-public class PaletteManager {
-	
-	protected static List<Object> lookupSelectedElements(ISelection selection) {
-		if (selection instanceof IStructuredSelection) {
-			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-			return structuredSelection.toList();
-		} else if (selection instanceof TreeSelection) {
-			TreeSelection treeSelection = (TreeSelection) selection;
-			return treeSelection.toList();
-		}
-		return null;
-	}
-	
-	public static void setPaletteVisibility(PapyrusMultiDiagramEditor editor, DiagramStatus ds) {
-		
-		Boolean checkPalette =
-				org.polarsys.chess.core.Activator.getDefault().getPreferenceStore().getBoolean(PreferenceProperties.PALETTES_IN_VIEW);
-		
-		if (!checkPalette)
-			return;
-		
-		try {
-			
-			IEditorPart ep = editor.getActiveEditor();
-			ISelection selection = ep.getSite().getSelectionProvider().getSelection();
-			List<Object> selections = lookupSelectedElements(selection);
-			GraphicalEditPart a = (GraphicalEditPart) selections.get(0);
-			DiagramEditDomain de = (DiagramEditDomain) a.getDiagramEditDomain();
-			PaletteViewer pv = de.getPaletteViewer();
-	
-			String viewName = ds.getActiveView();
-			
-			String diagramName = ds.getCurrentView().getCurrentDiagramName();
-			
-			for (Object o : pv.getPaletteRoot().getChildren()){
-				if (o instanceof PaletteDrawer){
-					PaletteDrawer d = (PaletteDrawer) o;
-					setPaletteVisibility(d, viewName, diagramName);
-				}
-			}
-		} catch (Exception e) {
-			System.out.println(e.getMessage());
-		}
-		
-	}
-	//TODO this code is temporary needs refactoring
-	private static void setPaletteVisibility(PaletteDrawer paletteDrawer, String viewName,
-			String diagramName) {
-				
-		if (diagramName.equals(CHESSProfileManager.SYSTEM_VIEW)) {
-			//paletteDrawer.setVisible(false);
-			return;
-		}
-		
-		if (diagramName.equals(ViewDiagramAssociations.ANYDIAGRAM)) {
-			paletteDrawer.setVisible(false);
-			return;
-		}
-		
-		paletteDrawer.setVisible(true);
-		String label = paletteDrawer.getLabel();
-		String paletteId = paletteDrawer.getId();
-		if (viewName.equals(CHESSProfileManager.COMPONENT_VIEW)){
-			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
-				//set visibility only for the palette's functional tools
-				paletteDrawer.setVisible(false);
-				if (paletteId.compareTo("CHESSNodesFunctionalViewDrawerID")==0 || 	
-						paletteId.compareTo("CHESSEdgeFunctionalViewDrawerID")==0 ||
-						paletteId.compareTo("ContractsClassDiagramDrawer")==0) //TODO here we should re-engineer the code to allow a more flexible management of additional profile palettes
-					paletteDrawer.setVisible(true);
-			}
-			if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
-					//set visibility only for the palette's functional tools
-					paletteDrawer.setVisible(false);
-					if (paletteId.compareTo("CompositeDiagramFunctionalViewDrawerID")==0 || 	
-						paletteId.compareTo("CompositeFunctionalViewContractDrawerID")==0) //TODO here we should re-engineer the code to allow a more flexible management of additional profile palettes
-						paletteDrawer.setVisible(true);
-				}
-			if (diagramName.equals(ViewDiagramAssociations.activityDiagram)){
-				paletteDrawer.setVisible(false);
-				if (label.equals("CHESS/Activity"))
-					paletteDrawer.setVisible(true);
-			}
-			
-			if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
-				paletteDrawer.setVisible(true);
-				String id = paletteDrawer.getId();
-				if (id.compareTo("SM_FunctionalDrawer__1317124986519")!=0)
-					paletteDrawer.setVisible(false);
-			}
-			
-			if (diagramName.equals(ViewDiagramAssociations.sequenceDiagram)){
-				paletteDrawer.setVisible(true);
-				String id = paletteDrawer.getId();
-				if (id.compareTo("CHESSSequenceDiagramPalette_Nodes")!=0 && id.compareTo("CHESSSequenceDiagramPalette_Edges")!=0)
-					paletteDrawer.setVisible(false);
-			}
-			
-		}
-		if (viewName.equals(CHESSProfileManager.EXTRAFUNCTIONAL_VIEW)){
-			
-				if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
-					paletteDrawer.setVisible(true);
-					if (paletteId.compareTo("SM_ErrorModelDrawer__1317126136270")!=0)
-						paletteDrawer.setVisible(false);
-				}
-				
-				if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
-					//hide the palette's functional tools
-					paletteDrawer.setVisible(true);
-					if (paletteId.compareTo("CSD_RTDrawer__1302019186026")!=0 && paletteId.compareTo("CSD_FPTC_Drawer__1317635175167")!=0)
-						paletteDrawer.setVisible(false);
-				}
-				
-				if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
-					
-					paletteDrawer.setVisible(false);
-				}
-					
-				if (diagramName.equals(ViewDiagramAssociations.activityDiagram)){
-					
-					paletteDrawer.setVisible(false);
-				}
-				
-				if (diagramName.equals(ViewDiagramAssociations.sequenceDiagram)){
-					paletteDrawer.setVisible(true);
-					if (paletteId.compareTo("drawer_1329924117088")!=0 && paletteId.compareTo("Drawer__1329924033356")!=0)
-						paletteDrawer.setVisible(false);
-				}
-				
-		}
-		if (viewName.equals(CHESSProfileManager.DEPLOYMENT_VIEW)){
-			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
-				//hide the palette's functional tools
-				paletteDrawer.setVisible(false);
-				if (paletteId.compareTo("DeploymentClassDrawerID")==0 || paletteId.compareTo("DeploymentContractClassDrawerID")==0)
-					paletteDrawer.setVisible(true);
-			}
-			if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
-				//hide the palette's functional tools
-				paletteDrawer.setVisible(false);
-				if (paletteId.compareTo("DeploymentCSDDrawerID")==0 || paletteId.compareTo("CompositeFunctionalViewContractDrawerID")==0)
-					paletteDrawer.setVisible(true);
-			}
-			
-			if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
-				paletteDrawer.setVisible(true);
-				if (paletteId.compareTo("SM_FunctionalDrawer__1317124986519")!=0)
-					paletteDrawer.setVisible(false);
-			}
-		}
-		
-		if (viewName.equals(CHESSProfileManager.DEPENDABILITY_VIEW)){
-				
-			if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
-				paletteDrawer.setVisible(true);
-				if (paletteId.compareTo("SM_ErrorModelDrawer__1317126136270")!=0)
-					paletteDrawer.setVisible(false);
-			}
-			else if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
-					paletteDrawer.setVisible(false);
-			}
-			else if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
-				paletteDrawer.setVisible(true);
-				if (paletteId.compareTo("CSD_FPTC_Drawer__1317635175167")!=0)
-					paletteDrawer.setVisible(false);
-			}
-		}
-		
-		if (viewName.equals(CHESSProfileManager.DEPENDABILITY_ANALYSIS_VIEW)){
-			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
-				paletteDrawer.setVisible(true);
-				if (paletteId.compareTo("DepAnalysisViewDrawer__1317300165546")!=0)
-					paletteDrawer.setVisible(false);
-			}
-		}
-		
-		if (viewName.equals(CHESSProfileManager.RT_ANALYSIS_VIEW)){
-			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
-				if (paletteId.compareTo("CHESS-TimingAnalysisDrawer")!=0)
-					paletteDrawer.setVisible(false);
-				else
-					paletteDrawer.setVisible(true);
-			}else if (diagramName.equals(ViewDiagramAssociations.activityDiagram)){
-				if (paletteId.compareTo("RTActivityDiagramDrawerID")!=0)
-					paletteDrawer.setVisible(false);
-				else
-					paletteDrawer.setVisible(true);
-			}
-		}
-		
-		if (viewName.equals(CHESSProfileManager.RAILWAY_VIEW)){
-			paletteDrawer.setVisible(false);
-			if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
-				//show only the railway palette
-				if (paletteId.compareTo("Drawer__1301934597253")==0)
-					paletteDrawer.setVisible(true);
-				}
-		}
-	
-	}
-
-}
+/*
+-----------------------------------------------------------------------
+--          			CHESS editor plugin							 --
+--                                                                   --
+--                    Copyright (C) 2011-2012                        --
+--                 University of Padova, ITALY                       --
+--                                                                   --
+-- Author: Alessandro Zovi         azovi@math.unipd.it 		         --
+--                                                                   --
+-- 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                         --
+-----------------------------------------------------------------------
+*/
+
+package org.polarsys.chess.service.internal.palette;
+
+import java.util.List;
+
+import javax.rmi.CORBA.Util;
+
+import org.eclipse.gef.palette.PaletteDrawer;
+import org.eclipse.gef.ui.palette.PaletteViewer;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagramImpl;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.uml2.uml.internal.impl.StateMachineImpl;
+import org.polarsys.chess.chessmlprofile.util.Constants;
+import org.polarsys.chess.core.constraint.PreferenceProperties;
+import org.polarsys.chess.core.profiles.CHESSProfileManager;
+import org.polarsys.chess.core.views.DiagramStatus;
+import org.polarsys.chess.core.views.ViewDiagramAssociations;
+import org.polarsys.chess.service.utils.CHESSEditorUtils;
+
+
+public class PaletteManager {
+	
+	protected static List<Object> lookupSelectedElements(ISelection selection) {
+		if (selection instanceof IStructuredSelection) {
+			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+			return structuredSelection.toList();
+		} else if (selection instanceof TreeSelection) {
+			TreeSelection treeSelection = (TreeSelection) selection;
+			return treeSelection.toList();
+		}
+		return null;
+	}
+	
+	public static void setPaletteVisibility(PapyrusMultiDiagramEditor editor, DiagramStatus ds) {
+		
+		Boolean checkPalette =
+				org.polarsys.chess.core.Activator.getDefault().getPreferenceStore().getBoolean(PreferenceProperties.PALETTES_IN_VIEW);
+		
+		if (!checkPalette)
+			return;
+		
+		try {
+			
+			IEditorPart ep = editor.getActiveEditor();
+			ISelection selection = ep.getSite().getSelectionProvider().getSelection();
+			List<Object> selections = lookupSelectedElements(selection);
+			GraphicalEditPart a = (GraphicalEditPart) selections.get(0);
+			DiagramEditDomain de = (DiagramEditDomain) a.getDiagramEditDomain();
+			PaletteViewer pv = de.getPaletteViewer();
+	
+			String viewName = ds.getActiveView();
+			
+			String diagramName = ds.getCurrentView().getCurrentDiagramName();
+			
+			for (Object o : pv.getPaletteRoot().getChildren()){
+				if (o instanceof PaletteDrawer){
+					PaletteDrawer d = (PaletteDrawer) o;
+					setPaletteVisibility(d, viewName, diagramName);
+				}
+			}
+		} catch (Exception e) {
+			System.out.println(e.getMessage());
+		}
+		
+	}
+	//TODO this code is temporary needs refactoring
+	private static void setPaletteVisibility(PaletteDrawer paletteDrawer, String viewName,
+			String diagramName) {
+		
+		String paletteId = paletteDrawer.getId();
+		
+		
+		
+		if (viewName.equals(CHESSProfileManager.SYSTEM_VIEW) ) {
+			//paletteDrawer.setVisible(false);
+			
+
+			if (diagramName.compareTo("PapyrusUMLStateMachineDiagram")==0){
+				paletteDrawer.setVisible(true);
+				
+				boolean isErrorModel = false;
+				try{
+					StateMachineImpl obj = (StateMachineImpl) ((CSSDiagramImpl) CHESSEditorUtils.getDiagramEditPart().getModel()).getElement();
+					if (obj != null){
+						if (obj.getAppliedStereotype(Constants.ERROR_MODEL)!= null){
+							isErrorModel = true;
+						}
+					}
+				}
+				catch(Exception ex){
+					ex.printStackTrace();
+				}
+				
+				
+				if (paletteId.compareTo("SM_ErrorModelDrawer__1317126136270")==0){
+					if (isErrorModel)
+							paletteDrawer.setVisible(true);
+					else
+						paletteDrawer.setVisible(false);
+				}
+					
+				
+				if (paletteId.compareTo("SM_FunctionalDrawer__1317124986519")==0)
+					if (!isErrorModel)
+						paletteDrawer.setVisible(true);
+					else
+						paletteDrawer.setVisible(false);
+			}
+			return;
+			
+		}
+		
+		if (diagramName.equals(ViewDiagramAssociations.ANYDIAGRAM)) {
+			paletteDrawer.setVisible(false);
+			return;
+		}
+		
+		paletteDrawer.setVisible(true);
+		String label = paletteDrawer.getLabel();
+		;
+		if (viewName.equals(CHESSProfileManager.COMPONENT_VIEW)){
+			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
+				//set visibility only for the palette's functional tools
+				paletteDrawer.setVisible(false);
+				if (paletteId.compareTo("CHESSNodesFunctionalViewDrawerID")==0 || 	
+						paletteId.compareTo("CHESSEdgeFunctionalViewDrawerID")==0 ||
+						paletteId.compareTo("ContractsClassDiagramDrawer")==0) //TODO here we should re-engineer the code to allow a more flexible management of additional profile palettes
+					paletteDrawer.setVisible(true);
+			}
+			if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
+					//set visibility only for the palette's functional tools
+					paletteDrawer.setVisible(false);
+					if (paletteId.compareTo("CompositeDiagramFunctionalViewDrawerID")==0 || 	
+						paletteId.compareTo("CompositeFunctionalViewContractDrawerID")==0) //TODO here we should re-engineer the code to allow a more flexible management of additional profile palettes
+						paletteDrawer.setVisible(true);
+				}
+			if (diagramName.equals(ViewDiagramAssociations.activityDiagram)){
+				paletteDrawer.setVisible(false);
+				if (label.equals("CHESS/Activity"))
+					paletteDrawer.setVisible(true);
+			}
+			
+			if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
+				paletteDrawer.setVisible(true);
+				String id = paletteDrawer.getId();
+				if (id.compareTo("SM_FunctionalDrawer__1317124986519")!=0)
+					paletteDrawer.setVisible(false);
+			}
+			
+			if (diagramName.equals(ViewDiagramAssociations.sequenceDiagram)){
+				paletteDrawer.setVisible(true);
+				String id = paletteDrawer.getId();
+				if (id.compareTo("CHESSSequenceDiagramPalette_Nodes")!=0 && id.compareTo("CHESSSequenceDiagramPalette_Edges")!=0)
+					paletteDrawer.setVisible(false);
+			}
+			
+		}
+		if (viewName.equals(CHESSProfileManager.EXTRAFUNCTIONAL_VIEW)){
+			
+				if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
+					paletteDrawer.setVisible(true);
+					if (paletteId.compareTo("SM_ErrorModelDrawer__1317126136270")!=0)
+						paletteDrawer.setVisible(false);
+				}
+				
+				if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
+					//hide the palette's functional tools
+					paletteDrawer.setVisible(true);
+					if (paletteId.compareTo("CSD_RTDrawer__1302019186026")!=0 && paletteId.compareTo("CSD_FPTC_Drawer__1317635175167")!=0)
+						paletteDrawer.setVisible(false);
+				}
+				
+				if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
+					
+					paletteDrawer.setVisible(false);
+				}
+					
+				if (diagramName.equals(ViewDiagramAssociations.activityDiagram)){
+					
+					paletteDrawer.setVisible(false);
+				}
+				
+				if (diagramName.equals(ViewDiagramAssociations.sequenceDiagram)){
+					paletteDrawer.setVisible(true);
+					if (paletteId.compareTo("drawer_1329924117088")!=0 && paletteId.compareTo("Drawer__1329924033356")!=0)
+						paletteDrawer.setVisible(false);
+				}
+				
+		}
+		if (viewName.equals(CHESSProfileManager.DEPLOYMENT_VIEW)){
+			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
+				//hide the palette's functional tools
+				paletteDrawer.setVisible(false);
+				if (paletteId.compareTo("DeploymentClassDrawerID")==0 || paletteId.compareTo("DeploymentContractClassDrawerID")==0)
+					paletteDrawer.setVisible(true);
+			}
+			if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
+				//hide the palette's functional tools
+				paletteDrawer.setVisible(false);
+				if (paletteId.compareTo("DeploymentCSDDrawerID")==0 || paletteId.compareTo("CompositeFunctionalViewContractDrawerID")==0)
+					paletteDrawer.setVisible(true);
+			}
+			
+			if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
+				paletteDrawer.setVisible(true);
+				if (paletteId.compareTo("SM_FunctionalDrawer__1317124986519")!=0)
+					paletteDrawer.setVisible(false);
+			}
+		}
+		
+		if (viewName.equals(CHESSProfileManager.DEPENDABILITY_VIEW)){
+				
+			if (diagramName.equals(ViewDiagramAssociations.stateMachineDiagram)){
+				paletteDrawer.setVisible(true);
+				if (paletteId.compareTo("SM_ErrorModelDrawer__1317126136270")!=0)
+					paletteDrawer.setVisible(false);
+			}
+			else if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
+					paletteDrawer.setVisible(false);
+			}
+			else if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
+				paletteDrawer.setVisible(true);
+				if (paletteId.compareTo("CSD_FPTC_Drawer__1317635175167")!=0)
+					paletteDrawer.setVisible(false);
+			}
+		}
+		
+		if (viewName.equals(CHESSProfileManager.DEPENDABILITY_ANALYSIS_VIEW)){
+			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
+				paletteDrawer.setVisible(true);
+				if (paletteId.compareTo("DepAnalysisViewDrawer__1317300165546")!=0)
+					paletteDrawer.setVisible(false);
+			}
+		}
+		
+		if (viewName.equals(CHESSProfileManager.RT_ANALYSIS_VIEW)){
+			if (diagramName.equals(ViewDiagramAssociations.classDiagram)){
+				if (paletteId.compareTo("CHESS-TimingAnalysisDrawer")!=0)
+					paletteDrawer.setVisible(false);
+				else
+					paletteDrawer.setVisible(true);
+			}else if (diagramName.equals(ViewDiagramAssociations.activityDiagram)){
+				if (paletteId.compareTo("RTActivityDiagramDrawerID")!=0)
+					paletteDrawer.setVisible(false);
+				else
+					paletteDrawer.setVisible(true);
+			}
+		}
+		
+		if (viewName.equals(CHESSProfileManager.RAILWAY_VIEW)){
+			paletteDrawer.setVisible(false);
+			if (diagramName.equals(ViewDiagramAssociations.compositeDiagram)){
+				//show only the railway palette
+				if (paletteId.compareTo("Drawer__1301934597253")==0)
+					paletteDrawer.setVisible(true);
+				}
+		}
+	
+	}
+
+}
-- 
GitLab