cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject svn commit: r1174167 - in /cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne: ./ extentions/modeler/ launcher/
Date Thu, 22 Sep 2011 14:43:46 GMT
Author: dkazimirchyk
Date: Thu Sep 22 14:43:45 2011
New Revision: 1174167

URL: http://svn.apache.org/viewvc?rev=1174167&view=rev
Log:
CAY-1620 Cayenne Modeler Eclipse Plugin: one instance of Modeler must be running for single
Cayenne project at one time

changes that enable only one instance of Modeler to be run at one time

Modified:
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/Activator.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginApplication.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginMain.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerController.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerFrame.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/launcher/EditorLauncher.java

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/Activator.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/Activator.java?rev=1174167&r1=1174166&r2=1174167&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/Activator.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/Activator.java
Thu Sep 22 14:43:45 2011
@@ -19,6 +19,12 @@
 
 package org.apache.cayenne;
 
+import org.apache.cayenne.configuration.server.ServerModule;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.extentions.modeler.bindings.PluginModelerModule;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.project.CayenneProjectModule;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.eclipse.core.resources.IProject;
@@ -40,14 +46,15 @@ public class Activator extends AbstractU
 	 */
 	private static Activator plugin;
 	public static final String PLUGIN_ID = "org.apache.cayenne.extentions";
+	
+	protected Injector injector;
+	protected String projectName;
 
 	/**
 	 * The constructor.
 	 */
 	public Activator() {
-		super();
 		plugin = this;
-
 	}
 
 	/**
@@ -90,5 +97,23 @@ public class Activator extends AbstractU
 	public static ImageDescriptor getImageDescriptor(String path) {
 		return imageDescriptorFromPlugin(PLUGIN_ID, path);
 	}
-
-}
\ No newline at end of file
+	
+	public Injector getInjector(String projectName) {
+		if (!projectName.equals(this.projectName)) {
+			
+			if (injector != null) {
+				Application app = injector.getInstance(Application.class);
+				app.getFrameController().projectClosedAction();
+				app.getFrameController().getFrame().dispose();
+			}
+			
+			injector = DIBootstrap.createInjector(
+					new ServerModule("CayenneModeler"), 
+					new CayenneProjectModule(), 
+					new PluginModelerModule());
+			
+			this.projectName = projectName;
+		}
+		return injector;
+	}
+}

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginApplication.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginApplication.java?rev=1174167&r1=1174166&r2=1174167&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginApplication.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginApplication.java
Thu Sep 22 14:43:45 2011
@@ -48,6 +48,8 @@ import org.scopemvc.view.swing.SwingView
  */
 
 public class PluginApplication extends Application {
+	
+	protected boolean started;
 
 	/**
 	 * <code>CayenneModelerController</code> of the main application frame. In
@@ -57,12 +59,6 @@ public class PluginApplication extends A
 	 */
 
 	/**
-	 * Constructor
-	 */
-	public PluginApplication() {
-	}
-
-	/**
 	 * Returns Action Manager of PlugingApplication object in the form of
 	 * <code>ActionManager</code>
 	 * 
@@ -95,6 +91,10 @@ public class PluginApplication extends A
 	 */
 	@Override
 	public void startup() {
+		if (started) {
+			return;
+		}
+		
 		initPreferences();
 		initClassLoader();
 		this.bindingFactory = new BindingFactory();
@@ -110,7 +110,8 @@ public class PluginApplication extends A
 		// open up
 		frameController.startupAction();
 		LogConsole.getInstance().showConsoleIfNeeded();
-		getFrame().setVisible(true);
+		getFrameController().getFrame().setVisible(true);
+		started = true;
 	}
 
 	final class ModelerContext extends SwingContext {
@@ -177,5 +178,17 @@ public class PluginApplication extends A
 			return frame;
 		}
 	}
+	
+	public boolean isStarted() {
+		return started;
+	}
+	
+	public void setStarted(boolean started) {
+		this.started = started;
+	}
+	
+	public void toFront() {
+		getFrameController().getFrame().toFront();
+	}
 
 }
