sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/properties/PIPropertyPage.java
changeset 2 b9ab3b238396
equal deleted inserted replaced
1:1050670c6980 2:b9ab3b238396
       
     1 /*
       
     2  * Copyright (c) 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 the License "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: 
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.carbide.cpp.internal.pi.properties;
       
    19 
       
    20 import java.io.BufferedInputStream;
       
    21 import java.io.EOFException;
       
    22 import java.io.IOException;
       
    23 import java.io.InputStream;
       
    24 import java.io.InvalidClassException;
       
    25 import java.io.ObjectInputStream;
       
    26 import java.io.ObjectStreamClass;
       
    27 import java.util.zip.GZIPInputStream;
       
    28 
       
    29 import org.eclipse.core.resources.IFile;
       
    30 import org.eclipse.core.runtime.CoreException;
       
    31 import org.eclipse.core.runtime.IAdaptable;
       
    32 import org.eclipse.swt.SWT;
       
    33 import org.eclipse.swt.widgets.Composite;
       
    34 import org.eclipse.swt.widgets.Control;
       
    35 import org.eclipse.swt.widgets.Label;
       
    36 import org.eclipse.ui.IWorkbenchPropertyPage;
       
    37 import org.eclipse.ui.dialogs.PropertyPage;
       
    38 
       
    39 import com.nokia.carbide.cpp.internal.pi.manager.PluginInitialiser;
       
    40 import com.nokia.carbide.cpp.internal.pi.test.AnalysisInfoHandler;
       
    41 import com.nokia.carbide.cpp.internal.pi.test.PIAnalysisInfo;
       
    42 import com.nokia.carbide.cpp.internal.pi.test.BappeaAnalysisInfo;
       
    43 import com.nokia.carbide.cpp.internal.pi.utils.PluginClassLoader;
       
    44 
       
    45 
       
    46 public class PIPropertyPage extends PropertyPage implements
       
    47 		IWorkbenchPropertyPage {
       
    48 
       
    49 	@Override
       
    50 	protected Control createContents(Composite parent) {
       
    51 		noDefaultAndApplyButton();
       
    52 
       
    53 		// we will read the first object in the file and use it to
       
    54 		IAdaptable resource = this.getElement();
       
    55 
       
    56 		if (!(resource instanceof IFile))
       
    57 			return null;
       
    58 
       
    59 		IFile file = (IFile) resource;
       
    60 		InputStream input = null;
       
    61 		
       
    62 		// make sure we can open an input stream to the trace file
       
    63 		try {
       
    64 			input = file.getContents();
       
    65 		} catch (CoreException e) {
       
    66 			System.out.println(Messages.getString("PIPropertyPage.cannotReadFile") + file.getName()); //$NON-NLS-1$
       
    67 			return null;
       
    68 		}
       
    69 		
       
    70 		if (input == null)
       
    71 			return null;
       
    72 		
       
    73 		// the file contains Java objects that have been gziped
       
    74 		GZIPInputStream ziss = null;
       
    75 		try {
       
    76 			ziss = new GZIPInputStream(input);
       
    77 		} catch (IOException e) {
       
    78 			System.out.println(Messages.getString("PIPropertyPage.cannotReadFile") + file.getName()); //$NON-NLS-1$
       
    79 			return null;
       
    80 		}
       
    81 
       
    82 		BufferedInputStream bis = new BufferedInputStream(ziss);
       
    83 		ObjectInputStream ois = null;
       
    84 		Object ou = null;
       
    85 
       
    86 	    try {
       
    87 			ois = new ObjectInputStream(bis) {
       
    88 			    @SuppressWarnings("unchecked") //$NON-NLS-1$
       
    89 				protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
       
    90 			    	// each object read must have a class corresponding to a plugin class
       
    91 			    	String name = desc.getName();
       
    92 					Class c = PluginInitialiser.getPluginClass(name);
       
    93 					
       
    94 					if (c == null) {
       
    95 						try {
       
    96 							c = Class.forName(name);
       
    97 						} catch (ClassNotFoundException e) {
       
    98 							// see if we have a replacement
       
    99 							PluginClassLoader pcl = (PluginClassLoader)PluginInitialiser.getPluginClassLoader();
       
   100 							// don't catch for class not found exception, they did it on purpose 
       
   101 							// to back out of this missing plugin that exist in data file
       
   102 							c = pcl.findClass(name);
       
   103 						}
       
   104 					}
       
   105 					
       
   106 			   		return c;
       
   107 			    }
       
   108 			};
       
   109 
       
   110 			//read the first object
       
   111            	ou = ois.readObject();
       
   112         }
       
   113     	catch (ClassNotFoundException cnfe) {
       
   114 	    }
       
   115 	    catch(EOFException eof) {
       
   116 	    }
       
   117 	    catch (InvalidClassException ie) {
       
   118 	    }
       
   119         catch (IOException e) {
       
   120         }
       
   121         catch (Exception eih) {
       
   122         };
       
   123 	    
       
   124 	    // close the readers
       
   125         if (ois != null)
       
   126 			try {
       
   127 				ois.close();
       
   128 			}
       
   129         	catch (IOException e) {
       
   130 			}
       
   131 		
       
   132 		if (bis != null)
       
   133 			try {
       
   134 				bis.close();
       
   135 			}
       
   136 			catch (IOException e) {
       
   137 			}
       
   138 		
       
   139 		if (ziss != null)
       
   140 			try {
       
   141 				ziss.close();
       
   142 			}
       
   143 			catch (IOException e) {
       
   144 			}
       
   145 
       
   146 		AnalysisInfoHandler aih = new AnalysisInfoHandler();
       
   147 		
       
   148 		if (ou instanceof PIAnalysisInfo) {
       
   149 			aih.analysisDataReader((PIAnalysisInfo) ou);
       
   150 			aih.getAnalysisInfoLabels(parent);
       
   151 		} else if (ou instanceof BappeaAnalysisInfo) {
       
   152 			aih.analysisDataReader((BappeaAnalysisInfo) ou);
       
   153 			aih.getAnalysisInfoLabels(parent);
       
   154 		} else {
       
   155 			Label label = new Label(parent, SWT.WRAP);
       
   156 			label.setText(Messages.getString("PIPropertyPage.noPIinformation")); //$NON-NLS-1$
       
   157 		}
       
   158 
       
   159 		return null;
       
   160 	}
       
   161 }