Coverage Report - org.seasar.eclipse.common.action.AbstractProjectAction
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractProjectAction
0%
0/20
0%
0/10
2.5
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.eclipse.common.action;
 17  
 
 18  
 import org.eclipse.core.resources.IProject;
 19  
 import org.eclipse.core.resources.IResource;
 20  
 import org.eclipse.core.runtime.CoreException;
 21  
 import org.eclipse.jface.action.IAction;
 22  
 import org.eclipse.jface.viewers.ISelection;
 23  
 import org.eclipse.jface.viewers.IStructuredSelection;
 24  
 import org.eclipse.ui.IActionDelegate;
 25  
 import org.seasar.eclipse.common.CommonPlugin;
 26  
 import org.seasar.eclipse.common.util.AdaptableUtil;
 27  
 import org.seasar.eclipse.common.util.ProjectUtil;
 28  
 
 29  
 /**
 30  
  * @author taichi
 31  
  * 
 32  
  */
 33  
 public abstract class AbstractProjectAction implements IActionDelegate {
 34  
 
 35  0
     private IProject project = null;
 36  
 
 37  
     /**
 38  
      * 
 39  
      */
 40  
     public AbstractProjectAction() {
 41  0
         super();
 42  0
     }
 43  
 
 44  
     /*
 45  
      * (non-Javadoc)
 46  
      * 
 47  
      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
 48  
      *      org.eclipse.jface.viewers.ISelection)
 49  
      */
 50  
     public void selectionChanged(IAction action, ISelection selection) {
 51  0
         if (selection instanceof IStructuredSelection) {
 52  0
             IStructuredSelection ss = (IStructuredSelection) selection;
 53  0
             Object o = ss.getFirstElement();
 54  0
             this.project = AdaptableUtil.toProject(o);
 55  0
             if (this.project == null) {
 56  0
                 IResource r = AdaptableUtil.toResource(o);
 57  0
                 if (r != null) {
 58  0
                     this.project = r.getProject();
 59  
                 }
 60  
             }
 61  
         }
 62  0
     }
 63  
 
 64  
     /*
 65  
      * (non-Javadoc)
 66  
      * 
 67  
      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 68  
      */
 69  
     public void run(IAction action) {
 70  
         try {
 71  0
             if (this.project == null) {
 72  0
                 this.project = ProjectUtil.getCurrentSelectedProject();
 73  
             }
 74  0
             if (this.project != null) {
 75  0
                 run(action, this.project);
 76  
             }
 77  0
         } catch (CoreException e) {
 78  0
             CommonPlugin.log(e);
 79  0
         }
 80  0
     }
 81  
 
 82  
     public abstract void run(IAction action, IProject project)
 83  
             throws CoreException;
 84  
 }