Skip to content

Commit

Permalink
Load default groovy file location from pom.xml-file
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Dec 18, 2015
1 parent 0a83d7e commit 3ac31d6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
21 changes: 14 additions & 7 deletions src/main/java/com/speedment/internal/ui/MainApp.java
Expand Up @@ -55,21 +55,20 @@ public void start(Stage stage) throws Exception {
SPEEDMENT = SpeedmentFactory.newSpeedmentInstance();
}

final UISession session = new UISession(SPEEDMENT, this, stage);
SpeedmentFont.loadAll();
Statistics.onGuiStarted();

final Parameters parameters = getParameters();
final List<String> params = parameters.getRaw();
final List<String> params = parameters.getRaw();
if (params.isEmpty()) {
final UISession session = createSession(stage, UISession.DEFAULT_GROOVY_LOCATION);

if (EmailUtil.hasEmail()) {
ConnectController.createAndShow(session);
} else {
MailPromptController.createAndShow(session);
}
} else {
final String filename = params.get(0).trim().replace("\\", "/");
final File file = new File(filename);
final String filename = params.get(0).trim().replace("\\", "/");
final UISession session = createSession(stage, filename);
final File file = new File(filename);
session.loadGroovyFile(file, USE_EXISTING_STAGE);
}
}
Expand All @@ -80,4 +79,12 @@ public void start(Stage stage) throws Exception {
public static void main(String[] args) {
launch(args);
}

private UISession createSession(Stage stage, String groovyLocation) {
final UISession session = new UISession(SPEEDMENT, this, stage, groovyLocation);
SpeedmentFont.loadAll();
Statistics.onGuiStarted();

return session;
}
}
34 changes: 18 additions & 16 deletions src/main/java/com/speedment/internal/ui/UISession.java
Expand Up @@ -59,6 +59,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import static com.speedment.internal.util.TextUtil.alignRight;
import java.nio.file.Paths;
import static java.util.Objects.requireNonNull;
import javafx.application.Platform;
import javafx.geometry.Insets;
Expand All @@ -76,8 +77,8 @@
* @author Emil Forslund
*/
public final class UISession {
public final static File DEFAULT_GROOVY_LOCATION = new File("src/main/groovy/speedment.groovy");

public final static String DEFAULT_GROOVY_LOCATION = "src/main/groovy/speedment.groovy";

public enum ReuseStage {
USE_EXISTING_STAGE,
Expand Down Expand Up @@ -105,24 +106,25 @@ public enum ReuseStage {
private final Speedment speedment;
private final Application application;
private final Stage stage;
private final String defaultGroovyLocation;
private final ProjectProperty project;
private final PropertySheetFactory propertySheetFactory;

private File currentlyOpenFile = null;

public UISession(Speedment speedment, Application application, Stage stage) {
this(speedment, application, stage, new ProjectProperty(speedment));
public UISession(Speedment speedment, Application application, Stage stage, String defaultGroovyLocation) {
this(speedment, application, stage, defaultGroovyLocation, new ProjectProperty(speedment));
}

public UISession(Speedment speedment, Application application, Stage stage, Project project) {
public UISession(Speedment speedment, Application application, Stage stage, String defaultGroovyLocation, Project project) {
requireNonNull(project);

this.speedment = requireNonNull(speedment);
this.application = requireNonNull(application);
this.stage = requireNonNull(stage);
this.project = new ProjectProperty(speedment, project);

this.propertySheetFactory = new PropertySheetFactory();
this.speedment = requireNonNull(speedment);
this.application = requireNonNull(application);
this.stage = requireNonNull(stage);
this.defaultGroovyLocation = requireNonNull(defaultGroovyLocation);
this.project = new ProjectProperty(speedment, project);
this.propertySheetFactory = new PropertySheetFactory();
}

public Speedment getSpeedment() {
Expand Down Expand Up @@ -151,7 +153,7 @@ public <T extends Event, E extends EventHandler<T>> E newProject() {
try {
final Stage newStage = new Stage();
final Speedment newSpeedment = speedment.newInstance();
final UISession session = new UISession(newSpeedment, application, newStage);
final UISession session = new UISession(newSpeedment, application, newStage, defaultGroovyLocation);

ConnectController.createAndShow(session);
} catch (Exception e) {
Expand Down Expand Up @@ -247,7 +249,7 @@ public <T extends Event, E extends EventHandler<T>> E generate() {
clearLog();

if (currentlyOpenFile == null) {
currentlyOpenFile = DEFAULT_GROOVY_LOCATION;
currentlyOpenFile = new File(defaultGroovyLocation);
}

saveGroovyFile(currentlyOpenFile);
Expand Down Expand Up @@ -415,7 +417,7 @@ public void loadGroovyFile(File file, ReuseStage reuse) {
case CREATE_A_NEW_STAGE :
final Stage newStage = new Stage();
final Speedment newSpeedment = speedment.newInstance();
final UISession session = new UISession(newSpeedment, application, newStage, p);
final UISession session = new UISession(newSpeedment, application, newStage, defaultGroovyLocation, p);
SceneController.createAndShow(session);
break;

Expand Down Expand Up @@ -453,7 +455,7 @@ private void saveGroovyFile() {
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Groovy files (*.groovy)", "*.groovy"));

if (currentlyOpenFile == null) {
final Path path = DEFAULT_GROOVY_LOCATION.toPath();
final Path path = Paths.get(defaultGroovyLocation);
final Path parent = path.getParent();

try {
Expand All @@ -466,7 +468,7 @@ private void saveGroovyFile() {
*/}

fileChooser.setInitialDirectory(parent.toFile());
fileChooser.setInitialFileName(DEFAULT_GROOVY_LOCATION.getName());
fileChooser.setInitialFileName(defaultGroovyLocation);
} else {
fileChooser.setInitialDirectory(currentlyOpenFile.getParentFile());
fileChooser.setInitialFileName(currentlyOpenFile.getName());
Expand Down

0 comments on commit 3ac31d6

Please sign in to comment.