- Revision
- 597
- Author
- felix
- Date
- 2006-11-30 09:28:46 -0600 (Thu, 30 Nov 2006)
Log Message
[FL] F3 if no class is found, bring up NewClassWizard, if classname is ambiguous bring up choice.
Modified Paths
Added Paths
- trunk/plugins/eclipse/src/main/java/wizzards/
- trunk/plugins/eclipse/src/main/java/wizzards/NewClassWizard.java
Diff
Modified: trunk/plugins/eclipse/src/main/java/jbehave/plugin/eclipse/actions/NavigateToJavaSource.java (596 => 597)
--- trunk/plugins/eclipse/src/main/java/jbehave/plugin/eclipse/actions/NavigateToJavaSource.java 2006-11-30 12:16:26 UTC (rev 596) +++ trunk/plugins/eclipse/src/main/java/jbehave/plugin/eclipse/actions/NavigateToJavaSource.java 2006-11-30 15:28:46 UTC (rev 597) @@ -17,29 +17,41 @@ import org.eclipse.jdt.core.search.SearchPattern; import org.eclipse.jdt.core.search.SearchRequestor; import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jdt.ui.IJavaElementSearchConstants; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.dialogs.SelectionDialog; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.TextSelectionNavigationLocation; +import wizzards.NewClassWizard; + public class NavigateToJavaSource implements IEditorActionDelegate { - + private StoryEditor editor; public void setActiveEditor(IAction action, IEditorPart targetEditor) { this.editor=(StoryEditor)targetEditor; - + } - - + + public void run(IAction action) { IDocumentProvider dp = editor.getDocumentProvider(); IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); @@ -50,19 +62,20 @@ String text=document.get(document.getLineOffset(line),document.getLineLength(line)); jbehave.plugin.eclipse.model.StoryLine storyLine = StoryLine.parseLine(text); if (storyLine!=null){ - findAndOpenClass(storyLine.asClassName()); + findAndOpenClass(storyLine); } } catch (BadLocationException e) { e.printStackTrace(); } } - - - private void findAndOpenClass(String className) { + + + private void findAndOpenClass(StoryLine storyLine) { try { + String className=storyLine.asClassName(); final List types = new ArrayList(); SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); @@ -75,16 +88,22 @@ SearchEngine searchEngine = new SearchEngine(); searchEngine.search( - pattern, - new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, - scope, - requestor, + pattern, + new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + scope, + requestor, null); if (types.size()==1){ - EditorUtility.openInEditor((IType)types.get(0), true); - } - - } catch (JavaModelException e) { + openInEditor((IType) types.get(0)); + } + if (types.size()==0){ + bringUpNewClassWizard(storyLine); + } + if (types.size()>1){ + openInEditor(selectType(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),className)); + } + + } catch (JavaModelException e) { throw new RuntimeException(e); } catch (CoreException e) { throw new RuntimeException(e); @@ -92,12 +111,48 @@ } + public IType selectType(Shell parent, String filter) throws JavaModelException { + SelectionDialog dialog= JavaUI.createTypeDialog( + parent, new ProgressMonitorDialog(parent), + SearchEngine.createWorkspaceScope(), + IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false, + filter - + ); + dialog.setTitle("Choose Class"); + dialog.setMessage(""); + if (dialog.open() == IDialogConstants.CANCEL_ID) + return null; - public void selectionChanged(IAction action, ISelection selection) { - // TODO Auto-generated method stub + Object[] types= dialog.getResult(); + if (types == null || types.length == 0) + return null; + return (IType)types[0]; + } - } + private void openInEditor(IType type) throws JavaModelException, PartInitException { + EditorUtility.openInEditor(type, true); + } + private void bringUpNewClassWizard( StoryLine storyLine) { + Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + MessageDialog dialog=new MessageDialog(null,"Type "+storyLine.asClassName()+" not found",null,"Do you want to create it?", + MessageDialog.QUESTION, + new String[]{"Yes","Yes, using Minimock","No"},0); + int ret=dialog.open(); + if ((ret==0)||(ret==1)){ + NewClassWizard wizard=new NewClassWizard(storyLine,ret==1); + wizard.init(PlatformUI.getWorkbench(), null); + WizardDialog wd=new WizardDialog(shell,wizard); + + wd.open(); + } + } + + + public void selectionChanged(IAction action, ISelection selection) { + // TODO Auto-generated method stub + + } + }
Added: trunk/plugins/eclipse/src/main/java/wizzards/NewClassWizard.java (0 => 597)
--- trunk/plugins/eclipse/src/main/java/wizzards/NewClassWizard.java (rev 0) +++ trunk/plugins/eclipse/src/main/java/wizzards/NewClassWizard.java 2006-11-30 15:28:46 UTC (rev 597) @@ -0,0 +1,124 @@ +package wizzards; +/******************************************************************************* + * 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 + *******************************************************************************/ +import jbehave.plugin.eclipse.model.StoryLine; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; + +import org.eclipse.jdt.core.IJavaElement; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.jdt.ui.wizards.NewClassWizardPage; + +import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.JavaPluginImages; +import org.eclipse.jdt.internal.ui.wizards.NewElementWizard; +import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; + +public class NewClassWizard extends NewElementWizard { + + private NewClassWizardPage fPage; + private final StoryLine storyLine; + private final boolean usingMinimock; + + + public NewClassWizard(StoryLine storyLine, boolean usingMinimock) { + + this.storyLine = storyLine; + this.usingMinimock = usingMinimock; + setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS); + setDialogSettings(JavaPlugin.getDefault().getDialogSettings()); + setWindowTitle(NewWizardMessages.NewClassCreationWizard_title); + + + } + + + /* + * @see Wizard#createPages + */ + public void addPages() { + super.addPages(); + if (fPage == null) { + fPage= new NewClassWizardPage(); + fPage.init(getSelection()); + fPage.setMethodStubSelection(false, false, true, true); + fPage.setTypeName(storyLine.asClassName(), true); + if ("given".equalsIgnoreCase(storyLine.getKeyWord())){ + if (usingMinimock){ + fPage.setSuperClass("jbehave.core.story.domain.GivenUsingMiniMock",true); + } + else{ + fPage.addSuperInterface("jbehave.core.story.domain.Given"); + } + } else + if ("when".equalsIgnoreCase(storyLine.getKeyWord())){ + if (usingMinimock){ + fPage.setSuperClass("jbehave.core.story.domain.EventUsingMiniMock",true); + } + else{ + fPage.addSuperInterface("jbehave.core.story.domain.Event"); + } + } else + if ("then".equalsIgnoreCase(storyLine.getKeyWord())){ + if (usingMinimock){ + fPage.setSuperClass("jbehave.core.story.domain.OutcomeUsingMiniMock",true); + } + else{ + fPage.addSuperInterface("jbehave.core.story.domain.Outcome"); + } + } + + } + addPage(fPage); + } + + /*(non-Javadoc) + * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#canRunForked() + */ + protected boolean canRunForked() { + return !fPage.isEnclosingTypeSelected(); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor) + */ + protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { + fPage.createType(monitor); // use the full progress monitor + } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.IWizard#performFinish() + */ + public boolean performFinish() { + warnAboutTypeCommentDeprecation(); + boolean res= super.performFinish(); + if (res) { + IResource resource= fPage.getModifiedResource(); + if (resource != null) { + selectAndReveal(resource); + openResource((IFile) resource); + } + } + return res; + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement() + */ + public IJavaElement getCreatedElement() { + return fPage.getCreatedType(); + } + +}
To unsubscribe from this list please visit:
