Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/ToggleAdvancedModelExplorerHandler.java')
-rw-r--r--plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/ToggleAdvancedModelExplorerHandler.java113
1 files changed, 65 insertions, 48 deletions
diff --git a/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/ToggleAdvancedModelExplorerHandler.java b/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/ToggleAdvancedModelExplorerHandler.java
index 8d5587c364e..265e4ca5643 100644
--- a/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/ToggleAdvancedModelExplorerHandler.java
+++ b/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/ToggleAdvancedModelExplorerHandler.java
@@ -13,11 +13,24 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.modelexplorer.handler;
+import java.util.LinkedList;
+import java.util.List;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationCatalogManager;
+import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationCatalogManagerFactory;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
import org.eclipse.papyrus.views.modelexplorer.Activator;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.navigator.CommonNavigator;
/**
* A Handler to toggle the Advanced/Simple UML ModelExplorer customization
@@ -42,56 +55,60 @@ public class ToggleAdvancedModelExplorerHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
- //State state = event.getCommand().getState("org.eclipse.papyrus.uml.modelexplorer.customization.advanced.state");
+ ICustomizationManager customizationManager = Activator.getDefault().getCustomizationManager();
+ if(customizationManager != null) {
+ if(event.getTrigger() instanceof Event) {
+ if(((Event)event.getTrigger()).widget instanceof ToolItem) {
+ ToolItem item = (ToolItem)((Event)event.getTrigger()).widget;
+ ICustomizationCatalogManager customCatalog = ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(customizationManager.getResourceSet());
+ Customization simpleUMLCustomization = null;
+ //look for SIMPLE UML Customization
+ for(Customization customization : customCatalog.getRegisteredCustomizations()) {
+ if(SIMPLE_UML_CUSTOMIZATION.equals(customization.getName())){
+ simpleUMLCustomization= customization;
+ }
+ }
- ICustomizationManager customizationManager = Activator.getDefault().getCustomizationManager();
-// if(customizationManager != null) {
-// if(event.getTrigger() instanceof Event) {
-// if(((Event)event.getTrigger()).widget instanceof ToolItem) {
-// ToolItem item = (ToolItem)((Event)event.getTrigger()).widget;
-//
-// MetamodelView simpleUMLCustomization = CustomizationsCatalog.getInstance().getCustomization(SIMPLE_UML_CUSTOMIZATION);
-// if(simpleUMLCustomization != null) {
-// if(item.getSelection()) {
-//
-// //Advanced view
-// List<MetamodelView> registeredCustomizations = new LinkedList<MetamodelView>(customizationManager.getRegisteredCustomizations());
-// if(registeredCustomizations.remove(simpleUMLCustomization)) {
-// customizationManager.clearCustomizations();
-// for(MetamodelView customization : registeredCustomizations) {
-// customizationManager.registerCustomization(customization);
-// }
-// } else {
-// //No change
-// return null;
-// }
-//
-// } else {
-// //Simple view
-// if(customizationManager.getRegisteredCustomizations().contains(simpleUMLCustomization)) {
-// return null; //No change
-// }
-//
-// customizationManager.registerCustomization(simpleUMLCustomization);
-// }
-//
-// customizationManager.loadCustomizations();
-// //Save the current state of the customizations
-// org.eclipse.papyrus.infra.emf.Activator.getDefault().saveCustomizationManagerState();
-// }
-// }
-//
-// }
-// }
-//
-// IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
-// if(activePart instanceof ModelExplorerPageBookView) {
-// IViewPart page = ((ModelExplorerPageBookView)activePart).getActiveView();
-// if(page instanceof CommonNavigator) {
-// ((CommonNavigator)page).getCommonViewer().refresh();
-// }
-// }
+ if(simpleUMLCustomization != null) {
+ if(item.getSelection()) {
+
+ //Advanced view
+ List<Customization> registeredCustomizations = new LinkedList<Customization>(customizationManager.getManagedCustomizations());
+ if(registeredCustomizations.remove(simpleUMLCustomization)) {
+ customizationManager.getManagedCustomizations().clear();
+ for(Customization customization : registeredCustomizations) {
+ customizationManager.getManagedCustomizations().add(customization);
+ }
+ } else {
+ //No change
+ return null;
+ }
+
+ } else {
+ //Simple view
+ if(customizationManager.getManagedCustomizations().contains(simpleUMLCustomization)) {
+ return null; //No change
+ }
+
+ customizationManager.getManagedCustomizations().add(0,simpleUMLCustomization);
+ }
+
+ //Save the current state of the customizations
+ org.eclipse.papyrus.infra.emf.Activator.getDefault().saveCustomizationManagerState();
+ }
+ }
+
+ }
+ }
+
+ IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ if(activePart instanceof ModelExplorerPageBookView) {
+ IViewPart page = ((ModelExplorerPageBookView)activePart).getActiveView();
+ if(page instanceof CommonNavigator) {
+ ((CommonNavigator)page).getCommonViewer().refresh();
+ }
+ }
return null;
}

Back to the top