cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject [20/50] cayenne-modeler git commit: Refactored the window/view layout mechanics to be more consistent and not redundant.
Date Thu, 05 Jan 2017 22:09:28 GMT
Refactored the window/view layout mechanics to be more consistent and not redundant.


Project: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/commit/2602dccd
Tree: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/tree/2602dccd
Diff: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/diff/2602dccd

Branch: refs/heads/master
Commit: 2602dccddf6585f4df049519cd688de249388b2c
Parents: c14d2ef
Author: mrg <blacknext@gmail.com>
Authored: Sat Oct 1 17:48:43 2016 -0400
Committer: mrg <blacknext@gmail.com>
Committed: Sat Oct 1 17:48:43 2016 -0400

----------------------------------------------------------------------
 .../modeler/layout/AbstractViewLayout.java      | 48 ++---------
 .../modeler/layout/AbstractWindowLayout.java    | 26 +++---
 .../layout/DataNodeConfigurationTabLayout.java  |  4 +-
 .../DataNodeDatabaseAdapterTabLayout.java       | 10 +--
 .../cayenne/modeler/layout/DataNodeLayout.java  |  2 +-
 .../DataNodePasswordEncoderTabLayout.java       |  4 +-
 .../layout/DatabaseEntityColumnsTabLayout.java  |  6 +-
 .../modeler/layout/DatabaseEntityLayout.java    |  2 +-
 .../cayenne/modeler/layout/LayoutSupport.java   | 84 ++++++++++++++++++++
 .../modeler/layout/MainToolBarLayout.java       |  4 +-
 .../modeler/layout/MainWindowLayout.java        | 30 ++-----
 .../layout/ObjectEntityAttributesTabLayout.java |  4 +-
 .../layout/ObjectEntityClassTabLayout.java      |  4 +-
 .../modeler/layout/ObjectEntityLayout.java      |  2 +-
 14 files changed, 135 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/AbstractViewLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/AbstractViewLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/AbstractViewLayout.java
index 6a03c01..de2c4c7 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/AbstractViewLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/AbstractViewLayout.java
@@ -24,51 +24,29 @@ import java.io.IOException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Node;
 import javafx.scene.layout.AnchorPane;
 
-public abstract class AbstractViewLayout extends AnchorPane implements MainWindowSupport
+public abstract class AbstractViewLayout
+    extends AnchorPane
+    implements LayoutSupport, MainWindowSupport
 {
     private static final Log LOGGER = LogFactory.getLog(AbstractViewLayout.class);
 
 //    private MainWindowLayout  mainWindow;
     private final MainWindowSupport parentComponent;
 
-    protected AbstractViewLayout(final MainWindowSupport parentComponent, final String layout)
throws IOException
+    protected AbstractViewLayout(final MainWindowSupport parentComponent, final String fxmlPath)
throws IOException
     {
-        final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(layout));
-
+        // Note: This assignment must precede the FXML load.
         this.parentComponent = parentComponent;
 
-        fxmlLoader.setRoot(this);
-        fxmlLoader.setController(this);
-        fxmlLoader.load();
-    }
-
-    public void initialize()
-    {
-        LOGGER.info("init " + this.getClass().getCanonicalName());
-
-        loadSubViews();
-    }
-
-    protected void loadSubViews()
-    {
-        // Override in subclasses to load in any necessary sub-views.
+        loadFXML(fxmlPath);
     }
 
+    @Deprecated // TODO: This can likely go away.
     protected void loadTab(final AnchorPane source, final AnchorPane destination)
     {
-        destination.getChildren().removeAll(destination.getChildren());
-
-        // Make the detail view fill the pane.
-        AnchorPane.setTopAnchor(source, 0.0);
-        AnchorPane.setLeftAnchor(source, 0.0);
-        AnchorPane.setRightAnchor(source, 0.0);
-        AnchorPane.setBottomAnchor(source, 0.0);
-
-        destination.getChildren().add(source);
+        displayView(source, destination);
     }
 
     @Override
