sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/ui/ATResourceListener.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 ATResourceListener
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.ui;
       
    19 
       
    20 
       
    21 import org.eclipse.core.resources.IResource;
       
    22 import org.eclipse.core.resources.IResourceChangeEvent;
       
    23 import org.eclipse.core.resources.IResourceChangeListener;
       
    24 import org.eclipse.core.resources.IResourceDelta;
       
    25 import org.eclipse.core.resources.IResourceDeltaVisitor;
       
    26 import org.eclipse.core.runtime.CoreException;
       
    27 
       
    28 import com.nokia.s60tools.analyzetool.Activator;
       
    29 
       
    30 /**
       
    31  * Listens projec changes
       
    32  * @author kihe
       
    33  *
       
    34  */
       
    35 public class ATResourceListener implements IResourceChangeListener{
       
    36 
       
    37 	/**
       
    38 	 * Listens workspace resource changes.
       
    39 	 * If resource is BuildComplete file => notifies AT UI that module build state is changed
       
    40 	 *
       
    41 	 * @param event Resource changed event
       
    42 	 */
       
    43 	public void resourceChanged(IResourceChangeEvent event) {
       
    44 		try {
       
    45 
       
    46 			//if event type is change
       
    47 			if( event.getType() == IResourceChangeEvent.POST_CHANGE ) {
       
    48 
       
    49 				//get delta
       
    50 				IResourceDelta delta = event.getDelta();
       
    51 
       
    52 				//
       
    53 				if(delta != null ) {
       
    54 
       
    55 					//add new IResourceDeltaVisitor for delta
       
    56 					//now we can thru all the changed files
       
    57 					delta.accept( new IResourceDeltaVisitor() {
       
    58 						boolean updateView = true;
       
    59 
       
    60 
       
    61 						public boolean visit(IResourceDelta newDelta) {
       
    62 
       
    63 							//we are only interested in new files
       
    64 							if(newDelta.getKind() != IResourceDelta.ADDED ) {
       
    65 								return true;
       
    66 							}
       
    67 
       
    68 							//get resource
       
    69 							IResource res = newDelta.getResource();
       
    70 
       
    71 							//resource if BuildComplete file
       
    72 							if( res.getName().equalsIgnoreCase("BuildComplete")) {
       
    73 
       
    74 								//notify AT UI that module build state is changed
       
    75 								IActionListener listener = Activator.getActionListener();
       
    76 								if( listener != null && updateView && res.getProject() != null ) {
       
    77 									listener.buildStateChanged(res.getProject());
       
    78 									updateView = false;
       
    79 								}
       
    80 							}
       
    81 
       
    82 							return true;
       
    83 						}
       
    84 					}
       
    85 					);
       
    86 				}
       
    87 			}
       
    88 		}catch(CoreException ce) {
       
    89 			ce.printStackTrace();
       
    90 		}
       
    91 
       
    92 
       
    93 
       
    94 	}
       
    95 
       
    96 
       
    97 }
       
    98 
       
    99