|
From: <caw...@us...> - 2007-09-14 16:09:50
|
Revision: 3182
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3182&view=rev
Author: cawilliams
Date: 2007-09-14 09:09:49 -0700 (Fri, 14 Sep 2007)
Log Message:
-----------
finally! fix #4947 - [Mac OS X | 0.2.8.15171] Debug As Ruby Application menu doesn't appear.
Now Run As and Debug As should appear in right-click context menu in Ruby Explorer!
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementAdapterFactory.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyElementResourceMapping.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IResourceLocator.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/PersistableRubyElementFactory.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/ResourceLocator.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementContainmentAdapter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementProperties.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyWorkbenchAdapter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyModelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyResourceMapping.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchPageScoreComputer.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-09-14 15:25:10 UTC (rev 3181)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-09-14 16:09:49 UTC (rev 3182)
@@ -1359,6 +1359,26 @@
<extension point="org.eclipse.core.runtime.adapters">
<factory
+ class="org.rubypeople.rdt.internal.ui.RubyElementAdapterFactory"
+ adaptableType="org.rubypeople.rdt.core.IRubyElement">
+
+ <adapter type="org.eclipse.core.resources.IResource"/>
+
+ <adapter type="org.eclipse.ui.IPersistableElement"/>
+ <adapter type="org.eclipse.ui.IContributorResourceAdapter"/>
+ <adapter type="org.eclipse.ui.ide.IContributorResourceAdapter2"/>
+ <adapter type="org.eclipse.ui.IContainmentAdapter"/>
+
+ <adapter type="org.eclipse.search.ui.ISearchPageScoreComputer"/>
+
+ <adapter type="org.eclipse.ui.model.IWorkbenchAdapter"/>
+ <adapter type="org.eclipse.ui.views.properties.IPropertySource"/>
+ <adapter type="org.eclipse.ui.views.tasklist.ITaskListResourceAdapter"/>
+
+ <adapter type="org.rubypeople.rdt.internal.ui.IResourceLocator"/>
+ </factory>
+
+ <factory
class="org.rubypeople.rdt.internal.ui.RubyProjectAdapterFactory"
adaptableType="org.rubypeople.rdt.core.IRubyProject">
<adapter type="org.eclipse.core.resources.IProject"/>
@@ -1369,16 +1389,6 @@
adaptableType="org.eclipse.core.resources.IResource">
<adapter type="org.rubypeople.rdt.core.IRubyElement"/>
</factory>
-
- <factory
- class="org.rubypeople.rdt.internal.ui.RubyElementAdapterFactory"
- adaptableType="org.rubypeople.rdt.core.IRubyElement">
-
- <adapter type="org.eclipse.core.resources.IResource"/>
- <adapter type="org.eclipse.ui.IContributorResourceAdapter"/>
-
- <adapter type="org.eclipse.ui.views.tasklist.ITaskListResourceAdapter"/>
- </factory>
</extension>
<extension
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyElementResourceMapping.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyElementResourceMapping.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyElementResourceMapping.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,352 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.util;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.mapping.RemoteResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.resources.mapping.ResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.model.RubyModelProvider;
+
+/**
+ * An abstract super class to describe mappings from a Ruby element to a
+ * set of resources. The class also provides factory methods to create
+ * resource mappings.
+ *
+ * @since 3.1
+ */
+public abstract class RubyElementResourceMapping extends ResourceMapping {
+
+ protected RubyElementResourceMapping() {
+ }
+
+ public IRubyElement getRubyElement() {
+ Object o= getModelObject();
+ if (o instanceof IRubyElement)
+ return (IRubyElement)o;
+ return null;
+ }
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof RubyElementResourceMapping))
+ return false;
+ return getRubyElement().equals(((RubyElementResourceMapping)obj).getRubyElement());
+ }
+
+ public int hashCode() {
+ IRubyElement javaElement= getRubyElement();
+ if (javaElement == null)
+ return super.hashCode();
+
+ return javaElement.hashCode();
+ }
+
+ public String getModelProviderId() {
+ return RubyModelProvider.RUBY_MODEL_PROVIDER_ID;
+ }
+
+ public boolean contains(ResourceMapping mapping) {
+ if (mapping instanceof RubyElementResourceMapping) {
+ RubyElementResourceMapping javaMapping = (RubyElementResourceMapping) mapping;
+ IRubyElement element = getRubyElement();
+ IRubyElement other = javaMapping.getRubyElement();
+ if (other != null && element != null)
+ return element.getPath().isPrefixOf(other.getPath());
+ }
+ return false;
+ }
+
+ //---- the factory code ---------------------------------------------------------------
+
+ private static final class RubyModelResourceMapping extends RubyElementResourceMapping {
+ private final IRubyModel fRubyModel;
+ private RubyModelResourceMapping(IRubyModel model) {
+ Assert.isNotNull(model);
+ fRubyModel= model;
+ }
+ public Object getModelObject() {
+ return fRubyModel;
+ }
+ public IProject[] getProjects() {
+ IRubyProject[] projects= null;
+ try {
+ projects= fRubyModel.getRubyProjects();
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ return new IProject[0];
+ }
+ IProject[] result= new IProject[projects.length];
+ for (int i= 0; i < projects.length; i++) {
+ result[i]= projects[i].getProject();
+ }
+ return result;
+ }
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ IRubyProject[] projects= fRubyModel.getRubyProjects();
+ ResourceTraversal[] result= new ResourceTraversal[projects.length];
+ for (int i= 0; i < projects.length; i++) {
+ result[i]= new ResourceTraversal(new IResource[] {projects[i].getProject()}, IResource.DEPTH_INFINITE, 0);
+ }
+ return result;
+ }
+ }
+
+ private static final class RubyProjectResourceMapping extends RubyElementResourceMapping {
+ private final IRubyProject fProject;
+ private RubyProjectResourceMapping(IRubyProject project) {
+ Assert.isNotNull(project);
+ fProject= project;
+ }
+ public Object getModelObject() {
+ return fProject;
+ }
+ public IProject[] getProjects() {
+ return new IProject[] {fProject.getProject() };
+ }
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ return new ResourceTraversal[] {
+ new ResourceTraversal(new IResource[] {fProject.getProject()}, IResource.DEPTH_INFINITE, 0)
+ };
+ }
+ }
+
+ private static final class PackageFragementRootResourceMapping extends RubyElementResourceMapping {
+ private final ISourceFolderRoot fRoot;
+ private PackageFragementRootResourceMapping(ISourceFolderRoot root) {
+ Assert.isNotNull(root);
+ fRoot= root;
+ }
+ public Object getModelObject() {
+ return fRoot;
+ }
+ public IProject[] getProjects() {
+ return new IProject[] {fRoot.getRubyProject().getProject() };
+ }
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ return new ResourceTraversal[] {
+ new ResourceTraversal(new IResource[] {fRoot.getResource()}, IResource.DEPTH_INFINITE, 0)
+ };
+ }
+ }
+
+ private static final class LocalPackageFragementTraversal extends ResourceTraversal {
+ private final ISourceFolder fPack;
+ public LocalPackageFragementTraversal(ISourceFolder pack) throws CoreException {
+ super(new IResource[] {pack.getResource()}, IResource.DEPTH_ONE, 0);
+ fPack= pack;
+ }
+ public void accept(IResourceVisitor visitor) throws CoreException {
+ IFile[] files= getPackageContent(fPack);
+ final IResource resource= fPack.getResource();
+ if (resource != null)
+ visitor.visit(resource);
+ for (int i= 0; i < files.length; i++) {
+ visitor.visit(files[i]);
+ }
+ }
+ }
+
+ private static final class SourceFolderResourceMapping extends RubyElementResourceMapping {
+ private final ISourceFolder fPack;
+ private SourceFolderResourceMapping(ISourceFolder pack) {
+ Assert.isNotNull(pack);
+ fPack= pack;
+ }
+ public Object getModelObject() {
+ return fPack;
+ }
+ public IProject[] getProjects() {
+ return new IProject[] { fPack.getRubyProject().getProject() };
+ }
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ if (context instanceof RemoteResourceMappingContext) {
+ return new ResourceTraversal[] {
+ new ResourceTraversal(new IResource[] {fPack.getResource()}, IResource.DEPTH_ONE, 0)
+ };
+ } else {
+ return new ResourceTraversal[] { new LocalPackageFragementTraversal(fPack) };
+ }
+ }
+ public void accept(ResourceMappingContext context, IResourceVisitor visitor, IProgressMonitor monitor) throws CoreException {
+ if (context instanceof RemoteResourceMappingContext) {
+ super.accept(context, visitor, monitor);
+ } else {
+ // We assume a local context.
+ IFile[] files= getPackageContent(fPack);
+ if (monitor == null)
+ monitor= new NullProgressMonitor();
+ monitor.beginTask("", files.length + 1); //$NON-NLS-1$
+ final IResource resource= fPack.getResource();
+ if (resource != null)
+ visitor.visit(resource);
+ monitor.worked(1);
+ for (int i= 0; i < files.length; i++) {
+ visitor.visit(files[i]);
+ monitor.worked(1);
+ }
+ }
+ }
+ }
+
+ private static IFile[] getPackageContent(ISourceFolder pack) throws CoreException {
+ List result= new ArrayList();
+ IContainer container= (IContainer)pack.getResource();
+ if (container != null) {
+ IResource[] members= container.members();
+ for (int m= 0; m < members.length; m++) {
+ IResource member= members[m];
+ if (member instanceof IFile) {
+ IFile file= (IFile)member;
+ if ("class".equals(file.getFileExtension()) && file.isDerived()) //$NON-NLS-1$
+ continue;
+ result.add(member);
+ }
+ }
+ }
+ return (IFile[])result.toArray(new IFile[result.size()]);
+ }
+
+
+ private static final class RubyScriptResourceMapping extends RubyElementResourceMapping {
+ private final IRubyScript fUnit;
+ private RubyScriptResourceMapping(IRubyScript unit) {
+ Assert.isNotNull(unit);
+ fUnit= unit;
+ }
+ public Object getModelObject() {
+ return fUnit;
+ }
+ public IProject[] getProjects() {
+ return new IProject[] {fUnit.getRubyProject().getProject() };
+ }
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ return new ResourceTraversal[] {
+ new ResourceTraversal(new IResource[] {fUnit.getResource()}, IResource.DEPTH_ONE, 0)
+ };
+ }
+ }
+
+ private static final class LogicalPackageResourceMapping extends ResourceMapping {
+ private final ISourceFolder[] fFragments;
+ private LogicalPackageResourceMapping(ISourceFolder[] fragments) {
+ fFragments= fragments;
+ }
+ public Object getModelObject() {
+ return fFragments;
+ }
+ public IProject[] getProjects() {
+ Set result= new HashSet();
+ for (int i= 0; i < fFragments.length; i++) {
+ result.add(fFragments[i].getRubyProject().getProject());
+ }
+ return (IProject[])result.toArray(new IProject[result.size()]);
+ }
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ List result= new ArrayList();
+ if (context instanceof RemoteResourceMappingContext) {
+ for (int i= 0; i < fFragments.length; i++) {
+ result.add(new ResourceTraversal(
+ new IResource[] {fFragments[i].getResource()}, IResource.DEPTH_ONE, 0));
+ }
+ } else {
+ for (int i= 0; i < fFragments.length; i++) {
+ result.add(new LocalPackageFragementTraversal(fFragments[i]));
+ }
+ }
+ return (ResourceTraversal[])result.toArray(new ResourceTraversal[result.size()]);
+ }
+
+ public String getModelProviderId() {
+ return RubyModelProvider.RUBY_MODEL_PROVIDER_ID;
+ }
+ }
+
+ public static ResourceMapping create(IRubyElement element) {
+ switch (element.getElementType()) {
+ case IRubyElement.TYPE:
+ return create((IType)element);
+ case IRubyElement.SCRIPT:
+ return create((IRubyScript)element);
+ case IRubyElement.SOURCE_FOLDER:
+ return create((ISourceFolder)element);
+ case IRubyElement.SOURCE_FOLDER_ROOT:
+ return create((ISourceFolderRoot)element);
+ case IRubyElement.RUBY_PROJECT:
+ return create((IRubyProject)element);
+ case IRubyElement.RUBY_MODEL:
+ return create((IRubyModel)element);
+ default:
+ return null;
+ }
+
+ }
+
+ public static ResourceMapping create(final IRubyModel model) {
+ return new RubyModelResourceMapping(model);
+ }
+
+ public static ResourceMapping create(final IRubyProject project) {
+ return new RubyProjectResourceMapping(project);
+ }
+
+ public static ResourceMapping create(final ISourceFolderRoot root) {
+ if (root.isExternal())
+ return null;
+ return new PackageFragementRootResourceMapping(root);
+ }
+
+ public static ResourceMapping create(final ISourceFolder pack) {
+ // test if in an archive
+ ISourceFolderRoot root= (ISourceFolderRoot)pack.getAncestor(IRubyElement.SOURCE_FOLDER_ROOT);
+ if (!root.isExternal()) {
+ return new SourceFolderResourceMapping(pack);
+ }
+ return null;
+ }
+
+ public static ResourceMapping create(IRubyScript unit) {
+ if (unit == null)
+ return null;
+ return new RubyScriptResourceMapping(unit.getPrimary());
+ }
+
+ public static ResourceMapping create(IType type) {
+ // top level types behave like the CU
+ IRubyElement parent= type.getParent();
+ if (parent instanceof IRubyScript) {
+ return create((IRubyScript)parent);
+ }
+ return null;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyElementResourceMapping.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IResourceLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IResourceLocator.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IResourceLocator.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.rubypeople.rdt.core.RubyModelException;
+
+/**
+ * This interface allows to locate different
+ * resources which are related to an object
+ */
+public interface IResourceLocator {
+ /**
+ * Returns the underlying finest granularity resource that contains
+ * the element, or <code>null</code> if the element is not contained
+ * in a resource (for example, a working copy, or an element contained
+ * in an external archive).
+ *
+ * @param element the element for which the resource is located
+ * @return the underlying resource
+ * @exception RubyModelException if the element does not exist or if an
+ * exception occurs while accessing its underlying resource
+ * @see org.eclipse.jdt.core.IRubyElement#getUnderlyingResource()
+ */
+ IResource getUnderlyingResource(Object element) throws RubyModelException;
+ /**
+ * Returns the resource that corresponds directly to the element,
+ * or <code>null</code> if there is no resource that corresponds to
+ * the element.
+ *
+ * <p>For example, the corresponding resource for an <code>ICompilationUnit</code>
+ * is its underlying <code>IFile</code>. The corresponding resource for
+ * an <code>IPackageFragment</code> that is not contained in an archive
+ * is its underlying <code>IFolder</code>. An <code>IPackageFragment</code>
+ * contained in an archive has no corresponding resource. Similarly, there
+ * are no corresponding resources for <code>IMethods</code>,
+ * <code>IFields</code>, etc.
+ *
+ * @param element the element for which the resource is located
+ * @return the corresponding resource
+ * @exception RubyModelException if the element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ * @see org.eclipse.jdt.core.IRubyElement#getCorrespondingResource()
+ */
+ IResource getCorrespondingResource(Object element) throws RubyModelException;
+ /**
+ * Returns the resource that contains the element. If the element is not
+ * directly contained by a resource then a helper resource or <code>null</code>
+ * is returned. Clients define the helper resource as needed.
+ *
+ * @param element the element for which the resource is located
+ * @return the containing resource
+ * @exception RubyModelException if the element does not exist or if an
+ * exception occurs while accessing its containing resource
+ */
+ IResource getContainingResource(Object element) throws RubyModelException;
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IResourceLocator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/PersistableRubyElementFactory.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/PersistableRubyElementFactory.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/PersistableRubyElementFactory.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyCore;
+
+/**
+ * The RubyElementFactory is used to save and recreate an IRubyElement object.
+ * As such, it implements the IPersistableElement interface for storage
+ * and the IElementFactory interface for recreation.
+ *
+ * @see IMemento
+ * @see IPersistableElement
+ * @see IElementFactory
+ */
+public class PersistableRubyElementFactory implements IElementFactory, IPersistableElement {
+
+ private static final String KEY= "elementID"; //$NON-NLS-1$
+ private static final String FACTORY_ID= "org.rubypeople.rdt.ui.PersistableRubyElementFactory"; //$NON-NLS-1$
+
+ private IRubyElement fElement;
+
+ /**
+ * Create a RubyElementFactory.
+ */
+ public PersistableRubyElementFactory() {
+ }
+
+ /**
+ * Create a RubyElementFactory. This constructor is typically used
+ * for our IPersistableElement side.
+ */
+ public PersistableRubyElementFactory(IRubyElement element) {
+ fElement= element;
+ }
+
+ /*
+ * @see IElementFactory
+ */
+ public IAdaptable createElement(IMemento memento) {
+
+ String identifier= memento.getString(KEY);
+ if (identifier != null) {
+ return RubyCore.create(identifier);
+ }
+ return null;
+ }
+
+ /*
+ * @see IPersistableElement.
+ */
+ public String getFactoryId() {
+ return FACTORY_ID;
+ }
+ /*
+ * @see IPersistableElement
+ */
+ public void saveState(IMemento memento) {
+ memento.putString(KEY, fElement.getHandleIdentifier());
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/PersistableRubyElementFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/ResourceLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/ResourceLocator.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/ResourceLocator.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyModelException;
+
+/**
+ * This class locates different resources
+ * which are related to an object
+ */
+public class ResourceLocator implements IResourceLocator {
+
+ public IResource getUnderlyingResource(Object element) throws RubyModelException {
+ if (element instanceof IRubyElement)
+ return ((IRubyElement) element).getUnderlyingResource();
+ else
+ return null;
+ }
+
+ public IResource getCorrespondingResource(Object element) throws RubyModelException {
+ if (element instanceof IRubyElement)
+ return ((IRubyElement) element).getCorrespondingResource();
+ else
+ return null;
+ }
+
+ public IResource getContainingResource(Object element) throws RubyModelException {
+ IResource resource= null;
+ if (element instanceof IResource)
+ resource= (IResource) element;
+ if (element instanceof IRubyElement) {
+ resource= ((IRubyElement) element).getResource();
+ if (resource == null)
+ resource= ((IRubyElement) element).getRubyProject().getProject();
+ }
+ return resource;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/ResourceLocator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementAdapterFactory.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementAdapterFactory.java 2007-09-14 15:25:10 UTC (rev 3181)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementAdapterFactory.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -1,96 +1,206 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.rubypeople.rdt.internal.ui;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+import org.eclipse.ui.IContainmentAdapter;
import org.eclipse.ui.IContributorResourceAdapter;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.ide.IContributorResourceAdapter2;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+import org.eclipse.ui.views.properties.FilePropertySource;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.ResourcePropertySource;
import org.eclipse.ui.views.tasklist.ITaskListResourceAdapter;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
-import org.rubypeople.rdt.core.ISourceFolder;
import org.rubypeople.rdt.core.ISourceFolderRoot;
-import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
+import org.rubypeople.rdt.internal.corext.util.RubyElementResourceMapping;
+import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptEditorInput;
+import org.rubypeople.rdt.internal.ui.search.RubySearchPageScoreComputer;
+import org.rubypeople.rdt.internal.ui.search.SearchUtil;
/**
- * Implements basic UI support for Ruby elements. Implements handle to
- * persistent support for Ruby elements.
+ * Implements basic UI support for Ruby elements.
+ * Implements handle to persistent support for Ruby elements.
*/
-public class RubyElementAdapterFactory implements IAdapterFactory, IContributorResourceAdapter{
-
- private static Class[] PROPERTIES = new Class[] { IResource.class, IContributorResourceAdapter.class, ITaskListResourceAdapter.class};
-
+public class RubyElementAdapterFactory implements IAdapterFactory, IContributorResourceAdapter, IContributorResourceAdapter2 {
+
+ private static Class[] PROPERTIES= new Class[] {
+ IPropertySource.class,
+ IResource.class,
+ IWorkbenchAdapter.class,
+ IResourceLocator.class,
+ IPersistableElement.class,
+ IContributorResourceAdapter.class,
+ IContributorResourceAdapter2.class,
+ ITaskListResourceAdapter.class,
+ IContainmentAdapter.class
+ };
+
+ /*
+ * Do not use real type since this would cause
+ * the Search plug-in to be loaded.
+ */
+ private Object fSearchPageScoreComputer;
+ private static IResourceLocator fgResourceLocator;
+ private static RubyWorkbenchAdapter fgRubyWorkbenchAdapter;
private static ITaskListResourceAdapter fgTaskListAdapter;
-
+ private static RubyElementContainmentAdapter fgRubyElementContainmentAdapter;
+
public Class[] getAdapterList() {
+ updateLazyLoadedAdapters();
return PROPERTIES;
}
-
+
public Object getAdapter(Object element, Class key) {
- IRubyElement ruby = getRubyElement(element);
-
- if (IResource.class.equals(key)) { return getResource(ruby); }
- if (IContributorResourceAdapter.class.equals(key)) { return this; }
- if (ITaskListResourceAdapter.class.equals(key)) { return getTaskListAdapter(); }
- return null;
+ updateLazyLoadedAdapters();
+ IRubyElement java= getRubyElement(element);
+
+ if (IPropertySource.class.equals(key)) {
+ return getProperties(java);
+ } if (IResource.class.equals(key)) {
+ return getResource(java);
+ } if (fSearchPageScoreComputer != null && ISearchPageScoreComputer.class.equals(key)) {
+ return fSearchPageScoreComputer;
+ } if (IWorkbenchAdapter.class.equals(key)) {
+ return getRubyWorkbenchAdapter();
+ } if (IResourceLocator.class.equals(key)) {
+ return getResourceLocator();
+ } if (IPersistableElement.class.equals(key)) {
+ return new PersistableRubyElementFactory(java);
+ } if (IContributorResourceAdapter.class.equals(key)) {
+ return this;
+ } if (IContributorResourceAdapter2.class.equals(key)) {
+ return this;
+ } if (ITaskListResourceAdapter.class.equals(key)) {
+ return getTaskListAdapter();
+ } if (IContainmentAdapter.class.equals(key)) {
+ return getRubyElementContainmentAdapter();
+ }
+ return null;
}
-
+
private IResource getResource(IRubyElement element) {
- // can't use IRubyElement.getResource directly as we are interrested in
- // the
+ // can't use IRubyElement.getResource directly as we are interested in the
// corresponding resource
switch (element.getElementType()) {
- case IRubyElement.TYPE:
- // top level types behave like the ruby script
- IRubyElement parent = element.getParent();
- if (parent instanceof IRubyScript) { return RubyModelUtil.toOriginal((IRubyScript) parent).getResource(); }
- return null;
- case IRubyElement.SCRIPT:
- return RubyModelUtil.toOriginal((IRubyScript) element).getResource();
- case IRubyElement.SOURCE_FOLDER:
- ISourceFolder folder = (ISourceFolder) element;
- ISourceFolderRoot root= (ISourceFolderRoot) element.getAncestor(IRubyElement.SOURCE_FOLDER_ROOT);
- if (!root.isExternal()) {
+ case IRubyElement.TYPE:
+ // top level types behave like the CU
+ IRubyElement parent= element.getParent();
+ if (parent instanceof IRubyScript) {
+ return ((IRubyScript) parent).getPrimary().getResource();
+ }
+ return null;
+ case IRubyElement.SCRIPT:
+ return ((IRubyScript) element).getPrimary().getResource();
+ case IRubyElement.SOURCE_FOLDER:
+ // test if external
+ ISourceFolderRoot root= (ISourceFolderRoot) element.getAncestor(IRubyElement.SOURCE_FOLDER_ROOT);
+ if (!root.isExternal()) {
+ return element.getResource();
+ }
+ return null;
+ case IRubyElement.SOURCE_FOLDER_ROOT:
+ case IRubyElement.RUBY_PROJECT:
+ case IRubyElement.RUBY_MODEL:
return element.getResource();
- }
- return null;
- case IRubyElement.SOURCE_FOLDER_ROOT:
- root = (ISourceFolderRoot) element;
- if (root.isExternal()) {
+ default:
return null;
- }
- return root.getResource();
- case IRubyElement.RUBY_PROJECT:
- case IRubyElement.RUBY_MODEL:
- return element.getResource();
- default:
- return null;
- }
- }
+ }
+ }
- public IResource getAdaptedResource(IAdaptable adaptable) {
- IRubyElement je = getRubyElement(adaptable);
- if (je != null) return getResource(je);
+ public IResource getAdaptedResource(IAdaptable adaptable) {
+ IRubyElement je= getRubyElement(adaptable);
+ if (je != null)
+ return getResource(je);
- return null;
- }
+ return null;
+ }
+
+ public ResourceMapping getAdaptedResourceMapping(IAdaptable adaptable) {
+ IRubyElement je= getRubyElement(adaptable);
+ if (je != null)
+ return RubyElementResourceMapping.create(je);
+ return null;
+ }
+
private IRubyElement getRubyElement(Object element) {
- if (element instanceof IRubyElement) return (IRubyElement) element;
+ if (element instanceof IRubyElement)
+ return (IRubyElement)element;
+ if (element instanceof IRubyScriptEditorInput)
+ return ((IRubyScriptEditorInput)element).getRubyScript().getPrimaryElement();
+
return null;
}
+
+ private IPropertySource getProperties(IRubyElement element) {
+ IResource resource= getResource(element);
+ if (resource == null)
+ return new RubyElementProperties(element);
+ if (resource.getType() == IResource.FILE)
+ return new FilePropertySource((IFile) resource);
+ return new ResourcePropertySource(resource);
+ }
+ private void updateLazyLoadedAdapters() {
+ if (fSearchPageScoreComputer == null && SearchUtil.isSearchPlugInActivated())
+ createSearchPageScoreComputer();
+ }
+
+ private void createSearchPageScoreComputer() {
+ fSearchPageScoreComputer= new RubySearchPageScoreComputer();
+ PROPERTIES= new Class[] {
+ IPropertySource.class,
+ IResource.class,
+ ISearchPageScoreComputer.class,
+ IWorkbenchAdapter.class,
+ IResourceLocator.class,
+ IPersistableElement.class,
+ IProject.class,
+ IContributorResourceAdapter.class,
+ IContributorResourceAdapter2.class,
+ ITaskListResourceAdapter.class,
+ IContainmentAdapter.class
+ };
+ }
+
+ private static IResourceLocator getResourceLocator() {
+ if (fgResourceLocator == null)
+ fgResourceLocator= new ResourceLocator();
+ return fgResourceLocator;
+ }
+
+ private static RubyWorkbenchAdapter getRubyWorkbenchAdapter() {
+ if (fgRubyWorkbenchAdapter == null)
+ fgRubyWorkbenchAdapter= new RubyWorkbenchAdapter();
+ return fgRubyWorkbenchAdapter;
+ }
+
private static ITaskListResourceAdapter getTaskListAdapter() {
- if (fgTaskListAdapter == null) fgTaskListAdapter = new RubyTaskListAdapter();
+ if (fgTaskListAdapter == null)
+ fgTaskListAdapter= new RubyTaskListAdapter();
return fgTaskListAdapter;
}
+
+ private static RubyElementContainmentAdapter getRubyElementContainmentAdapter() {
+ if (fgRubyElementContainmentAdapter == null)
+ fgRubyElementContainmentAdapter= new RubyElementContainmentAdapter();
+ return fgRubyElementContainmentAdapter;
+ }
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementContainmentAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementContainmentAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementContainmentAdapter.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IContainmentAdapter;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.RubyCore;
+
+public class RubyElementContainmentAdapter implements IContainmentAdapter {
+
+ private IRubyModel fRubyModel= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+
+ public boolean contains(Object workingSetElement, Object element, int flags) {
+ if (!(workingSetElement instanceof IRubyElement) || element == null)
+ return false;
+
+ IRubyElement workingSetRubyElement= (IRubyElement)workingSetElement;
+ IResource resource= null;
+ IRubyElement jElement= null;
+ if (element instanceof IRubyElement) {
+ jElement= (IRubyElement)element;
+ resource= jElement.getResource();
+ } else {
+ if (element instanceof IAdaptable) {
+ resource= (IResource)((IAdaptable)element).getAdapter(IResource.class);
+ if (resource != null) {
+ if (fRubyModel.contains(resource)) {
+ jElement= RubyCore.create(resource);
+ if (jElement != null && !jElement.exists())
+ jElement= null;
+ }
+ }
+ }
+ }
+
+ if (jElement != null) {
+ if (contains(workingSetRubyElement, jElement, flags))
+ return true;
+ if (workingSetRubyElement.getElementType() == IRubyElement.SOURCE_FOLDER &&
+ resource.getType() == IResource.FOLDER && checkIfDescendant(flags))
+ return isChild(workingSetRubyElement, resource);
+ } else if (resource != null) {
+ return contains(workingSetRubyElement, resource, flags);
+ }
+ return false;
+ }
+
+ private boolean contains(IRubyElement workingSetElement, IRubyElement element, int flags) {
+ if (checkContext(flags) && workingSetElement.equals(element)) {
+ return true;
+ }
+ if (checkIfChild(flags) && workingSetElement.equals(element.getParent())) {
+ return true;
+ }
+ if (checkIfDescendant(flags) && check(workingSetElement, element)) {
+ return true;
+ }
+ if (checkIfAncestor(flags) && check(element, workingSetElement)) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean check(IRubyElement ancestor, IRubyElement descendent) {
+ descendent= descendent.getParent();
+ while (descendent != null) {
+ if (ancestor.equals(descendent))
+ return true;
+ descendent= descendent.getParent();
+ }
+ return false;
+ }
+
+ private boolean isChild(IRubyElement workingSetElement, IResource element) {
+ IResource resource= workingSetElement.getResource();
+ if (resource == null)
+ return false;
+ return check(element, resource);
+ }
+
+ private boolean contains(IRubyElement workingSetElement, IResource element, int flags) {
+ IResource workingSetResource= workingSetElement.getResource();
+ if (workingSetResource == null)
+ return false;
+ if (checkContext(flags) && workingSetResource.equals(element)) {
+ return true;
+ }
+ if (checkIfChild(flags) && workingSetResource.equals(element.getParent())) {
+ return true;
+ }
+ if (checkIfDescendant(flags) && check(workingSetResource, element)) {
+ return true;
+ }
+ if (checkIfAncestor(flags) && check(element, workingSetResource)) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean check(IResource ancestor, IResource descendent) {
+ descendent= descendent.getParent();
+ while(descendent != null) {
+ if (ancestor.equals(descendent))
+ return true;
+ descendent= descendent.getParent();
+ }
+ return false;
+ }
+
+ private boolean checkIfDescendant(int flags) {
+ return (flags & CHECK_IF_DESCENDANT) != 0;
+ }
+
+ private boolean checkIfAncestor(int flags) {
+ return (flags & CHECK_IF_ANCESTOR) != 0;
+ }
+
+ private boolean checkIfChild(int flags) {
+ return (flags & CHECK_IF_CHILD) != 0;
+ }
+
+ private boolean checkContext(int flags) {
+ return (flags & CHECK_CONTEXT) != 0;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementContainmentAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementProperties.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementProperties.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementProperties.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.ui;
+
+
+import org.eclipse.jface.viewers.IBasicPropertyConstants;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+import org.rubypeople.rdt.core.IRubyElement;
+
+public class RubyElementProperties implements IPropertySource {
+
+ private IRubyElement fSource;
+
+ // Property Descriptors
+ private static final IPropertyDescriptor[] fgPropertyDescriptors= new IPropertyDescriptor[1];
+ static {
+ PropertyDescriptor descriptor;
+
+ // resource name
+ descriptor= new PropertyDescriptor(IBasicPropertyConstants.P_TEXT, RubyUIMessages.RubyElementProperties_name);
+ descriptor.setAlwaysIncompatible(true);
+ fgPropertyDescriptors[0]= descriptor;
+ }
+
+ public RubyElementProperties(IRubyElement source) {
+ fSource= source;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ return fgPropertyDescriptors;
+ }
+
+ public Object getPropertyValue(Object name) {
+ if (name.equals(IBasicPropertyConstants.P_TEXT)) {
+ return fSource.getElementName();
+ }
+ return null;
+ }
+
+ public void setPropertyValue(Object name, Object value) {
+ }
+
+ public Object getEditableValue() {
+ return this;
+ }
+
+ public boolean isPropertySet(Object property) {
+ return false;
+ }
+
+ public void resetPropertyValue(Object property) {
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyElementProperties.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2007-09-14 15:25:10 UTC (rev 3181)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -107,6 +107,7 @@
public static String Spelling_ignore_label;
public static String RubyPlugin_initializing_ui;
public static String InitializeAfterLoadJob_starter_job_name;
+ public static String RubyElementProperties_name;
private RubyUIMessages() {
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties 2007-09-14 15:25:10 UTC (rev 3181)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties 2007-09-14 16:09:49 UTC (rev 3182)
@@ -3,6 +3,8 @@
# All Rights Reserved.
#########################################
+RubyElementProperties_name=Name
+
InitializeAfterLoadJob_starter_job_name=Starting Ruby Tooling initialization
RubyPlugin_initializing_ui=Initializing Ruby Tooling
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyWorkbenchAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyWorkbenchAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyWorkbenchAdapter.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui;
+
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+import org.rubypeople.rdt.core.IParent;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptEditorInput;
+import org.rubypeople.rdt.internal.ui.viewsupport.RubyElementImageProvider;
+import org.rubypeople.rdt.ui.RubyElementLabels;
+
+/**
+ * An imlementation of the IWorkbenchAdapter for IRubyElements.
+ */
+public class RubyWorkbenchAdapter implements IWorkbenchAdapter {
+
+ protected static final Object[] NO_CHILDREN= new Object[0];
+
+ private RubyElementImageProvider fImageProvider;
+
+ public RubyWorkbenchAdapter() {
+ fImageProvider= new RubyElementImageProvider();
+ }
+
+ public Object[] getChildren(Object element) {
+ IRubyElement je= getRubyElement(element);
+ if (je instanceof IParent) {
+ try {
+ return ((IParent)je).getChildren();
+ } catch(RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+ }
+ return NO_CHILDREN;
+ }
+
+ public ImageDescriptor getImageDescriptor(Object element) {
+ IRubyElement je= getRubyElement(element);
+ if (je != null)
+ return fImageProvider.getRubyImageDescriptor(je, RubyElementImageProvider.OVERLAY_ICONS | RubyElementImageProvider.SMALL_ICONS);
+
+ return null;
+
+ }
+
+ public String getLabel(Object element) {
+ return RubyElementLabels.getTextLabel(getRubyElement(element), RubyElementLabels.ALL_DEFAULT);
+ }
+
+ public Object getParent(Object element) {
+ IRubyElement je= getRubyElement(element);
+ return je != null ? je.getParent() : null;
+ }
+
+ private IRubyElement getRubyElement(Object element) {
+ if (element instanceof IRubyElement)
+ return (IRubyElement)element;
+ if (element instanceof IRubyScriptEditorInput)
+ return ((IRubyScriptEditorInput)element).getRubyScript().getPrimaryElement();
+
+ return null;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyWorkbenchAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyModelProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyModelProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyModelProvider.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.model;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ModelProvider;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.resources.mapping.ResourceMappingContext;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.corext.util.RubyElementResourceMapping;
+
+/**
+ * Ruby-aware model provider.
+ *
+ * @since 3.2
+ */
+public final class RubyModelProvider extends ModelProvider {
+
+ /** The model provider id */
+ public static final String RUBY_MODEL_PROVIDER_ID= "org.rubypeople.rdt.ui.modelProvider"; //$NON-NLS-1$
+
+ /**
+ * Returns the resource associated with the corresponding model element.
+ *
+ * @param element
+ * the model element
+ * @return the associated resource, or <code>null</code>
+ */
+ public static IResource getResource(final Object element) {
+ IResource resource= null;
+ if (element instanceof IRubyElement) {
+ resource= ((IRubyElement) element).getResource();
+ } else if (element instanceof IResource) {
+ resource= (IResource) element;
+ } else if (element instanceof IAdaptable) {
+ final IAdaptable adaptable= (IAdaptable) element;
+ final Object adapted= adaptable.getAdapter(IResource.class);
+ if (adapted instanceof IResource)
+ resource= (IResource) adapted;
+ } else {
+ final Object adapted= Platform.getAdapterManager().getAdapter(element, IResource.class);
+ if (adapted instanceof IResource)
+ resource= (IResource) adapted;
+ }
+ return resource;
+ }
+
+ /**
+ * Creates a new java model provider.
+ */
+ public RubyModelProvider() {
+ // Used by the runtime
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResourceMapping[] getMappings(final IResource resource, final ResourceMappingContext context, final IProgressMonitor monitor) throws CoreException {
+ final IRubyElement element= RubyCore.create(resource);
+ if (element != null)
+ return new ResourceMapping[] { RubyElementResourceMapping.create(element)};
+ final Object adapted= resource.getAdapter(ResourceMapping.class);
+ if (adapted instanceof ResourceMapping)
+ return new ResourceMapping[] { ((ResourceMapping) adapted)};
+ return new ResourceMapping[] { new RubyResourceMapping(resource)};
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyModelProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyResourceMapping.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyResourceMapping.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyResourceMapping.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.model;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.resources.mapping.ResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Resource mapping for the ruby model provider.
+ *
+ * @since 3.2
+ */
+public final class RubyResourceMapping extends ResourceMapping {
+
+ /** The resource to map */
+ private final IResource fResource;
+
+ /**
+ * Creates a new java resource mapping.
+ *
+ * @param resource
+ * the resource to map
+ */
+ public RubyResourceMapping(final IResource resource) {
+ Assert.isNotNull(resource);
+ fResource= resource;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getModelObject() {
+ return fResource;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getModelProviderId() {
+ return RubyModelProvider.RUBY_MODEL_PROVIDER_ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IProject[] getProjects() {
+ return new IProject[] { fResource.getProject() };
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResourceTraversal[] getTraversals(final ResourceMappingContext context, final IProgressMonitor monitor) {
+ return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { fResource }, IResource.DEPTH_INFINITE, IResource.NONE) };
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/model/RubyResourceMapping.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchPageScoreComputer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchPageScoreComputer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchPageScoreComputer.java 2007-09-14 16:09:49 UTC (rev 3182)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.search;
+
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptEditorInput;
+
+public class RubySearchPageScoreComputer implements ISearchPageScoreComputer {
+
+ public int computeScore(String id, Object element) {
+ if (!RubySearchPage.EXTENSION_POINT_ID.equals(id))
+ // Can't decide
+ return ISearchPageScoreComputer.UNKNOWN;
+
+ if (element instanceof IRubyElement || element instanceof IRubyScriptEditorInput /*|| element instanceof LogicalPackage*/)
+ return 90;
+
+ return ISearchPageScoreComputer.LOWEST;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchPageScoreComputer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|