@@ -81,14 +59,4 @@ public abstract class AbstractViewLayout extends AnchorPane implements
MainWindo
     {
         return parentComponent;
     }
-
-    public void disable(Node node)
-    {
-        node.setDisable(true);
-    }
-
-    public void enable(Node node)
-    {
-        node.setDisable(false);
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/AbstractWindowLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/AbstractWindowLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/AbstractWindowLayout.java
index 5813a57..2d8d9bb 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/AbstractWindowLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/AbstractWindowLayout.java
@@ -21,26 +21,28 @@ package org.apache.cayenne.modeler.layout;
 
 import java.io.IOException;
 
-import javafx.fxml.FXMLLoader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import javafx.scene.Scene;
 import javafx.scene.layout.AnchorPane;
 import javafx.stage.Stage;
 import javafx.stage.StageStyle;
 
-public abstract class AbstractWindowLayout extends AnchorPane
+public abstract class AbstractWindowLayout
+    extends AnchorPane
+    implements LayoutSupport
 {
+    private static final Log LOGGER = LogFactory.getLog(AbstractWindowLayout.class);
+
     private final Stage stage;
 
-    public AbstractWindowLayout(Stage stage, String fxmlPath) throws IOException
+    public AbstractWindowLayout(final Stage stage, final String fxmlPath) throws IOException
     {
-        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxmlPath));
+        loadFXML(fxmlPath);
 
         this.stage = stage;
 
-        fxmlLoader.setRoot(this);
-        fxmlLoader.setController(this);
-        fxmlLoader.load();
-
         stage.setScene(new Scene(this));
     }
 
@@ -49,23 +51,23 @@ public abstract class AbstractWindowLayout extends AnchorPane
         return stage;
     }
 
-    public void initializeStyle(StageStyle stageStyle)
+    public void initializeStyle(final StageStyle stageStyle)
     {
         stage.initStyle(stageStyle);
     }
 
-    public void setMinimumWindowSize(int width, int height)
+    public void setMinimumWindowSize(final int width, final int height)
     {
         stage.setMinWidth(900);
         stage.setMinHeight(700);
     }
 
-    public void setResizable(boolean resizable)
+    public void setResizable(final boolean resizable)
     {
         stage.setResizable(resizable);
     }
 
-    public void setTitle(String title)
+    public void setTitle(final String title)
     {
         stage.setTitle(title);
     }

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/DataNodeConfigurationTabLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/DataNodeConfigurationTabLayout.java
b/src/main/java/org/apache/cayenne/modeler/layout/DataNodeConfigurationTabLayout.java
index 0c91b53..c0d2d60 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/DataNodeConfigurationTabLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/DataNodeConfigurationTabLayout.java
@@ -109,9 +109,9 @@ public class DataNodeConfigurationTabLayout
     }
 
     @Override
-    public void initialize()
+    public void initializeLayout()
     {
-        super.initialize();
+        super.initializeLayout();
 
         configureDevelopmentDataSourceButton.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.COGS,
"16px"));
         configureDevelopmentDataSourceButton.setText("");

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/DataNodeDatabaseAdapterTabLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/DataNodeDatabaseAdapterTabLayout.java
b/src/main/java/org/apache/cayenne/modeler/layout/DataNodeDatabaseAdapterTabLayout.java
index 76c5430..26adafb 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/DataNodeDatabaseAdapterTabLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/DataNodeDatabaseAdapterTabLayout.java
@@ -41,11 +41,11 @@ public class DataNodeDatabaseAdapterTabLayout
         super(parentComponent.getMainWindow(), "/layouts/DataNodeDatabaseAdapterTabLayout.fxml");
     }
 
-    @Override
-    public void initialize()
-    {
-        super.initialize();
-    }
+//    @Override
+//    public void initializeView()
+//    {
+//        super.initializeView();
+//    }
 
     public void tabChanged(final Event event)
     {

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/DataNodeLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/DataNodeLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/DataNodeLayout.java
index b554a5c..5544f33 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/DataNodeLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/DataNodeLayout.java
@@ -59,7 +59,7 @@ public class DataNodeLayout
     }
 
     @Override
