Skip to content

Commit 4b11e84

Browse files
committed
Changed the contents of the new file fron a string in the class to a resources file. Commenst are cleaned and remaned messages files.
1 parent fba67af commit 4b11e84

File tree

5 files changed

+67
-73
lines changed

5 files changed

+67
-73
lines changed
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
Sample story file
2+
13
Narrative:
2-
In Order To communicate effectively to the business some functionality
3-
As A development team
4-
I Want To use Behaviour-Driven Development
4+
In order to communicate effectively to the business some functionality
5+
As a development team
6+
I want to use Behaviour-Driven Development
57

68
Scenario: A scenario is a collection of executable steps of different type
7-
Given step represents a precondition to an event
8-
When step represents the occurrence of the event
9-
Then step represents the outcome of the event
9+
Given step represents a precondition to an event
10+
When step represents the occurrence of the event
11+
Then step represents the outcome of the event
1012

1113
Scenario: Another scenario exploring different combination of events
12-
Given a precondition
13-
When a negative event occurs
14-
Then a the outcome should be captured
14+
Given a precondition
15+
When a negative event occurs
16+
Then a the outcome should be captured

org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/NewStoryWizard.java

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,56 @@
1414
import java.io.*;
1515
import org.eclipse.ui.*;
1616
import org.eclipse.ui.ide.IDE;
17-
18-
/**
19-
* This is a sample new wizard. Its role is to create a new file
20-
* resource in the provided container. If the container resource
21-
* (a folder or a project) is selected in the workspace
22-
* when the wizard is opened, it will accept it as the target
23-
* container. The wizard creates one file with the extension
24-
* "mpe". If a sample multi-page editor (also available
25-
* as a template) is registered for the same extension, it will
26-
* be able to open it.
27-
*/
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
2819

