Skip to content

Commit

Permalink
Add company name as project attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Feb 26, 2016
1 parent c44deb8 commit d614082
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 61 deletions.
59 changes: 25 additions & 34 deletions src/main/java/com/speedment/config/db/Project.java
Expand Up @@ -25,6 +25,7 @@
import com.speedment.config.db.trait.HasName;
import com.speedment.internal.core.config.db.mutator.DocumentMutator;
import com.speedment.internal.core.config.db.mutator.ProjectMutator;
import com.speedment.internal.util.JavaLanguageNamer;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
Expand All @@ -45,26 +46,40 @@ public interface Project extends
HasMutator<ProjectMutator> {

final String
PACKAGE_NAME = "packageName",
COMPANY_NAME = "companyName",
PACKAGE_NAME = "packageName",
PACKAGE_LOCATION = "packageLocation",
CONFIG_PATH = "configPath",
DBMSES = "dbmses";
CONFIG_PATH = "configPath",
DBMSES = "dbmses";

final String
DEFAULT_PACKAGE_NAME = "com.speedment.example",
DEFAULT_COMPANY_NAME = "company",
DEFAULT_PACKAGE_NAME = "com.",
DEFAULT_PACKAGE_LOCATION = "src/main/java/",
DEFAULT_PROJECT_NAME = Project.class.getSimpleName();
DEFAULT_PROJECT_NAME = Project.class.getSimpleName();


/**
* Returns the name of the company that should be used in generated code.
*
* @return the name of the company generating code
*/
default String getCompanyName() {
return getAsString(COMPANY_NAME).orElse(DEFAULT_COMPANY_NAME);
}

/**
* Returns the name of the generated package where this project will be
* located.
*
* @return the name of the generated package
* @return the name of the generated package or {@code empty}
*/
default String getPackageName() {
return getAsString(PACKAGE_NAME).orElse(DEFAULT_PACKAGE_NAME);
default Optional<String> getPackageName() {
return getAsString(PACKAGE_NAME);
}

default String findPackageName(JavaLanguageNamer namer) {
return getPackageName()
.orElseGet(() -> DEFAULT_PACKAGE_NAME + namer.javaPackageName(getCompanyName()));
}

/**
Expand Down Expand Up @@ -94,27 +109,6 @@ default Optional<Path> getConfigPath() {
*/
Stream<? extends Dbms> dbmses();

// /**
// * Return a {@link Stream} of all dbmses that exists in this Project.
// *
// * @return a {@link Stream} of all dbmses that exists in this Project
// */
// default Stream<? extends Dbms> dbmses() {
// return children(DBMSES, dbmsConstructor());
// }
//
// /**
// * Creates and adds a new {@link Dbms} as a child to this node in the
// * configuration tree.
// *
// * @return the newly added child
// */
// default Dbms addNewDbms() {
// return dbmsConstructor().apply(this, newDocument(this, DBMSES));
// }
//
// BiFunction<Project, Map<String, Object>, ? extends Dbms> dbmsConstructor();

@Override
default Class<Project> mainInterface() {
return Project.class;
Expand Down Expand Up @@ -142,8 +136,6 @@ default ProjectMutator mutator() {
* @param fullName the full name of the table
* @return the table found
*/


default Table findTableByName(String fullName) {

final String[] parts = SPLIT_PATTERN.split(fullName);
Expand Down Expand Up @@ -171,5 +163,4 @@ default Table findTableByName(String fullName) {
.orElseThrow(() -> new IllegalArgumentException(
"Could not find table: '" + tableName + "'."));
}

}
}
Expand Up @@ -169,24 +169,24 @@ public File get() {
protected abstract String getJavadocRepresentText();

protected Javadoc getJavaDoc() {
final String owner, message;

if (isInGeneratedPackage()) {
final String owner = getSpeedment().getUserInterfaceComponent().getBrand().title();
return Javadoc.of(
getJavadocRepresentText() +
" representing an entity (for example, a row) in the " +
getDocument().mainInterface().getSimpleName() +
" " + relativeName(getDocument(), Project.class) +
"." + GENERATED_JAVADOC_MESSAGE
).add(AUTHOR.setValue(owner));
owner = getSpeedment().getUserInterfaceComponent().getBrand().title();
message = GENERATED_JAVADOC_MESSAGE;
} else {
return Javadoc.of(
getJavadocRepresentText() +
" representing an entity (for example, a row) in the " +
getDocument().mainInterface().getSimpleName() +
" " + relativeName(getDocument(), Project.class) +
"." + JAVADOC_MESSAGE
).add(AUTHOR.setValue("Your Name")); // TODO: Enter name automatically?
owner = getSpeedment().getProjectComponent().getProject().getCompanyName();
message = JAVADOC_MESSAGE;

}

return Javadoc.of(
getJavadocRepresentText() +
" representing an entity (for example, a row) in the " +
getDocument().mainInterface().getSimpleName() +
" " + relativeName(getDocument(), Project.class) +
"." + message
).add(AUTHOR.setValue(owner));
}

@Override
Expand Down
Expand Up @@ -263,7 +263,7 @@ default String fullyQualifiedTypeName(String subPath, String filePrefix) {
* @return the base package name in lowercase.
*/
default String basePackageName() {
final String packName = projectOrThrow().getPackageName().toLowerCase() + ".";
final String packName = projectOrThrow().findPackageName(javaLanguageNamer()) + ".";
if (getDocument() instanceof Project) {
return packName + javaLanguageNamer().javaPackageName(projectOrThrow().getName());
} else {
Expand Down
Expand Up @@ -78,7 +78,7 @@ public static Type getEntityType(Table table, JavaLanguageNamer javaLanguageName
requireNonNull(javaLanguageNamer);
final Project project = ancestor(table, Project.class).get();

return Type.of(project.getPackageName().toLowerCase() + DOT
return Type.of(project.findPackageName(javaLanguageNamer) + DOT
+ relativeName(table, Project.class, javaLanguageNamer::javaPackageName) + DOT
+ javaLanguageNamer.javaTypeName(table.getJavaName())
);
Expand Down
Expand Up @@ -22,14 +22,12 @@
import com.speedment.internal.core.config.db.ProjectImpl;
import com.speedment.internal.util.document.DocumentDbUtil;
import com.speedment.internal.util.document.DocumentUtil;
import static com.speedment.internal.util.document.DocumentUtil.toStringHelper;
import com.speedment.stream.MapStream;
import java.nio.file.Path;
import static java.util.Collections.unmodifiableList;
import java.util.List;
import java.util.Optional;
import java.util.Map;
import java.util.function.BiFunction;
import static java.util.stream.Collectors.toList;
import java.util.stream.Stream;

Expand All @@ -41,7 +39,8 @@ public final class ImmutableProject extends ImmutableDocument implements Project

private final transient boolean enabled;
private final transient String name;
private final transient String packageName;
private final transient String companyName;
private final transient Optional<String> packageName;
private final transient String packageLocation;
private final transient Optional<Path> configPath;

Expand All @@ -55,8 +54,9 @@ public final class ImmutableProject extends ImmutableDocument implements Project

this.enabled = prototype.isEnabled();
this.name = prototype.getName();
this.companyName = prototype.getCompanyName();
this.packageName = prototype.getPackageName();
this.packageLocation = prototype.getPackageName();
this.packageLocation = prototype.getPackageLocation();
this.configPath = prototype.getConfigPath();

this.dbmses = unmodifiableList(super.children(DBMSES, ImmutableDbms::new).collect(toList()));
Expand All @@ -78,7 +78,12 @@ public String getName() {
}

@Override
public String getPackageName() {
public String getCompanyName() {
return companyName;
}

@Override
public Optional<String> getPackageName() {
return packageName;
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.speedment.internal.core.config.db.mutator;

import com.speedment.config.db.*;
import static com.speedment.config.db.Project.COMPANY_NAME;
import static com.speedment.config.db.Project.CONFIG_PATH;
import static com.speedment.config.db.Project.DBMSES;
import static com.speedment.config.db.Project.PACKAGE_LOCATION;
Expand All @@ -39,6 +40,10 @@ public ProjectMutator(DOC project) {
super(project);
}

public void setCompanyName(String companyName) {
put(COMPANY_NAME, companyName);
}

public void setPackageName(String packageName) {
put(PACKAGE_NAME, packageName);
}
Expand Down
Expand Up @@ -36,6 +36,7 @@
import java.util.Optional;
import java.util.stream.Stream;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
Expand Down Expand Up @@ -64,13 +65,29 @@ public String getName() throws SpeedmentException {
.orElse(DEFAULT_PROJECT_NAME);
}

public StringProperty companyNameProperty() {
return stringPropertyOf(COMPANY_NAME, Project.super::getCompanyName);
}

@Override
public String getCompanyName() {
return getAsString(COMPANY_NAME).orElse(DEFAULT_COMPANY_NAME);
}

public StringProperty packageNameProperty() {
return stringPropertyOf(PACKAGE_NAME, Project.super::getPackageName);
return stringPropertyOf(PACKAGE_NAME, () -> Project.super.getPackageName().orElse(null));
}

@Override
public String getPackageName() {
return packageNameProperty().get();
public Optional<String> getPackageName() {
return Optional.ofNullable(packageNameProperty().get());
}

public StringBinding defaultPackageNameProperty() {
return Bindings.createStringBinding(
() -> Project.DEFAULT_PACKAGE_LOCATION + getCompanyName(),
companyNameProperty()
);
}

public StringProperty packageLocationProperty() {
Expand Down Expand Up @@ -121,9 +138,14 @@ public Stream<PropertySheet.Item> getUiVisibleProperties(Speedment speedment) {
"Project Name",
"The name that should be used for this project."
),
new StringPropertyItem(
companyNameProperty(),
"Company Name",
"The name that should be used for this project."
),
new DefaultStringPropertyItem(
packageNameProperty(),
new SimpleStringProperty(DEFAULT_PACKAGE_NAME),
defaultPackageNameProperty(),
"Package Name",
"The name of the package to place all generated files in. This should be a fully qualified java package name."
),
Expand Down
Expand Up @@ -90,7 +90,8 @@ private DefaultStringNode(StringProperty textProperty, ObservableStringValue def
this.auto = new CheckBox("Auto");
this.text = new TextField();

final boolean isAutoByDefault = textProperty.isEmpty().get();
final boolean isAutoByDefault = textProperty.isEmpty().get()
|| textProperty.get().equals(defaultValue.get());

this.enteredValue = new SimpleStringProperty(textProperty.get());
this.auto.selectedProperty().setValue(isAutoByDefault);
Expand Down

0 comments on commit d614082

Please sign in to comment.