/**
* 获得当前选中的文件路径
* @return
*/
private static String getCurrentSelectionLoction(){
ISelectionService selectionService =
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
//IProject project = null;
IResource resource = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
resource= ((IResource)element).getProject();
String resourceLocation = ((IResource)element).getLocation().toString();
int isProject = resourceLocation.compareTo(resource.getLocation().toString());
if (isProject > 0) {
String FilePath = resourceLocation;
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
}
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
resource = (IResource) adaptable.getAdapter(org.eclipse.core.resources.IResource.class);
if (resource instanceof IFile) {
String FilePath = ((IFile) resource).getLocation().toString();
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
}
}
}
if (resource == null) {
return null;
}
if (resource.getLocation() != null) {
String FilePath = resource.getLocation().toString();
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
} else {
return null;
}
}
* 获得当前选中的文件路径
* @return
*/
private static String getCurrentSelectionLoction(){
ISelectionService selectionService =
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
//IProject project = null;
IResource resource = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
resource= ((IResource)element).getProject();
String resourceLocation = ((IResource)element).getLocation().toString();
int isProject = resourceLocation.compareTo(resource.getLocation().toString());
if (isProject > 0) {
String FilePath = resourceLocation;
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
}
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
resource = (IResource) adaptable.getAdapter(org.eclipse.core.resources.IResource.class);
if (resource instanceof IFile) {
String FilePath = ((IFile) resource).getLocation().toString();
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
}
}
}
if (resource == null) {
return null;
}
if (resource.getLocation() != null) {
String FilePath = resource.getLocation().toString();
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
} else {
return null;
}
}