[openrtm-commit:00491] r226 - in trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder: . nl ui/editors util

openrtm @ openrtm.org openrtm @ openrtm.org
2011年 12月 18日 (日) 01:11:24 JST


Author: sakamoto
Date: 2011-12-18 01:11:24 +0900 (Sun, 18 Dec 2011)
New Revision: 226

Added:
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/ShutdownListener.java
Modified:
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/RtcBuilderPlugin.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/RtcBuilderEditor.java
Log:
Modified Exit Procedure #2242

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/RtcBuilderPlugin.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/RtcBuilderPlugin.java	2011-12-17 16:10:59 UTC (rev 225)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/RtcBuilderPlugin.java	2011-12-17 16:11:24 UTC (rev 226)
@@ -7,6 +7,9 @@
 import java.util.logging.LogManager;
 import java.util.logging.Logger;
 
+import jp.go.aist.rtm.rtcbuilder.util.ShutdownListener;
+
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -30,6 +33,9 @@
 	private ImportExtensionLoader importExtensionLoader;
 	private ExportExtensionLoader exportExtensionLoader;
 	
+	//終了時フラグ
+	private boolean canExit;
+	
 	/**
 	 * The constructor
 	 */
@@ -42,6 +48,7 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
+		canExit = true;
 	}
 
 	/*
@@ -50,6 +57,7 @@
 	 */
 	public void start(BundleContext context) throws Exception {
 		logHandler.start();
+		PlatformUI.getWorkbench().addWorkbenchListener(new ShutdownListener());
 		//
 		super.start(context);
 		loader = new ExtensionLoader();
@@ -141,4 +149,10 @@
 		}
 	}
 
+	public boolean isCanExit() {
+		return canExit;
+	}
+	public void setCanExit(boolean canExit) {
+		this.canExit = canExit;
+	}
 }

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties	2011-12-17 16:10:59 UTC (rev 225)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties	2011-12-17 16:11:24 UTC (rev 226)
@@ -422,6 +422,8 @@
 
 IMessageConstants.SELECT_DIRECTORY=Select Output directory
 
+IMessageConstants.SAVE_MESSAGE=Current project has been modified. Save changes?
+
 IRTCBMessageConstants.VALIDATE_ERROR_OUTPUTPROJECT=No OutputProject is specified.
 IRTCBMessageConstants.VALIDATE_ERROR_COMPONENTNAME=No Component Name is specified.
 IRTCBMessageConstants.VALIDATE_ERROR_PORTSAMENAME=The same Port name already exists.

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java	2011-12-17 16:10:59 UTC (rev 225)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java	2011-12-17 16:11:24 UTC (rev 226)
@@ -465,4 +465,6 @@
 	public static final String PROFILE_VALIDATE_ERROR_MESSAGE = Messages.getString("IMessageConstants.PROFILE_VALIDATE_ERROR_MESSAGE"); //$NON-NLS-1$
 
 	public static final String SELECT_DIRECTORY = Messages.getString("IMessageConstants.SELECT_DIRECTORY"); //$NON-NLS-1$
+	
+	public static final String SAVE_MESSAGE = Messages.getString("IMessageConstants.SAVE_MESSAGE"); //$NON-NLS-1$
 }

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/RtcBuilderEditor.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/RtcBuilderEditor.java	2011-12-17 16:10:59 UTC (rev 225)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/RtcBuilderEditor.java	2011-12-17 16:11:24 UTC (rev 226)
@@ -373,6 +373,7 @@
 	public void doSave(IProgressMonitor monitor) {
 		boolean isRtcXml = getCurrentPage() == rtcXmlFormPage.getIndex();
 		this.allUpdates();
+		RtcBuilderPlugin.getDefault().setCanExit(true);
 
 		if (isRtcXml) {
 			try {
@@ -386,6 +387,8 @@
 					errMessage = e.getCause().toString();
 				}
 				MessageDialog.openError(getSite().getShell(), "XML Save Error", errMessage);
+				//例外発生時には処理中断
+				RtcBuilderPlugin.getDefault().setCanExit(false);
 				return;
 			}
 		}else{
@@ -399,9 +402,14 @@
 						ex.getMessage(),
     					IMessageConstants.PROFILE_VALIDATE_ERROR_MESSAGE + System.getProperty("line.separator") + ex.getCause().toString()
     				); 
-    			if( !result ) return;// 「いいえ」のときは保存しない
+    			if( !result ) {
+    				RtcBuilderPlugin.getDefault().setCanExit(false);
+    				return;// 「いいえ」のときは保存しない
+    			}
 			} catch (Exception e) {
 				MessageDialog.openError(getSite().getShell(), "XML Save Error", e.getMessage());
+				//例外発生時には処理中断
+				RtcBuilderPlugin.getDefault().setCanExit(false);
 				return;
 			}
 		}
@@ -524,7 +532,7 @@
 		return isDirty;
 	}
 
-	private void setDirty(boolean isDirty) {
+	public void setDirty(boolean isDirty) {
 		this.isDirty = isDirty;
 	}
 

Added: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/ShutdownListener.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/ShutdownListener.java	                        (rev 0)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/ShutdownListener.java	2011-12-17 16:11:24 UTC (rev 226)
@@ -0,0 +1,48 @@
+package jp.go.aist.rtm.rtcbuilder.util;
+
+import jp.go.aist.rtm.rtcbuilder.RtcBuilderPlugin;
+import jp.go.aist.rtm.rtcbuilder.ui.editors.IMessageConstants;
+import jp.go.aist.rtm.rtcbuilder.ui.editors.RtcBuilderEditor;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchListener;
+import org.eclipse.ui.internal.WorkbenchMessages;
+
+public class ShutdownListener implements IWorkbenchListener {
+	private final int RETURN_YES = 0;
+	private final int RETURN_NO = 1;
+	private final int RETURN_CANCEL = 2;
+
+	@Override
+	public void postShutdown(IWorkbench workbench) {
+	}
+
+	@Override
+	public boolean preShutdown(IWorkbench workbench, boolean forced) {
+		if( workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof RtcBuilderEditor ) {
+			RtcBuilderEditor editor = (RtcBuilderEditor)workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+			if( editor.isDirty() ) {
+				String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
+				MessageDialog dialog = new MessageDialog(workbench.getDisplay().getActiveShell(), WorkbenchMessages.Save_Resource,
+					null, IMessageConstants.SAVE_MESSAGE, MessageDialog.QUESTION, buttons, 0);
+				int result = dialog.open();
+				switch (result) {
+					case RETURN_YES:
+						editor.doSave(new NullProgressMonitor());
+						break;
+					case RETURN_NO: // no
+						editor.setDirty(false);
+						break;
+					case RETURN_CANCEL: // cancel
+						return false;
+				}
+			}
+			return RtcBuilderPlugin.getDefault().isCanExit();
+		} else {
+			return true;
+		}
+	}
+}



openrtm-commit メーリングリストの案内