Skip to content

Commit

Permalink
The gui should use the observable model
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Nov 19, 2015
1 parent f4f52e8 commit 31b8d19
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 167 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/speedment/component/UserInterfaceComponent.java
@@ -1,7 +1,23 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.component;

import com.speedment.annotation.Api;
import com.speedment.config.aspects.Child;
import com.speedment.internal.gui.config.AbstractNodeProperty;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.TreeItem;
Expand Down Expand Up @@ -39,5 +55,5 @@ default Class<UserInterfaceComponent> getComponentClass() {
*
* @return a view of the selected tree nodes
*/
ObservableList<TreeItem<Child<?>>> getCurrentSelection();
ObservableList<TreeItem<AbstractNodeProperty>> getCurrentSelection();
}
2 changes: 1 addition & 1 deletion src/main/java/com/speedment/config/Dbms.java
Expand Up @@ -190,4 +190,4 @@ default Class<Project> getParentInterfaceMainClass() {
* @return the new Schema
*/
Schema schema(Closure<?> c);
}
}
@@ -1,15 +1,28 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.internal.core.platform.component.impl;

import com.speedment.Speedment;
import com.speedment.component.UserInterfaceComponent;
import com.speedment.config.aspects.Child;
import com.speedment.internal.gui.config.AbstractNodeProperty;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.TreeItem;
import static javafx.collections.FXCollections.observableArrayList;
import static javafx.collections.FXCollections.observableArrayList;
import static javafx.collections.FXCollections.observableArrayList;
import static javafx.collections.FXCollections.observableArrayList;

