2323import org .apache .cayenne .modeler .action .ExitAction ;
2424import org .apache .cayenne .modeler .action .OpenProjectAction ;
2525import org .apache .cayenne .modeler .dialog .validator .ValidatorDialog ;
26- import org .apache .cayenne .modeler .editor .EditorView ;
2726import org .apache .cayenne .modeler .editor .DbImportController ;
27+ import org .apache .cayenne .modeler .editor .EditorPanel ;
2828import org .apache .cayenne .modeler .init .platform .PlatformInitializer ;
2929import org .apache .cayenne .modeler .pref .ComponentGeometry ;
3030import org .apache .cayenne .modeler .pref .FSPath ;
3131import org .apache .cayenne .modeler .util .CayenneController ;
3232import org .apache .cayenne .modeler .util .FileFilters ;
33- import org .apache .cayenne .modeler .util .state .ProjectStateUtil ;
3433import org .apache .cayenne .project .Project ;
3534import org .apache .cayenne .project .validation .ProjectValidator ;
3635import org .apache .cayenne .validation .ValidationFailure ;
3736import org .apache .cayenne .validation .ValidationResult ;
3837
39- import javax .swing .WindowConstants ;
38+ import javax .swing .* ;
4039import javax .swing .filechooser .FileFilter ;
41- import java .awt .Component ;
40+ import java .awt .* ;
4241import java .awt .datatransfer .DataFlavor ;
4342import java .awt .datatransfer .Transferable ;
4443import java .awt .dnd .DropTarget ;
6059 */
6160public class CayenneModelerController extends CayenneController {
6261
63- private static final ProjectStateUtil PROJECT_STATE_UTIL = new ProjectStateUtil ();
64-
6562 private final ProjectController projectController ;
6663 private final CayenneModelerFrame frame ;
67- private EditorView editorView ;
68- private final DbImportController dbImportController ;
64+ private EditorPanel editorPanel ;
65+ private final DbImportController dbImportController ;
6966
7067 public CayenneModelerController (Application application ) {
7168 super (application );
@@ -99,21 +96,42 @@ public FSPath getLastEOModelDirectory() {
9996 return path ;
10097 }
10198
102- protected void initBindings () {
99+ private boolean processDropAction (Transferable transferable ) {
100+ List <File > fileList ;
101+ try {
102+ fileList = (List <File >) transferable .getTransferData (DataFlavor .javaFileListFlavor );
103+ } catch (Exception e ) {
104+ return false ;
105+ }
106+
107+ File transferFile = fileList .get (0 );
108+ if (transferFile .isFile ()) {
109+ FileFilter filter = FileFilters .getApplicationFilter ();
110+ if (filter .accept (transferFile )) {
111+ ActionEvent e = new ActionEvent (transferFile , ActionEvent .ACTION_PERFORMED , "OpenProject" );
112+ Application .getInstance ().getActionManager ().getAction (OpenProjectAction .class ).actionPerformed (e );
113+ return true ;
114+ }
115+ }
116+
117+ return false ;
118+ }
119+
120+ public void onStartup () {
103121 frame .setDefaultCloseOperation (WindowConstants .DO_NOTHING_ON_CLOSE );
104122
105123 frame .addWindowListener (new WindowAdapter () {
106124 @ Override
107125 public void windowClosing (WindowEvent e ) {
108- PROJECT_STATE_UTIL . saveLastState ( projectController );
126+ projectController . saveSelectionToPrefs ( );
109127 getApplication ().getActionManager ().getAction (ExitAction .class ).exit ();
110128 }
111129 });
112130
113131 // Register a hook to save the window position when quit via the app menu.
114132 // This is in Mac OSX only.
115133 if (System .getProperty ("os.name" ).startsWith ("Mac OS" )) {
116- Runnable runner = () -> PROJECT_STATE_UTIL . saveLastState ( projectController );
134+ Runnable runner = () -> projectController . saveSelectionToPrefs ( );
117135 Runtime .getRuntime ().addShutdownHook (new Thread (runner , "Window Prefs Hook" ));
118136 }
119137
@@ -128,35 +146,7 @@ public void drop(DropTargetDropEvent dtde) {
128146
129147 ComponentGeometry geometry = new ComponentGeometry (frame .getClass (), null );
130148 geometry .bind (frame , 1200 , 720 , 0 );
131- }
132-
133-
134- @ SuppressWarnings ("unchecked" )
135- private boolean processDropAction (Transferable transferable ) {
136- List <File > fileList ;
137- try {
138- fileList = (List <File >) transferable .getTransferData (DataFlavor .javaFileListFlavor );
139- } catch (Exception e ) {
140- return false ;
141- }
142149
143- if (fileList != null ) {
144- File transferFile = fileList .get (0 );
145- if (transferFile .isFile ()) {
146- FileFilter filter = FileFilters .getApplicationFilter ();
147- if (filter .accept (transferFile )) {
148- ActionEvent e = new ActionEvent (transferFile , ActionEvent .ACTION_PERFORMED , "OpenProject" );
149- Application .getInstance ().getActionManager ().getAction (OpenProjectAction .class ).actionPerformed (e );
150- return true ;
151- }
152- }
153- }
154-
155- return false ;
156- }
157-
158- public void onStartup () {
159- initBindings ();
160150 frame .setVisible (true );
161151 }
162152
@@ -172,19 +162,17 @@ public void onProjectSaved() {
172162 }
173163
174164 public void onProjectClosed () {
175- PROJECT_STATE_UTIL . saveLastState ( projectController );
165+ projectController . saveSelectionToPrefs ( );
176166
177167 // --- update view
178- frame .setView (null );
168+ frame .setEditorPanel (null );
179169
180170 // repaint is needed, since sometimes there is a
181171 // trace from menu left on the screen
182172 frame .repaint ();
183173 frame .setTitle ("" );
184174
185- projectController .setProject (null );
186-
187- projectController .reset ();
175+ projectController .projectClosed ();
188176 application .getActionManager ().projectClosed ();
189177
190178 updateStatus ("Project Closed..." );
@@ -195,12 +183,13 @@ public void onProjectClosed() {
195183 */
196184 public void onProjectOpened (Project project ) {
197185
198- projectController .setProject (project );
186+ projectController .projectOpened (project );
187+ frame .setTitle (getProjectLocationString ());
199188
200- editorView = new EditorView (projectController );
201- frame .setView ( editorView );
189+ editorPanel = new EditorPanel (projectController );
190+ frame .setEditorPanel ( editorPanel );
202191
203- projectController .projectOpened ();
192+ projectController .restoreSelectionFromPrefs ();
204193 application .getActionManager ().projectOpened ();
205194
206195 // do status update AFTER the project is actually opened...
@@ -217,10 +206,6 @@ public void onProjectOpened(Project project) {
217206 }
218207 }
219208
220- frame .setTitle (getProjectLocationString ());
221-
222- PROJECT_STATE_UTIL .fireLastState (projectController );
223-
224209 // for validation purposes combine load failures with post-load validation (not
225210 // sure if that'll cause duplicate messages?).
226211 List <ValidationFailure > allFailures = new ArrayList <>();
@@ -242,11 +227,13 @@ public void onProjectOpened(Project project) {
242227 }
243228 }
244229
245- public EditorView getEditorView () {
246- return editorView ;
230+ public EditorPanel getEditorView () {
231+ return editorPanel ;
247232 }
248233
249- /** Adds path to the list of last opened projects in preferences. */
234+ /**
235+ * Adds path to the list of last opened projects in preferences.
236+ */
250237 public void addToLastProjListAction (File file ) {
251238 Preferences prefLastProjFiles = ModelerPreferences .getLastProjFilesPref ();
252239 List <File > arr = ModelerPreferences .getLastProjFiles ();
@@ -290,7 +277,7 @@ public void updateStatus(String message) {
290277 new Thread (() -> {
291278 try {
292279 Thread .sleep (6 * 10000 );
293- } catch (InterruptedException ignore ){
280+ } catch (InterruptedException ignore ) {
294281 }
295282 if (message .equals (frame .getStatus ().getText ())) {
296283 updateStatus (null );
@@ -304,7 +291,7 @@ public DbImportController getDbImportController() {
304291 }
305292
306293 protected String getProjectLocationString () {
307- if (projectController .getProject ().getConfigurationResource () == null ) {
294+ if (projectController .getProject ().getConfigurationResource () == null ) {
308295 return "[New Project]" ;
309296 }
310297 try {
@@ -314,5 +301,4 @@ protected String getProjectLocationString() {
314301 throw new CayenneRuntimeException ("Invalid project source URL" , e );
315302 }
316303 }
317-
318304}
0 commit comments