| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractEditorActionDelegate |
|
| 2.5;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.IResource; | |
| 19 | import org.eclipse.jface.action.IAction; | |
| 20 | import org.eclipse.jface.viewers.ISelection; | |
| 21 | import org.eclipse.jface.viewers.IStructuredSelection; | |
| 22 | import org.eclipse.ui.IEditorActionDelegate; | |
| 23 | import org.eclipse.ui.IEditorPart; | |
| 24 | import org.seasar.eclipse.common.util.AdaptableUtil; | |
| 25 | ||
| 26 | /** | |
| 27 | * @author taichi | |
| 28 | * | |
| 29 | */ | |
| 30 | 0 | public abstract class AbstractEditorActionDelegate implements |
| 31 | IEditorActionDelegate { | |
| 32 | ||
| 33 | protected IEditorPart editorPart; | |
| 34 | ||
| 35 | protected IResource resource; | |
| 36 | ||
| 37 | /* | |
| 38 | * (non-Javadoc) | |
| 39 | * | |
| 40 | * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, | |
| 41 | * org.eclipse.ui.IEditorPart) | |
| 42 | */ | |
| 43 | public void setActiveEditor(IAction action, IEditorPart targetEditor) { | |
| 44 | 0 | this.editorPart = targetEditor; |
| 45 | 0 | if (targetEditor != null) { |
| 46 | 0 | this.resource = AdaptableUtil.toResource(targetEditor |
| 47 | .getEditorInput()); | |
| 48 | } | |
| 49 | 0 | } |
| 50 | ||
| 51 | /* | |
| 52 | * (non-Javadoc) | |
| 53 | * | |
| 54 | * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, | |
| 55 | * org.eclipse.jface.viewers.ISelection) | |
| 56 | */ | |
| 57 | public void selectionChanged(IAction action, ISelection selection) { | |
| 58 | 0 | if (selection instanceof IStructuredSelection |
| 59 | && selection.isEmpty() == false) { | |
| 60 | 0 | IStructuredSelection struct = (IStructuredSelection) selection; |
| 61 | 0 | Object o = struct.getFirstElement(); |
| 62 | 0 | if (o instanceof IResource) { |
| 63 | 0 | this.resource = (IResource) o; |
| 64 | } | |
| 65 | } | |
| 66 | 0 | } |
| 67 | } |