# helpers for Eclipse and resources require 'java' def workspace() include_class 'org.eclipse.core.resources.ResourcesPlugin' $res = ResourcesPlugin return $res.getWorkspace() end def create_new_scratch_view(newViewIdAsString) syncExec do # Hack: the constant "1" is the VIEW_CREATE constant in IWorkbenchPage active_page().showView("net.sf.eclipseshell.views.ScratchPadView", newViewIdAsString, 1) end end # Creates a ScratchPadView and returns the ScratchPadView object. Use the getComponent method to # access it's component and add components to it. # @param nameAsString a String as the secondaryViewId, this is needed to distinguish several instances of the View # @return object of ScratchPadView def createScratchPadView(nameAsString) create_new_scratch_view(nameAsString) retVal = nil syncExec do $refs = active_page().getViewReferences() $refs.each{|ref| id = ref.getSecondaryId if id != nil if id.include?(nameAsString) retVal = ref.getView(true) end end } end retVal end def project_by_name(projectNameString) root = workspace().root return root.getProject(projectNameString) end def workbench() include_class 'org.eclipse.ui.PlatformUI' return PlatformUI.getWorkbench().getActiveWorkbenchWindow() end def active_page() return workbench().getActivePage() end # returns the activePart in the activePage in the Workbench def active_part() return active_Page().getActivePart() end def open_editor(iFileObject) include_class 'org.eclipse.ui.ide.IDE' IDE.openEditor(workbench().activePage, iFileObject) end # Call the Display.syncExec method def syncExec(&block) include_class 'org.eclipse.swt.widgets.Display' include_class 'java.lang.Runnable' disp = Display.getDefault() # yield # setup a runnable = Runnable.new class << runnable def setBlock(bl) @block = bl end def run #IDE.openEditor(active_page(), $dginp , "DependencyGraph") @block.call(self) end end runnable.setBlock(block) disp.syncExec(runnable) end def open_file(nameAsString) syncExec do open_editor(workspace().getRoot.getFile(nameAsString)) end end def ps(*args) include_class "net.sf.eclipseshell.extensions.ExecutionEnvironmentLaunchManager" processes = ExecutionEnvironmentLaunchManager.getAllActiveExecutionEnvironments.toArray # bit of a hack: Java arrays don't seem to support collect{} retVal = [] pr = false if(args.length > 0 ) if(args[0] == :pr) pr = true end end processes.each{|pr| if(pr) retVal << pr.to_s + "\n" else retVal << pr end } retVal end $workspace = workspace() $workbench = syncExec {workbench()}