/* * Created on Jun 8, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package CELLDEV.buttons; import java.util.ArrayList; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; import CDBuilder.console.ConsoleDocument; /** * @author ssim, Ali Monadi * * This class will be invoked when the GrafLog button is pressed. * It will check to see if needed files exist for the simuation to continue. * */ public class GraflogAction extends Action implements IWorkbenchWindowActionDelegate{ IContainer container; String COLFileName; public GraflogAction() { super(); setText("graph log"); setDescription("generate graph based on clor palette"); } public void run() { try { //show console view PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("ConsoleView"); ConsoleDocument cdos = ConsoleDocument.getCDOS(); IWorkspaceRoot root = (IWorkspaceRoot)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput(); //get path IPath projectPath = root.getLocation(); String selectPath = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(IPageLayout.ID_RES_NAV).toString(); COLFileName = selectPath.substring( selectPath.lastIndexOf("/")+1, selectPath.lastIndexOf("]") ); selectPath = selectPath.substring(selectPath.indexOf("/")+1, selectPath.lastIndexOf("/")); //concatenate the string to get rid of [] projectPath = projectPath.append(selectPath +"/"); IPath internalPath = root.getLocation().removeLastSegments(1); internalPath = internalPath.append("/plugins/CD++Builder_1.1.0/internal/"); System.out.println("Internal Path" + internalPath); IContainer container = root.getContainerForLocation(projectPath); String projectPathForUnix = projectPath.toString().charAt(0) + projectPath.toString().substring(2); String internalPathForUnix = internalPath.toString().charAt(0) + internalPath.toString().substring(2); Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); if (!COLFileName.endsWith("col") && !COLFileName.endsWith("COL")) COLFileName = null; try { IResource[] projectFiles; IFile COLFile = null; String line; ArrayList typeFiles = new ArrayList(); projectFiles = root.getContainerForLocation(projectPath).members(); for(int i = 0; i < projectFiles.length; i++){ if(projectFiles[i]instanceof IFile && (projectFiles[i].getName().endsWith(".col")||projectFiles[i].getName().endsWith(".COL"))){ COLFile = (IFile) projectFiles[i]; break; } } if (COLFile == null){ throw new NullPointerException(); } } catch (Exception e1) { MessageBox noSimu = new MessageBox(parent, SWT.ICON_ERROR | SWT.OK); noSimu.setMessage("Color palette file (.col) not found"); noSimu.setText("File Not Found"); noSimu.open(); return; } cdos.clear(); GraflogGUI dialog = new GraflogGUI(parent, projectPath, internalPath, COLFileName); dialog.create(); dialog.open(); dialog.close(); container.refreshLocal(1, null); }catch (Exception np) { MessageBox npGui = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); npGui.setMessage("You must select a file or project folder to start simulations! "); npGui.setText("Project Not Selected"); npGui.open(); ConsoleDocument.getCDOS().set("Please select a project or folder from the navigator."); } } public void run(IAction action) { run(); } public void dispose() { // do nothing. } public void init(IWorkbenchWindow window) { // do nothing. } public void selectionChanged(IAction action, ISelection selection) { } }