2920
public class NewStoryWizard extends Wizard implements INewWizard {
21+
private static Logger log = LoggerFactory.getLogger(NewStoryWizard.class);
22+
3023
private NewStoryWizardPage page;
3124
private IStructuredSelection selection;
3225
private IWorkbench workbench;
3326

34-
/**
35-
* Constructor for SampleNewWizard.
36-
*/
3727
public NewStoryWizard() {
3828
super();
39-
setWindowTitle(Messages.NewStoryWizard_0);
29+
setWindowTitle(WizardsMessages.NewStoryWizard_0);
4030
}
4131

42-
/**
43-
* Adding the page to the wizard.
44-
*/
45-
4632
public void addPages() {
4733
page = new NewStoryWizardPage(selection);
4834
addPage(page);
4935
}
36+
37+
private void openEditor(final IFile file){
38+
if(file != null){
39+
getShell().getDisplay().asyncExec(new Runnable(){
40+
public void run(){
41+
try{
42+
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
43+
IDE.openEditor(page, file,true);
44+
}catch( PartInitException e){
45+
log.debug(e.getMessage(), e);
46+
}
47+
}
48+
});
49+
}
50+
}
5051

51-
/**
52-
* This method is called when 'Finish' button is pressed in
53-
* the wizard. We will create an operation and run it
54-
* using wizard as execution context.
55-
*/
5652
public boolean performFinish() {
53+
boolean performedOK = false;
54+
5755
IFile file = page.createNewFile();
5856
if(file != null)
5957
{
60-
return true;
61-
}else
62-
{
63-
return false;
58+
// open the file in editor
59+
openEditor(file);
60+
61+
// everything is fine
62+
performedOK = true;
6463
}
64+
return performedOK;
6565
}
6666

67-
/**
68-
* We will accept the selection in the workbench to see if
69-
* we can initialize from it.
70-
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
71-
*/
7267
public void init(IWorkbench workbench, IStructuredSelection selection) {
7368
this.selection = selection;
7469
this.workbench = workbench;
Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
11
package org.jbehave.eclipse.wizards;
22

3-
import java.io.ByteArrayInputStream;
43
import java.io.IOException;
54
import java.io.InputStream;
65

6+
import org.eclipse.core.resources.IResource;
7+
import org.eclipse.core.resources.IWorkspace;
8+
import org.eclipse.core.resources.ResourcesPlugin;
9+
import org.eclipse.core.runtime.IPath;
10+
import org.eclipse.core.runtime.IStatus;
11+
import org.eclipse.jface.dialogs.IMessageProvider;
712
import org.eclipse.jface.viewers.ISelection;
813
import org.eclipse.jface.viewers.IStructuredSelection;
14+
import org.eclipse.osgi.util.NLS;
15+
import org.eclipse.swt.widgets.Composite;
916
import org.eclipse.swt.widgets.Text;
1017
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
18+
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
19+
import org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup;
1120
import org.jbehave.eclipse.Activator;
1221

13-
/**
14-
* The "New" wizard page allows setting the container for the new file as well
15-
* as the file name. The page will only accept file name without the extension
16-
* OR with the extension that matches the expected one (mpe).
17-
*/
18-
1922
public class NewStoryWizardPage extends WizardNewFileCreationPage {
20-
private Text containerText;
21-
22-
private Text fileText;
2323

24-
private ISelection selection;
25-
26-
/**
27-
* Constructor for SampleNewWizardPage.
28-
*
29-
* @param pageName
30-
*/
3124
public NewStoryWizardPage(IStructuredSelection selection) {
32-
super(Messages.NewStoryWizardPage_0, selection);
33-
setTitle(Messages.NewStoryWizardPage_1);
34-
setDescription(Messages.NewStoryWizardPage_2);
35-
setFileExtension(Messages.NewStoryWizardPage_3);
25+
super(WizardsMessages.NewStoryWizardPage_0, selection);
26+
setTitle(WizardsMessages.NewStoryWizardPage_1);
27+
setDescription(WizardsMessages.NewStoryWizardPage_2);
28+
setFileExtension(WizardsMessages.NewStoryWizardPage_3);
29+
setFileName(WizardsMessages.NewStoryWizardPage_5);
3630
}
3731

3832
@Override
3933
protected InputStream getInitialContents() {
40-
41-
try {
42-
return Activator.getDefault().getBundle().getEntry(Messages.NewStoryWizardPage_4).openStream();
43-
} catch (IOException e) {
44-
return null;
45-
}
34+
35+
try {
36+
return Activator.getDefault().getBundle()
37+
.getEntry(WizardsMessages.NewStoryWizardPage_4).openStream();
38+
} catch (IOException e) {
39+
return null;
40+
}
4641
}
4742
}

org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/Messages.java renamed to org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/WizardsMessages.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
import org.eclipse.osgi.util.NLS;
44

5-
public class Messages extends NLS {
6-
private static final String BUNDLE_NAME = "org.jbehave.eclipse.wizards.messages"; //$NON-NLS-1$
5+
public class WizardsMessages extends NLS {
6+
private static final String BUNDLE_NAME = "org.jbehave.eclipse.wizards.wizardsMessages"; //$NON-NLS-1$
77
public static String NewStoryWizard_0;
88
public static String NewStoryWizardPage_0;
99
public static String NewStoryWizardPage_1;
1010
public static String NewStoryWizardPage_2;
1111
public static String NewStoryWizardPage_3;
1212
public static String NewStoryWizardPage_4;
13+
public static String NewStoryWizardPage_5;
1314
static {
1415
// initialize resource bundle
15-
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
16+
NLS.initializeMessages(BUNDLE_NAME, WizardsMessages.class);
1617
}
1718

18-
private Messages() {
19+
private WizardsMessages() {
1920
}
2021
}

org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/messages.properties renamed to org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/wizardsMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ NewStoryWizardPage_1=Story file
44
NewStoryWizardPage_2=This wizard creates a new story file.
55
NewStoryWizardPage_3=story
66
NewStoryWizardPage_4=/resources/newStoryFile.contents
7+
NewStoryWizardPage_5=NewStoryFile

0 commit comments

Comments
 (0)