|
From: Christopher W. <caw...@us...> - 2006-04-04 23:06:16
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/browsing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20474/src/org/rubypeople/rdt/internal/ui/browsing Modified Files: RubyBrowsingPart.java Added Files: ToggleLinkingAction.java Log Message: fix null pointer bug on RubyBrowsingPart.setInitialSelection --- NEW FILE: ToggleLinkingAction.java --- /******************************************************************************* * 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.browsing; import org.rubypeople.rdt.internal.ui.actions.AbstractToggleLinkingAction; /** * This action toggles whether this package explorer links its selection to the active * editor. * * @since 2.1 */ public class ToggleLinkingAction extends AbstractToggleLinkingAction { RubyBrowsingPart fRubyBrowsingPart; /** * Constructs a new action. */ public ToggleLinkingAction(RubyBrowsingPart part) { setChecked(part.isLinkingEnabled()); fRubyBrowsingPart= part; } /** * Runs the action. */ public void run() { fRubyBrowsingPart.setLinkingEnabled(isChecked()); } } Index: RubyBrowsingPart.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/browsing/RubyBrowsingPart.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RubyBrowsingPart.java 30 Mar 2006 03:09:01 -0000 1.2 --- RubyBrowsingPart.java 4 Apr 2006 23:06:09 -0000 1.3 *************** *** 8,12 **** --- 8,14 ---- import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; + import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; + import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.IAction; *************** *** 16,19 **** --- 18,22 ---- import org.eclipse.jface.util.Assert; import org.eclipse.jface.viewers.IContentProvider; + import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.IOpenListener; import org.eclipse.jface.viewers.ISelection; *************** *** 28,41 **** --- 31,49 ---- import org.eclipse.search.ui.ISearchResultViewPart; import org.eclipse.swt.widgets.Composite; + import org.eclipse.swt.widgets.Display; + import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; + import org.eclipse.ui.IMemento; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.ISelectionListener; + import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchPartSite; + import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionContext; *************** *** 44,47 **** --- 52,56 ---- import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.part.ViewPart; + import org.eclipse.ui.texteditor.ITextEditor; import org.osgi.framework.Bundle; import org.rubypeople.rdt.core.IRubyElement; *************** *** 57,60 **** --- 66,72 ---- import org.rubypeople.rdt.ui.IWorkingCopyManager; import org.rubypeople.rdt.ui.PreferenceConstants; + import org.rubypeople.rdt.ui.RubyElementLabelProvider; + import org.rubypeople.rdt.ui.RubyElementLabels; + import org.rubypeople.rdt.ui.RubyElementSorter; import org.rubypeople.rdt.ui.StandardRubyElementContentProvider; import org.rubypeople.rdt.ui.actions.CustomFiltersActionGroup; *************** *** 65,71 **** --- 77,85 ---- private StructuredViewer fViewer; + private IMemento fMemento; private RubyUILabelProvider fLabelProvider; protected IWorkbenchPart fPreviousSelectionProvider; protected Object fPreviousSelectedElement; + private ILabelProvider fTitleProvider; // Actions *************** *** 73,76 **** --- 87,91 ---- private OpenEditorActionGroup fOpenEditorGroup; protected CompositeActionGroup fActionGroups; + private ToggleLinkingAction fToggleLinkingAction; // Filters *************** *** 123,126 **** --- 138,142 ---- }; + public RubyBrowsingPart() { super(); *************** *** 136,139 **** --- 152,157 ---- if (fHasCustomFilter) fCustomFiltersActionGroup= new CustomFiltersActionGroup(this, fViewer); + + fToggleLinkingAction= new ToggleLinkingAction(this); } *************** *** 191,200 **** --- 209,228 ---- .setLabelProvider(new DecoratingRubyLabelProvider( fLabelProvider)); + fViewer.setSorter(createRubyElementSorter()); fViewer.setUseHashlookup(true); + fTitleProvider= createTitleProvider(); getSite().setSelectionProvider(fViewer); + if (fMemento != null) { // initialize linking state before creating the actions + restoreLinkingEnabled(fMemento); + } createActions(); // call before registering for selection changes + if (fMemento != null) + restoreState(fMemento); + + getSite().setSelectionProvider(fViewer); + hookViewerListeners(); *************** *** 213,216 **** --- 241,276 ---- } + protected ILabelProvider createTitleProvider() { + return new RubyElementLabelProvider(RubyElementLabelProvider.SHOW_BASICS | RubyElementLabelProvider.SHOW_SMALL_ICONS); + } + + /* + * Implements method from IViewPart. + */ + public void init(IViewSite site, IMemento memento) throws PartInitException { + super.init(site, memento); + fMemento= memento; + } + + private void restoreLinkingEnabled(IMemento memento) { + Integer val= memento.getInteger(getLinkToEditorKey()); + if (val != null) { + fLinkingEnabled= val.intValue() != 0; + } + } + + protected void restoreState(IMemento memento) { + // if (fHasWorkingSetFilter) + // fWorkingSetFilterActionGroup.restoreState(memento); + if (fHasCustomFilter) + fCustomFiltersActionGroup.restoreState(memento); + + if (fHasCustomFilter /*|| fHasWorkingSetFilter*/) { + fViewer.getControl().setRedraw(false); + fViewer.refresh(); + fViewer.getControl().setRedraw(true); + } + } + protected StructuredViewer createViewer(Composite parent) { // TODO Use ProblemTreeViewer *************** *** 233,238 **** fCustomFiltersActionGroup.fillActionBars(actionBars); ! // IMenuManager menu= actionBars.getMenuManager(); ! // menu.add(fToggleLinkingAction); } --- 293,298 ---- fCustomFiltersActionGroup.fillActionBars(actionBars); ! IMenuManager menu= actionBars.getMenuManager(); ! menu.add(fToggleLinkingAction); } *************** *** 273,280 **** protected void setInput(Object input) { setViewerInput(input); ! // TODO Update the title ! // updateTitle(); } private void setViewerInput(Object input) { fProcessSelectionEvents = false; --- 333,373 ---- protected void setInput(Object input) { setViewerInput(input); ! updateTitle(); ! } ! ! void updateTitle() { ! setTitleToolTip(getToolTipText(fViewer.getInput())); ! } ! ! /** ! * Returns the tool tip text for the given element. ! */ ! String getToolTipText(Object element) { ! String result; ! if (!(element instanceof IResource)) { ! result= RubyElementLabels.getTextLabel(element, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS); ! } else { ! IPath path= ((IResource) element).getFullPath(); ! if (path.isRoot()) { ! result= getConfigurationElement().getAttribute("name"); //$NON-NLS-1$ ! } else { ! result= path.makeRelative().toString(); ! } ! } ! ! // if (fWorkingSetFilterActionGroup == null || fWorkingSetFilterActionGroup.getWorkingSet() == null) ! return result; ! ! // IWorkingSet ws= fWorkingSetFilterActionGroup.getWorkingSet(); ! // String wsstr= Messages.format(RubyBrowsingMessages.RubyBrowsingPart_toolTip, new String[] { ws.getLabel() }); ! // if (result.length() == 0) ! // return wsstr; ! // return Messages.format(RubyBrowsingMessages.RubyBrowsingPart_toolTip2, new String[] { result, ws.getLabel() }); } + protected final void setViewer(StructuredViewer viewer){ + fViewer= viewer; + } + private void setViewerInput(Object input) { fProcessSelectionEvents = false; *************** *** 308,317 **** return; ! // TODO Handle editor selections ! // if (fToggleLinkingAction.isChecked() && (part instanceof ! // ITextEditor)) { ! // setSelectionFromEditor(part, selection); ! // return; ! // } if (!(selection instanceof IStructuredSelection)) --- 401,409 ---- return; ! ! if (fToggleLinkingAction.isChecked() && (part instanceof ITextEditor)) { ! setSelectionFromEditor(part, selection); ! return; ! } if (!(selection instanceof IStructuredSelection)) *************** *** 335,344 **** elementToSelect) < 0) setSelection(new StructuredSelection(elementToSelect), true); ! // TODO Uncomment when we have a MembersView ! // else if (elementToSelect == null && (this instanceof ! // MembersView)) { ! // setSelection(StructuredSelection.EMPTY, true); ! // fPreviousSelectedElement= StructuredSelection.EMPTY; ! // } fPreviousSelectionProvider = part; return; --- 427,434 ---- elementToSelect) < 0) setSelection(new StructuredSelection(elementToSelect), true); ! else if (elementToSelect == null && (this instanceof MembersView)) { ! setSelection(StructuredSelection.EMPTY, true); ! fPreviousSelectedElement = StructuredSelection.EMPTY; ! } fPreviousSelectionProvider = part; return; *************** *** 640,643 **** --- 730,756 ---- } + protected RubyElementSorter createRubyElementSorter() { + return new RubyElementSorter(); + } + + /** + * Returns the shell to use for opening dialogs. + * Used in this class, and in the actions. + */ + Shell getShell() { + return fViewer.getControl().getShell(); + } + + protected final Display getDisplay() { + return fViewer.getControl().getDisplay(); + } + + /** + * Returns the selection provider. + */ + ISelectionProvider getSelectionProvider() { + return fViewer; + } + /** * Answers if the given <code>element</code> is a valid input for this *************** *** 739,742 **** --- 852,878 ---- } + /* + * Implements method from IViewPart. + */ + public void saveState(IMemento memento) { + if (fViewer == null) { + // part has not been created + if (fMemento != null) //Keep the old state; + memento.putMemento(fMemento); + return; + } + // if (fHasWorkingSetFilter) + // fWorkingSetFilterActionGroup.saveState(memento); + if (fHasCustomFilter) + fCustomFiltersActionGroup.saveState(memento); + // saveSelectionState(memento); + saveLinkingEnabled(memento); + } + + private void saveLinkingEnabled(IMemento memento) { + memento.putInteger(getLinkToEditorKey(), fLinkingEnabled ? 1 : 0); + } + + protected void setInitialSelection() { // Use the selection, if any |