\ No newline at end of file

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginMain.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginMain.java?rev=1174167&r1=1174166&r2=1174167&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginMain.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginMain.java
Thu Sep 22 14:43:45 2011
@@ -20,21 +20,15 @@
 package org.apache.cayenne.extentions.modeler;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
 
 import javax.swing.SwingUtilities;
 
-import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.Activator;
 import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.di.Module;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.Main;
 import org.apache.cayenne.modeler.action.OpenProjectAction;
 import org.apache.cayenne.modeler.init.platform.PlatformInitializer;
-import org.apache.cayenne.project.CayenneProjectModule;
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.extentions.modeler.bindings.PluginModelerModule;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -61,9 +55,9 @@ public class PluginMain extends Main {
 	/**
 	 * Main method that starts the CayenneModeler.
 	 */
-	public static void main(String[] args) {
+	public void start() {
 		try {
-			new PluginMain(args).launch();
+			launch();
 		} catch (Exception e) {
 			e.printStackTrace();
 			System.exit(1);
@@ -75,12 +69,13 @@ public class PluginMain extends Main {
 	 */
 	@Override
 	protected void launch() {
-		final Injector injector = DIBootstrap
-				.createInjector(appendModules(new ArrayList<Module>()));
 		logger.info("Starting CayenneModeler.");
 		logger.info("JRE v." + System.getProperty("java.version") + " at "
 				+ System.getProperty("java.home"));
+		
+		final File project = initialProjectFromArgs();
 
+		final Injector injector = Activator.getDefault().getInjector(project.getPath());
 		// init look and feel before starting any Swing classes...
 		injector.getInstance(PlatformInitializer.class).initLookAndFeel();
 
@@ -90,35 +85,18 @@ public class PluginMain extends Main {
 				PluginApplication application = (PluginApplication) injector
 						.getInstance(Application.class);
 				PluginApplication.setInstance(application);
-				application.startup();
 
-				// start initial project AFTER the app startup, as we need
-				// Application
-				// preferences to be bootstrapped.
-
-				File project = initialProjectFromArgs();
-				if (project == null) {
-					project = initialProjectFromPreferences();
-				}
-
-				if (project != null) {
-					new OpenProjectAction(application).openProject(project);
+				if (application.isStarted()) {
+					application.toFront();
+				} else {
+					application.startup();
+
+					if (project != null) {
+						new OpenProjectAction(application).openProject(project);
+					}
 				}
 			}
 		});
 
 	}
-
-	/**
-	 * PlugingModlerModule is added to bind Cayanne modeler Eclipse Integration
-	 * implementations.
-	 */
-	@Override
-	protected Collection<Module> appendModules(Collection<Module> modules) {
-		modules.add(new ServerModule("CayenneModeler"));
-		modules.add(new CayenneProjectModule());
-		modules.add(new PluginModelerModule());
-
-		return modules;
-	}
 }
\ No newline at end of file

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerController.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerController.java?rev=1174167&r1=1174166&r2=1174167&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerController.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerController.java
Thu Sep 22 14:43:45 2011
@@ -77,7 +77,9 @@ public class PluginModelerController ext
 		// since super class constructor is setting application we need to set
 		// it here
 		this.application = application;
-		this.frame = new PluginModelerFrame(application.getActionManager());
+		this.frame = new PluginModelerFrame(
+				application.getActionManager(),
+				application.getInjector());
 
 		application.getInjector().getInstance(PlatformInitializer.class)
 				.setupMenus(frame);
@@ -113,7 +115,7 @@ public class PluginModelerController ext
 				try {
 					generator.execute();
 					JOptionPane.showMessageDialog(this.getView(),
-							"Java Classes are Sucessfuly Updated ");
+							"Java Classes are Successfully Updated ");
 				} catch (Exception e) {
 					JOptionPane.showMessageDialog(this.getView(),
 							"Error generating classes - " + e.getMessage());
@@ -232,4 +234,4 @@ public class PluginModelerController ext
 			ValidatorDialog.showDialog(frame, validationResult.getFailures());
 		}
 	}
-}
\ No newline at end of file
+}

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerFrame.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerFrame.java?rev=1174167&r1=1174166&r2=1174167&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerFrame.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extentions/modeler/PluginModelerFrame.java
Thu Sep 22 14:43:45 2011
@@ -28,10 +28,12 @@ import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 
+import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.extentions.modeler.action.PluginExitAction;
 import org.apache.cayenne.extentions.modeler.action.PluginProjectAction;
 
 import org.apache.cayenne.modeler.action.ActionManager;
