blob: 739c7becb913b9b366c06163229e6eb9b6363f96 [file] [log] [blame]
/*******************************************************************************
* 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 static 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()
{
logger.log("Closing OData Perspective"); //$NON-NLS-1$
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)
{
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
*
*/
protected void executeUninstall()
{
logger.log(FrameworkMessages.UninstallAction_2);
ExtensionRegistry extensionRegistry = (ExtensionRegistry) Platform.getExtensionRegistry();
extensionRegistry.clearRegistryCache();
logger.log(FrameworkMessages.UninstallAction_3);
}
protected 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);
logger.log("Closed OData Perspective"); //$NON-NLS-1$
}
}
}
}
}
}
}