Skip to content
Permalink
Browse files
Just starting to add some data synchronization.
  • Loading branch information
mrg committed Apr 27, 2016
1 parent ae63b44 commit 055809b0e3b7680391563401143ab0459c22e39c
Showing 10 changed files with 168 additions and 11 deletions.
@@ -40,6 +40,8 @@ From the top-level project, where the `pom.xml` file is located:

The [FontAwesomeFX](https://bitbucket.org/Jerady/fontawesomefx) library is used to provide icons from [FontAwesome](https://fortawesome.github.io/Font-Awesome/).

The [JFXtras Labs](http://jfxtras.org/) library is used for data synchronization.

## License

[Apache Software Foundation](http://www.apache.org/licenses/LICENSE-2.0)
@@ -30,6 +30,7 @@
<properties>
<cayenne.version>4.0.M3</cayenne.version>
<fontawesomefx.version>8.9</fontawesomefx.version>
<jfxtras.version>8.0-r4</jfxtras.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

@@ -83,5 +84,10 @@
<artifactId>fontawesomefx</artifactId>
<version>${fontawesomefx.version}</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>${jfxtras.version}</version>
</dependency>
</dependencies>
</project>
@@ -83,8 +83,12 @@ public static void openProject(String path) throws Exception
mainWindow.displayCayenneModel(cayenneModel);
mainWindow.show();

// For grins, this creates a second editor window:
// new MainWindowLayout().displayCayenneModel(cayenneModel);
// For testing data sync across windows, this creates a second editor window:
MainWindowLayout mainWindow2 = new MainWindowLayout();

mainWindow2.displayCayenneModel(cayenneModel);
mainWindow2.show();

}

private static PreferencesLayout preferencesLayout;
@@ -20,15 +20,31 @@
package org.apache.cayenne.modeler.layout;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.cayenne.modeler.model.CayenneModel;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import jfxtras.labs.scene.control.BeanPathAdapter;

// org.apache.cayenne.modeler.controller.DataDomainViewController
public class DataDomainLayout extends AnchorPane implements MainWindowSupport
public class DataDomainLayout extends AnchorPane implements DetailEditorSupport, MainWindowSupport
{
private MainWindowLayout mainWindow;

private static Map<CayenneModel, BeanPathAdapter<CayenneModel>> dataDomainPropertyAdapterMap = new HashMap<CayenneModel, BeanPathAdapter<CayenneModel>>();

@FXML
private TextField dataDomainNameTextField;

@FXML
private CheckBox objectValidationCheckBox;

public DataDomainLayout(MainWindowLayout mainWindow) throws IOException
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/layouts/DataDomainLayout.fxml"));
@@ -50,4 +66,41 @@ public MainWindowLayout getMainWindow()
{
return mainWindow;
}

@Override
public void beginEditing()
{
System.out.println("begin editing");

BeanPathAdapter<CayenneModel> dataDomainAdapter = getDataDomainPropertyAdapterMap(getMainWindow().getCayenneModel());

dataDomainAdapter.bindBidirectional("dataDomainName", dataDomainNameTextField.textProperty());
dataDomainAdapter.bindBidirectional("dataDomainValidatingObjects", objectValidationCheckBox.selectedProperty());
}

@Override
public void endEditing()
{
BeanPathAdapter<CayenneModel> dataDomainAdapter = getDataDomainPropertyAdapterMap(getMainWindow().getCayenneModel());

dataDomainAdapter.unBindBidirectional("dataDomainName", dataDomainNameTextField.textProperty());
dataDomainAdapter.unBindBidirectional("dataDomainValidatingObjects", objectValidationCheckBox.selectedProperty());
}

private BeanPathAdapter<CayenneModel> getDataDomainPropertyAdapterMap(CayenneModel cayenneModel)
{
BeanPathAdapter<CayenneModel> dataDomainAdapter = dataDomainPropertyAdapterMap.get(cayenneModel);

if (dataDomainAdapter == null)
{
dataDomainAdapter = new BeanPathAdapter<CayenneModel>(getMainWindow().getCayenneModel());

dataDomainAdapter.fieldPathValueProperty().addListener((observable, oldValue, newValue) ->
System.out.println("Observable: " + observable + ", oldValue: " + oldValue + ", newValue: " + newValue));

dataDomainPropertyAdapterMap.put(cayenneModel, dataDomainAdapter);
}

return dataDomainAdapter;
}
}
@@ -0,0 +1,9 @@
package org.apache.cayenne.modeler.layout;

public interface DetailEditorSupport
{
void beginEditing();
void endEditing();

// void windowWillClose();
}
@@ -180,7 +180,7 @@ private void configureMainToolbar()
private void addDataDomain(CayenneModel model)
{
TreeItem<CayenneTreeViewModel> dataDomainBranch =
TreeViewUtilities.addNode(new TreeItem<>(new DataDomainTreeViewModel(model.getDataDomainName())),
TreeViewUtilities.addNode(new TreeItem<>(new DataDomainTreeViewModel(model.getDataDomain().getName())),
treeRoot,
FontAwesomeIcon.DATABASE);

@@ -220,9 +220,10 @@ private void addDbEntity(DbEntity dbEntity, TreeItem<CayenneTreeViewModel> dataM
// TreeItem<String> dbEntityLeaf = TreeViewUtilities.addNode(dbEntity.getName(), dataMapBranch, FontAwesomeIcon.TABLE);
}


private void displayDataDomain(DataDomainTreeViewModel domain)
{
System.out.println("data domain!!!");
System.out.println("data domain!!! " + domain);
displayDetailView(dataDomainDetail);
}

@@ -256,6 +257,7 @@ public void onNewButtonClicked()

private void displayDetailView(Node detailView)
{
// TODO: Call endEditing() on children here.
detailAnchorPane.getChildren().removeAll(detailAnchorPane.getChildren());

// Make the detail view fill the pane.
@@ -265,6 +267,9 @@ private void displayDetailView(Node detailView)
AnchorPane.setBottomAnchor(detailView, 0.0);

detailAnchorPane.getChildren().add(detailView);

if (detailView instanceof DetailEditorSupport)
((DetailEditorSupport) detailView).beginEditing();
}

// private void displayDetailView(BaseView detailView)
@@ -28,13 +28,16 @@
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.AnchorPane;

public class ObjectEntityClassTabLayout extends AnchorPane implements MainWindowSupport
{
@FXML
private Button dbEntitySyncButton;

@FXML
private CheckBox abstractClassCheckbox;

private MainWindowSupport parent;

@@ -60,9 +63,13 @@ public void initialize()
dbEntitySyncButton.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.REFRESH, "16px"));
}

public void display(ObjEntity objEntity)
private ObjEntity objectEntity;
public void display(ObjEntity objectEntity)
{
System.out.println("trying to display: " + objEntity);
this.objectEntity = objectEntity;
System.out.println("trying to display: " + objectEntity);

// abstractClassCheckbox.selectedProperty().bind(objectEntity.isAbstract());
}

@Override
@@ -23,7 +23,9 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Map;

import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.configuration.DataChannelDescriptor;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.modeler.CayenneModeler;
@@ -35,6 +37,7 @@
import org.apache.cayenne.project.upgrade.UpgradeType;
import org.apache.cayenne.resource.Resource;
import org.apache.cayenne.resource.URLResource;
import org.apache.cayenne.util.Util;

public class CayenneModel
{
@@ -106,13 +109,82 @@ private Project openProjectResourse(Resource resource)
return project;
}

public DataChannelDescriptor getDataDomain()
{
return root;
}

public String getDataDomainName()
{
return root.getName();
}

public boolean isDataDomainValidatingObjects()
{
return getDomainBooleanProperty(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY,
Boolean.toString(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_DEFAULT));
}

public void setDataDomainValidatingObjects(boolean validatingObjects)
{
String value = validatingObjects ? "true" : "false";

setDomainProperty(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY,
value,
Boolean.toString(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_DEFAULT));
}

public void setDataDomainName(String name)
{
root.setName(name);
}
public Collection<DataMap> getDataMaps()
{
return root.getDataMaps();
}

/**
* Helper method that updates domain properties. If a value equals to
* default, null value is used instead.
*/
protected void setDomainProperty(String property, String value, String defaultValue)
{
if (getDataDomain() == null)
return;

// no empty strings
if ("".equals(value))
value = null;

// use NULL for defaults
if (value != null && value.equals(defaultValue))
value = null;

Map<String, String> properties = getDataDomain().getProperties();

Object oldValue = properties.get(property);

if (!Util.nullSafeEquals(value, oldValue))
{
properties.put(property, value);

// DomainEvent e = new DomainEvent(this, domain);
// projectController.fireDomainEvent(e);
}
}

public String getDomainProperty(String property, String defaultValue)
{
if (getDataDomain() == null)
return null;

String value = getDataDomain().getProperties().get(property);
return value != null ? value : defaultValue;
}

public boolean getDomainBooleanProperty(String property, String defaultValue)
{
return "true".equalsIgnoreCase(getDomainProperty(property, defaultValue));
}

}
@@ -48,8 +48,8 @@
</rowConstraints>
<children>
<Label alignment="CENTER_RIGHT" text="Name: " />
<TextField maxWidth="-Infinity" minWidth="-Infinity" prefWidth="200.0" GridPane.columnIndex="1" />
<CheckBox mnemonicParsing="false" text="Object Validation" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="dataDomainNameTextField" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="200.0" GridPane.columnIndex="1" />
<CheckBox fx:id="objectValidationCheckBox" mnemonicParsing="false" text="Object Validation" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<CheckBox mnemonicParsing="false" text="Container-Managed Transactions" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
@@ -6,7 +6,6 @@
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="512.0" prefWidth="759.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox layoutX="10.0" layoutY="10.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
@@ -45,7 +44,7 @@
<Label alignment="CENTER_RIGHT" text="Class Name: " GridPane.rowIndex="3" />
<TextField maxWidth="-Infinity" minWidth="-Infinity" prefWidth="360.0" promptText="ClassName" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Inheritance: " GridPane.rowIndex="5" />
<CheckBox mnemonicParsing="false" text="Abstract Class" GridPane.columnIndex="1" />
<CheckBox fx:id="abstractClassCheckbox" mnemonicParsing="false" text="Abstract Class" GridPane.columnIndex="1" />
<ComboBox prefWidth="360.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label text="Mapped to Database Table/View: " GridPane.rowIndex="4" />
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4">

0 comments on commit 055809b

Please sign in to comment.