+import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.CayenneModelerFrame;
 import org.apache.cayenne.modeler.action.AboutAction;
 import org.apache.cayenne.modeler.action.ConfigurePreferencesAction;
@@ -66,7 +68,6 @@ import org.apache.cayenne.modeler.action
 import org.apache.cayenne.modeler.action.UndoAction;
 import org.apache.cayenne.modeler.action.ValidateAction;
 import org.apache.cayenne.modeler.dialog.LogConsole;
-import org.apache.cayenne.modeler.util.RecentFileMenu;
 
 /**
  * A <code>PluginModelerFrame</code> is a subclass of
@@ -74,6 +75,8 @@ import org.apache.cayenne.modeler.util.R
  * <code>CayenneModeler</code> Eclipse Integration.
  */
 public class PluginModelerFrame extends CayenneModelerFrame {
+	
+	protected Injector injector;
 
 	/**
 	 * Constructor of <code>PluginModelerFrame</code>
@@ -82,8 +85,10 @@ public class PluginModelerFrame extends 
 	 *            ActionManager which Stores a map of modeler actions, and deals
 	 *            with those actions
 	 */
-	public PluginModelerFrame(ActionManager actionManager) {
+	public PluginModelerFrame(ActionManager actionManager, Injector injector) {
 		super(actionManager);
+		
+		this.injector = injector;
 	}
 
 	/**
@@ -190,30 +195,16 @@ public class PluginModelerFrame extends 
 	private <T extends Action> T getAction(Class<T> type) {
 
 		return actionManager.getAction(type);
-
 	}
-
+	
 	@Override
 	protected void processWindowEvent(WindowEvent e) {
 		super.processWindowEvent(e);
-
-		if (e.getID() == WindowEvent.WINDOW_CLOSING) {
-			switch (HIDE_ON_CLOSE) {
-			case HIDE_ON_CLOSE:
-				setVisible(false);
-				break;
-			case DISPOSE_ON_CLOSE:
-				dispose();
-				break;
-			case DO_NOTHING_ON_CLOSE:
-			default:
-				break;
-			case EXIT_ON_CLOSE:				
-				// noop
-				// we don't want Eclipse to exit 
-				// when Modeler's window closed
-				break;
-			}
+		
+		if (e.getID() == WindowEvent.WINDOW_CLOSED) {
+			PluginApplication app = (PluginApplication)injector.getInstance(
+					Application.class);
+			app.setStarted(false);
 		}
 	}
 
@@ -232,4 +223,4 @@ public class PluginModelerFrame extends 
 			}
 		}
 	}
-}
\ No newline at end of file
+}

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/launcher/EditorLauncher.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/launcher/EditorLauncher.java?rev=1174167&r1=1174166&r2=1174167&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/launcher/EditorLauncher.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/launcher/EditorLauncher.java
Thu Sep 22 14:43:45 2011
@@ -30,13 +30,13 @@ public class EditorLauncher implements I
 	
 	private static Log logger = LogFactory.getLog(EditorLauncher.class);
 
-	@SuppressWarnings("static-access")
 	public void open(IPath file) {
 		logger.info("Launch Successful : file Location = "
 				+ file.toString());
 
 		String[] args = new String[] { file.toString() };
-		new PluginMain(args).main(args);
+		PluginMain plugin = new PluginMain(args);
+		plugin.start();
 
 	}
 



Mime
View raw message