package CDBuilder.couplingSyntaxEditor.convertToXML; import org.eclipse.core.internal.resources.WorkspaceRoot; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.IInputSelectionProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.actions.ActionDelegate; /** * This class lets the user select a xml file and change it into a .ma file * Initializes the path to save the .ma file at and adds it to the existing project * @author Lucie Zhao and Sherwin Sim * @version 1 May - Aug 2003 */ public class convertToXMLActionDelegate extends ActionDelegate implements IObjectActionDelegate { /** * @see ActionDelegate#run(IAction) */ public void run(IAction action) { } /** * Sets up the path for saving the new .ma file to and initializes the xml * reader * @param action the action that is selected * @param targetPart the workbench part that used * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) */ public void setActivePart(IAction action, IWorkbenchPart targetPart) { //gets thelocation of the root of the project IWorkbenchPartSite site= targetPart.getSite(); ISelectionProvider newProvider = site.getSelectionProvider(); IInputSelectionProvider provider = (IInputSelectionProvider) newProvider; Object input = provider.getInput(); WorkspaceRoot root = (WorkspaceRoot)input; IPath path = root.getLocation(); //gets the project name and the selected file name ISelection selection = provider.getSelection(); String string = selection.toString(); int num = string.length(); int number = string.lastIndexOf("/"); //initialize a new reader with the full path of the file selected XMLReader newReader = new XMLReader(path + string.substring(2, num-1)); //after adding the .ma file to the project, refresh the window so it shows up IContainer container = root.getContainerForLocation((path.append(string.substring(2, number+1)))); IProject project = container.getProject(); try { project.refreshLocal(1,null); } catch (Exception e) { System.out.println(e); } } }