Skip to content

Commit

Permalink
#28 Show EasyShell entry on maven dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Bossert <[email protected]>
  • Loading branch information
anb0s committed Dec 27, 2016
1 parent 1768f64 commit 367128c
Showing 1 changed file with 50 additions and 56 deletions.
106 changes: 50 additions & 56 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/ResourceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
//import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
//import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.osgi.framework.Bundle;


@SuppressWarnings("restriction")
public class ResourceUtils {

static public ISelection getResourceSelection(IWorkbenchPart part) {
Expand All @@ -49,79 +53,76 @@ static public ISelection getResourceSelection(IWorkbenchPart part) {
return selection;
}

static public Resource getResource(Object myObj) {
static public Resource getResource(Object myObj) {
Object object = null;

// handle IEditorPart
if (myObj instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart)myObj;
IEditorInput input = editorPart.getEditorInput();
Object adapter = input.getAdapter(IFile.class);
if(adapter instanceof IFile){
object = (IFile) adapter;
} else {
adapter = editorPart.getAdapter(IFile.class);
if(adapter instanceof IFile){
object = (IFile) adapter;
} else {
object = input;
}
}
if (input instanceof IFileEditorInput) {
object = ((IFileEditorInput)input).getFile();
} else {
Object adapter = input.getAdapter(IFile.class);
if(adapter instanceof IFile){
object = (IFile) adapter;
} else {
adapter = editorPart.getAdapter(IFile.class);
if(adapter instanceof IFile){
object = (IFile) adapter;
} else {
object = input;
}
}
}
} else {
object = myObj;
}

/*
IEditorInput input = activeEditorPart.getEditorInput();
if (input instanceof IFileEditorInput) {
ifile = ((IFileEditorInput)input).getFile();
} else if (input instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) input;
ifile = (IFile) adaptable.getAdapter(IFile.class);
if (ifile == null) {
if (adaptable instanceof FileStoreEditorInput) {
URI fileuri = ((FileStoreEditorInput) adaptable).getURI();
file = new File(fileuri.getPath());
} else {
file = (File) adaptable.getAdapter(File.class);
}
}
}
*/

// the most input types first
if (object instanceof Resource) {
return new Resource((Resource)object);
}

if (object instanceof IFile) {
return new Resource(((IFile) object));
}
if (object instanceof File) {
return new Resource((File) object);
}

// still adaptable
if (object instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) object;
// IFile
IFile iFile = (IFile) adaptable.getAdapter(IFile.class);
if (iFile != null) {
return new Resource(iFile);
}
// IResource
IResource ires = (IResource) adaptable.getAdapter(IResource.class);
if (ires != null) {
IPath path = ires.getLocation();
if (path != null) {
return new Resource(ires);
}
}
/*
if (adaptable instanceof PackageFragment
&& ((PackageFragment) adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot) {
return new Resource(getJarFile(((PackageFragment) adaptable)
.getPackageFragmentRoot()),projectName);
} else if (adaptable instanceof JarPackageFragmentRoot) {
return new Resource(getJarFile(adaptable),projectName);
}*/
else if (adaptable instanceof FileStoreEditorInput) {
// FileStoreEditorInput
if (adaptable instanceof FileStoreEditorInput) {
URI fileuri = ((FileStoreEditorInput) adaptable).getURI();
return new Resource(new File(fileuri.getPath()));
}
// optional org.eclipse.jdt.core
Bundle bundle = Platform.getBundle("org.eclipse.jdt.core");
if (bundle != null) {
if ( (adaptable instanceof PackageFragment) &&
( ((PackageFragment) adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot) ) {
return new Resource(getJarFile(((PackageFragment) adaptable)
.getPackageFragmentRoot()));
} else if (adaptable instanceof JarPackageFragmentRoot) {
return new Resource(getJarFile(adaptable));
}
}
// File
File file = (File) adaptable.getAdapter(File.class);
if (file != null) {
return new Resource(file);
Expand All @@ -130,21 +131,14 @@ else if (adaptable instanceof FileStoreEditorInput) {
return null;
}

/*
static public File getJarFile(IAdaptable adaptable) {
static private File getJarFile(IAdaptable adaptable) {
JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot) adaptable;
File resource = (File) jpfr.getPath().makeAbsolute().toFile();
if (!((File) resource).exists()) {
File projectFile =
new File(
jpfr
.getJavaProject()
.getProject()
.getLocation()
.toOSString());
resource = new File(projectFile.getParent() + resource.toString());
File file = (File)jpfr.getPath().makeAbsolute().toFile();
if (!((File)file).exists()) {
File projectFile = new File(jpfr.getJavaProject().getProject().getLocation().toOSString());
file = new File(projectFile.getParent() + file.toString());
}
return resource;
return file;
}
*/

}

0 comments on commit 367128c

Please sign in to comment.