|
From: <caw...@us...> - 2007-07-18 21:25:18
|
Revision: 2789
http://svn.sourceforge.net/rubyeclipse/?rev=2789&view=rev
Author: cawilliams
Date: 2007-07-18 14:25:17 -0700 (Wed, 18 Jul 2007)
Log Message:
-----------
type. hierarchy.
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SubTypeHierarchyViewer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SuperTypeHierarchyViewer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/TraditionalHierarchyViewer.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SubTypeHierarchyViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SubTypeHierarchyViewer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SubTypeHierarchyViewer.java 2007-07-18 21:25:17 UTC (rev 2789)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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.ui.typehierarchy;
+
+import java.util.List;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.ITypeHierarchy;
+
+/**
+ * A viewer including the content provider for the subtype hierarchy.
+ * Used by the TypeHierarchyViewPart which has to provide a TypeHierarchyLifeCycle
+ * on construction (shared type hierarchy)
+ */
+public class SubTypeHierarchyViewer extends TypeHierarchyViewer {
+
+ public SubTypeHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) {
+ super(parent, new SubTypeHierarchyContentProvider(lifeCycle), lifeCycle, part);
+ }
+
+ /*
+ * @see TypeHierarchyViewer#getTitle
+ */
+ public String getTitle() {
+ if (isMethodFiltering()) {
+ return TypeHierarchyMessages.SubTypeHierarchyViewer_filtered_title;
+ } else {
+ return TypeHierarchyMessages.SubTypeHierarchyViewer_title;
+ }
+ }
+
+ /*
+ * @see TypeHierarchyViewer#updateContent
+ */
+ public void updateContent(boolean expand) {
+ getTree().setRedraw(false);
+ refresh();
+
+ if (expand) {
+ int expandLevel= 2;
+ if (isMethodFiltering()) {
+ expandLevel++;
+ }
+ expandToLevel(expandLevel);
+ }
+ getTree().setRedraw(true);
+ }
+
+ /**
+ * Content provider for the subtype hierarchy
+ */
+ public static class SubTypeHierarchyContentProvider extends TypeHierarchyContentProvider {
+ public SubTypeHierarchyContentProvider(TypeHierarchyLifeCycle lifeCycle) {
+ super(lifeCycle);
+ }
+
+ protected final void getTypesInHierarchy(IType type, List res) {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ IType[] types= hierarchy.getSubtypes(type);
+ if (isObject(type)) {
+ for (int i= 0; i < types.length; i++) {
+ IType curr= types[i];
+ if (!isAnonymousFromInterface(curr)) {
+ res.add(curr);
+ }
+ }
+ } else {
+ for (int i= 0; i < types.length; i++) {
+ res.add(types[i]);
+ }
+ }
+ }
+
+ }
+
+ protected IType getParentType(IType type) {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ return hierarchy.getSuperclass(type);
+ // dont handle interfaces
+ }
+ return null;
+ }
+
+}
+
+
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SubTypeHierarchyViewer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SuperTypeHierarchyViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SuperTypeHierarchyViewer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SuperTypeHierarchyViewer.java 2007-07-18 21:25:17 UTC (rev 2789)
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.typehierarchy;
+
+import java.util.List;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.ITypeHierarchy;
+
+/**
+ * A viewer including the content provider for the supertype hierarchy.
+ * Used by the TypeHierarchyViewPart which has to provide a TypeHierarchyLifeCycle
+ * on construction (shared type hierarchy)
+ */
+public class SuperTypeHierarchyViewer extends TypeHierarchyViewer {
+
+ public SuperTypeHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) {
+ super(parent, new SuperTypeHierarchyContentProvider(lifeCycle), lifeCycle, part);
+ }
+
+ /*
+ * @see TypeHierarchyViewer#getTitle
+ */
+ public String getTitle() {
+ if (isMethodFiltering()) {
+ return TypeHierarchyMessages.SuperTypeHierarchyViewer_filtered_title;
+ } else {
+ return TypeHierarchyMessages.SuperTypeHierarchyViewer_title;
+ }
+ }
+
+ /*
+ * @see TypeHierarchyViewer#updateContent
+ */
+ public void updateContent(boolean expand) {
+ getTree().setRedraw(false);
+ refresh();
+ if (expand) {
+ expandAll();
+ }
+ getTree().setRedraw(true);
+ }
+
+ /*
+ * Content provider for the supertype hierarchy
+ */
+ public static class SuperTypeHierarchyContentProvider extends TypeHierarchyContentProvider {
+ public SuperTypeHierarchyContentProvider(TypeHierarchyLifeCycle lifeCycle) {
+ super(lifeCycle);
+ }
+
+ protected final void getTypesInHierarchy(IType type, List res) {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ IType[] types= hierarchy.getSupertypes(type);
+ for (int i= 0; i < types.length; i++) {
+ res.add(types[i]);
+ }
+ }
+ }
+
+ protected IType getParentType(IType type) {
+ // cant handle
+ return null;
+ }
+
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/SuperTypeHierarchyViewer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/TraditionalHierarchyViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/TraditionalHierarchyViewer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/TraditionalHierarchyViewer.java 2007-07-18 21:25:17 UTC (rev 2789)
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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.ui.typehierarchy;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.rubypeople.rdt.core.Flags;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.ITypeHierarchy;
+
+/**
+ * A TypeHierarchyViewer that looks like the type hierarchy view of VA/Java:
+ * Starting form Object down to the element in focus, then all subclasses from
+ * this element.
+ * Used by the TypeHierarchyViewPart which has to provide a TypeHierarchyLifeCycle
+ * on construction (shared type hierarchy)
+ */
+public class TraditionalHierarchyViewer extends TypeHierarchyViewer {
+
+ public TraditionalHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) {
+ super(parent, new TraditionalHierarchyContentProvider(lifeCycle), lifeCycle, part);
+ }
+
+ /*
+ * @see TypeHierarchyViewer#getTitle
+ */
+ public String getTitle() {
+ if (isMethodFiltering()) {
+ return TypeHierarchyMessages.TraditionalHierarchyViewer_filtered_title;
+ } else {
+ return TypeHierarchyMessages.TraditionalHierarchyViewer_title;
+ }
+ }
+
+ /*
+ * @see TypeHierarchyViewer#updateContent
+ */
+ public void updateContent(boolean expand) {
+ getTree().setRedraw(false);
+ refresh();
+
+ if (expand) {
+ TraditionalHierarchyContentProvider contentProvider= (TraditionalHierarchyContentProvider) getContentProvider();
+ int expandLevel= contentProvider.getExpandLevel();
+ if (isMethodFiltering()) {
+ expandLevel++;
+ }
+ expandToLevel(expandLevel);
+ }
+ getTree().setRedraw(true);
+ }
+
+ /**
+ * Content provider for the 'traditional' type hierarchy.
+ */
+ public static class TraditionalHierarchyContentProvider extends TypeHierarchyContentProvider {
+
+
+ public TraditionalHierarchyContentProvider(TypeHierarchyLifeCycle provider) {
+ super(provider);
+ }
+
+ public int getExpandLevel() {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ IType input= hierarchy.getType();
+ if (input != null) {
+ return getDepth(hierarchy, input) + 2;
+ } else {
+ return 5;
+ }
+ }
+ return 2;
+ }
+
+ private int getDepth(ITypeHierarchy hierarchy, IType input) {
+ int count= 0;
+ IType superType= hierarchy.getSuperclass(input);
+ while (superType != null) {
+ count++;
+ superType= hierarchy.getSuperclass(superType);
+ }
+ return count;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyContentProvider#getRootTypes(java.util.List)
+ */
+ protected final void getRootTypes(List res) {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ IType input= hierarchy.getType();
+ if (input == null) {
+ IType[] classes= hierarchy.getRootClasses();
+ for (int i= 0; i < classes.length; i++) {
+ res.add(classes[i]);
+ }
+ IType[] interfaces= hierarchy.getRootInterfaces();
+ for (int i= 0; i < interfaces.length; i++) {
+ res.add(interfaces[i]);
+ }
+ } else {
+ if (Flags.isModule(hierarchy.getCachedFlags(input))) {
+ res.add(input);
+ } else if (isAnonymousFromInterface(input)) {
+ res.add(hierarchy.getSuperInterfaces(input)[0]);
+ } else {
+ IType[] roots= hierarchy.getRootClasses();
+ for (int i= 0; i < roots.length; i++) {
+ if (isObject(roots[i])) {
+ res.add(roots[i]);
+ return;
+ }
+ }
+ res.addAll(Arrays.asList(roots)); // something wrong with the hierarchy
+ }
+ }
+ }
+ }
+
+ /*
+ * @see TypeHierarchyContentProvider.getTypesInHierarchy
+ */
+ protected final void getTypesInHierarchy(IType type, List res) {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ IType[] types= hierarchy.getSubtypes(type);
+ if (isObject(type)) {
+ for (int i= 0; i < types.length; i++) {
+ IType curr= types[i];
+ if (!isAnonymousFromInterface(curr)) { // no anonymous classes on 'Object' -> will be children of interface
+ res.add(curr);
+ }
+ }
+ } else {
+ boolean isHierarchyOnType= (hierarchy.getType() != null);
+ boolean isClass= !Flags.isModule(hierarchy.getCachedFlags(type));
+ if (isClass || isHierarchyOnType) {
+ for (int i= 0; i < types.length; i++) {
+ res.add(types[i]);
+ }
+ } else {
+ for (int i= 0; i < types.length; i++) {
+ IType curr= types[i];
+ // no classes implementing interfaces, only if anonymous
+ if (Flags.isModule(hierarchy.getCachedFlags(curr)) || isAnonymous(curr)) {
+ res.add(curr);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected IType getParentType(IType type) {
+ ITypeHierarchy hierarchy= getHierarchy();
+ if (hierarchy != null) {
+ return hierarchy.getSuperclass(type);
+ // don't handle interfaces
+ }
+ return null;
+ }
+
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/TraditionalHierarchyViewer.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.
|