1 12 package org.eclipse.jdt.internal.debug.ui.snippeteditor; 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 16 import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart; 17 import org.eclipse.jface.action.Action; 18 import org.eclipse.jface.dialogs.MessageDialog; 19 import org.eclipse.jface.viewers.IElementComparer; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.jface.viewers.StructuredSelection; 22 import org.eclipse.ui.PlatformUI; 23 24 32 public class ShowInPackageViewAction extends Action { 33 34 private JavaSnippetEditor fEditor; 35 36 41 public ShowInPackageViewAction() { 42 super(SnippetMessages.getString("ShowInPackageViewAction.label")); setDescription(SnippetMessages.getString("ShowInPackageViewAction.description")); setToolTipText(SnippetMessages.getString("ShowInPackageViewAction.tooltip")); PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SHOW_IN_PACKAGEVIEW_ACTION); 46 } 47 48 51 public ShowInPackageViewAction(JavaSnippetEditor editor) { 52 this(); 53 fEditor= editor; 54 } 55 56 59 public void run() { 60 IFile file= fEditor.getFile(); 61 if (file == null) { 62 return; 63 } 64 PackageExplorerPart view= PackageExplorerPart.openInActivePerspective(); 65 if (!reveal(view, file)) { 66 MessageDialog.openInformation(fEditor.getShell(), getDialogTitle(), SnippetMessages.getString("ShowInPackageViewAction.not_found")); } 68 } 69 70 private boolean reveal(PackageExplorerPart view, Object element) { 71 if (view == null) { 72 return false; 73 } 74 view.selectReveal(new StructuredSelection(element)); 75 IElementComparer comparer= view.getTreeViewer().getComparer(); 76 Object selected= getSelectedElement(view); 77 if (comparer != null ? comparer.equals(element, selected) : element.equals(selected)) { 78 return true; 79 } 80 return false; 81 } 82 83 private Object getSelectedElement(PackageExplorerPart view) { 84 return ((IStructuredSelection) view.getSite().getSelectionProvider().getSelection()).getFirstElement(); 85 } 86 87 private static String getDialogTitle() { 88 return SnippetMessages.getString("ShowInPackageViewAction.dialog.title"); } 90 } 91 | Popular Tags |