Merge "Uninstall action for Ogee"
diff --git a/org.eclipse.ogee.core/META-INF/MANIFEST.MF b/org.eclipse.ogee.core/META-INF/MANIFEST.MF
index 3eaaf3a..6a218cd 100644
--- a/org.eclipse.ogee.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.ogee.core/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@
 Bundle-Vendor: %providerName
 Require-Bundle: org.eclipse.ogee.help,
  org.eclipse.ui,
+ org.eclipse.equinox.p2.engine,
  org.eclipse.core.runtime;bundle-version="3.8.0",
  org.eclipse.ui.ide;bundle-version="3.8.0",
  org.eclipse.jdt.core;bundle-version="3.8.0",
diff --git a/org.eclipse.ogee.core/plugin.xml b/org.eclipse.ogee.core/plugin.xml
index 6545611..9641460 100644
--- a/org.eclipse.ogee.core/plugin.xml
+++ b/org.eclipse.ogee.core/plugin.xml
@@ -95,5 +95,13 @@
          </command>
       </menuContribution>
    </extension>
+   <extension
+         point="org.eclipse.equinox.p2.engine.actions">
+      <action
+            class="org.eclipse.ogee.core.UninstallAction"
+            name="uninstall_action"
+            version="1.0">
+      </action>
+   </extension>
 
 </plugin>
diff --git a/org.eclipse.ogee.core/src/org/eclipse/ogee/core/UninstallAction.java b/org.eclipse.ogee.core/src/org/eclipse/ogee/core/UninstallAction.java
new file mode 100644
index 0000000..23c9028
--- /dev/null
+++ b/org.eclipse.ogee.core/src/org/eclipse/ogee/core/UninstallAction.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ *  Copyright (c) 2012-2014 SAP SE.
+ *  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:
+ *  SAP SE - initial API and implementation and/or initial documentation
+ *
+ *******************************************************************************/
+package org.eclipse.ogee.core;
+
+import java.util.Map;
+
+import org.eclipse.core.internal.registry.ExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
+import org.eclipse.ogee.core.nls.messages.FrameworkMessages;
+import org.eclipse.ogee.utils.logger.Logger;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+public class UninstallAction extends ProvisioningAction
+{
+	private Logger logger = Logger.getUtilsLogger();
+
+	private static final String ODATA_PERSPECTIVE_ID = "org.eclipse.ogee.utils.perspective"; //$NON-NLS-1$
+
+	public UninstallAction()
+	{
+	}
+
+	@Override
+	public IStatus execute(Map<String, Object> parameters)
+	{
+		try
+		{
+			Display.getDefault().asyncExec(new Runnable()
+			{
+				@Override
+				public void run()
+				{
+					closeODataPerspective();
+				}
+			});
+
+			String operandObject = parameters.get("operand").toString(); //$NON-NLS-1$			
+			if (operandObject != null && !operandObject.isEmpty() && operandObject.contains("--> null")) //$NON-NLS-1$
+			{
+				executeUninstall();
+			}
+		}
+		catch (Exception e)
+		{
+			this.logger.logError(FrameworkMessages.UninstallAction_0, e);
+		}
+
+
+		return Status.OK_STATUS;
+	}
+
+	@Override
+	public IStatus undo(Map<String, Object> parameters)
+	{
+		return null;
+	}
+
+	/**
+	 * Removes all preferences GW configurations and encripted password
+	 * 
+	 */
+	public void executeUninstall()
+	{
+		this.logger.log(FrameworkMessages.UninstallAction_2);
+		ExtensionRegistry extensionRegistry = (ExtensionRegistry) Platform.getExtensionRegistry();
+		extensionRegistry.clearRegistryCache();
+		this.logger.log(FrameworkMessages.UninstallAction_3);
+
+	}
+
+	public void closeODataPerspective()
+	{
+		IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+		if (w != null)
+		{
+			IWorkbenchPage wp = w.getActivePage();
+			if (wp != null)
+			{
+				IPerspectiveDescriptor[] pds = wp.getOpenPerspectives();
+				if (pds != null && pds.length > 1)
+				{
+					for (IPerspectiveDescriptor pd : pds)
+					{
+						if (ODATA_PERSPECTIVE_ID.equals(pd.getId()))
+						{
+							wp.closePerspective(pd, true, true);
+							this.logger.log("Closed OData Perspective"); //$NON-NLS-1$
+						}
+					}
+				}
+			}
+		}
+	}
+
+}
diff --git a/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/FrameworkMessages.java b/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/FrameworkMessages.java
index 96bfac1..b6771dd 100644
--- a/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/FrameworkMessages.java
+++ b/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/FrameworkMessages.java
@@ -193,6 +193,15 @@
 	public static String ServiceFromODataWizardPage_2;
 
 	public static String ServiceFromODataWizardPage_3;
+	
+	public static String UninstallAction_0;
+	
+	public static String UninstallAction_1;
+	
+	public static String UninstallAction_2;
+	
+	public static String UninstallAction_3;
+	
 	static
 	{
 		// initialize resource bundle
diff --git a/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/framework.properties b/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/framework.properties
index da60ddc..6ea718c 100644
--- a/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/framework.properties
+++ b/org.eclipse.ogee.core/src/org/eclipse/ogee/core/nls/messages/framework.properties
@@ -280,4 +280,12 @@
 # YMSG
 ServiceFromODataWizardPage_2=Select an existing OData Model file from the file system
 # YMSG
-ServiceFromODataWizardPage_3=Copy an existing OData Model
\ No newline at end of file
+ServiceFromODataWizardPage_3=Copy an existing OData Model
+# YMSG
+UninstallAction_0=Framework SAP plug-in uninstall process error
+# YMSG
+UninstallAction_1=Framework SAP plug-in uninstall process error
+# YMSG
+UninstallAction_2=Framework SAP plug-in uninstall process has started
+# YMSG
+UninstallAction_3=Framework SAP plug-in uninstall process has finished successfully
\ No newline at end of file