Skip to content

Instantly share code, notes, and snippets.

@laurentpetit
Created March 8, 2012 14:10
Show Gist options
  • Save laurentpetit/2001151 to your computer and use it in GitHub Desktop.
Save laurentpetit/2001151 to your computer and use it in GitHub Desktop.
(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