core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/sdk/ui/shared/BuildTargetTreeNode.java
changeset 1931 d7c1f804f316
parent 1820 5c955fcfdc3d
child 1974 71a660e8393e
equal deleted inserted replaced
1930:d8b5c1e3a21e 1931:d7c1f804f316
    17 
    17 
    18 
    18 
    19 package com.nokia.carbide.cpp.sdk.ui.shared;
    19 package com.nokia.carbide.cpp.sdk.ui.shared;
    20 
    20 
    21 import java.io.File;
    21 import java.io.File;
       
    22 import java.lang.reflect.InvocationTargetException;
    22 import java.util.ArrayList;
    23 import java.util.ArrayList;
    23 import java.util.List;
    24 import java.util.List;
    24 
    25 
       
    26 import org.eclipse.core.runtime.IProgressMonitor;
       
    27 import org.eclipse.jface.operation.IRunnableContext;
       
    28 import org.eclipse.jface.operation.IRunnableWithProgress;
    25 import org.eclipse.jface.viewers.TreeNode;
    29 import org.eclipse.jface.viewers.TreeNode;
    26 
    30 
    27 import com.nokia.carbide.cpp.internal.api.sdk.ISBSv2BuildContext;
    31 import com.nokia.carbide.cpp.internal.api.sdk.ISBSv2BuildContext;
    28 import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils;
    32 import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils;
    29 import com.nokia.carbide.cpp.sdk.core.ISDKManager;
    33 import com.nokia.carbide.cpp.sdk.core.ISDKManager;
   110 	/**
   114 	/**
   111 	 * Gets the list of SDK tree nodes for use in a tree viewer.  The SDK's are gathered
   115 	 * Gets the list of SDK tree nodes for use in a tree viewer.  The SDK's are gathered
   112 	 * from the SDK preferences page.  Only enabled SDK's are used.  Each SDK node will
   116 	 * from the SDK preferences page.  Only enabled SDK's are used.  Each SDK node will
   113 	 * have build configurations for children appropriate for the SDK.  These configurations
   117 	 * have build configurations for children appropriate for the SDK.  These configurations
   114 	 * are filtered based on the platform filtering preference panel.
   118 	 * are filtered based on the platform filtering preference panel.
   115 	 * @return
       
   116 	 */
       
   117 	public static BuildTargetTreeNode[] getTreeViewerInput() {
       
   118 		return getTreeViewerInput(false);
       
   119 	}
       
   120 
       
   121 	/**
       
   122 	 * Gets the list of SDK tree nodes for use in a tree viewer.  The SDK's are gathered
       
   123 	 * from the SDK preferences page.  Only enabled SDK's are used.  Each SDK node will
       
   124 	 * have build configurations for children appropriate for the SDK.  These configurations
       
   125 	 * are filtered based on the platform filtering preference panel.
       
   126 	 * @param sbsv2Project true if this is an SBSv2 project which affects how the build
   119 	 * @param sbsv2Project true if this is an SBSv2 project which affects how the build
   127 	 * configuration list is calculated
   120 	 * configuration list is calculated
       
   121 	 * @param IRunnableContext - a runnable context for which to update a progress monitor. Cannot be null.
   128 	 * @return array of BuildTargetTreeNode, or null
   122 	 * @return array of BuildTargetTreeNode, or null
   129 	 * @since 1.4
   123 	 * @since 1.4
   130 	 */
   124 	 */
   131 	public static BuildTargetTreeNode[] getTreeViewerInput(boolean sbsv2Project) {
   125 	public static BuildTargetTreeNode[] getTreeViewerInput(final boolean sbsv2Project, IRunnableContext runnableContext) {
   132 		ISDKManager sdkMgr = SDKCorePlugin.getSDKManager();
   126 		
   133 		List<ISymbianSDK> sdkList = sdkMgr.getSDKList();
   127 		final List<BuildTargetTreeNode> assembledInput = new ArrayList<BuildTargetTreeNode>();
   134 		if (sdkList == null)
   128 		
       
   129 		try {
       
   130 			runnableContext.run(true, false, new IRunnableWithProgress(){
       
   131 
       
   132 				public void run(IProgressMonitor monitor)
       
   133 						throws InvocationTargetException, InterruptedException {
       
   134 					
       
   135 					String msgPrefix = "Building SDK/Configuration Model: "; //$NON-NLS-N$
       
   136 					
       
   137 					ISDKManager sdkMgr = SDKCorePlugin.getSDKManager();
       
   138 					List<ISymbianSDK> sdkList = sdkMgr.getSDKList();
       
   139 					monitor.beginTask(msgPrefix, sdkList.size() + 2);
       
   140 					if (sdkList == null)
       
   141 						return;
       
   142 					
       
   143 					monitor.worked(1);
       
   144 					List<ISymbianSDK> sdkListCopy = new ArrayList<ISymbianSDK>();
       
   145 					// Only add SDKs that are enabled
       
   146 					for (ISymbianSDK currSDK : sdkList) {
       
   147 						if (currSDK.isEnabled()) {
       
   148 							sdkListCopy.add(currSDK);
       
   149 						}
       
   150 					}
       
   151 
       
   152 					if (sbsv2Project) {
       
   153 						// filter non-SBSv2 supported SDK's
       
   154 						sdkListCopy = SBSv2Utils.getSupportedSDKs(sdkListCopy);
       
   155 					}
       
   156 
       
   157 					BuildTargetTreeNode[] input = new BuildTargetTreeNode[sdkListCopy
       
   158 							.size()];
       
   159 					int index = 0;
       
   160 					monitor.worked(1);
       
   161 					for (ISymbianSDK sdk : sdkListCopy) {
       
   162 						monitor.worked(1);
       
   163 						monitor.setTaskName(msgPrefix + sdk.getUniqueId());
       
   164 						BuildTargetTreeNode treeNode = new BuildTargetTreeNode(
       
   165 								sdk, sbsv2Project);
       
   166 						if (treeNode.getChildren() != null || sbsv2Project) {
       
   167 							input[index++] = treeNode;
       
   168 						}
       
   169 					}
       
   170 
       
   171 					// Filter out any SDKs that don't have configs
       
   172 					monitor.worked(1);
       
   173 					for (BuildTargetTreeNode currNode : input) {
       
   174 						if (currNode != null) {
       
   175 							assembledInput.add(currNode);
       
   176 						}
       
   177 					}
       
   178 					monitor.done();
       
   179 				}
       
   180 			
       
   181 			
       
   182 			});
       
   183 		} catch (InvocationTargetException e) {
       
   184 			e.printStackTrace();
       
   185 		} catch (InterruptedException e) {
       
   186 			e.printStackTrace();
       
   187 		}
       
   188 		
       
   189 		if (assembledInput.size() == 0){
   135 			return null;
   190 			return null;
   136 		
   191 		}
   137 		List<ISymbianSDK> sdkListCopy = new ArrayList<ISymbianSDK>();
   192 
   138 		// Only add SDKs that are enabled
   193 		return assembledInput.toArray(new BuildTargetTreeNode[assembledInput.size()]);
   139 		for (ISymbianSDK currSDK : sdkList){
       
   140 			if (currSDK.isEnabled()){
       
   141 				sdkListCopy.add(currSDK);
       
   142 			}
       
   143 		}
       
   144 		
       
   145 		if (sbsv2Project) {
       
   146 			// filter non-SBSv2 supported SDK's
       
   147 			sdkListCopy = SBSv2Utils.getSupportedSDKs(sdkListCopy);
       
   148 		}
       
   149 		
       
   150 		BuildTargetTreeNode[] input = new BuildTargetTreeNode[sdkListCopy.size()];
       
   151 		int index = 0;
       
   152 		for (ISymbianSDK sdk : sdkListCopy) {
       
   153 			
       
   154 			BuildTargetTreeNode treeNode = new BuildTargetTreeNode(sdk, sbsv2Project);
       
   155 			if (treeNode.getChildren() != null || sbsv2Project){
       
   156 				input[index++] = treeNode;
       
   157 			}
       
   158 		}
       
   159 		
       
   160 		// Filter out any SDKs that don't have configs
       
   161 		BuildTargetTreeNode[] realInput = new BuildTargetTreeNode[index];
       
   162 		index = 0;
       
   163 		for (BuildTargetTreeNode currNode : input) {
       
   164 			if (currNode != null){
       
   165 				realInput[index++] = currNode;
       
   166 			}
       
   167 		}
       
   168 		return realInput;
       
   169 	}
   194 	}
   170 	
   195 	
   171 	private static String stripSDKIDFromConfigName(String configName, String sdkID){
   196 	private static String stripSDKIDFromConfigName(String configName, String sdkID){
   172 		return configName.replace("[" + sdkID + "]", "");
   197 		return configName.replace("[" + sdkID + "]", "");
   173 	}
   198 	}