1 26 30 package org.omg.lifl.eclipse.plugin.utils; 31 32 import org.eclipse.core.resources.IResource; 33 import org.eclipse.core.runtime.IAdaptable; 34 import org.eclipse.jface.dialogs.MessageDialog; 35 import org.eclipse.jface.viewers.ISelection; 36 import org.eclipse.jface.viewers.IStructuredSelection; 37 import org.eclipse.swt.widgets.Shell; 38 import org.omg.lifl.eclipse.plugin.project.OpenCCM.MainPlugin; 39 40 44 public class WorkBenchHelper { 45 public static void log() { 46 Shell shell = new Shell(); 47 48 MessageDialog.openInformation( 49 shell, 50 "PopUpMenu Plug-in", 51 "Launch Shell was executed.\nOn ressource : \n" 52 + "filename = " 53 + WorkBenchHelper.getSelectedRessourceFileName() 54 + "\n" 55 + "full filename = " 56 + WorkBenchHelper.getSelectedRessourceFullFileName() 57 + "\n" 58 + "path = " 59 + WorkBenchHelper.getSelectedRessourcePath() 60 + "\n" 61 + "full path = " 62 + WorkBenchHelper.getSelectedRessourceFullPath() 63 + "\n" 64 + "extension = " 65 + WorkBenchHelper.getSelectedRessourceExtension() 66 + "\n" 67 ); 68 } 69 70 protected static IResource getRessource() { 71 Object selection = null; 72 ISelection currentSelection = 73 MainPlugin 74 .getDefault() 75 .getWorkbench() 76 .getActiveWorkbenchWindow() 77 .getSelectionService() 78 .getSelection(); 79 if ((currentSelection != null) 80 && (currentSelection instanceof IStructuredSelection)) 81 selection = 82 ((IStructuredSelection) currentSelection).getFirstElement(); 83 IResource resource = null; 84 if (selection instanceof IAdaptable) 85 resource = 86 (IResource) ((IAdaptable) selection).getAdapter( 87 IResource.class); 88 return resource; 89 } 90 91 96 public static String getSelectedRessourceFileName() { 97 return getRessource().getFullPath().lastSegment(); 98 } 99 100 105 public static String getSelectedRessourceFullFileName() { 106 return getRessource().getLocation().toOSString(); 107 } 108 109 114 public static String getSelectedRessourcePath() { 115 return getRessource().getFullPath().toOSString(); 116 } 117 118 123 public static String getSelectedRessourceFullPath() { 124 return getRessource().getLocation().removeLastSegments(1).toOSString(); 125 } 126 127 132 public static String getSelectedRessourceExtension() { 133 return getRessource().getFileExtension(); 134 } 135 136 141 public static String getSelectedRessourceProjectName() { 142 return getRessource().getProject().getName(); 143 } 144 145 146 147 } 148 | Popular Tags |