X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=case-study%2Fjdt-before%2Fui%2Forg%2Feclipse%2Fjdt%2Finternal%2Fui%2Fcallhierarchy%2FOpenDeclarationAction.java;fp=case-study%2Fjdt-before%2Fui%2Forg%2Feclipse%2Fjdt%2Finternal%2Fui%2Fcallhierarchy%2FOpenDeclarationAction.java;h=7ee803cf7cd30e45c11ed3bc2b4c21893e9116b4;hb=1b2798f607d741df30e5197f427381cbff326adc;hp=0000000000000000000000000000000000000000;hpb=246231e4bd9b24345490f369747c0549ca308c4d;p=ifi-stolz-refaktor.git diff --git a/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/callhierarchy/OpenDeclarationAction.java b/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/callhierarchy/OpenDeclarationAction.java new file mode 100644 index 00000000..7ee803cf --- /dev/null +++ b/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/callhierarchy/OpenDeclarationAction.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation + * (report 36180: Callers/Callees view) + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.callhierarchy; + +import org.eclipse.jface.viewers.ISelection; + +import org.eclipse.ui.IWorkbenchSite; + +import org.eclipse.jdt.core.IMember; + +import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper; + +import org.eclipse.jdt.ui.actions.OpenAction; + +import org.eclipse.jdt.internal.ui.util.SelectionUtil; + +/** + * This class is used for opening the declaration of an element from the call hierarchy view. + */ +class OpenDeclarationAction extends OpenAction { + public OpenDeclarationAction(IWorkbenchSite site) { + super(site); + } + + public boolean canActionBeAdded() { + // It is safe to cast to IMember since the selection has already been converted + IMember member = (IMember) SelectionUtil.getSingleElement(getSelection()); + + if (member != null) { + return true; + } + + return false; + } + + @Override + public ISelection getSelection() { + return CallHierarchyUI.convertSelection(getSelectionProvider().getSelection()); + } + + @Override + public Object getElementToOpen(Object object) { + if (object instanceof MethodWrapper) { + return ((MethodWrapper) object).getMember(); + } + return object; + } +}