blob: a28ca5a0be2d3e5ad4ca26f668a6b69930139827 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010 Eteration A.S. and others.
* 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:
* IBM Corporation - initial API and implementation
* - This code is based on WTP SDK frameworks and Tomcat Server Adapters
* org.eclipse.jst.server.core
* org.eclipse.jst.server.ui
*
* Naci Dai and Murat Yener, Eteration A.S.
*******************************************************************************/
package org.eclipse.libra.framework.ui.internal.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.libra.framework.ui.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;
public class CleanWorkDirAction implements IObjectActionDelegate {
private IWorkbenchPart targetPart;
private IServer selectedServer;
private IModule selectedModule;
/**
* Constructor for Action1.
*/
public CleanWorkDirAction() {
super();
}
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
/**
* @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();
}
}
}
}
}