|
From: <caw...@us...> - 2007-07-18 21:11:41
|
Revision: 2785
http://svn.sourceforge.net/rubyeclipse/?rev=2785&view=rev
Author: cawilliams
Date: 2007-07-18 14:11:39 -0700 (Wed, 18 Jul 2007)
Log Message:
-----------
what could this possibly be? Type hier-archy!
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/HierarchyViewerSorter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsContentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsViewer.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java 2007-07-18 21:09:04 UTC (rev 2784)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java 2007-07-18 21:11:39 UTC (rev 2785)
@@ -288,6 +288,7 @@
* @return Returns <code>true</code> if the method has the given name and parameter types and constructor state.
*/
public static boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod curr) throws RubyModelException {
+ // XXX Remove paramTypes arg!
if (isConstructor || name.equals(curr.getElementName())) {
if (isConstructor == curr.isConstructor()) {
// if (paramTypes.length == curr.getNumberOfParameters()) {
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/HierarchyViewerSorter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/HierarchyViewerSorter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/HierarchyViewerSorter.java 2007-07-18 21:11:39 UTC (rev 2785)
@@ -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.typehierarchy;
+
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.ITypeHierarchy;
+
+/**
+ */
+public class HierarchyViewerSorter extends AbstractHierarchyViewerSorter {
+
+ private final TypeHierarchyLifeCycle fHierarchy;
+ private boolean fSortByDefiningType;
+
+ public HierarchyViewerSorter(TypeHierarchyLifeCycle cycle) {
+ fHierarchy= cycle;
+ }
+
+ public void setSortByDefiningType(boolean sortByDefiningType) {
+ fSortByDefiningType= sortByDefiningType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#getTypeKind(org.eclipse.jdt.core.IType)
+ */
+ protected int getTypeFlags(IType type) {
+ ITypeHierarchy hierarchy= getHierarchy(type);
+ if (hierarchy != null) {
+ return fHierarchy.getHierarchy().getCachedFlags(type);
+ }
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#isSortByDefiningType()
+ */
+ public boolean isSortByDefiningType() {
+ return fSortByDefiningType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#isSortAlphabetically()
+ */
+ public boolean isSortAlphabetically() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#getHierarchy(org.eclipse.jdt.core.IType)
+ */
+ protected ITypeHierarchy getHierarchy(IType type) {
+ return fHierarchy.getHierarchy(); // hierarchy contains all types shown
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/HierarchyViewerSorter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsContentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsContentProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsContentProvider.java 2007-07-18 21:11:39 UTC (rev 2785)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.ITypeHierarchy;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.ui.IWorkingCopyProvider;
+
+/**
+ * Content provider used for the method view.
+ * Allows also seeing methods inherited from base classes.
+ */
+public class MethodsContentProvider implements IStructuredContentProvider, IWorkingCopyProvider {
+
+ private static final Object[] NO_ELEMENTS = new Object[0];
+
+ private boolean fShowInheritedMethods;
+ private TypeHierarchyLifeCycle fHierarchyLifeCycle;
+ private TableViewer fViewer;
+
+ public MethodsContentProvider(TypeHierarchyLifeCycle lifecycle) {
+ fHierarchyLifeCycle= lifecycle;
+ fShowInheritedMethods= false;
+ fViewer= null;
+ }
+
+ /**
+ * Turn on / off showing of inherited methods
+ */
+ public void showInheritedMethods(boolean show) {
+ if (show != fShowInheritedMethods) {
+ fShowInheritedMethods= show;
+ if (fViewer != null) {
+ fViewer.refresh();
+ }
+ }
+ }
+
+ /* (non-Rubydoc)
+ * @see IStructuredContentProvider#providesWorkingCopies()
+ */
+ public boolean providesWorkingCopies() {
+ return true;
+ }
+
+ /**
+ * Returns true if inherited methods are shown
+ */
+ public boolean isShowInheritedMethods() {
+ return fShowInheritedMethods;
+ }
+
+
+ private void addAll(Object[] arr, List res) {
+ if (arr != null) {
+ for (int j= 0; j < arr.length; j++) {
+ res.add(arr[j]);
+ }
+ }
+ }
+
+ /*
+ * @see IStructuredContentProvider#getElements
+ */
+ public Object[] getElements(Object element) {
+ if (element instanceof IType) {
+ IType type= (IType)element;
+
+ List res= new ArrayList();
+ try {
+ ITypeHierarchy hierarchy= fHierarchyLifeCycle.getHierarchy();
+ if (fShowInheritedMethods && hierarchy != null) {
+ IType[] allSupertypes= hierarchy.getAllSupertypes(type);
+ // sort in from last to first: elements with same name
+ // will show up in hierarchy order
+ for (int i= allSupertypes.length - 1; i >= 0; i--) {
+ IType superType= allSupertypes[i];
+ if (superType.exists()) {
+ addAll(superType.getMethods(), res);
+ addAll(superType.getFields(), res);
+ }
+ }
+ }
+ if (type.exists()) {
+ addAll(type.getMethods(), res);
+ addAll(type.getFields(), res);
+ }
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+ return res.toArray();
+ }
+ return NO_ELEMENTS;
+ }
+
+
+ /*
+ * @see IContentProvider#inputChanged
+ */
+ public void inputChanged(Viewer input, Object oldInput, Object newInput) {
+ Assert.isTrue(input instanceof TableViewer);
+
+ fViewer= (TableViewer) input;
+ }
+
+ /*
+ * @see IContentProvider#dispose
+ */
+ public void dispose() {
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsContentProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsViewer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsViewer.java 2007-07-18 21:11:39 UTC (rev 2785)
@@ -0,0 +1,299 @@
+/*******************************************************************************
+ * 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.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.ScrollBar;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.rubypeople.rdt.core.IMethod;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.util.SelectionUtil;
+import org.rubypeople.rdt.internal.ui.viewsupport.DecoratingRubyLabelProvider;
+import org.rubypeople.rdt.internal.ui.viewsupport.ProblemTableViewer;
+import org.rubypeople.rdt.ui.RubyElementLabels;
+import org.rubypeople.rdt.ui.actions.MemberFilterActionGroup;
+import org.rubypeople.rdt.ui.actions.OpenAction;
+
+/**
+ * Method viewer shows a list of methods of a input type.
+ * Offers filter actions.
+ * No dependency to the type hierarchy view
+ */
+public class MethodsViewer extends ProblemTableViewer {
+
+ private static final String TAG_SHOWINHERITED= "showinherited"; //$NON-NLS-1$
+ private static final String TAG_SORTBYDEFININGTYPE= "sortbydefiningtype"; //$NON-NLS-1$
+ private static final String TAG_VERTICAL_SCROLL= "mv_vertical_scroll"; //$NON-NLS-1$
+
+ private MethodsLabelProvider fLabelProvider;
+
+ private MemberFilterActionGroup fMemberFilterActionGroup;
+
+ private OpenAction fOpen;
+ private ShowInheritedMembersAction fShowInheritedMembersAction;
+ private SortByDefiningTypeAction fSortByDefiningTypeAction;
+
+ public MethodsViewer(Composite parent, final TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) {
+ super(new Table(parent, SWT.MULTI));
+
+// addFilter(new SyntheticMembersFilter());
+
+ fLabelProvider= new MethodsLabelProvider(lifeCycle, this);
+
+ setLabelProvider(new DecoratingRubyLabelProvider(fLabelProvider, true));
+ setContentProvider(new MethodsContentProvider(lifeCycle));
+
+ HierarchyViewerSorter sorter= new HierarchyViewerSorter(lifeCycle);
+ sorter.setSortByDefiningType(false);
+ setSorter(sorter);
+
+ fOpen= new OpenAction(part.getSite());
+ addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ fOpen.run();
+ }
+ });
+
+ fMemberFilterActionGroup= new MemberFilterActionGroup(this, "HierarchyMethodView", false, MemberFilterActionGroup.ALL_FILTERS & ~MemberFilterActionGroup.FILTER_LOCALTYPES); //$NON-NLS-1$
+
+ fShowInheritedMembersAction= new ShowInheritedMembersAction(this, false);
+ fSortByDefiningTypeAction= new SortByDefiningTypeAction(this, false);
+
+ showInheritedMethodsNoRedraw(false);
+ sortByDefiningTypeNoRedraw(false);
+ // FIXME Uncomment when we have RubyUIHelp
+// RubyUIHelp.setHelp(this, IRubyHelpContextIds.TYPE_HIERARCHY_VIEW);
+ }
+
+ private void showInheritedMethodsNoRedraw(boolean on) {
+ MethodsContentProvider cprovider= (MethodsContentProvider) getContentProvider();
+ cprovider.showInheritedMethods(on);
+ fShowInheritedMembersAction.setChecked(on);
+ if (on) {
+ fLabelProvider.setTextFlags(fLabelProvider.getTextFlags() | RubyElementLabels.ALL_POST_QUALIFIED);
+ } else {
+ fLabelProvider.setTextFlags(fLabelProvider.getTextFlags() & ~RubyElementLabels.ALL_POST_QUALIFIED);
+ }
+ if (on) {
+ sortByDefiningTypeNoRedraw(false);
+ }
+ fSortByDefiningTypeAction.setEnabled(!on);
+
+ }
+
+ /**
+ * Show inherited methods
+ */
+ public void showInheritedMethods(boolean on) {
+ if (on == isShowInheritedMethods()) {
+ return;
+ }
+ try {
+ getTable().setRedraw(false);
+ showInheritedMethodsNoRedraw(on);
+ refresh();
+ } finally {
+ getTable().setRedraw(true);
+ }
+ }
+
+ private void sortByDefiningTypeNoRedraw(boolean on) {
+ fSortByDefiningTypeAction.setChecked(on);
+ fLabelProvider.setShowDefiningType(on);
+ ((HierarchyViewerSorter) getSorter()).setSortByDefiningType(on);
+ }
+
+ /**
+ * Show the name of the defining type
+ */
+ public void sortByDefiningType(boolean on) {
+ if (on == isShowDefiningTypes()) {
+ return;
+ }
+ try {
+ getTable().setRedraw(false);
+ sortByDefiningTypeNoRedraw(on);
+ refresh();
+ } finally {
+ getTable().setRedraw(true);
+ }
+ }
+
+ /*
+ * @see Viewer#inputChanged(Object, Object)
+ */
+ protected void inputChanged(Object input, Object oldInput) {
+ super.inputChanged(input, oldInput);
+ }
+
+ /**
+ * Returns <code>true</code> if inherited methods are shown.
+ */
+ public boolean isShowInheritedMethods() {
+ return ((MethodsContentProvider) getContentProvider()).isShowInheritedMethods();
+ }
+
+ /**
+ * Returns <code>true</code> if defining types are shown.
+ */
+ public boolean isShowDefiningTypes() {
+ return fLabelProvider.isShowDefiningType();
+ }
+
+ /**
+ * Saves the state of the filter actions
+ */
+ public void saveState(IMemento memento) {
+ fMemberFilterActionGroup.saveState(memento);
+
+ memento.putString(TAG_SHOWINHERITED, String.valueOf(isShowInheritedMethods()));
+ memento.putString(TAG_SORTBYDEFININGTYPE, String.valueOf(isShowDefiningTypes()));
+
+ ScrollBar bar= getTable().getVerticalBar();
+ int position= bar != null ? bar.getSelection() : 0;
+ memento.putString(TAG_VERTICAL_SCROLL, String.valueOf(position));
+ }
+
+ /**
+ * Restores the state of the filter actions
+ */
+ public void restoreState(IMemento memento) {
+ fMemberFilterActionGroup.restoreState(memento);
+ getControl().setRedraw(false);
+ refresh();
+ getControl().setRedraw(true);
+
+ boolean showInherited= Boolean.valueOf(memento.getString(TAG_SHOWINHERITED)).booleanValue();
+ showInheritedMethods(showInherited);
+
+ boolean showDefiningTypes= Boolean.valueOf(memento.getString(TAG_SORTBYDEFININGTYPE)).booleanValue();
+ sortByDefiningType(showDefiningTypes);
+
+ ScrollBar bar= getTable().getVerticalBar();
+ if (bar != null) {
+ Integer vScroll= memento.getInteger(TAG_VERTICAL_SCROLL);
+ if (vScroll != null) {
+ bar.setSelection(vScroll.intValue());
+ }
+ }
+ }
+
+ /**
+ * Attaches a contextmenu listener to the table
+ */
+ public void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) {
+ MenuManager menuMgr= new MenuManager();
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(menuListener);
+ Menu menu= menuMgr.createContextMenu(getTable());
+ getTable().setMenu(menu);
+ viewSite.registerContextMenu(popupId, menuMgr, this);
+ }
+
+
+ /**
+ * Fills up the context menu with items for the method viewer
+ * Should be called by the creator of the context menu
+ */
+ public void contributeToContextMenu(IMenuManager menu) {
+ }
+
+ /**
+ * Fills up the tool bar with items for the method viewer
+ * Should be called by the creator of the tool bar
+ */
+ public void contributeToToolBar(ToolBarManager tbm) {
+ tbm.add(fShowInheritedMembersAction);
+ tbm.add(fSortByDefiningTypeAction);
+ tbm.add(new Separator());
+ fMemberFilterActionGroup.contributeToToolBar(tbm);
+ }
+
+ public void dispose() {
+ if (fMemberFilterActionGroup != null) {
+ fMemberFilterActionGroup.dispose();
+ fMemberFilterActionGroup= null;
+ }
+ }
+
+ /*
+ * @see StructuredViewer#handleInvalidSelection(ISelection, ISelection)
+ */
+ protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) {
+ // on change of input, try to keep selected methods stable by selecting a method with the same
+ // signature: See #5466
+ List oldSelections= SelectionUtil.toList(invalidSelection);
+ List newSelections= SelectionUtil.toList(newSelection);
+ if (!oldSelections.isEmpty()) {
+ ArrayList newSelectionElements= new ArrayList(newSelections);
+ try {
+ Object[] currElements= getFilteredChildren(getInput());
+ for (int i= 0; i < oldSelections.size(); i++) {
+ Object curr= oldSelections.get(i);
+ if (curr instanceof IMethod && !newSelections.contains(curr)) {
+ IMethod method= (IMethod) curr;
+ if (method.exists()) {
+ IMethod similar= findSimilarMethod(method, currElements);
+ if (similar != null) {
+ newSelectionElements.add(similar);
+ }
+ }
+ }
+ }
+ if (!newSelectionElements.isEmpty()) {
+ newSelection= new StructuredSelection(newSelectionElements);
+ } else if (currElements.length > 0) {
+ newSelection= new StructuredSelection(currElements[0]);
+ }
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+ }
+ setSelection(newSelection);
+ updateSelection(newSelection);
+ }
+
+ private IMethod findSimilarMethod(IMethod meth, Object[] elements) throws RubyModelException {
+ String name= meth.getElementName();
+ String[] paramTypes= null;
+ boolean isConstructor= meth.isConstructor();
+
+ for (int i= 0; i < elements.length; i++) {
+ Object curr= elements[i];
+ if (curr instanceof IMethod && RubyModelUtil.isSameMethodSignature(name, paramTypes, isConstructor, (IMethod) curr)) {
+ return (IMethod) curr;
+ }
+ }
+ return null;
+ }
+
+
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/typehierarchy/MethodsViewer.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.
|