-    protected void loadSubViews()
+    public void loadChildLayouts()
     {
         try
         {

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/DataNodePasswordEncoderTabLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/DataNodePasswordEncoderTabLayout.java
b/src/main/java/org/apache/cayenne/modeler/layout/DataNodePasswordEncoderTabLayout.java
index 89877ec..ef7c44c 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/DataNodePasswordEncoderTabLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/DataNodePasswordEncoderTabLayout.java
@@ -68,9 +68,9 @@ public class DataNodePasswordEncoderTabLayout
     }
 
     @Override
-    public void initialize()
+    public void initializeLayout()
     {
-        super.initialize();
+        super.initializeLayout();
 
         passwordEncoderComboBox.getItems().add(passwordEncoderPlainTextSetting);
         passwordEncoderComboBox.getItems().add(passwordEncoderRot13Setting);

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityColumnsTabLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityColumnsTabLayout.java
b/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityColumnsTabLayout.java
index b7b274e..f7b1f23 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityColumnsTabLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityColumnsTabLayout.java
@@ -80,7 +80,7 @@ public class DatabaseEntityColumnsTabLayout
     private static ObservableList javaTypes = FXCollections.observableArrayList(ObjectEntityUtilities.getRegisteredTypeNames());
 
     @Override
-    public void initialize()
+    public void initializeLayout()
     {
 //        getScene().getWindow().getScene();
 //        getStage().getScene().getWindow().get
@@ -89,7 +89,7 @@ public class DatabaseEntityColumnsTabLayout
 //
 //        loadComponents();
 
-        super.initialize();
+        super.initializeLayout();
 
         primaryKeyColumn.setText(null);
         mandatoryColumn.setText(null);
@@ -131,7 +131,7 @@ public class DatabaseEntityColumnsTabLayout
     }
 
     @Override
-    protected void loadSubViews()
+    public void loadChildLayouts()
     {
         try
         {

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityLayout.java
index 20bc48e..2908d40 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/DatabaseEntityLayout.java
@@ -53,7 +53,7 @@ public class DatabaseEntityLayout
     }
 
     @Override
-    protected void loadSubViews()
+    public void loadChildLayouts()
     {
         try
         {

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/LayoutSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/LayoutSupport.java b/src/main/java/org/apache/cayenne/modeler/layout/LayoutSupport.java
new file mode 100644
index 0000000..4eec5c5
--- /dev/null
+++ b/src/main/java/org/apache/cayenne/modeler/layout/LayoutSupport.java
@@ -0,0 +1,84 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.cayenne.modeler.layout;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Node;
+import javafx.scene.layout.AnchorPane;
+
+public interface LayoutSupport
+{
+    static final Log LOGGER = LogFactory.getLog(LayoutSupport.class);
+
+    default FXMLLoader loadFXML(final String fxmlPath) throws IOException
+    {
+        final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxmlPath));
+
+        fxmlLoader.setRoot(this);
+        fxmlLoader.setController(this);
+        fxmlLoader.load();
+
+        initializeLayout();
+
+        return fxmlLoader;
+    }
+
+    default void initializeLayout()
+    {
+        LOGGER.info("init " + this.getClass().getCanonicalName());
+
+        loadChildLayouts();
+    }
+
+    default void loadChildLayouts()
+    {
+        // Override in subclasses to load in any necessary child layouts.
+    }
+
+    default void displayView(final AnchorPane anchorPane, final Node view)
+    {
+        // Remove anything already there.
+        anchorPane.getChildren().removeAll(anchorPane.getChildren());
+
+        // Make the view fill the anchor pane.
+        AnchorPane.setTopAnchor(view, 0.0);
+        AnchorPane.setLeftAnchor(view, 0.0);
+        AnchorPane.setRightAnchor(view, 0.0);
+        AnchorPane.setBottomAnchor(view, 0.0);
+
+        // Add the view into the anchor pane.
+        anchorPane.getChildren().add(view);
+    }
+
+    default void disable(final Node node)
+    {
+        node.setDisable(true);
+    }
+
+    default void enable(final Node node)
+    {
+        node.setDisable(false);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/MainToolBarLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/MainToolBarLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/MainToolBarLayout.java
index f212b1d..5c3f746 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/MainToolBarLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/MainToolBarLayout.java
@@ -58,9 +58,9 @@ public class MainToolBarLayout
     }
 
     @Override
-    public void initialize()
+    public void initializeLayout()
     {
-        super.initialize();
+        super.initializeLayout();
 
         setToolBarValues();
     }

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/MainWindowLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/MainWindowLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/MainWindowLayout.java
index 4c5f3fe..6670712 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/MainWindowLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/MainWindowLayout.java
@@ -173,12 +173,12 @@ public class MainWindowLayout
         addDataDomain();
     }
 
-    public void initialize()
-    {
-//        configureMainToolbar();
-
-        loadComponents();
-    }
+//    public void initialize()
+//    {
+////        configureMainToolbar();
+//
+//        loadComponents();
+//    }
 
 //    private boolean toolbarNeedsInitialization = true;
 
@@ -286,20 +286,6 @@ public class MainWindowLayout
         databaseEntityDetail.beginEditing();
     }
 
-    private void displayView(final AnchorPane anchorPane, final Node view)
-    {
-        // Remove anything already there.
-        anchorPane.getChildren().removeAll(anchorPane.getChildren());
-
-        // Make the view fill the anchor pane.
-        AnchorPane.setTopAnchor(view, 0.0);
-        AnchorPane.setLeftAnchor(view, 0.0);
-        AnchorPane.setRightAnchor(view, 0.0);
-        AnchorPane.setBottomAnchor(view, 0.0);
-
-        // Add the view inot the anchor pane.
-        anchorPane.getChildren().add(view);
-    }
     private void displayDetailView(final Node detailView)
     {
         displayView(detailAnchorPane, detailView);
@@ -321,8 +307,8 @@ public class MainWindowLayout
 
     private MainToolBarLayout mainToolBarLayout;
 
-    // FIXME: Shouldn't this be loadSubViews to be consistent?
-    private void loadComponents()
+    @Override
+    public void loadChildLayouts()
     {
         try
         {

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityAttributesTabLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityAttributesTabLayout.java
b/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityAttributesTabLayout.java
index d391c55..84b6242 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityAttributesTabLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityAttributesTabLayout.java
@@ -121,9 +121,9 @@ public class ObjectEntityAttributesTabLayout
 //    private Button cutButton, copyButton, pasteButton;
 
     @Override
-    public void initialize()
+    public void initializeLayout()
     {
-        super.initialize();
+        super.initializeLayout();
 
         newAttributeButton.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.PLUS, "16px"));
         newAttributeButton.setText(null);

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityClassTabLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityClassTabLayout.java
b/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityClassTabLayout.java
index 23f7301..e1896e4 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityClassTabLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityClassTabLayout.java
@@ -54,9 +54,9 @@ public class ObjectEntityClassTabLayout
 
 
     @Override
-    public void initialize()
+    public void initializeLayout()
     {
-        super.initialize();
+        super.initializeLayout();
 
         synchronizeWithDatabaseEntityButton.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.REFRESH,
"16px"));
         synchronizeWithDatabaseEntityButton.setText(null);

http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/2602dccd/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityLayout.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityLayout.java
index dd62187..e557898 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/ObjectEntityLayout.java
@@ -52,7 +52,7 @@ public class ObjectEntityLayout
     }
 
     @Override
-    protected void loadSubViews()
+    public void loadChildLayouts()
     {
         try
         {


Mime
View raw message