/**
*
Expand All @@ -18,7 +31,7 @@
public final class UserInterfaceComponentImpl extends Apache2AbstractComponent implements UserInterfaceComponent {

private final ObservableList<Node> properties;
private final ObservableList<TreeItem<Child<?>>> currentSelection;
private final ObservableList<TreeItem<AbstractNodeProperty>> currentSelection;

public UserInterfaceComponentImpl(Speedment speedment) {
super(speedment);
Expand All @@ -32,7 +45,7 @@ public ObservableList<Node> getProperties() {
}

@Override
public ObservableList<TreeItem<Child<?>>> getCurrentSelection() {
public ObservableList<TreeItem<AbstractNodeProperty>> getCurrentSelection() {
return currentSelection;
}
}
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.internal.gui.config.view;

import com.speedment.config.Node;
Expand Down

This file was deleted.

Expand Up @@ -20,7 +20,6 @@
import com.speedment.component.UserInterfaceComponent;
import com.speedment.internal.core.code.MainGenerator;
import com.speedment.config.Project;
import com.speedment.config.aspects.Child;
import com.speedment.config.Node;
import com.speedment.event.ProjectLoaded;
import com.speedment.internal.gui.MainApp;
Expand Down Expand Up @@ -69,29 +68,18 @@
import java.time.temporal.UnsupportedTemporalTypeException;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.speedment.internal.gui.MainApp.showWebsite;
import com.speedment.internal.gui.config.AbstractNodeProperty;
import com.speedment.internal.gui.config.ProjectProperty;
import static com.speedment.internal.gui.controller.NotificationController.showNotification;
import static com.speedment.internal.gui.util.ProjectUtil.*;
import static javafx.animation.Animation.INDEFINITE;
import static javafx.animation.Interpolator.EASE_BOTH;
import static javafx.scene.control.SelectionMode.MULTIPLE;
import static javafx.util.Duration.ZERO;
import static com.speedment.util.NullUtil.requireNonNulls;
import static com.speedment.internal.gui.util.FadeAnimation.fadeIn;
import static java.util.Objects.requireNonNull;
import static javafx.application.Platform.runLater;
import static javafx.util.Duration.millis;
import static com.speedment.util.NullUtil.requireNonNulls;
import static com.speedment.internal.gui.util.FadeAnimation.fadeIn;
import static java.util.Objects.requireNonNull;
import static javafx.util.Duration.millis;
import static com.speedment.util.NullUtil.requireNonNulls;
import static com.speedment.internal.gui.util.FadeAnimation.fadeIn;
import static java.util.Objects.requireNonNull;
import static javafx.util.Duration.millis;
import static com.speedment.util.NullUtil.requireNonNulls;
import static com.speedment.internal.gui.util.FadeAnimation.fadeIn;
import static java.util.Objects.requireNonNull;
Expand All @@ -114,7 +102,7 @@ public final class SceneController implements Initializable {
@FXML private Button buttonOpen;
@FXML private Button buttonGenerate;
@FXML private ImageView logo;
@FXML private TreeView<Child<?>> treeHierarchy;
@FXML private TreeView<AbstractNodeProperty> treeHierarchy;
@FXML private VBox propertiesContainer;
@FXML private WebView output;
@FXML private MenuItem mbNew;
Expand All @@ -130,7 +118,7 @@ public final class SceneController implements Initializable {

private final Speedment speedment;
private final Stage stage;
private Project project;
private ProjectProperty project;
private File savedFile;
private TablePropertyManager propertyMgr;

Expand All @@ -157,7 +145,7 @@ private SceneController(Speedment speedment, Stage stage, Project project) {
private SceneController(Speedment speedment, Stage stage, Project project, File savedFile) {
this.speedment = requireNonNull(speedment);
this.stage = requireNonNull(stage);
this.project = requireNonNull(project);
this.project = new ProjectProperty(speedment, requireNonNull(project));
this.savedFile = savedFile; // Nullable
}

Expand Down Expand Up @@ -211,9 +199,11 @@ public void initialize(URL url, ResourceBundle rb) {
final EventHandler<ActionEvent> openProject = createOpenProjectHandler(
speedment, stage, (f, p) -> {

final ProjectProperty projProp = new ProjectProperty(speedment, p);

savedFile = f;
treeHierarchy.setRoot(branch(p));
project = p;
treeHierarchy.setRoot(branch(projProp));
project = projProp;
writeToLog("Opened config file: " + savedFile);
});

Expand Down Expand Up @@ -347,7 +337,7 @@ public SceneController setLastSaved(File savedFile) {
*
* @param project the project to display
*/
private void populateTree(Project project) {
private void populateTree(ProjectProperty project) {
requireNonNull(project);

speedment.getEventComponent().notify(new ProjectLoaded(project));
Expand All @@ -363,10 +353,10 @@ private void populateTree(Project project) {
// };

treeHierarchy.setCellFactory(v -> {
final TreeCell<Child<?>> cell = new TreeCell<Child<?>>() {
final TreeCell<AbstractNodeProperty> cell = new TreeCell<AbstractNodeProperty>() {

@Override
protected void updateItem(Child<?> item, boolean empty) {
protected void updateItem(AbstractNodeProperty item, boolean empty) {
// item nullable
super.updateItem(item, requireNonNull(empty));

Expand Down Expand Up @@ -413,9 +403,9 @@ private ImageView iconFor(Node node) {
* @param node the node
* @return the created branch
*/
private TreeItem<Child<?>> branch(Child<?> node) {
private TreeItem<AbstractNodeProperty> branch(AbstractNodeProperty node) {
requireNonNull(node);
final TreeItem<Child<?>> branch = new TreeItem<>(node);
final TreeItem<AbstractNodeProperty> branch = new TreeItem<>(node);

branch.setExpanded(node.isExpanded());
branch.expandedProperty().set(node.isExpanded());
Expand All @@ -425,7 +415,9 @@ private TreeItem<Child<?>> branch(Child<?> node) {
});

node.asParent().ifPresent(p ->
p.stream().map(this::branch).forEachOrdered(
p.stream()
.map(n -> (AbstractNodeProperty) n)
.map(this::branch).forEachOrdered(
branch.getChildren()::add
)
);
Expand Down
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.internal.gui.controller.handle;

import com.speedment.config.Node;
Expand Down

0 comments on commit 31b8d19

Please sign in to comment.