Created
March 8, 2012 14:10
-
-
Save laurentpetit/2001151 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ^{:doc "Eclipse interop utilities"} | |
ccw.util.eclipse | |
(:require [clojure.java.io :as io]) | |
(:import [org.eclipse.core.resources IResource | |
ResourcesPlugin | |
IWorkspaceRunnable | |
IWorkspace] | |
[org.eclipse.core.runtime IPath | |
Path] | |
[org.eclipse.jdt.core IJavaProject] | |
[org.eclipse.ui.handers HandlerUtil] | |
[org.eclipse.jface.viewers StructuredSelection | |
TreeSelection])) | |
(defprotocol IResourceCoercion | |
(resource [this] "Coerce this in a IResource")) | |
(extend-protocol IResourceCoercion | |
nil | |
(resource [this] nil) | |
IResource | |
(resource [this] this) | |
IJavaProject | |
(resource [this] (project this)) | |
String | |
(resource [filesystem-path] (resource (path filesystem-path))) | |
IPath | |
(resource [filesystem-path] | |
(.getFileForLocation (workspace-root) filesystem-path)) | |
IStructuredSelection | |
(resource [selection] | |
(resource (.getFirstElement selection)))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Event Handler utilities | |
(defn current-selection [execution-event] | |
(HandlerUtil/getCurrentSelection execution-event)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment