sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/ui/actions/CompileSymbianComponent.java
changeset 1 1050670c6980
child 6 f65f740e69f9
equal deleted inserted replaced
0:5ad7ad99af01 1:1050670c6980
       
     1 /*
       
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Definitions for the class CompileSymbianComponent
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.ui.actions;
       
    19 
       
    20 import java.util.ArrayList;
       
    21 import java.util.Iterator;
       
    22 import java.util.List;
       
    23 import java.util.Locale;
       
    24 
       
    25 import org.eclipse.core.resources.IFile;
       
    26 import org.eclipse.core.runtime.IAdaptable;
       
    27 import org.eclipse.jface.action.IAction;
       
    28 import org.eclipse.jface.viewers.ISelection;
       
    29 import org.eclipse.jface.viewers.IStructuredSelection;
       
    30 import org.eclipse.ui.IObjectActionDelegate;
       
    31 import org.eclipse.ui.IWorkbenchPart;
       
    32 
       
    33 import com.nokia.s60tools.analyzetool.builder.CustomPreBuilder;
       
    34 
       
    35 /**
       
    36  * Class to instrument and compile user selected mmp files with atool.exe.
       
    37  *
       
    38  * @author kihe
       
    39  *
       
    40  */
       
    41 public class CompileSymbianComponent implements IObjectActionDelegate {
       
    42 
       
    43 	/** list of user selected files.*/
       
    44 	public List<IFile> selectedFiles;
       
    45 
       
    46 	/**
       
    47 	 * Constructor.
       
    48 	 */
       
    49 	public CompileSymbianComponent() {
       
    50 		super();
       
    51 		selectedFiles = new ArrayList<IFile>(0);
       
    52 	}
       
    53 
       
    54 	/**
       
    55 	 * Instruments, builds and unistruments selected mmp's with AnalyzeTool builder.
       
    56 	 *
       
    57 	 * @param action User selected action
       
    58 	 */
       
    59 	public void run(IAction action) {
       
    60 
       
    61 		// if for some reason makefile list is empty => leave
       
    62 		if (selectedFiles.isEmpty()) {
       
    63 			return;
       
    64 		}
       
    65 
       
    66 		CustomPreBuilder builder = new CustomPreBuilder();
       
    67 		builder.buildComponents(selectedFiles);
       
    68 
       
    69 	}
       
    70 
       
    71 	/**
       
    72 	 * Listening selection changed events and is selection is mmp file stores it to list.
       
    73 	 *
       
    74 	 * @param action User selected action
       
    75 	 *
       
    76 	 * @param selection User selection
       
    77 	 */
       
    78 	@SuppressWarnings("unchecked")
       
    79 	public void selectionChanged(IAction action, ISelection selection) {
       
    80 
       
    81 		// clear existing data
       
    82 		selectedFiles.clear();
       
    83 
       
    84 		// if selection is null => leave
       
    85 		if (selection == null) {
       
    86 			return;
       
    87 		}
       
    88 
       
    89 		// if selection is
       
    90 		if (selection instanceof IStructuredSelection) {
       
    91 			// thru selections
       
    92 			for (Iterator<Object> iter = ((IStructuredSelection) selection)
       
    93 					.iterator(); iter.hasNext();) {
       
    94 
       
    95 				// get next selection
       
    96 				Object selectionItem = iter.next();
       
    97 				IFile file = null;
       
    98 				// if selection is IFile
       
    99 				if (selectionItem instanceof IFile) {
       
   100 					file = (IFile) selectionItem;
       
   101 				} else if (selectionItem instanceof IAdaptable) {
       
   102 					file = (IFile) ((IAdaptable) selectionItem)
       
   103 							.getAdapter(IFile.class);
       
   104 				}
       
   105 
       
   106 				// only allow mmp and mk files
       
   107 				if ( file != null
       
   108 						&& (file.getName().toUpperCase(Locale.US).endsWith(".MMP")
       
   109 						|| file.getName().toUpperCase(Locale.US).endsWith(".MK"))) {
       
   110 					selectedFiles.add(file);
       
   111 				}
       
   112 
       
   113 			}
       
   114 		}
       
   115 	}
       
   116 
       
   117 	/**
       
   118 	 * Sets the active part for the delegate.
       
   119 	 *
       
   120 	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
       
   121 	 *
       
   122 	 * @param action User selected action
       
   123 	 *
       
   124 	 * @param targetPart Workbench Part
       
   125 	 */
       
   126 	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
       
   127 		// MethodDeclaration/Block[count(BlockStatement) = 0 and
       
   128 		// @containsComment = 'false']
       
   129 
       
   130 		//do nothing be design
       
   131 	}
       
   132 }