Skip to content

Commit

Permalink
Added controller and menu support for opening preferences in support of
Browse files Browse the repository at this point in the history
  • Loading branch information
mrg committed Apr 9, 2016
1 parent bb7ae1e commit 7eed645
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/apache/cayenne/modeler/CayenneModeler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.cayenne.di.Module;
import org.apache.cayenne.modeler.di.CayenneModelerModule;
import org.apache.cayenne.modeler.layout.MainWindowLayout;
import org.apache.cayenne.modeler.layout.PreferencesLayout;
import org.apache.cayenne.modeler.layout.SplashLayout;
import org.apache.cayenne.modeler.model.CayenneModel;
import org.apache.cayenne.project.CayenneProjectModule;
Expand Down Expand Up @@ -66,6 +67,8 @@ public void start(Stage primaryStage) throws Exception

// Create and display the Splash layout with recent document list.
splashLayout = new SplashLayout(primaryStage);

splashLayout.show();
}

public static void openProject(String path) throws Exception
Expand All @@ -78,11 +81,22 @@ public static void openProject(String path) throws Exception
MainWindowLayout mainWindow = new MainWindowLayout(new Stage());

mainWindow.displayCayenneModel(cayenneModel);
mainWindow.show();

// For grins, this creates a second editor window:
// new MainWindowLayout(new Stage()).displayCayenneModel(cayenneModel);
}

private static PreferencesLayout preferencesLayout;

public static void openPreferences() throws Exception
{
if (preferencesLayout == null)
preferencesLayout = new PreferencesLayout(new Stage());

preferencesLayout.show();
}

/**
* Initializes the root layout.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.modeler.CayenneModeler;
import org.apache.cayenne.modeler.model.CayenneModel;
import org.apache.cayenne.modeler.model.CayenneTreeViewModel;
import org.apache.cayenne.modeler.model.DataDomainTreeViewModel;
Expand Down Expand Up @@ -92,7 +93,7 @@ public MainWindowLayout(Stage stage) throws IOException
stage.setScene(scene);
stage.setMinWidth(900);
stage.setMinHeight(700);
stage.show();
// stage.show();
}

public CayenneModel getCayenneModel()
Expand Down Expand Up @@ -330,6 +331,11 @@ private void loadComponents()
}
}

public void openPreferences() throws Exception
{
System.out.println("opening prefs");
CayenneModeler.openPreferences();
}

public boolean isDirty()
{
Expand All @@ -341,5 +347,13 @@ public void setDirty(boolean dirty)
this.dirty = dirty;
}

public void show()
{
stage.show();
}

public void hide()
{
stage.hide();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*****************************************************************
* 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 javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class PreferencesLayout extends VBox
{
private Stage stage;

public PreferencesLayout(Stage stage) throws IOException
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/layouts/PreferencesLayout.fxml"));

this.stage = stage;

fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
fxmlLoader.load();

Scene splashScene = new Scene(this);

stage.setScene(splashScene);
}

public void initialize()
{
stage.initStyle(StageStyle.DECORATED);
stage.setResizable(false);
}

public void show()
{
stage.show();
}

public void hide()
{
stage.hide();
}
}
14 changes: 12 additions & 2 deletions src/main/java/org/apache/cayenne/modeler/layout/SplashLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public SplashLayout(Stage initialStage) throws IOException
Scene splashScene = new Scene(this);

initialStage.setScene(splashScene);
initialStage.show();
// initialStage.show();
}

// public Stage getWindow()
Expand Down Expand Up @@ -121,12 +121,22 @@ private void openSelectedModel()
try
{
CayenneModeler.openProject(projectListView.getSelectionModel().getSelectedItem());
initialStage.hide();
hide();
}
catch (Exception exception)
{
// TODO Auto-generated catch block
exception.printStackTrace();
}
}

public void show()
{
initialStage.show();
}

public void hide()
{
initialStage.hide();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/layouts/MainWindowLayout.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<MenuItem mnemonicParsing="false" text="Save As…" />
<MenuItem mnemonicParsing="false" text="Revert" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Preferences…" />
<MenuItem mnemonicParsing="false" onAction="#openPreferences" text="Preferences…" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Quit" />
</items>
Expand Down

0 comments on commit 7eed645

Please sign in to comment.