1/* 2 * ActionUtils.java 3 * Copyright (C) 2005 Amin Ahmad. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 * Amin Ahmad can be contacted at amin.ahmad@gmail.com or on the web at 20 * www.ahmadsoft.org. 21 */ 22 23package org.ahmadsoft.foprocessor.popup.actions; 24 25import java.util.ArrayList; 26import java.util.Iterator; 27import java.util.List; 28 29import org.ahmadsoft.foprocessor.core.FileRenderSpecification; 30import org.eclipse.core.resources.IFile; 31import org.eclipse.core.resources.IResource; 32import org.eclipse.jface.viewers.ISelection; 33import org.eclipse.jface.viewers.IStructuredSelection; 34 35/** 36 * Miscellaneous utilities for actions. 37 * @author Amin Ahmad 38 */ 39public class ActionUtils { 40 @SuppressWarnings("unchecked") 41 public static final List<FileRenderSpecification> asRenderSpecs(String mimeType, String extension, ISelection selection) { 42 List<FileRenderSpecification> result = new ArrayList<FileRenderSpecification>(); 43 44 if (selection instanceof IStructuredSelection) { 45 IStructuredSelection structuredSelection = (IStructuredSelection) selection; 46 for (Iterator i = structuredSelection.iterator(); i.hasNext();) { 47 IResource resource = (IResource) i.next(); 48 if (resource instanceof IFile) { 49 IFile file = (IFile) resource; 50 51 FileRenderSpecification renderSpec = new FileRenderSpecification(); 52 renderSpec.setInputFile(file); 53 renderSpec.setOutputFile(FileRenderSpecification.computeOutputFile(file, extension)); 54 renderSpec.setMimeType(mimeType); 55 result.add(renderSpec); 56 } 57 } 58 } 59 60 return result; 61 } 62} 63