/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* 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:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package com.vmware.vfabric.ide.eclipse.tcserver.internal.ui;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jst.server.tomcat.ui.internal.CleanWorkDirDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.ui.IServerModule;
/**
* Copied from
* org.eclipse.jst.server.tomcat.ui.internal.actions.CleanWorkDirAction due to
* missing export:
* 266789: org.eclipse.jst.server.tomcat.ui does not export all packages
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=266789
* @author Steffen Pingel
* @author Christian Dupuis
*/
public class CleanTcServerWorkDirAction implements IObjectActionDelegate {
private IWorkbenchPart targetPart;
private IServer selectedServer;
private IModule selectedModule;
/**
* Constructor for Action1.
*/
public CleanTcServerWorkDirAction() {
super();
}
/**
* @see org.eclipse.ui.IActionDelegate#run(IAction)
*/
public void run(IAction action) {
CleanWorkDirDialog dlg = new CleanWorkDirDialog(targetPart.getSite().getShell(), selectedServer, selectedModule);
dlg.open();
}
/**
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
selectedServer = null;
selectedModule = null;
if (!selection.isEmpty()) {
if (selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof IServer) {
selectedServer = (IServer) obj;
}
else if (obj instanceof IServerModule) {
IServerModule sm = (IServerModule) obj;
IModule[] module = sm.getModule();
selectedModule = module[module.length - 1];
if (selectedModule != null) {
selectedServer = sm.getServer();
}
}
}
}
}
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
}